Skip to content

Commit f67e61a

Browse files
authored
Enable sign extension ops by default (AssemblyScript#1869)
BREAKING: With all major browsers now shipping them, sign extension operations are now enabled by default. To disable: `--disable sign-extension`.
1 parent 6540a2d commit f67e61a

24 files changed

+4104
-2379
lines changed

cli/asc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@
209209
"description": [
210210
"Enables WebAssembly features being disabled by default.",
211211
"",
212-
" sign-extension Sign-extension operations",
213212
" nontrapping-f2i Non-trapping float to integer ops.",
214213
" bulk-memory Bulk memory operations.",
215214
" simd SIMD types and operations.",
@@ -233,6 +232,7 @@
233232
"Disables WebAssembly features being enabled by default.",
234233
"",
235234
" mutable-globals Mutable global imports and exports.",
235+
" sign-extension Sign-extension operations",
236236
""
237237
],
238238
"type": "S",
@@ -376,7 +376,6 @@
376376
" ...": {
377377
"description": "Specifies node.js options (CLI only). See: node --help"
378378
},
379-
380379
"-Os": { "value": { "optimizeLevel": 0, "shrinkLevel": 1 } },
381380
"-Oz": { "value": { "optimizeLevel": 0, "shrinkLevel": 2 } },
382381
"-O0": { "value": { "optimizeLevel": 0, "shrinkLevel": 0 } },

src/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export class Options {
240240
/** Global aliases, mapping alias names as the key to internal names to be aliased as the value. */
241241
globalAliases: Map<string,string> | null = null;
242242
/** Features to activate by default. These are the finished proposals. */
243-
features: Feature = Feature.MUTABLE_GLOBALS;
243+
features: Feature = Feature.MUTABLE_GLOBALS | Feature.SIGN_EXTENSION;
244244
/** If true, disallows unsafe features in user code. */
245245
noUnsafe: bool = false;
246246
/** If true, enables pedantic diagnostics. */

tests/compiler/abi.untouched.wat

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@
3131
i32.const 256
3232
local.set $0
3333
local.get $0
34-
i32.const 24
35-
i32.shl
36-
i32.const 24
37-
i32.shr_s
34+
i32.extend8_s
3835
i32.eqz
3936
i32.eqz
4037
if
@@ -50,28 +47,19 @@
5047
global.get $abi/condition
5148
if
5249
local.get $0
53-
i32.const 24
54-
i32.shl
55-
i32.const 24
56-
i32.shr_s
50+
i32.extend8_s
5751
i32.const 2
5852
i32.div_s
5953
local.set $0
6054
else
6155
local.get $0
62-
i32.const 24
63-
i32.shl
64-
i32.const 24
65-
i32.shr_s
56+
i32.extend8_s
6657
i32.const 2
6758
i32.div_s
6859
local.set $0
6960
end
7061
local.get $0
71-
i32.const 24
72-
i32.shl
73-
i32.const 24
74-
i32.shr_s
62+
i32.extend8_s
7563
i32.eqz
7664
i32.eqz
7765
if
@@ -87,10 +75,7 @@
8775
global.get $abi/condition
8876
if
8977
local.get $0
90-
i32.const 24
91-
i32.shl
92-
i32.const 24
93-
i32.shr_s
78+
i32.extend8_s
9479
i32.const 24
9580
i32.const 7
9681
i32.and
@@ -103,6 +88,7 @@
10388
local.set $0
10489
end
10590
local.get $0
91+
i32.extend8_s
10692
i32.eqz
10793
i32.eqz
10894
if
@@ -114,10 +100,7 @@
114100
unreachable
115101
end
116102
i32.const 256
117-
i32.const 24
118-
i32.shl
119-
i32.const 24
120-
i32.shr_s
103+
i32.extend8_s
121104
global.set $abi/y
122105
global.get $abi/y
123106
i32.eqz
@@ -189,20 +172,15 @@
189172
)
190173
(func $abi/exported (result i32)
191174
i32.const 128
192-
i32.const 24
193-
i32.shl
194-
i32.const 24
195-
i32.shr_s
175+
i32.extend8_s
196176
)
197177
(func $abi/exportedExported (result i32)
198178
call $abi/exported
179+
i32.extend8_s
199180
)
200181
(func $abi/exportedInternal (result i32)
201182
call $abi/internal
202-
i32.const 24
203-
i32.shl
204-
i32.const 24
205-
i32.shr_s
183+
i32.extend8_s
206184
)
207185
(func $~start
208186
call $start:abi

tests/compiler/asc-constants.untouched.wat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(global $~lib/ASC_MEMORY_BASE i32 (i32.const 0))
66
(global $~lib/ASC_OPTIMIZE_LEVEL i32 (i32.const 0))
77
(global $~lib/ASC_SHRINK_LEVEL i32 (i32.const 0))
8-
(global $~lib/ASC_FEATURE_SIGN_EXTENSION i32 (i32.const 0))
8+
(global $~lib/ASC_FEATURE_SIGN_EXTENSION i32 (i32.const 1))
99
(global $~lib/ASC_FEATURE_MUTABLE_GLOBALS i32 (i32.const 1))
1010
(global $~lib/ASC_FEATURE_NONTRAPPING_F2I i32 (i32.const 0))
1111
(global $~lib/ASC_FEATURE_BULK_MEMORY i32 (i32.const 0))
@@ -36,7 +36,7 @@
3636
drop
3737
i32.const 0
3838
drop
39-
i32.const 0
39+
i32.const 1
4040
drop
4141
i32.const 1
4242
drop

tests/compiler/builtins.untouched.wat

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,10 @@
333333
(local $4 i32)
334334
(local $5 i32)
335335
local.get $0
336-
i32.const 24
337-
i32.shl
338-
i32.const 24
339-
i32.shr_s
336+
i32.extend8_s
340337
local.tee $5
341338
local.get $1
342-
i32.const 24
343-
i32.shl
344-
i32.const 24
345-
i32.shr_s
339+
i32.extend8_s
346340
local.tee $3
347341
local.get $2
348342
local.tee $4
@@ -369,26 +363,17 @@
369363
i32.and
370364
i32.shr_u
371365
i32.or
372-
i32.const 24
373-
i32.shl
374-
i32.const 24
375-
i32.shr_s
366+
i32.extend8_s
376367
)
377368
(func $builtins/rotr3 (param $0 i32) (param $1 i32) (param $2 i32) (result i32)
378369
(local $3 i32)
379370
(local $4 i32)
380371
(local $5 i32)
381372
local.get $0
382-
i32.const 24
383-
i32.shl
384-
i32.const 24
385-
i32.shr_s
373+
i32.extend8_s
386374
local.tee $5
387375
local.get $1
388-
i32.const 24
389-
i32.shl
390-
i32.const 24
391-
i32.shr_s
376+
i32.extend8_s
392377
local.tee $3
393378
local.get $2
394379
local.tee $4
@@ -415,10 +400,7 @@
415400
i32.and
416401
i32.shl
417402
i32.or
418-
i32.const 24
419-
i32.shl
420-
i32.const 24
421-
i32.shr_s
403+
i32.extend8_s
422404
)
423405
(func $builtins/test
424406
nop
@@ -556,10 +538,7 @@
556538
i32.const 1
557539
i32.const 2
558540
i32.add
559-
i32.const 24
560-
i32.shl
561-
i32.const 24
562-
i32.shr_s
541+
i32.extend8_s
563542
global.set $builtins/l
564543
global.get $builtins/l
565544
i32.const 3
@@ -576,10 +555,7 @@
576555
i32.const 2
577556
i32.const 1
578557
i32.sub
579-
i32.const 24
580-
i32.shl
581-
i32.const 24
582-
i32.shr_s
558+
i32.extend8_s
583559
global.set $builtins/l
584560
global.get $builtins/l
585561
i32.const 1
@@ -612,10 +588,7 @@
612588
i32.const 6
613589
i32.const 2
614590
i32.div_s
615-
i32.const 24
616-
i32.shl
617-
i32.const 24
618-
i32.shr_s
591+
i32.extend8_s
619592
global.set $builtins/l
620593
global.get $builtins/l
621594
i32.const 3
@@ -2058,10 +2031,7 @@
20582031
drop
20592032
global.get $~lib/builtins/i8.MIN_VALUE
20602033
i32.const 128
2061-
i32.const 24
2062-
i32.shl
2063-
i32.const 24
2064-
i32.shr_s
2034+
i32.extend8_s
20652035
i32.eq
20662036
drop
20672037
global.get $~lib/builtins/i8.MAX_VALUE
@@ -2070,10 +2040,7 @@
20702040
drop
20712041
global.get $~lib/builtins/i16.MIN_VALUE
20722042
i32.const 32768
2073-
i32.const 16
2074-
i32.shl
2075-
i32.const 16
2076-
i32.shr_s
2043+
i32.extend16_s
20772044
i32.eq
20782045
drop
20792046
global.get $~lib/builtins/i16.MAX_VALUE

tests/compiler/features/simd.untouched.wat

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,10 +1817,7 @@
18171817
end
18181818
local.get $2
18191819
i8x16.extract_lane_s 0
1820-
i32.const 24
1821-
i32.shl
1822-
i32.const 24
1823-
i32.shr_s
1820+
i32.extend8_s
18241821
i32.const 2
18251822
i32.eq
18261823
i32.eqz
@@ -1834,10 +1831,7 @@
18341831
end
18351832
local.get $2
18361833
i8x16.extract_lane_s 15
1837-
i32.const 24
1838-
i32.shl
1839-
i32.const 24
1840-
i32.shr_s
1834+
i32.extend8_s
18411835
i32.const -128
18421836
i32.eq
18431837
i32.eqz
@@ -2416,10 +2410,7 @@
24162410
end
24172411
local.get $2
24182412
i16x8.extract_lane_s 0
2419-
i32.const 16
2420-
i32.shl
2421-
i32.const 16
2422-
i32.shr_s
2413+
i32.extend16_s
24232414
i32.const 2
24242415
i32.eq
24252416
i32.eqz
@@ -2433,10 +2424,7 @@
24332424
end
24342425
local.get $2
24352426
i16x8.extract_lane_s 7
2436-
i32.const 16
2437-
i32.shl
2438-
i32.const 16
2439-
i32.shr_s
2427+
i32.extend16_s
24402428
i32.const -32768
24412429
i32.eq
24422430
i32.eqz

tests/compiler/many-locals.optimized.wat

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
)
1212
(func $many-locals/testI8 (param $0 i32) (result i32)
1313
local.get $0
14-
i32.const 24
15-
i32.shl
16-
i32.const 24
17-
i32.shr_s
14+
i32.extend8_s
1815
)
1916
)

tests/compiler/many-locals.untouched.wat

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,7 @@
787787
local.get $127
788788
local.set $128
789789
local.get $128
790-
i32.const 24
791-
i32.shl
792-
i32.const 24
793-
i32.shr_s
790+
i32.extend8_s
794791
)
795792
(func $start:many-locals
796793
i32.const 42
@@ -808,6 +805,7 @@
808805
end
809806
i32.const 42
810807
call $many-locals/testI8
808+
i32.extend8_s
811809
i32.const 42
812810
i32.eq
813811
i32.eqz

0 commit comments

Comments
 (0)