예제 #1
0
    def gen_test_case_with_const(self):
        """generate tests calling function with const"""
        cnt = 0
        cases = '\n\n;; Const vs const'
        for op in self.BINARY_OPS:
            for param_1, param_2 in self.get_test_data_with_const:
                result = []
                for idx in range(0, len(param_1)):
                    result.append(
                        IntOp.binary_op(op, param_1[idx], param_2[idx],
                                        self.lane_width))
                cases += '\n' + str(
                    AssertReturn(
                        '{lane_type}.{op}_with_const_{cnt}'.format(
                            lane_type=self.LANE_TYPE, op=op, cnt=cnt), [],
                        SIMD.v128_const(result, self.LANE_TYPE)))
                cnt += 1

        cases += '\n\n;; Param vs const'
        for op in self.BINARY_OPS:
            for param_1, param_2 in self.get_test_data_with_const:
                result = []
                for idx in range(0, len(param_1)):
                    result.append(
                        IntOp.binary_op(op, param_1[idx], param_2[idx],
                                        self.lane_width))
                cases += '\n' + str(
                    AssertReturn(
                        '{lane_type}.{op}_with_const_{cnt}'.format(
                            lane_type=self.LANE_TYPE, op=op, cnt=cnt),
                        [SIMD.v128_const(param_2, self.LANE_TYPE)],
                        SIMD.v128_const(result, self.LANE_TYPE)))
                cnt += 1

        return cases
예제 #2
0
    def get_normal_case(self):

        s = SIMD()

        case_data = self.get_case_data()

        cases = []

        for item in case_data:
            # Recognize '#' as a commentary
            if item[0] == '#':
                cases.append('\n;; {}'.format(item[1]))
                continue
            """
            Generate assert_return
            Params: instruction: instruction name;
                    param: param for instruction;
                    ret: excepted result;
                    lane_type: lane type
            """
            instruction, param, ret, lane_type = item
            cases.append(
                str(
                    AssertReturn(instruction, [
                        s.v128_const(param[0], lane_type[0]),
                        s.v128_const(param[1], lane_type[1])
                    ], s.v128_const(ret, lane_type[2]))))

        return '\n'.join(cases)
예제 #3
0
    def get_combine_cases(self):
        combine_cases = [';; combination\n(module']
        ternary_func_template = '  (func (export "{func}") (param v128 v128 v128) (result v128)\n' \
                              '    ({lane}.{op1} ({lane}.{op2} (local.get 0) (local.get 1))'\
                              '(local.get 2)))'
        for func in sorted(self.combine_ternary_arith_test_data):
            func_parts = func.split('-')
            op1 = func_parts[1].replace('_', '_saturate_')
            op2 = func_parts[2].replace('_', '_saturate_')
            combine_cases.append(ternary_func_template.format(func=func,
                                                            lane=self.LANE_TYPE,
                                                            op1=op1,
                                                            op2=op2))
        binary_func_template = '  (func (export "{func}") (param v128 v128) (result v128)\n'\
                             '    ({lane}.{op1} ({lane}.{op2} (local.get 0)) (local.get 1)))'
        for func in sorted(self.combine_binary_arith_test_data):
            func_parts = func.split('-')
            op1 = func_parts[1].replace('_', '_saturate_')
            combine_cases.append(binary_func_template.format(func=func,
                                                           lane=self.LANE_TYPE,
                                                           op1=op1,
                                                           op2=func_parts[2]))
        combine_cases.append(')\n')

        for func, test in sorted(self.combine_ternary_arith_test_data.items()):
            combine_cases.append(str(AssertReturn(func,
                                 [SIMD.v128_const(elem, self.LANE_TYPE) for elem in test[:-1]],
                                 SIMD.v128_const(test[-1], self.LANE_TYPE))))

        for func, test in sorted(self.combine_binary_arith_test_data.items()):
            combine_cases.append(str(AssertReturn(func,
                                 [SIMD.v128_const(elem, self.LANE_TYPE) for elem in test[:-1]],
                                 SIMD.v128_const(test[-1], self.LANE_TYPE))))

        return '\n'.join(combine_cases)
예제 #4
0
    def gen_test_case_combination(self):
        """generate combination test cases"""

        cases = '\n'

        binary_ops = list(self.BINARY_OPS)
        binary_ops.reverse()
        for op1 in self.BINARY_OPS:
            for op2 in binary_ops:

                result = []
                ret = IntOp.binary_op(op2, '0', '1', self.lane_width)
                ret = IntOp.binary_op(op1, ret, '2', self.lane_width)
                result.append(ret)

                cases += '\n' + str(
                    AssertReturn(
                        '{lane_type}.{op1}-{lane_type}.{op2}'.format(
                            lane_type=self.LANE_TYPE, op1=op1, op2=op2), [
                                SIMD.v128_const('0', self.LANE_TYPE),
                                SIMD.v128_const('1', self.LANE_TYPE),
                                SIMD.v128_const('2', self.LANE_TYPE)
                            ], SIMD.v128_const(result, self.LANE_TYPE)))
        cases += '\n'
        return cases
예제 #5
0
    def get_normal_case(self):
        s = SIMD()
        cases = []

        # store using arg
        for (addr, ret) in self.get_case_data():
            i32_addr = s.const(addr, "i32")
            v128_val = s.v128_const(list_stringify(ret), self.LANE_TYPE)
            result = s.const(ret[addr], "i64")
            instr = "v128.store{lane_len}_lane_{idx}".format(
                lane_len=self.LANE_LEN, idx=addr)
            cases.append(str(AssertReturn(instr, [i32_addr, v128_val],
                                          result)))

        # store using offset
        for (addr, ret) in self.get_case_data():
            v128_val = s.v128_const(list_stringify(ret), self.LANE_TYPE)
            result = s.const(ret[addr], "i64")
            instr = "v128.store{lane_len}_lane_{idx}_offset_{idx}".format(
                lane_len=self.LANE_LEN, idx=addr)
            cases.append(str(AssertReturn(instr, [v128_val], result)))

        # store using offset with alignment
        for (addr, ret) in self.get_case_data():
            for align in self.valid_alignments():
                i32_addr = s.const(addr, "i32")
                v128_val = s.v128_const(list_stringify(ret), self.LANE_TYPE)
                result = s.const(ret[addr], "i64")
                instr = "v128.store{lane_len}_lane_{idx}_align_{align}".format(
                    lane_len=self.LANE_LEN, idx=addr, align=align)
                cases.append(
                    str(AssertReturn(instr, [i32_addr, v128_val], result)))

        return '\n'.join(cases)
예제 #6
0
    def init_case_data(case_data):
        """
        Rearrange const data into standard format
        e.g. [0][i32x4] => (v128.const i32x4 0 0 0 0)
             [0][i32]   => (i32.const 0)
        """

        s_i = SIMD()

        lst_i_p_r = []

        for item in case_data:
            # Recognize '#' as a commentary
            if item[0] == '#':
                comment = '\n' if len(item[1]) == 0 else '\n;; {}'.format(item[1])
                lst_i_p_r.append(['#', comment])
                continue

            # Params: instruction: instruction name;
            #         params: param for instruction;
            #         rets: excepted result;
            #         lane_type: lane type for param and ret
            instruction, params, rets, lane_type = item

            p_const_list = []
            for idx, param in enumerate(params):
                p_const_list.append(s_i.v128_const(param, lane_type[idx]))

            r_const_list = []
            for idx, ret in enumerate(rets):
                r_const_list.append(s_i.v128_const(ret, lane_type[idx + len(params)]))

            lst_i_p_r.append([instruction, p_const_list, r_const_list])

        return lst_i_p_r
예제 #7
0
    def gen_funcs_with_const(self):
        """generate functions with const arguments"""
        binary_func_with_const = '\n  (func (export "{lane_type}.{op}_with_const_{cnt}") (result v128) ({lane_type}.{op} {param_1} {param_2}))'
        unary_func_with_const = '\n  (func (export "{lane_type}.{op}_with_const_{cnt}") (result v128) ({lane_type}.{op} {param}))'
        binary_func_with_param_and_const = '\n  (func (export "{lane_type}.{op}_with_const_{cnt}") (param v128) (result v128) ({lane_type}.{op} (local.get 0) {param_1}))'
        funcs = ''
        cnt = 0
        for op in self.BINARY_OPS:
            for param_1, param_2 in self.get_binary_test_data_with_const:
                funcs += binary_func_with_const.format(
                    lane_type=self.LANE_TYPE,
                    op=op,
                    param_1=SIMD.v128_const(param_1, self.LANE_TYPE),
                    param_2=SIMD.v128_const(param_2, self.LANE_TYPE),
                    cnt=cnt)
                cnt += 1
        for op in self.UNARY_OPS:
            for param in self.get_unary_complex_test_data:
                funcs += unary_func_with_const.format(lane_type=self.LANE_TYPE,
                                                      op=op,
                                                      param=SIMD.v128_const(
                                                          param,
                                                          self.LANE_TYPE),
                                                      cnt=cnt)
                cnt += 1
        for op in self.BINARY_OPS:
            for param_1, param_2 in self.get_binary_test_data_with_const:
                funcs += binary_func_with_param_and_const.format(
                    lane_type=self.LANE_TYPE,
                    op=op,
                    param_1=SIMD.v128_const(param_1, self.LANE_TYPE),
                    cnt=cnt)
                cnt += 1

        return funcs
예제 #8
0
    def get_normal_case(self):
        cases = []

        for op in self.UNARY_OPS:
            src_lane_type = self.src_lane_type(op)
            src_value = self.LANE_VALUE[src_lane_type]
            operands = self.get_test_cases(src_value)

            for (low, high) in operands:
                result = low if "low" in op else high

                if self.is_unsigned(op):
                    # Unsign-extend, mask top bits.
                    result = result & src_value.mask

                cases.append(
                    str(
                        AssertReturn(
                            op,
                            [SIMD.v128_const([str(low), str(high)], src_lane_type)],
                            SIMD.v128_const(str(result), self.dst_lane_type(op)),
                        )
                    )
                )

            cases.append("")

        return "\n".join(cases)
예제 #9
0
    def gen_test_case_unknown_operators(self):
        """generate unknown operators test cases"""
        cases = ['\n\n;; Unknown operators']

        for op in self.UNKNOWN_OPS:
            cases.append(
                AssertMalformed.get_unknown_op_test(
                    op, 'v128', SIMD.v128_const('0', self.LANE_TYPE),
                    SIMD.v128_const('1', self.LANE_TYPE)))
        return '\n'.join(cases)
예제 #10
0
 def gen(case_data):
     cases = ''
     for op in self.BINARY_OPS:
         for param_1, param_2 in case_data:
             result = []
             for idx in range(0, len(param_1)):
                 result.append(IntOp.binary_op(op, param_1[idx], param_2[idx], self.lane_width))
             cases += '\n' + str(AssertReturn('{lane_type}.{op}'.format(lane_type=self.LANE_TYPE, op=op),
                                              [SIMD.v128_const(param_1, self.LANE_TYPE), SIMD.v128_const(param_2, self.LANE_TYPE)],
                                              SIMD.v128_const(result, self.LANE_TYPE)))
     return cases
예제 #11
0
    def get_normal_case(self):
        """Normal test cases from WebAssembly core tests
        """
        cases = []
        binary_test_data = []
        unary_test_data = []

        for op in self.BINARY_OPS:
            op_name = self.full_op_name(op)
            for operand1 in self.FLOAT_NUMBERS_SPECIAL:
                for operand2 in self.FLOAT_NUMBERS_SPECIAL + self.NAN_NUMBERS:
                    result = self.floatOp.binary_op(op, operand1, operand2)
                    binary_test_data.append(
                        [op_name, operand1, operand2, result])

            for operand1 in self.LITERAL_NUMBERS:
                for operand2 in self.LITERAL_NUMBERS:
                    result = self.floatOp.binary_op(op, operand1, operand2)
                    binary_test_data.append(
                        [op_name, operand1, operand2, result])

            for operand1 in self.NAN_NUMBERS:
                for operand2 in self.FLOAT_NUMBERS_SPECIAL + self.NAN_NUMBERS:
                    result = self.floatOp.binary_op(op, operand1, operand2)
                    binary_test_data.append(
                        [op_name, operand1, operand2, result])

        for op in self.BINARY_OPS:
            op_name = self.full_op_name(op)
            for operand1 in self.FLOAT_NUMBERS_NORMAL:
                for operand2 in self.FLOAT_NUMBERS_NORMAL:
                    result = self.floatOp.binary_op(op, operand1, operand2)
                    binary_test_data.append(
                        [op_name, operand1, operand2, result])

        for case in binary_test_data:
            cases.append(
                str(
                    AssertReturn(case[0], [
                        SIMD.v128_const(elem, self.LANE_TYPE)
                        for elem in case[1:-1]
                    ], SIMD.v128_const(case[-1], 'i64x2'))))

        for case in unary_test_data:
            cases.append(
                str(
                    AssertReturn(case[0], [
                        SIMD.v128_const(elem, self.LANE_TYPE)
                        for elem in case[1:-1]
                    ], SIMD.v128_const(case[-1], 'i64x2'))))

        self.get_unknown_operator_case(cases)

        return '\n'.join(cases)
예제 #12
0
 def gen_unary(case_data):
     cases = ''
     for op in self.UNARY_OPS:
         o = ArithmeticOp(op)
         for param in case_data:
             result = []
             for idx in range(0, len(param)):
                 result.append(o.unary_op(param[idx], self.LANE_VALUE))
             cases += '\n' + str(
                 AssertReturn(
                     '{lane_type}.{op}'.format(lane_type=self.LANE_TYPE,
                                               op=op),
                     [SIMD.v128_const(param, self.LANE_TYPE)],
                     SIMD.v128_const(result, self.LANE_TYPE)))
     return cases
예제 #13
0
    def argument_empty_cases(self):
        """Test cases with empty argument.
        """
        cases = []

        case_data = {
            'op': '',
            'extended_name': 'arg-empty',
            'param_type': '',
            'result_type': '(result v128)',
            'params': '',
        }

        for op in self.BINARY_OPS:
            case_data['op'] = '{lane_type}.{op}'.format(
                lane_type=self.LANE_TYPE, op=op)
            case_data['extended_name'] = '1st-arg-empty'
            case_data['params'] = SIMD.v128_const('0', self.LANE_TYPE)
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

            case_data['extended_name'] = 'arg-empty'
            case_data['params'] = ''
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

        return '\n'.join(cases)
예제 #14
0
    def get_normal_case(self):
        """Normal test cases from WebAssembly core tests.
        """
        cases = []
        unary_test_data = []

        for op in self.UNARY_OPS:
            op_name = self.full_op_name(op)
            for operand in self.FLOAT_NUMBERS:
                result = self.floatOp.unary_op(op, operand)
                if 'nan' in result:
                    unary_test_data.append([op_name, operand, 'nan:canonical'])
                else:
                    unary_test_data.append([op_name, operand, result])

            for operand in self.LITERAL_NUMBERS:
                result = self.floatOp.unary_op(op, operand, hex_form=False)
                unary_test_data.append([op_name, operand, result])

            for operand in self.NAN_NUMBERS:
                if 'nan:' in operand:
                    unary_test_data.append([op_name, operand, 'nan:arithmetic'])
                else:
                    unary_test_data.append([op_name, operand, 'nan:canonical'])

        for case in unary_test_data:
            cases.append(str(AssertReturn(case[0],
                        [SIMD.v128_const(elem, self.LANE_TYPE) for elem in case[1:-1]],
                        SIMD.v128_const(case[-1], self.LANE_TYPE))))

        self.get_unknown_operator_case(cases)

        return '\n'.join(cases)
예제 #15
0
    def argument_empty_test(self):
        """Test cases with empty argument.
        """
        cases = []

        cases.append('\n\n;; Test operation with empty argument\n')

        case_data = {
            'op': '',
            'extended_name': 'arg-empty',
            'param_type': '',
            'result_type': '(result v128)',
            'params': '',
        }

        for op in self.UNARY_OPS:
            case_data['op'] = self.op_name(op)
            case_data['extended_name'] = 'arg-empty'
            case_data['params'] = ''
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

        for op in self.BINARY_OPS:
            case_data['op'] = self.op_name(op)
            case_data['extended_name'] = '1st-arg-empty'
            case_data['params'] = SIMD.v128_const('0', self.LANE_TYPE)
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

            case_data['extended_name'] = 'arg-empty'
            case_data['params'] = ''
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

        return '\n'.join(cases)
예제 #16
0
    def get_normal_case(self):
        """Normal test cases from WebAssembly core tests.
        """
        cases = []
        binary_test_data = []
        unary_test_data = []

        for op in self.BINARY_OPS:
            op_name = self.full_op_name(op)
            for operand1 in self.FLOAT_NUMBERS + self.LITERAL_NUMBERS:
                for operand2 in self.FLOAT_NUMBERS + self.LITERAL_NUMBERS:
                    result = self.floatOp.binary_op(op, operand1, operand2)
                    binary_test_data.append([op_name, operand1, operand2, result])

            # pmin and pmax always return operand1 if either operand is a nan
            for operand1 in self.NAN_NUMBERS:
                for operand2 in self.FLOAT_NUMBERS + self.LITERAL_NUMBERS + self.NAN_NUMBERS:
                    binary_test_data.append([op_name, operand1, operand2, operand1])
            for operand2 in self.NAN_NUMBERS:
                for operand1 in self.FLOAT_NUMBERS + self.LITERAL_NUMBERS:
                    binary_test_data.append([op_name, operand1, operand2, operand1])

        for case in binary_test_data:
            cases.append(str(AssertReturn(case[0],
                        [SIMD.v128_const(c, self.LANE_TYPE) for c in case[1:-1]],
                        SIMD.v128_const(case[-1], self.LANE_TYPE))))

        self.get_unknown_operator_case(cases)

        return '\n'.join(cases)
예제 #17
0
    def gen_test_case_unknown_operators(self):
        """generate unknown operators test cases"""

        if self.LANE_TYPE != 'i32x4':
            return ''

        cases = '\n\n;; Unknown operators'
        lane_types = ('f32x4', 'i64x2',)
        assert_template = '(assert_malformed (module quote "(memory 1) (func (result v128) ({lane_type}.{op} {param_1} {param_2}))") "unknown operator")'
        for lane_type in lane_types:
            for op in self.BINARY_OPS:
                cases += '\n' + assert_template.format(lane_type=lane_type,
                                                       op=op,
                                                       param_1=SIMD.v128_const('0', self.LANE_TYPE),
                                                       param_2=SIMD.v128_const('1', self.LANE_TYPE))

        return cases
예제 #18
0
    def get_normal_case(self):
        s = SIMD()
        case_data = self.get_case_data()
        cases = []

        for item in case_data:
            # Recognize '#' as a commentary
            if item[0] == '#':
                cases.append('\n;; {}'.format(item[1]))
                continue

            instruction, param, ret, lane_type = item
            v128_result = s.v128_const(ret, lane_type[-1])
            v128_params = []
            for i, p in enumerate(param):
                v128_params.append(s.v128_const(p, lane_type[i]))
            cases.append(
                str(AssertReturn(instruction, v128_params, v128_result)))

        return '\n'.join(cases)
예제 #19
0
    def get_argument_empty_case(self):
        """
        Generate argument empty cases
        """

        cases = []

        param_1 = SIMD.v128_const('0', 'i32x4')

        cases.append('\n\n;; Test operation with empty argument\n')

        case_data = {
            'op': '',
            'extended_name': 'arg-empty',
            'param_type': '',
            'result_type': '(result v128)',
            'params': '',
        }

        for op in self.UNARY_OPS:
            case_data['op'] = 'v128.' + op
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

        for op in self.BINARY_OPS:
            case_data['op'] = 'v128.' + op
            case_data['extended_name'] = '1st-arg-empty'
            case_data['params'] = param_1
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

            case_data['extended_name'] = 'arg-empty'
            case_data['params'] = ''
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

        for op in self.TERNARY_OPS:
            case_data['op'] = 'v128.' + op
            case_data['extended_name'] = '1st-arg-empty'
            case_data['params'] = param_1 + ' ' + param_1
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

            case_data['extended_name'] = 'two-args-empty'
            case_data['params'] = param_1
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

            case_data['extended_name'] = 'arg-empty'
            case_data['params'] = ''
            cases.append(AssertInvalid.get_arg_empty_test(**case_data))

        return '\n'.join(cases) + '\n'
예제 #20
0
    def gen_test_case_combination(self):
        """generate combination test cases"""

        cases = '\n'

        binary_ops = list(self.BINARY_OPS)
        binary_ops.reverse()
        unary_ops = list(self.UNARY_OPS)
        unary_ops.reverse()
        for op1 in self.BINARY_OPS:
            """binary vs binary"""
            o1 = ArithmeticOp(op1)
            for op2 in binary_ops:
                o2 = ArithmeticOp(op2)
                result = []
                ret = o2.binary_op('0', '1', self.LANE_VALUE)
                ret = o1.binary_op(ret, '2', self.LANE_VALUE)
                result.append(ret)

                cases += '\n' + str(
                    AssertReturn(
                        '{lane_type}.{op1}-{lane_type}.{op2}'.format(
                            lane_type=self.LANE_TYPE, op1=op1, op2=op2), [
                                SIMD.v128_const('0', self.LANE_TYPE),
                                SIMD.v128_const('1', self.LANE_TYPE),
                                SIMD.v128_const('2', self.LANE_TYPE)
                            ], SIMD.v128_const(result, self.LANE_TYPE)))
            for op2 in self.UNARY_OPS:
                """binary vs unary"""
                o2 = ArithmeticOp(op2)
                result1 = []
                ret1 = o2.unary_op('-1', self.LANE_VALUE)
                ret1 = o1.binary_op(ret1, '0', self.LANE_VALUE)
                result1.append(ret1)
                cases += '\n' + str(
                    AssertReturn(
                        '{lane_type}.{op1}-{lane_type}.{op2}'.format(
                            lane_type=self.LANE_TYPE, op1=op1, op2=op2), [
                                SIMD.v128_const('-1', self.LANE_TYPE),
                                SIMD.v128_const('0', self.LANE_TYPE)
                            ], SIMD.v128_const(result1, self.LANE_TYPE)))
                """unary vs binary"""
                result2 = []
                ret2 = o1.binary_op('0', '-1', self.LANE_VALUE)
                ret2 = o2.unary_op(ret2, self.LANE_VALUE)
                result2.append(ret2)
                cases += '\n' + str(
                    AssertReturn(
                        '{lane_type}.{op1}-{lane_type}.{op2}'.format(
                            lane_type=self.LANE_TYPE, op1=op2, op2=op1), [
                                SIMD.v128_const('0', self.LANE_TYPE),
                                SIMD.v128_const('-1', self.LANE_TYPE)
                            ], SIMD.v128_const(result2, self.LANE_TYPE)))
        for op1 in self.UNARY_OPS:
            """unary vs unary"""
            o1 = ArithmeticOp(op1)
            for op2 in unary_ops:
                o2 = ArithmeticOp(op2)
                result3 = []
                ret3 = o2.unary_op('-1', self.LANE_VALUE)
                ret3 = o1.unary_op(ret3, self.LANE_VALUE)
                result3.append(ret3)
                cases += '\n' + str(
                    AssertReturn(
                        '{lane_type}.{op1}-{lane_type}.{op2}'.format(
                            lane_type=self.LANE_TYPE, op1=op1, op2=op2),
                        [SIMD.v128_const('-1', self.LANE_TYPE)],
                        SIMD.v128_const(result3, self.LANE_TYPE)))

        cases += '\n'
        return cases
예제 #21
0
    def gen_test_case_empty_argument(self):
        """generate empty argument test cases"""

        assert_1st_empyt_template = '\n(assert_invalid' \
                                    '\n  (module' \
                                    '\n    (func ${lane_type}.{op}-1st-arg-empty (result v128)' \
                                    '\n      ({lane_type}.{op} {param_1})' \
                                    '\n    )' \
                                    '\n  )' \
                                    '\n  "type mismatch"' \
                                    '\n)'
        assert_all_empty_template = '\n(assert_invalid' \
                                    '\n  (module' \
                                    '\n    (func ${lane_type}.{op}-all-args-empty (result v128)' \
                                    '\n      ({lane_type}.{op})' \
                                    '\n    )' \
                                    '\n  )' \
                                    '\n  "type mismatch"' \
                                    '\n)'

        cases = ''

        cases += '\n\n;; Test operation with empty argument\n'
        for op in self.BINARY_OPS:
            cases += assert_1st_empyt_template.format(lane_type=self.LANE_TYPE, op=op, param_1=SIMD.v128_const('0', self.LANE_TYPE))
            cases += assert_all_empty_template.format(lane_type=self.LANE_TYPE, op=op)

        return cases
예제 #22
0
    def get_normal_case(self):
        """Normal test cases from WebAssembly core tests
        """
        cases = []
        binary_test_data = []
        unary_test_data = []

        for op in self.BINARY_OPS:
            op_name = self.full_op_name(op)
            for operand1 in self.FLOAT_NUMBERS:
                for operand2 in self.FLOAT_NUMBERS:
                    result = self.floatOp.binary_op(op, operand1, operand2)
                    if 'nan' not in result:
                        # Normal floating point numbers as the results
                        binary_test_data.append(
                            [op_name, operand1, operand2, result])
                    else:
                        # Since the results contain the 'nan' string, the result literals would be
                        # nan:canonical
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:canonical'])

            for operand1 in self.NAN_NUMBERS:
                for operand2 in self.FLOAT_NUMBERS:
                    if 'nan:' in operand1 or 'nan:' in operand2:
                        # When the arguments contain 'nan:', the result literal is nan:arithmetic
                        # Consider the different order of arguments as different cases.
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:arithmetic'])
                        binary_test_data.append(
                            [op_name, operand2, operand1, 'nan:arithmetic'])
                    else:
                        # No 'nan' string found, then the result literal is nan:canonical.
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:canonical'])
                        binary_test_data.append(
                            [op_name, operand2, operand1, 'nan:canonical'])
                for operand2 in self.NAN_NUMBERS:
                    if 'nan:' in operand1 or 'nan:' in operand2:
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:arithmetic'])
                    else:
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:canonical'])

            for operand in self.LITERAL_NUMBERS:
                if self.LANE_TYPE == 'f32x4':
                    single_precision = True
                else:
                    single_precision = False
                result = self.floatOp.binary_op(op,
                                                operand,
                                                operand,
                                                single_prec=single_precision)
                binary_test_data.append([op_name, operand, operand, result])

        for case in binary_test_data:
            cases.append(
                str(
                    AssertReturn(case[0], [
                        SIMD.v128_const(elem, self.LANE_TYPE)
                        for elem in case[1:-1]
                    ], SIMD.v128_const(case[-1], self.LANE_TYPE))))

        for operand in self.FLOAT_NUMBERS + self.NAN_NUMBERS + self.LITERAL_NUMBERS:
            if 'nan:' in operand:
                unary_test_data.append([op_name, operand, 'nan:arithmetic'])
            elif 'nan' in operand:
                unary_test_data.append([op_name, operand, 'nan:canonical'])
            else:
                # Normal floating point numbers for sqrt operation
                op_name = self.full_op_name('sqrt')
                result = self.floatOp.float_sqrt(operand)
                if 'nan' not in result:
                    # Get the sqrt value correctly
                    unary_test_data.append([op_name, operand, result])
                else:
                    #
                    unary_test_data.append([op_name, operand, 'nan:canonical'])

        for operand in self.FLOAT_NUMBERS + self.NAN_NUMBERS + self.LITERAL_NUMBERS:
            op_name = self.full_op_name('neg')
            result = self.floatOp.float_neg(operand)
            # Neg operation is valid for all the floating point numbers
            unary_test_data.append([op_name, operand, result])

        for case in unary_test_data:
            cases.append(
                str(
                    AssertReturn(case[0], [
                        SIMD.v128_const(elem, self.LANE_TYPE)
                        for elem in case[1:-1]
                    ], SIMD.v128_const(case[-1], self.LANE_TYPE))))

        self.mixed_nan_test(cases)

        return '\n'.join(cases)
예제 #23
0
    def get_normal_case(self):
        """Normal test cases from WebAssembly core tests
        """
        cases = []
        binary_test_data = []
        unary_test_data = []

        for op in self.BINARY_OPS:
            op_name = self.full_op_name(op)
            for operand1 in self.FLOAT_NUMBERS:
                for operand2 in self.FLOAT_NUMBERS:
                    result = self.floatOp.binary_op(op, operand1, operand2)
                    if 'nan' not in result:
                        # Normal floating point numbers as the results
                        binary_test_data.append(
                            [op_name, operand1, operand2, result])
                    else:
                        # Since the results contain the 'nan' string, the result literals would be
                        # nan:canonical
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:canonical'])

            for operand1 in self.NAN_NUMBERS:
                for operand2 in self.FLOAT_NUMBERS:
                    if 'nan:' in operand1 or 'nan:' in operand2:
                        # When the arguments contain 'nan:', the result literal is nan:arithmetic
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:arithmetic'])
                    else:
                        # No 'nan' string found, then the result literal is nan:canonical
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:canonical'])
                for operand2 in self.NAN_NUMBERS:
                    if 'nan:' in operand1 or 'nan:' in operand2:
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:arithmetic'])
                    else:
                        binary_test_data.append(
                            [op_name, operand1, operand2, 'nan:canonical'])

            for operand1 in self.LITERAL_NUMBERS:
                for operand2 in self.LITERAL_NUMBERS:
                    result = self.floatOp.binary_op(op,
                                                    operand1,
                                                    operand2,
                                                    hex_form=False)
                    binary_test_data.append(
                        [op_name, operand1, operand2, result])

        for case in binary_test_data:
            cases.append(
                str(
                    AssertReturn(case[0], [
                        SIMD.v128_const(elem, self.LANE_TYPE)
                        for elem in case[1:-1]
                    ], SIMD.v128_const(case[-1], self.LANE_TYPE))))

        # Test opposite signs of zero
        lst_oppo_signs_0 = [
            '\n;; Test opposite signs of zero',
            [
                'f64x2.min', [['0', '0'], ['+0', '-0']], [['0', '-0']],
                ['f64x2', 'f64x2', 'f64x2']
            ],
            [
                'f64x2.min', [['-0', '+0'], ['+0', '-0']], [['-0', '-0']],
                ['f64x2', 'f64x2', 'f64x2']
            ],
            [
                'f64x2.min', [['-0', '-0'], ['+0', '+0']], [['-0', '-0']],
                ['f64x2', 'f64x2', 'f64x2']
            ],
            [
                'f64x2.max', [['0', '0'], ['+0', '-0']], [['0', '0']],
                ['f64x2', 'f64x2', 'f64x2']
            ],
            [
                'f64x2.max', [['-0', '+0'], ['+0', '-0']], [['0', '0']],
                ['f64x2', 'f64x2', 'f64x2']
            ],
            [
                'f64x2.max', [['-0', '-0'], ['+0', '+0']], [['+0', '+0']],
                ['f64x2', 'f64x2', 'f64x2']
            ], '\n'
        ]

        # Generate test case for opposite signs of zero
        for case_data in lst_oppo_signs_0:

            if isinstance(case_data, str):
                cases.append(case_data)
                continue

            cases.append(
                str(
                    AssertReturn(
                        case_data[0], [
                            self.v128_const(case_data[3][0], case_data[1][0]),
                            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 + self.LITERAL_NUMBERS:
            op_name = self.full_op_name('abs')
            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([op_name, p, result])

        for case in unary_test_data:
            cases.append(
                str(
                    AssertReturn(case[0], [
                        SIMD.v128_const(c, self.LANE_TYPE) for c in case[1:-1]
                    ], SIMD.v128_const(case[-1], self.LANE_TYPE))))

        return '\n'.join(cases)