Skip to content

Commit 6807b39

Browse files
Add sub tests
1 parent c6f541c commit 6807b39

2 files changed

Lines changed: 105 additions & 24 deletions

File tree

src/gen-s-parser.inc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4102,12 +4102,23 @@ switch (buf[0]) {
41024102
default: goto parse_error;
41034103
}
41044104
}
4105-
case 'u':
4106-
if (op == "i64.sub"sv) {
4107-
CHECK_ERR(makeBinary(ctx, pos, annotations, BinaryOp::SubInt64));
4108-
return Ok{};
4105+
case 'u': {
4106+
switch (buf[7]) {
4107+
case '\0':
4108+
if (op == "i64.sub"sv) {
4109+
CHECK_ERR(makeBinary(ctx, pos, annotations, BinaryOp::SubInt64));
4110+
return Ok{};
4111+
}
4112+
goto parse_error;
4113+
case '1':
4114+
if (op == "i64.sub128"sv) {
4115+
CHECK_ERR(makeWideIntAddSub(ctx, pos, annotations, WideIntAddSubOp::SubInt128));
4116+
return Ok{};
4117+
}
4118+
goto parse_error;
4119+
default: goto parse_error;
41094120
}
4110-
goto parse_error;
4121+
}
41114122
default: goto parse_error;
41124123
}
41134124
}

test/spec/wide-arithmetic.wast

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
;;; --enable-wide-arithmetic
12
(module
23
(func (export "i64.add128") (param i64 i64 i64 i64) (result i64 i64)
34
local.get 0
@@ -113,6 +114,28 @@
113114
(i64.const 1) (i64.const 0))
114115
(i64.const 414720966820876429) (i64.const -1))
115116

117+
;; simple subtraction
118+
(assert_return (invoke "i64.sub128"
119+
(i64.const 0) (i64.const 0)
120+
(i64.const 0) (i64.const 0))
121+
(i64.const 0) (i64.const 0))
122+
(assert_return (invoke "i64.sub128"
123+
(i64.const 1) (i64.const 0)
124+
(i64.const 1) (i64.const 0))
125+
(i64.const 0) (i64.const 0))
126+
(assert_return (invoke "i64.sub128"
127+
(i64.const 0) (i64.const 0)
128+
(i64.const 1) (i64.const 0))
129+
(i64.const 0xffffffffffffffff) (i64.const 0xffffffffffffffff))
130+
(assert_return (invoke "i64.sub128"
131+
(i64.const 0) (i64.const 1)
132+
(i64.const 1) (i64.const 0))
133+
(i64.const 0xffffffffffffffff) (i64.const 0))
134+
(assert_return (invoke "i64.sub128"
135+
(i64.const 1) (i64.const 2)
136+
(i64.const 3) (i64.const 4))
137+
(i64.const 0xfffffffffffffffe) (i64.const 0xfffffffffffffffd))
138+
116139
;; assert overlong encodings for each instruction's binary encoding are accepted
117140
(module binary
118141
"\00asm" "\01\00\00\00"
@@ -171,24 +194,71 @@
171194
)
172195
"type mismatch")
173196

174-
;; simple subtraction
175-
(assert_return (invoke "i64.sub128"
176-
(i64.const 0) (i64.const 0)
177-
(i64.const 0) (i64.const 0))
178-
(i64.const 0) (i64.const 0))
179-
(assert_return (invoke "i64.sub128"
180-
(i64.const 1) (i64.const 0)
181-
(i64.const 1) (i64.const 0))
182-
(i64.const 0) (i64.const 0))
183-
(assert_return (invoke "i64.sub128"
184-
(i64.const 0) (i64.const 0)
185-
(i64.const 1) (i64.const 0))
186-
(i64.const 0xffffffffffffffff) (i64.const 0xffffffffffffffff))
187-
(assert_return (invoke "i64.sub128"
188-
(i64.const 0) (i64.const 1)
189-
(i64.const 1) (i64.const 0))
190-
(i64.const 0xffffffffffffffff) (i64.const 0))
191-
(assert_return (invoke "i64.sub128"
197+
(assert_invalid
198+
(module
199+
(func (param i64 i64 i64 i64) (result i64)
200+
local.get 0
201+
local.get 1
202+
local.get 2
203+
local.get 3
204+
i64.sub128)
205+
)
206+
"type mismatch")
207+
(assert_invalid
208+
(module
209+
(func (param i64 i64 i64) (result i64 i64)
210+
local.get 0
211+
local.get 1
212+
local.get 2
213+
i64.sub128)
214+
)
215+
"type mismatch")
216+
217+
(module binary
218+
"\00asm" "\01\00\00\00"
219+
220+
"\01\0a" ;; type section, 10 bytes
221+
"\01" ;; 1 count
222+
"\60" ;; type0 = function
223+
"\04\7e\7e\7e\7e" ;; 4 params - all i64
224+
"\02\7e\7e" ;; 2 results - both i64
225+
226+
"\03\03" ;; function section, 3 byte
227+
"\02" ;; 2 count
228+
"\00\00" ;; types of each function (0, 0)
229+
230+
"\07\1b" ;; export section 0x1b bytes
231+
"\02" ;; 2 count
232+
"\0ai64.add128\00\00" ;; "i64.add128" which is function 0
233+
"\0ai64.sub128\00\01" ;; "i64.sub128" which is function 1
234+
235+
"\0a\1e" ;; code section + byte length
236+
"\02" ;; 2 count
237+
238+
"\0e" ;; byte length
239+
"\00" ;; no locals
240+
"\20\00" ;; local.get 0
241+
"\20\01" ;; local.get 1
242+
"\20\02" ;; local.get 2
243+
"\20\03" ;; local.get 3
244+
"\fc\93\80\00" ;; i64.add128 (overlong)
245+
"\0b" ;; end
246+
247+
"\0d" ;; byte length
248+
"\00" ;; no locals
249+
"\20\00" ;; local.get 0
250+
"\20\01" ;; local.get 1
251+
"\20\02" ;; local.get 2
252+
"\20\03" ;; local.get 3
253+
"\fc\94\00" ;; i64.sub128 (overlong)
254+
"\0b" ;; end
255+
)
256+
257+
(assert_return (invoke "i64.add128"
192258
(i64.const 1) (i64.const 2)
193259
(i64.const 3) (i64.const 4))
194-
(i64.const 0xfffffffffffffffe) (i64.const 0xfffffffffffffffd))
260+
(i64.const 4) (i64.const 6))
261+
(assert_return (invoke "i64.sub128"
262+
(i64.const 2) (i64.const 5)
263+
(i64.const 1) (i64.const 2))
264+
(i64.const 1) (i64.const 3))

0 commit comments

Comments
 (0)