Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit 7efcf94

Browse files
Honrytlively
authored andcommitted
[test] Add spec tests for integer rounding average ops (#171)
Optimize unknown operator test method to make it as a common method BTW Sync tests from WAVM/WAVM#250
1 parent 52c7623 commit 7efcf94

File tree

8 files changed

+340
-57
lines changed

8 files changed

+340
-57
lines changed

test/core/simd/meta/simd_f32x4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def get_unknown_operator_case(self, cases):
350350
unknown_op_cases = ['\n\n;; Unknown operators\n']
351351
cases.extend(unknown_op_cases)
352352

353-
for lane_type in ['i8x16', 'i16x8', 'i32x4']:
353+
for lane_type in ['i8x16', 'i16x8', 'i32x4', 'i64x2']:
354354

355355
for op in self.UNARY_OPS:
356356
cases.append(tpl_assert.format(lane_type=lane_type, op=op, value=self.v128_const('i32x4', '0')))

test/core/simd/meta/simd_int_arith2.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from simd import SIMD
8-
from test_assert import AssertReturn, AssertInvalid
8+
from test_assert import AssertReturn, AssertInvalid, AssertMalformed
99
from simd_lane_value import LaneValue
1010
from simd_integer_op import IntegerSimpleOp as IntOp
1111

@@ -17,7 +17,7 @@ class SimdLaneWiseInteger:
1717

1818
BINARY_OPS = ('min_s', 'min_u', 'max_s', 'max_u',)
1919

20-
class_summary = """;; Tests for {lane_type} [min_s, min_u, max_s, max_u] operations."""
20+
class_summary = """;; Tests for {lane_type} [min_s, min_u, max_s, max_u, avgr_u] operations."""
2121

2222
def __init__(self):
2323

@@ -246,21 +246,15 @@ def gen(case_data):
246246
@property
247247
def gen_test_case_unknown_operators(self):
248248
"""generate unknown operators test cases"""
249-
250-
if self.LANE_TYPE != 'i32x4':
251-
return ''
252-
253-
cases = '\n\n;; Unknown operators'
254-
lane_types = ('f32x4', 'i64x2',)
255-
assert_template = '(assert_malformed (module quote "(memory 1) (func (result v128) ({lane_type}.{op} {param_1} {param_2}))") "unknown operator")'
256-
for lane_type in lane_types:
257-
for op in self.BINARY_OPS:
258-
cases += '\n' + assert_template.format(lane_type=lane_type,
259-
op=op,
260-
param_1=SIMD.v128_const('0', self.LANE_TYPE),
261-
param_2=SIMD.v128_const('1', self.LANE_TYPE))
262-
263-
return cases
249+
cases = ['\n\n;; Unknown operators']
250+
251+
for op in self.UNKNOWN_OPS:
252+
cases.append(AssertMalformed.get_unknown_op_test(
253+
op, 'v128',
254+
SIMD.v128_const('0', self.LANE_TYPE),
255+
SIMD.v128_const('1', self.LANE_TYPE)
256+
))
257+
return '\n'.join(cases)
264258

265259
@property
266260
def gen_test_case_type_check(self):
@@ -373,15 +367,28 @@ def gen_test_cases(self):
373367

374368
class Simdi32x4Case(SimdLaneWiseInteger):
375369
LANE_TYPE = 'i32x4'
370+
class_summary = """;; Tests for {lane_type} [min_s, min_u, max_s, max_u] operations."""
371+
372+
UNKNOWN_OPS = ('f32x4.min_s', 'f32x4.min_u', 'f32x4.max_s', 'f32x4.max_u',
373+
'i64x2.min_s', 'i64x2.min_u', 'i64x2.max_s', 'i64x2.max_u',
374+
'f64x2.min_s', 'f64x2.min_u', 'f64x2.max_s', 'f64x2.max_u')
376375

377376

378377
class Simdi16x8Case(SimdLaneWiseInteger):
379378
LANE_TYPE = 'i16x8'
380379

380+
BINARY_OPS = ('min_s', 'min_u', 'max_s', 'max_u', 'avgr_u')
381+
UNKNOWN_OPS = ('i16x8.avgr', 'i16x8.avgr_s')
382+
381383

382384
class Simdi8x16Case(SimdLaneWiseInteger):
383385
LANE_TYPE = 'i8x16'
384386

387+
BINARY_OPS = ('min_s', 'min_u', 'max_s', 'max_u', 'avgr_u')
388+
UNKNOWN_OPS = ('i32x4.avgr_u', 'f32x4.avgr_u',
389+
'i64x2.avgr_u', 'f64x2.avgr_u',
390+
'i8x16.avgr', 'i8x16.avgr_s')
391+
385392

386393
def gen_test_cases():
387394
simd_i32x4_case = Simdi32x4Case()
@@ -395,4 +402,4 @@ def gen_test_cases():
395402

396403

397404
if __name__ == '__main__':
398-
gen_test_cases()
405+
gen_test_cases()

test/core/simd/meta/simd_integer_op.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from simd_lane_value import LaneValue
66

7+
78
class IntegerSimpleOp:
89
"""Common integer simple ops:
910
min_s, min_u, max_s, max_u
@@ -47,6 +48,15 @@ def binary_op(op: str, p1: str, p2: str, lane_width: int) -> str:
4748
else:
4849
return p1 if i1 >= i2 else p2
4950

51+
elif op == 'avgr_u':
52+
i1 = IntegerSimpleOp.get_valid_value(v1, lane_width, signed=False)
53+
i2 = IntegerSimpleOp.get_valid_value(v2, lane_width, signed=False)
54+
result = (i1 + i2 + 1) // 2
55+
if base1 == 16 or base2 == 16:
56+
return hex(result)
57+
else:
58+
return str(result)
59+
5060
else:
5161
raise Exception('Unknown binary operation')
5262

test/core/simd/meta/test_assert.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,14 @@ def str_with_space(input_str):
7878
}
7979

8080
return arg_empty_test.format(**param_map)
81+
82+
83+
class AssertMalformed:
84+
"""Generate an assert_malformed test"""
85+
86+
@staticmethod
87+
def get_unknown_op_test(op, result_type, *params):
88+
malformed_template = '(assert_malformed (module quote "(memory 1) (func (result {result_type}) ({operator} {param}))") "unknown operator")'
89+
return malformed_template.format(
90+
operator=op, result_type=result_type, param=' '.join(params)
91+
)

test/core/simd/simd_f32x4.wast

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,9 @@
23312331
(assert_malformed (module quote "(memory 1) (func (result v128) (i32x4.abs (v128.const i32x4 0 0 0 0)))") "unknown operator")
23322332
(assert_malformed (module quote "(memory 1) (func (result v128) (i32x4.min (v128.const i32x4 0 0 0 0) (v128.const i32x4 0 0 0 0)))") "unknown operator")
23332333
(assert_malformed (module quote "(memory 1) (func (result v128) (i32x4.max (v128.const i32x4 0 0 0 0) (v128.const i32x4 0 0 0 0)))") "unknown operator")
2334+
(assert_malformed (module quote "(memory 1) (func (result v128) (i64x2.abs (v128.const i32x4 0 0 0 0)))") "unknown operator")
2335+
(assert_malformed (module quote "(memory 1) (func (result v128) (i64x2.min (v128.const i32x4 0 0 0 0) (v128.const i32x4 0 0 0 0)))") "unknown operator")
2336+
(assert_malformed (module quote "(memory 1) (func (result v128) (i64x2.max (v128.const i32x4 0 0 0 0) (v128.const i32x4 0 0 0 0)))") "unknown operator")
23342337

23352338
;; type check
23362339
(assert_invalid (module (func (result v128) (f32x4.abs (i32.const 0)))) "type mismatch")

0 commit comments

Comments
 (0)