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
def conversion_op(self, op, operand): fop = FloatingPointRoundingOp() signed = self.is_signed(op) sat_op = ArithmeticOp("sat_s") if signed else ArithmeticOp("sat_u") result = fop.unary_op("trunc", operand, hex_form=False) if result == "nan": return "0" elif result == "+inf": return str(str(self.lane.max) if signed else str(self.lane.mask)) elif result == "-inf": return str(self.lane.min if signed else 0) else: float_result = self.to_float_precision(float(result)) trunced = int(trunc(float_result)) saturated = sat_op.unary_op(trunced, self.lane) return str(saturated)
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: o = ArithmeticOp(op) for param_1, param_2 in self.get_binary_test_data_with_const: result = [] for idx in range(0, len(param_1)): result.append( o.binary_op(param_1[idx], param_2[idx], self.LANE_VALUE)) 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 for op in self.UNARY_OPS: o = ArithmeticOp(op) for param in self.get_unary_complex_test_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}_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: o = ArithmeticOp(op) for param_1, param_2 in self.get_binary_test_data_with_const: result = [] for idx in range(0, len(param_1)): result.append( o.binary_op(param_1[idx], param_2[idx], self.LANE_VALUE)) 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
def get_case_data(self): case_data = [] # i8x16.op (i8x16) (i8x16) for op in self.BINARY_OPS: o = ArithmeticOp(op) op_name = self.LANE_TYPE + '.' + op case_data.append(['#', op_name]) for data_group, v128_forms in self.bin_test_data: for data in data_group: case_data.append([ op_name, [str(data[0]), str(data[1])], str(o.binary_op(data[0], data[1], self.lane)), v128_forms ]) for data_group in self.full_bin_test_data: for data in data_group.get(op_name): case_data.append([op_name, *data]) for op in self.UNARY_OPS: o = ArithmeticOp(op) op_name = self.LANE_TYPE + '.' + op case_data.append(['#', op_name]) for data_group, v128_forms in self.unary_test_data: for data in data_group: case_data.append([ op_name, [str(data)], str(o.unary_op(data, self.lane)), v128_forms ]) return case_data
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
def binary_op(self, x, y, lane): # For test data we always splat a single value to the # entire v128, so '* 2' will work here. return ArithmeticOp.get_valid_value( x, i16) * ArithmeticOp.get_valid_value(y, i16) * 2
def unary_op(self, x, signed): # For test data we always splat a single value to the # entire v128, so doubling the input works. return ArithmeticOp.get_valid_value(x, self.src_lane, signed=signed) * 2