|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +""" |
| 4 | +Generate f32x4 [ceil, floor, trunc, nearest] cases. |
| 5 | +""" |
| 6 | + |
| 7 | +from simd_f32x4_arith import Simdf32x4ArithmeticCase |
| 8 | +from simd_float_op import FloatingPointRoundingOp |
| 9 | +from simd import SIMD |
| 10 | +from test_assert import AssertReturn |
| 11 | + |
| 12 | + |
| 13 | +class Simdf32x4RoundingCase(Simdf32x4ArithmeticCase): |
| 14 | + UNARY_OPS = ('ceil', 'floor', 'trunc', 'nearest') |
| 15 | + BINARY_OPS = () |
| 16 | + floatOp = FloatingPointRoundingOp() |
| 17 | + |
| 18 | + def get_combine_cases(self): |
| 19 | + return '' |
| 20 | + |
| 21 | + def get_normal_case(self): |
| 22 | + """Normal test cases from WebAssembly core tests. |
| 23 | + """ |
| 24 | + cases = [] |
| 25 | + unary_test_data = [] |
| 26 | + |
| 27 | + for op in self.UNARY_OPS: |
| 28 | + op_name = self.full_op_name(op) |
| 29 | + for operand in self.FLOAT_NUMBERS: |
| 30 | + result = self.floatOp.unary_op(op, operand) |
| 31 | + if 'nan' in result: |
| 32 | + unary_test_data.append([op_name, operand, 'nan:canonical']) |
| 33 | + else: |
| 34 | + unary_test_data.append([op_name, operand, result]) |
| 35 | + |
| 36 | + for operand in self.LITERAL_NUMBERS: |
| 37 | + result = self.floatOp.unary_op(op, operand, hex_form=False) |
| 38 | + unary_test_data.append([op_name, operand, result]) |
| 39 | + |
| 40 | + for operand in self.NAN_NUMBERS: |
| 41 | + if 'nan:' in operand: |
| 42 | + unary_test_data.append([op_name, operand, 'nan:arithmetic']) |
| 43 | + else: |
| 44 | + unary_test_data.append([op_name, operand, 'nan:canonical']) |
| 45 | + |
| 46 | + for case in unary_test_data: |
| 47 | + cases.append(str(AssertReturn(case[0], |
| 48 | + [SIMD.v128_const(elem, self.LANE_TYPE) for elem in case[1:-1]], |
| 49 | + SIMD.v128_const(case[-1], self.LANE_TYPE)))) |
| 50 | + |
| 51 | + self.get_unknown_operator_case(cases) |
| 52 | + |
| 53 | + return '\n'.join(cases) |
| 54 | + |
| 55 | + def get_unknown_operator_case(self, cases): |
| 56 | + """Unknown operator cases. |
| 57 | + """ |
| 58 | + |
| 59 | + tpl_assert = "(assert_malformed (module quote \"(memory 1) (func (result v128) " \ |
| 60 | + "({lane_type}.{op} {value}))\") \"unknown operator\")" |
| 61 | + |
| 62 | + unknown_op_cases = ['\n\n;; Unknown operators\n'] |
| 63 | + cases.extend(unknown_op_cases) |
| 64 | + |
| 65 | + for lane_type in ['i8x16', 'i16x8', 'i32x4', 'i64x2']: |
| 66 | + for op in self.UNARY_OPS: |
| 67 | + cases.append(tpl_assert.format(lane_type=lane_type, op=op, value=self.v128_const('i32x4', '0'))) |
| 68 | + |
| 69 | + def gen_test_cases(self): |
| 70 | + wast_filename = '../simd_{lane_type}_rounding.wast'.format(lane_type=self.LANE_TYPE) |
| 71 | + with open(wast_filename, 'w') as fp: |
| 72 | + txt_test_case = self.get_all_cases() |
| 73 | + txt_test_case = txt_test_case.replace( |
| 74 | + self.LANE_TYPE + ' arithmetic', |
| 75 | + self.LANE_TYPE + ' [ceil, floor, trunc, nearest]') |
| 76 | + fp.write(txt_test_case) |
| 77 | + |
| 78 | + |
| 79 | +def gen_test_cases(): |
| 80 | + simd_f32x4_case = Simdf32x4RoundingCase() |
| 81 | + simd_f32x4_case.gen_test_cases() |
| 82 | + |
| 83 | + |
| 84 | +if __name__ == '__main__': |
| 85 | + gen_test_cases() |
0 commit comments