Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions test/core/simd/meta/simd_f32x4.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Simdf32x4Case(Simdf32x4ArithmeticCase):
'0x1.921fb6p+2', '-0x1.921fb6p+2', '0x1.fffffep+127', '-0x1.fffffep+127', 'inf', '-inf'
)

LITERAL_NUMBERS = (
'0123456789e019', '0123456789e-019',
'0123456789.e019', '0123456789.e+019',
'-0123456789.0123456789'
)
NAN_NUMBERS = ('nan', '-nan', 'nan:0x200000', '-nan:0x200000')
binary_params_template = ('({assert_type} (invoke "{func}" ', '{operand_1}', '{operand_2})', '{expected_result})')
unary_param_template = ('({assert_type} (invoke "{func}" ', '{operand})', '{expected_result})')
Expand Down Expand Up @@ -330,6 +335,11 @@ def get_normal_case(self):
# assert_return_canonical_nan statements
binary_test_data.append(['assert_return_canonical_nan_f32x4', op_name, p1, p2])

for p1 in self.LITERAL_NUMBERS:
for p2 in self.LITERAL_NUMBERS:
result = self.floatOp.binary_op(op, p1, p2, hex_form=False)
binary_test_data.append(['assert_return', op_name, p1, p2, result])

# assert_return_canonical_nan and assert_return_arithmetic_nan cases
for p1 in self.NAN_NUMBERS:
for p2 in self.FLOAT_NUMBERS:
Expand Down Expand Up @@ -395,9 +405,12 @@ def get_normal_case(self):
self.v128_const(case_data[3][1], case_data[1][1])],
self.v128_const(case_data[3][2], case_data[2][0]))))

for p in self.FLOAT_NUMBERS:
for p in self.FLOAT_NUMBERS + self.LITERAL_NUMBERS:
op_name = self.full_op_name('abs')
result = self.floatOp.unary_op('abs', p)
hex_literal = True
if p in self.LITERAL_NUMBERS:
hex_literal = False
result = self.floatOp.unary_op('abs', p, hex_form=hex_literal)
# Abs operation is valid for all the floating point numbers
unary_test_data.append(['assert_return', op_name, p, result])

Expand Down
19 changes: 15 additions & 4 deletions test/core/simd/meta/simd_f64x2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class Simdf64x2Case(Simdf32x4Case):
'0x0p+0', '-0x0p+0', '0x1p-1074', '-0x1p-1074', '0x1p-1022', '-0x1p-1022', '0x1p-1', '-0x1p-1', '0x1p+0', '-0x1p+0',
'0x1.921fb54442d18p+2', '-0x1.921fb54442d18p+2', '0x1.fffffffffffffp+1023', '-0x1.fffffffffffffp+1023', 'inf', '-inf'
)

LITERAL_NUMBERS = ('01234567890123456789e038', '01234567890123456789e-038',
'0123456789.e038', '0123456789.e+038',
'-01234567890123456789.01234567890123456789'
)
NAN_NUMBERS = ('nan', '-nan', 'nan:0x4000000000000', '-nan:0x4000000000000')

def gen_test_func_template(self):
Expand All @@ -28,7 +31,7 @@ def gen_test_func_template(self):
# Function template
tpl_func = ' (func (export "{func}"){params} (result v128) ({op} {operand_1}{operand_2}))'

# Raw data list specific for "const vs const" and "param vs const" tests
# Raw data list specific for "const vs const" and "param vs const" tests"
const_test_raw_data = [
[
[['0', '1'], ['0', '2']],
Expand Down Expand Up @@ -362,6 +365,11 @@ def get_normal_case(self):
else:
binary_test_data.append(['assert_return_canonical_nan_f64x2', op_name, p1, p2])

for p1 in self.LITERAL_NUMBERS:
for p2 in self.LITERAL_NUMBERS:
result = self.floatOp.binary_op(op, p1, p2, hex_form=False)
binary_test_data.append(['assert_return', op_name, p1, p2, result])

for case in binary_test_data:
cases.append(self.single_binary_test(case))

Expand Down Expand Up @@ -419,9 +427,12 @@ def get_normal_case(self):
self.v128_const(case_data[3][1], case_data[1][1])],
self.v128_const(case_data[3][2], case_data[2][0]))))

for p in self.FLOAT_NUMBERS:
for p in self.FLOAT_NUMBERS + self.LITERAL_NUMBERS:
op_name = self.full_op_name('abs')
result = self.floatOp.unary_op('abs', p)
hex_literal = True
if p in self.LITERAL_NUMBERS:
hex_literal = False
result = self.floatOp.unary_op('abs', p, hex_form=hex_literal)
# Abs operation is valid for all the floating point numbers
unary_test_data.append(['assert_return', op_name, p, result])

Expand Down
37 changes: 27 additions & 10 deletions test/core/simd/meta/simd_float_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,23 @@ def float_neg(self, p):
class FloatingPointSimpleOp(FloatingPointOp):
"""Common simple ops for both f32x4 and f64x2: abs, min, max"""

def binary_op(self, op: str, p1: str, p2: str) -> str:
def binary_op(self, op: str, p1: str, p2: str, hex_form=True) -> str:
"""Binary operation on p1 and p2 with the operation specified by op

:param op: min, max,
:param p1: float number in hex
:param p2: float number in hex
:return:
"""
f1 = float.fromhex(p1)
f2 = float.fromhex(p2)
if '0x' in p1:
f1 = float.fromhex(p1)
else:
f1 = float(p1)

if '0x' in p2:
f2 = float.fromhex(p2)
else:
f2 = float(p2)

if '-nan' in [p1, p2] and 'nan' in [p1, p2]:
return p1
Expand All @@ -160,28 +167,38 @@ def binary_op(self, op: str, p1: str, p2: str) -> str:
if op == 'min':
if '-0x0p+0' in [p1, p2] and '0x0p+0' in [p1, p2]:
return '-0x0p+0'
result = min(f1, f2)
if hex_form:
return min(f1, f2).hex()
else:
return p1 if f1 <= f2 else p2

elif op == 'max':
if '-0x0p+0' in [p1, p2] and '0x0p+0' in [p1, p2]:
return '0x0p+0'
result = max(f1, f2)
if hex_form:
return max(f1, f2).hex()
else:
return p1 if f1 > f2 else p2

else:
raise Exception('Unknown binary operation: {}'.format(op))

return result.hex()

def unary_op(self, op: str, p1: str) -> str:
def unary_op(self, op: str, p1: str, hex_form=True) -> str:
"""Unnary operation on p1 with the operation specified by op

:param op: abs,
:param p1: float number in hex
:return:
"""
f1 = float.fromhex(p1)
if '0x' in p1:
f1 = float.fromhex(p1)
else:
f1 = float(p1)
if op == 'abs':
return abs(f1).hex()
if hex_form:
return abs(f1).hex()
else:
return p1 if not p1.startswith('-') else p1[1:]

raise Exception('Unknown unary operation: {}'.format(op))

Expand Down
Loading