Skip to content

Commit f39d98a

Browse files
committed
[test] Sync tests from WAVM#232
WAVM/WAVM#232 [simd] Add more literal tests for float-point comparison ops Part of WAVM/WAVM#195
1 parent f7c5db5 commit f39d98a

File tree

5 files changed

+935
-7
lines changed

5 files changed

+935
-7
lines changed

test/core/simd/meta/simd_f32x4_cmp.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
f32x4 only has 6 comparison instructions but with amounts of
99
test datas.
1010
"""
11-
11+
import struct
1212
from simd_compare import SimdCmpCase
1313

1414

@@ -337,7 +337,10 @@ def get_case_data(self):
337337
'0x1p+0', '-0x1.fffffep+127', '-0x0p+0', '-0x1p-1', '0x1.fffffep+127',
338338
'-nan', '-0x1p-149', '-0x1p-126', '0x1p-1', '-0x1.921fb6p+2',
339339
'nan:0x200000', '0x0p+0', 'inf', '-0x1p+0', '0x1p-126')
340-
340+
LITERAL_NUMBERS = (
341+
'0123456789e019', '0123456789e-019',
342+
'0123456789.e019', '0123456789.e+019',
343+
'0123456789.0123456789')
341344
Ops = ('eq', 'ne', 'lt', 'le', 'gt', 'ge')
342345

343346
# Combinations between operand1 and operand2
@@ -346,6 +349,10 @@ def get_case_data(self):
346349
for param1 in operand1:
347350
for param2 in operand2:
348351
case_data.append([op, [param1, param2], self.operate(op, param1, param2), ['f32x4', 'f32x4', 'i32x4']])
352+
353+
for param1 in LITERAL_NUMBERS:
354+
for param2 in LITERAL_NUMBERS:
355+
case_data.append([op, [param1, param2], self.operate(op, param1, param2), ['f32x4', 'f32x4', 'i32x4']])
349356
# eq
350357
case_data.append(['#', 'eq'])
351358

@@ -446,7 +453,12 @@ def special_float2dec(self, p):
446453
if p == '-inf':
447454
return -float(340282366920938463463374607431768211456)
448455

449-
return float.fromhex(p)
456+
if '0x' in p:
457+
f = float.fromhex(p)
458+
else:
459+
f = float(p)
460+
461+
return struct.unpack('f', struct.pack('f', f))[0]
450462

451463
def operate(self, op, p1, p2):
452464
for p in (p1, p2):
@@ -489,4 +501,4 @@ def gen_test_cases():
489501

490502
if __name__ == '__main__':
491503
f32x4 = Simdf32x4CmpCase()
492-
f32x4.gen_test_cases()
504+
f32x4.gen_test_cases()

test/core/simd/meta/simd_f64x2_cmp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ class Simdf64x2CmpCase(SimdArithmeticCase):
2626
'-0x1p-1074', '-0x1p-1022', '0x1p-1', '-0x1.921fb54442d18p+2',
2727
'0x0p+0', 'inf', '-0x1p+0', '0x1p-1022'
2828
)
29+
LITERAL_NUMBERS = ('01234567890123456789e038', '01234567890123456789e-038',
30+
'0123456789.e038', '0123456789.e+038',
31+
'01234567890123456789.01234567890123456789'
2932

33+
)
3034
FLOAT_NUMBERS_NORMAL = ('-1', '0', '1', '2.0')
3135

3236
NAN_NUMBERS = ('nan', '-nan', 'nan:0x4000000000000', '-nan:0x4000000000000')
@@ -219,6 +223,11 @@ def get_normal_case(self):
219223
result = self.floatOp.binary_op(op, p1, p2)
220224
binary_test_data.append(['assert_return', op_name, p1, p2, result])
221225

226+
for p1 in self.LITERAL_NUMBERS:
227+
for p2 in self.LITERAL_NUMBERS:
228+
result = self.floatOp.binary_op(op, p1, p2)
229+
binary_test_data.append(['assert_return', op_name, p1, p2, result])
230+
222231
for p1 in self.NAN_NUMBERS:
223232
for p2 in self.FLOAT_NUMBERS_SPECIAL + self.NAN_NUMBERS:
224233
result = self.floatOp.binary_op(op, p1, p2)

test/core/simd/meta/simd_float_op.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,15 @@ def binary_op(self, op: str, p1: str, p2: str) -> str:
207207
if 'nan' in p1.lower() or 'nan' in p2.lower():
208208
return '0'
209209

210-
f1 = float.fromhex(p1)
211-
f2 = float.fromhex(p2)
210+
if '0x' in p1:
211+
f1 = float.fromhex(p1)
212+
else:
213+
f1 = float(p1)
214+
215+
if '0x' in p2:
216+
f2 = float.fromhex(p2)
217+
else:
218+
f2 = float(p2)
212219

213220
if op == 'eq':
214221
return '-1' if f1 == f2 else '0'

0 commit comments

Comments
 (0)