Skip to content

Commit 30fb700

Browse files
modulovaluedart-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
[dart2wasm] Use WasmV128 for I32x4 backing storage
Replaces the four 32-bit int fields in the wasm Int32x4 implementation (renamed NaiveInt32x4 -> I32x4) with a single WasmV128 _bits field. Operators and lane getters delegate to the existing WasmV128Extension and WasmI32x4 extension-type intrinsics. Adds a Wasm SIMD probe to the .support.js feature detection since the core lib now emits v128 instructions. Work towards #63471. TEST=ci Bug: #63471 Change-Id: Ia92b9af30808589d66d6abc3a09cdb7e94a1879d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507760 Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com> Commit-Queue: Martin Kustermann <kustermann@google.com> Reviewed-by: Michael Thomsen <mit@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
1 parent 41caa76 commit 30fb700

44 files changed

Lines changed: 240 additions & 284 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pkg/dart2wasm/lib/compile.dart‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,20 @@ String _generateSupportJs(TranslatorOptions options) {
869869
const String supportsWasmGC =
870870
'WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,95,1,120,0]))';
871871

872+
// Copied from
873+
// https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/main/src/detectors/simd/module.wat
874+
//
875+
// Uses `i8x16.popcnt` so only engines with full Wasm SIMD support validate:
876+
// ```
877+
// (module
878+
// (func (result v128)
879+
// i32.const 0
880+
// i8x16.splat
881+
// i8x16.popcnt))
882+
// ```
883+
const String supportsWasmSimd =
884+
'WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]))';
885+
872886
// Imports a `js-string` builtin spec function *with wrong signature*. An engine
873887
//
874888
// * *without* knowledge about `js-string` builtin would accept such an import at
@@ -887,6 +901,7 @@ String _generateSupportJs(TranslatorOptions options) {
887901

888902
final requiredFeatures = [
889903
supportsWasmGC,
904+
supportsWasmSimd,
890905
if (options.requireJsStringBuiltin) supportsJsStringBuiltins,
891906
];
892907
return '(${requiredFeatures.join('&&')})';

‎pkg/dart2wasm/lib/intrinsics.dart‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,42 +1814,48 @@ class Intrinsifier {
18141814
case StaticIntrinsic.wasmI32x4ConstructorFromInts:
18151815
codeGen.translateExpression(
18161816
node.arguments.positional[0],
1817-
w.NumType.i32,
1817+
w.NumType.i64,
18181818
);
1819+
b.i32_wrap_i64();
18191820
b.i32x4_splat();
18201821
for (int i = 1; i < 4; i++) {
18211822
codeGen.translateExpression(
18221823
node.arguments.positional[i],
1823-
w.NumType.i32,
1824+
w.NumType.i64,
18241825
);
1826+
b.i32_wrap_i64();
18251827
b.i32x4_replace_lane(i);
18261828
}
18271829
return w.NumType.v128;
18281830
case StaticIntrinsic.wasmI16x8ConstructorFromInts:
18291831
codeGen.translateExpression(
18301832
node.arguments.positional[0],
1831-
w.NumType.i32,
1833+
w.NumType.i64,
18321834
);
1835+
b.i32_wrap_i64();
18331836
b.i16x8_splat();
18341837
for (int i = 1; i < 8; i++) {
18351838
codeGen.translateExpression(
18361839
node.arguments.positional[i],
1837-
w.NumType.i32,
1840+
w.NumType.i64,
18381841
);
1842+
b.i32_wrap_i64();
18391843
b.i16x8_replace_lane(i);
18401844
}
18411845
return w.NumType.v128;
18421846
case StaticIntrinsic.wasmI8x16ConstructorFromInts:
18431847
codeGen.translateExpression(
18441848
node.arguments.positional[0],
1845-
w.NumType.i32,
1849+
w.NumType.i64,
18461850
);
1851+
b.i32_wrap_i64();
18471852
b.i8x16_splat();
18481853
for (int i = 1; i < 16; i++) {
18491854
codeGen.translateExpression(
18501855
node.arguments.positional[i],
1851-
w.NumType.i32,
1856+
w.NumType.i64,
18521857
);
1858+
b.i32_wrap_i64();
18531859
b.i8x16_replace_lane(i);
18541860
}
18551861
return w.NumType.v128;

‎pkg/dart2wasm/test/deferred_loading/partition_tests_dart2js/custom_split/fuse_with_and.constraints.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Part 0
55
- pkg/compiler/test/custom_split/data/fuse_with_and/lib3.dart prefix: b3
66
- pkg/compiler/test/custom_split/data/fuse_with_and/lib4.dart prefix: b4
77
References
8-
- dart:_boxed_int::BoxedInt::@methods::toRadixString
98
- dart:_string::@methods::dart:_string::_JS_Inline_173
109
- dart:_string::@methods::dart:_string::_JS_Inline_181
1110
- dart:_string::@methods::dart:_string::_jsIdentical
@@ -92,7 +91,6 @@ Part 0
9291
- StringConstant("\\x")
9392
- StringConstant("at index ")
9493
- StringConstant("equals")
95-
- StringConstant("radix")
9694

9795
Part 1
9896
ImportSet

‎pkg/dart2wasm/test/deferred_loading/partition_tests_dart2js/custom_split/fuse_with_and.default.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Part 0
55
- pkg/compiler/test/custom_split/data/fuse_with_and/lib3.dart prefix: b3
66
- pkg/compiler/test/custom_split/data/fuse_with_and/lib4.dart prefix: b4
77
References
8-
- dart:_boxed_int::BoxedInt::@methods::toRadixString
98
- dart:_string::@methods::dart:_string::_JS_Inline_173
109
- dart:_string::@methods::dart:_string::_JS_Inline_181
1110
- dart:_string::@methods::dart:_string::_jsIdentical
@@ -63,7 +62,6 @@ Part 0
6362
- StringConstant("\\x")
6463
- StringConstant("at index ")
6564
- StringConstant("equals")
66-
- StringConstant("radix")
6765

6866
Part 1
6967
ImportSet

‎pkg/dart2wasm/test/deferred_loading/partition_tests_dart2js/custom_split/fuse_with_or.constraints.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Part 0
55
- pkg/compiler/test/custom_split/data/fuse_with_or/lib3.dart prefix: b3
66
- pkg/compiler/test/custom_split/data/fuse_with_or/lib4.dart prefix: b4
77
References
8-
- dart:_boxed_int::BoxedInt::@methods::toRadixString
98
- dart:_string::@methods::dart:_string::_JS_Inline_173
109
- dart:_string::@methods::dart:_string::_JS_Inline_181
1110
- dart:_string::@methods::dart:_string::_jsIdentical
@@ -82,7 +81,6 @@ Part 0
8281
- StringConstant("\\x")
8382
- StringConstant("at index ")
8483
- StringConstant("equals")
85-
- StringConstant("radix")
8684

8785
Part 1
8886
ImportSet

‎pkg/dart2wasm/test/deferred_loading/partition_tests_dart2js/custom_split/fuse_with_or.default.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Part 0
55
- pkg/compiler/test/custom_split/data/fuse_with_or/lib3.dart prefix: b3
66
- pkg/compiler/test/custom_split/data/fuse_with_or/lib4.dart prefix: b4
77
References
8-
- dart:_boxed_int::BoxedInt::@methods::toRadixString
98
- dart:_string::@methods::dart:_string::_JS_Inline_173
109
- dart:_string::@methods::dart:_string::_JS_Inline_181
1110
- dart:_string::@methods::dart:_string::_jsIdentical
@@ -63,7 +62,6 @@ Part 0
6362
- StringConstant("\\x")
6463
- StringConstant("at index ")
6564
- StringConstant("equals")
66-
- StringConstant("radix")
6765

6866
Part 1
6967
ImportSet

‎pkg/dart2wasm/test/deferred_loading/partition_tests_dart2js/custom_split/just_fuse.constraints.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Part 0
55
- pkg/compiler/test/custom_split/data/just_fuse/lib3.dart prefix: b3
66
- pkg/compiler/test/custom_split/data/just_fuse/lib4.dart prefix: b4
77
References
8-
- dart:_boxed_int::BoxedInt::@methods::toRadixString
98
- dart:_string::@methods::dart:_string::_JS_Inline_173
109
- dart:_string::@methods::dart:_string::_JS_Inline_181
1110
- dart:_string::@methods::dart:_string::_jsIdentical
@@ -67,7 +66,6 @@ Part 0
6766
- StringConstant("\\x")
6867
- StringConstant("at index ")
6968
- StringConstant("equals")
70-
- StringConstant("radix")
7169

7270
Part 1
7371
ImportSet

‎pkg/dart2wasm/test/deferred_loading/partition_tests_dart2js/custom_split/just_fuse.default.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Part 0
55
- pkg/compiler/test/custom_split/data/just_fuse/lib3.dart prefix: b3
66
- pkg/compiler/test/custom_split/data/just_fuse/lib4.dart prefix: b4
77
References
8-
- dart:_boxed_int::BoxedInt::@methods::toRadixString
98
- dart:_string::@methods::dart:_string::_JS_Inline_173
109
- dart:_string::@methods::dart:_string::_JS_Inline_181
1110
- dart:_string::@methods::dart:_string::_jsIdentical
@@ -63,7 +62,6 @@ Part 0
6362
- StringConstant("\\x")
6463
- StringConstant("at index ")
6564
- StringConstant("equals")
66-
- StringConstant("radix")
6765

6866
Part 1
6967
ImportSet

‎pkg/dart2wasm/test/ir_tests/constant_string_ops.wat‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
(func $JSStringImpl.fromRefUnchecked (param $var0 externref) (result (ref $JSExternWrapper)) <...>)
99
(@binaryen.inline 0)
1010
(func $constantStringOps
11-
i32.const 99
11+
i32.const 101
1212
i64.const 3
1313
struct.new $BoxedInt
1414
call $print
15-
i32.const 99
15+
i32.const 101
1616
i64.const 102
1717
struct.new $BoxedInt
1818
call $print

‎pkg/dart2wasm/test/ir_tests/constructor.wat‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
local.get $var0
117117
local.get $onlyUsedInSuper
118118
local.set $var3
119-
i32.const 94
119+
i32.const 92
120120
local.get $var3
121121
struct.new $BoxedInt
122122
call $"new _MixinApplication1&Base&SubMixin.named (initializer)"
@@ -248,7 +248,7 @@
248248
global.get $"\", \""
249249
local.get $onlyUsedInSubBody
250250
local.set $var4
251-
i32.const 94
251+
i32.const 92
252252
local.get $var4
253253
struct.new $BoxedInt
254254
array.new_fixed $Array<Object?> 6
@@ -273,7 +273,7 @@
273273
local.get $var0
274274
local.get $onlyUsedInSuper1
275275
local.set $var3
276-
i32.const 94
276+
i32.const 92
277277
local.get $var3
278278
struct.new $BoxedInt
279279
local.get $onlyUsedInSuper2
@@ -328,7 +328,7 @@
328328
local.get $var0
329329
local.get $onlyUsedInSuper1
330330
local.set $var3
331-
i32.const 94
331+
i32.const 92
332332
local.get $var3
333333
struct.new $BoxedInt
334334
call $"new _MixinApplication1&Base&SubMixin.sub2 (initializer)"
@@ -356,7 +356,7 @@
356356
i32.const 9
357357
i32.const 0
358358
i32.const 0
359-
i32.const 167
359+
i32.const 179
360360
local.get $var0
361361
array.new_fixed $Array<_Type> 1
362362
struct.new $_InterfaceType
@@ -420,7 +420,7 @@
420420
i32.const 9
421421
i32.const 0
422422
i32.const 0
423-
i32.const 165
423+
i32.const 166
424424
local.get $var0
425425
array.new_fixed $Array<_Type> 1
426426
struct.new $_InterfaceType
@@ -449,7 +449,7 @@
449449
i32.const 9
450450
i32.const 0
451451
i32.const 0
452-
i32.const 176
452+
i32.const 188
453453
local.get $var0
454454
array.new_fixed $Array<_Type> 1
455455
struct.new $_InterfaceType
@@ -461,7 +461,7 @@
461461
(func $JSStringImpl._interpolate4 (param $value1 (ref null $#Top)) (param $value2 (ref null $#Top)) (param $value3 (ref null $#Top)) (param $value4 (ref null $#Top)) (result (ref $JSExternWrapper)) <...>)
462462
(func $SubNamed (param $var0 (ref $_Type)) (param $onlyUsedInSubField i64) (param $onlyUsedInSuper i64) (result (ref $SubNamed))
463463
(local $var1 (ref $SubNamed))
464-
i32.const 107
464+
i32.const 109
465465
i32.const 0
466466
local.get $var0
467467
local.get $onlyUsedInSubField
@@ -483,7 +483,7 @@
483483
)
484484
(func $SubOptionalNamed (param $var0 (ref $_Type)) (param $onlyUsedInSubField (ref null $BoxedInt)) (param $onlyUsedInSuper (ref null $BoxedInt)) (result (ref $SubOptionalNamed))
485485
(local $var1 (ref $SubOptionalNamed))
486-
i32.const 109
486+
i32.const 111
487487
i32.const 0
488488
local.get $var0
489489
local.get $onlyUsedInSubField
@@ -527,7 +527,7 @@
527527
local.set $var6
528528
local.set $var7
529529
local.set $var8
530-
i32.const 108
530+
i32.const 110
531531
i32.const 0
532532
local.get $var6
533533
local.get $var5
@@ -575,7 +575,7 @@
575575
local.set $var6
576576
local.set $var7
577577
local.set $var8
578-
i32.const 105
578+
i32.const 107
579579
i32.const 0
580580
local.get $var6
581581
local.get $var5
@@ -601,7 +601,7 @@
601601
)
602602
(func $SubPos2 (param $var0 (ref $_Type)) (param $onlyUsedInSubField i64) (param $onlyUsedInSuper1 i64) (result (ref $SubPos2))
603603
(local $var1 (ref $SubPos2))
604-
i32.const 106
604+
i32.const 108
605605
i32.const 0
606606
local.get $var0
607607
local.get $onlyUsedInSubField

0 commit comments

Comments
 (0)