Skip to content

Commit 584bacf

Browse files
authored
feat: Add trueish conversion for v128 types (AssemblyScript#2135)
1 parent 3b3fe60 commit 584bacf

File tree

5 files changed

+174
-137
lines changed

5 files changed

+174
-137
lines changed

src/compiler.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3771,6 +3771,10 @@ export class Compiler extends DiagnosticEmitter {
37713771
}
37723772
}
37733773

3774+
// v128 to bool
3775+
} else if (fromType == Type.v128 && toType.isBooleanValue) {
3776+
expr = this.makeIsTrueish(expr, Type.v128, reportNode);
3777+
37743778
// int to int
37753779
} else {
37763780
// i64 to ...
@@ -10299,6 +10303,9 @@ export class Compiler extends DiagnosticEmitter {
1029910303
module.i64(0xFFFFFFFE, 0xFFDFFFFF) // (0x7FF0000000000000 - 1) << 1
1030010304
);
1030110305
}
10306+
case TypeKind.V128: {
10307+
return module.unary(UnaryOp.AnyTrueV128, expr);
10308+
}
1030210309
case TypeKind.FUNCREF:
1030310310
case TypeKind.EXTERNREF:
1030410311
case TypeKind.ANYREF:

src/flow.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ export class Flow {
939939
let key = _keys[i];
940940
let leftFlags = changetype<FieldFlags>(leftFieldFlags.get(key));
941941
if (
942-
(leftFlags & FieldFlags.INITIALIZED) != 0 && rightFieldFlags.has(key) &&
942+
(leftFlags & FieldFlags.INITIALIZED) != 0 && rightFieldFlags.has(key) &&
943943
(changetype<FieldFlags>(rightFieldFlags.get(key)) & FieldFlags.INITIALIZED)
944944
) {
945945
newFieldFlags.set(key, FieldFlags.INITIALIZED);
@@ -1396,6 +1396,7 @@ export class Flow {
13961396
case <u32>TypeRef.I64: { value = getConstValueI64Low(expr); break; } // discards upper bits
13971397
case <u32>TypeRef.F32: { value = i32(getConstValueF32(expr)); break; }
13981398
case <u32>TypeRef.F64: { value = i32(getConstValueF64(expr)); break; }
1399+
case <u32>TypeRef.V128: return false;
13991400
default: assert(false);
14001401
}
14011402
switch (type.kind) {

tests/compiler/features/simd.optimized.wat

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@
10151015
if
10161016
i32.const 0
10171017
i32.const 1184
1018-
i32.const 59
1018+
i32.const 67
10191019
i32.const 5
10201020
call $~lib/builtins/abort
10211021
unreachable
@@ -1044,7 +1044,7 @@
10441044
if
10451045
i32.const 0
10461046
i32.const 1184
1047-
i32.const 69
1047+
i32.const 77
10481048
i32.const 5
10491049
call $~lib/builtins/abort
10501050
unreachable
@@ -1073,7 +1073,7 @@
10731073
if
10741074
i32.const 0
10751075
i32.const 1184
1076-
i32.const 79
1076+
i32.const 87
10771077
i32.const 5
10781078
call $~lib/builtins/abort
10791079
unreachable
@@ -1102,7 +1102,7 @@
11021102
if
11031103
i32.const 0
11041104
i32.const 1184
1105-
i32.const 89
1105+
i32.const 97
11061106
i32.const 5
11071107
call $~lib/builtins/abort
11081108
unreachable
@@ -1131,7 +1131,7 @@
11311131
if
11321132
i32.const 0
11331133
i32.const 1184
1134-
i32.const 99
1134+
i32.const 107
11351135
i32.const 5
11361136
call $~lib/builtins/abort
11371137
unreachable
@@ -1160,7 +1160,7 @@
11601160
if
11611161
i32.const 0
11621162
i32.const 1184
1163-
i32.const 109
1163+
i32.const 117
11641164
i32.const 5
11651165
call $~lib/builtins/abort
11661166
unreachable
@@ -1169,7 +1169,7 @@
11691169
call $~lib/rt/tlsf/__free
11701170
i32.const 0
11711171
i32.const 1184
1172-
i32.const 255
1172+
i32.const 263
11731173
i32.const 3
11741174
call $~lib/builtins/abort
11751175
unreachable

tests/compiler/features/simd.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// hint: asc tests/compiler/simd --enable simd
22

33
function test_v128(): void {
4+
// check trueish
5+
// @ts-ignore
6+
assert(<bool>v128(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) == true);
7+
// @ts-ignore
8+
assert(<bool>v128(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1) == true);
9+
// @ts-ignore
10+
assert(<bool>v128(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) == false);
11+
412
// equality and inequality
513
assert(
614
v128(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)

0 commit comments

Comments
 (0)