From c8492cf8a1059ec055c9a939a71c4ff302203c81 Mon Sep 17 00:00:00 2001 From: Ng Zhi An Date: Thu, 11 Feb 2021 16:04:53 -0800 Subject: [PATCH 1/3] [interpreter] Implement i32x4.trunc_sat_f64x2_{s,u}_zero This converts 2 f64 to 2 i32, then zeroes the top 2 lanes. These 2 instructions were merged as part of #383. This change also refactors some test cases from simd_conversions out into a script that generates both i32x4.trunc_sat_i32x4_{s,u} and i32x4.trunc_sat_f64x2_{s,u}_zero. --- interpreter/exec/eval_simd.ml | 4 + interpreter/exec/simd.ml | 6 + interpreter/syntax/ast.ml | 2 +- interpreter/syntax/operators.ml | 2 + interpreter/text/lexer.mll | 2 + test/core/simd/meta/gen_tests.py | 1 + test/core/simd/meta/simd_float_op.py | 62 ++--- .../simd/meta/simd_int_trunc_sat_float.py | 178 +++++++++++++ test/core/simd/meta/simd_integer_op.py | 6 + test/core/simd/simd_conversions.wast | 199 --------------- .../core/simd/simd_i32x4_trunc_sat_f32x4.wast | 239 ++++++++++++++++++ .../core/simd/simd_i32x4_trunc_sat_f64x2.wast | 239 ++++++++++++++++++ 12 files changed, 701 insertions(+), 239 deletions(-) create mode 100644 test/core/simd/meta/simd_int_trunc_sat_float.py create mode 100644 test/core/simd/simd_i32x4_trunc_sat_f32x4.wast create mode 100644 test/core/simd/simd_i32x4_trunc_sat_f64x2.wast diff --git a/interpreter/exec/eval_simd.ml b/interpreter/exec/eval_simd.ml index 2445f682a..673030952 100644 --- a/interpreter/exec/eval_simd.ml +++ b/interpreter/exec/eval_simd.ml @@ -31,6 +31,10 @@ module SimdOp (SXX : Simd.S) (Value : ValueType with type t = SXX.t) = struct | I32x4 WidenHighU -> to_value (SXX.I32x4_convert.widen_high_u (of_value 1 v)) | I32x4 TruncSatF32x4S -> to_value (SXX.I32x4_convert.trunc_sat_f32x4_s (of_value 1 v)) | I32x4 TruncSatF32x4U -> to_value (SXX.I32x4_convert.trunc_sat_f32x4_u (of_value 1 v)) + | I32x4 TruncSatF64x2SZero -> + to_value (SXX.I32x4_convert.trunc_sat_f64x2_s_zero (of_value 1 v)) + | I32x4 TruncSatF64x2UZero -> + to_value (SXX.I32x4_convert.trunc_sat_f64x2_u_zero (of_value 1 v)) | I64x2 Abs -> to_value (SXX.I64x2.abs (of_value 1 v)) | I64x2 Neg -> to_value (SXX.I64x2.neg (of_value 1 v)) | I64x2 WidenLowS -> to_value (SXX.I64x2_convert.widen_low_s (of_value 1 v)) diff --git a/interpreter/exec/simd.ml b/interpreter/exec/simd.ml index d15a53931..892ee24d3 100644 --- a/interpreter/exec/simd.ml +++ b/interpreter/exec/simd.ml @@ -186,6 +186,8 @@ sig module I32x4_convert : sig val trunc_sat_f32x4_s : t -> t val trunc_sat_f32x4_u : t -> t + val trunc_sat_f64x2_s_zero : t -> t + val trunc_sat_f64x2_u_zero : t -> t val widen_low_s : t -> t val widen_high_s : t -> t val widen_low_u : t -> t @@ -444,6 +446,10 @@ struct let trunc_sat_f32x4_s = convert I32_convert.trunc_sat_f32_s let trunc_sat_f32x4_u = convert I32_convert.trunc_sat_f32_u + let convert_zero f v = Rep.of_i32x4 (I32.zero :: I32.zero :: (List.map f (Rep.to_f64x2 v))) + let trunc_sat_f64x2_s_zero = convert_zero I32_convert.trunc_sat_f64_s + let trunc_sat_f64x2_u_zero = convert_zero I32_convert.trunc_sat_f64_u + let widen take_or_drop mask x = Rep.of_i32x4 (List.map (Int32.logand mask) (take_or_drop 4 (Rep.to_i16x8 x))) let widen_low_s = widen Lib.List.take 0xffffffffl diff --git a/interpreter/syntax/ast.ml b/interpreter/syntax/ast.ml index 077c08a2c..9d57d0e1d 100644 --- a/interpreter/syntax/ast.ml +++ b/interpreter/syntax/ast.ml @@ -50,7 +50,7 @@ module SimdOp = struct type iunop = Abs | Neg | TruncSatF32x4S | TruncSatF32x4U | WidenLowS | WidenLowU | WidenHighS | WidenHighU - | Popcnt + | Popcnt | TruncSatF64x2SZero | TruncSatF64x2UZero type ibinop = Add | Sub | MinS | MinU | MaxS | MaxU | Mul | AvgrU | Eq | Ne | LtS | LtU | LeS | LeU | GtS | GtU | GeS | GeU | Swizzle | Shuffle of int list | NarrowS | NarrowU diff --git a/interpreter/syntax/operators.ml b/interpreter/syntax/operators.ml index e3351f844..d8990bcaa 100644 --- a/interpreter/syntax/operators.ml +++ b/interpreter/syntax/operators.ml @@ -388,6 +388,8 @@ let i32x4_max_u = Binary (V128 V128Op.(I32x4 MaxU)) let i32x4_mul = Binary (V128 V128Op.(I32x4 Mul)) let i32x4_trunc_sat_f32x4_s = Unary (V128 V128Op.(I32x4 TruncSatF32x4S)) let i32x4_trunc_sat_f32x4_u = Unary (V128 V128Op.(I32x4 TruncSatF32x4U)) +let i32x4_trunc_sat_f64x2_s_zero = Unary (V128 V128Op.(I32x4 TruncSatF64x2SZero)) +let i32x4_trunc_sat_f64x2_u_zero = Unary (V128 V128Op.(I32x4 TruncSatF64x2UZero)) let i32x4_dot_i16x8_s = Binary (V128 V128Op.(I32x4 DotI16x8S)) let i32x4_extmul_low_i16x8_s = Binary (V128 V128Op.(I32x4 ExtMulLowS)) let i32x4_extmul_high_i16x8_s = Binary (V128 V128Op.(I32x4 ExtMulHighS)) diff --git a/interpreter/text/lexer.mll b/interpreter/text/lexer.mll index d5f5ed121..2d74b0f68 100644 --- a/interpreter/text/lexer.mll +++ b/interpreter/text/lexer.mll @@ -553,6 +553,8 @@ rule token = parse UNARY (simd_int_op s i8x16_avgr_u i16x8_avgr_u unreachable unreachable) } | "i32x4.trunc_sat_f32x4_"(sign as s) { UNARY (ext s i32x4_trunc_sat_f32x4_s i32x4_trunc_sat_f32x4_u) } + | "i32x4.trunc_sat_f64x2_"(sign as s)"_zero" + { UNARY (ext s i32x4_trunc_sat_f64x2_s_zero i32x4_trunc_sat_f64x2_u_zero) } | "f32x4.convert_i32x4_"(sign as s) { UNARY (ext s f32x4_convert_i32x4_s f32x4_convert_i32x4_u) } | "i8x16.narrow_i16x8_"(sign as s) diff --git a/test/core/simd/meta/gen_tests.py b/test/core/simd/meta/gen_tests.py index fdee79f10..74824a723 100644 --- a/test/core/simd/meta/gen_tests.py +++ b/test/core/simd/meta/gen_tests.py @@ -36,6 +36,7 @@ 'simd_store_lane', 'simd_ext_mul', 'simd_int_to_int_widen', + 'simd_int_trunc_sat_float', ) diff --git a/test/core/simd/meta/simd_float_op.py b/test/core/simd/meta/simd_float_op.py index 8d9bb1fa3..4e65443a6 100644 --- a/test/core/simd/meta/simd_float_op.py +++ b/test/core/simd/meta/simd_float_op.py @@ -15,6 +15,20 @@ class FloatingPointOp: def binary_op(self, op: str, p1: str, p2: str) -> str: pass + def of_string(self, value: str) -> float: + if '0x' in value: + return float.fromhex(value) + else: + return float(value) + + def is_hex(self, value:str) -> bool: + return '0x' in value + + def to_single_precision(self, value: float) -> str: + # Python only has doubles, when reading in float, we need to convert to + # single-precision first. + return struct.unpack('f', struct.pack('f', value))[0] + class FloatingPointArithOp(FloatingPointOp): """Common arithmetic ops for both f32x4 and f64x2: @@ -29,19 +43,9 @@ def binary_op(self, op: str, p1: str, p2: str, single_prec=False) -> str: :param p2: float number in hex :return: """ - if '0x' in p1 or '0x' in p2: - hex_form = True - else: - hex_form = False - - if '0x' in p1: - f1 = float.fromhex(p1) - else: - f1 = float(p1) - if '0x' in p2: - f2 = float.fromhex(p2) - else: - f2 = float(p2) + hex_form = self.is_hex(p1) or self.is_hex(p2) + f1 = self.of_string(p1) + f2 = self.of_string(p2) if op == 'add': if 'inf' in p1 and 'inf' in p2 and p1 != p2: @@ -145,15 +149,8 @@ def binary_op(self, op: str, p1: str, p2: str, hex_form=True) -> str: :param p2: float number in hex :return: """ - if '0x' in p1: - f1 = float.fromhex(p1) - else: - f1 = float(p1) - - if '0x' in p2: - f2 = float.fromhex(p2) - else: - f2 = float(p2) + f1 = self.of_string(p1) + f2 = self.of_string(p2) if '-nan' in [p1, p2] and 'nan' in [p1, p2]: return p1 @@ -205,10 +202,7 @@ def unary_op(self, op: str, p1: str, hex_form=True) -> str: :param p1: float number in hex :return: """ - if '0x' in p1: - f1 = float.fromhex(p1) - else: - f1 = float(p1) + f1 = self.of_string(p1) if op == 'abs': if hex_form: return abs(f1).hex() @@ -239,15 +233,8 @@ def binary_op(self, op: str, p1: str, p2: str) -> str: if 'nan' in p1.lower() or 'nan' in p2.lower(): return '0' - if '0x' in p1: - f1 = float.fromhex(p1) - else: - f1 = float(p1) - - if '0x' in p2: - f2 = float.fromhex(p2) - else: - f2 = float(p2) + f1 = self.of_string(p1) + f2 = self.of_string(p2) if op == 'eq': return '-1' if f1 == f2 else '0' @@ -278,10 +265,7 @@ def unary_op(self, op: str, p1: str, hex_form=True) -> str: :param p1: float number in hex :return: """ - if '0x' in p1: - f1 = float.fromhex(p1) - else: - f1 = float(p1) + f1 = self.of_string(p1) if 'nan' in p1: return 'nan' diff --git a/test/core/simd/meta/simd_int_trunc_sat_float.py b/test/core/simd/meta/simd_int_trunc_sat_float.py new file mode 100644 index 000000000..eee912d7a --- /dev/null +++ b/test/core/simd/meta/simd_int_trunc_sat_float.py @@ -0,0 +1,178 @@ +#!/usr/bin/env python3 + +"""Base class for generating SIMD .trun_sat_ test cases. +Subclasses should set: + - LANE_TYPE + - SRC_LANE_TYPE + - UNARY_OPS +""" + +from abc import abstractmethod +import struct +from math import trunc +from simd import SIMD +from simd_arithmetic import SimdArithmeticCase +from test_assert import AssertReturn +from simd_float_op import FloatingPointOp, FloatingPointRoundingOp +from simd_integer_op import ArithmeticOp + + +class SimdConversionCase(SimdArithmeticCase): + BINARY_OPS = () + TEST_FUNC_TEMPLATE_HEADER = ";; Tests for {} trunc sat conversions from float.\n" + + def is_signed(self, op): + return op.endswith("_s") or op.endswith("_s_zero") + + def get_test_data(self, lane): + return [ + "0.0", + "-0.0", + "1.5", + "-1.5", + "1.9", + "2.0", + "-1.9", + "-2.0", + str(float(lane.max - 127)), + str(float(-(lane.max - 127))), + str(float(lane.max + 1)), + str(float(-(lane.max + 1))), + str(float(lane.max * 2)), + str(float(-(lane.max * 2))), + str(float(lane.max)), + str(float(-lane.max)), + str(float(lane.mask - 1)), + str(float(lane.mask)), + str(float(lane.mask + 1)), + "0x1p-149", + "-0x1p-149", + "0x1p-126", + "-0x1p-126", + "0x1p-1", + "-0x1p-1", + "0x1p+0", + "-0x1p+0", + "0x1.19999ap+0", + "-0x1.19999ap+0", + "0x1.921fb6p+2", + "-0x1.921fb6p+2", + "0x1.fffffep+127", + "-0x1.fffffep+127", + "0x1.ccccccp-1", + "-0x1.ccccccp-1", + "0x1.fffffep-1", + "-0x1.fffffep-1", + "0x1.921fb6p+2", + "-0x1.921fb6p+2", + "0x1.fffffep+127", + "-0x1.fffffep+127", + "+inf", + "-inf", + "+nan", + "-nan", + "nan:0x444444", + "-nan:0x444444", + "42", + "-42", + "0123456792.0", + "01234567890.0", + ] + + def to_float_precision(self, value): + # Python supports double precision, so given an an input that cannot be + # precisely represented in f32, we need to round it. + return value + + @abstractmethod + def to_results(self, result: str): + # Subclasses can override this to set the shape of the results. This is + # useful if instructions zero top lanes. + pass + + 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 get_case_data(self): + test_data = [] + for op in self.UNARY_OPS: + op_name = "{}.{}".format(self.LANE_TYPE, op) + test_data.append(["#", op_name]) + + for operand in self.get_test_data(self.lane): + operand = str(operand) + if "nan" in operand: + test_data.append( + [op_name, [operand], "0", [self.SRC_LANE_TYPE, self.LANE_TYPE]] + ) + else: + result = self.conversion_op(op_name, operand) + results = self.to_results(result) + assert "nan" not in result + test_data.append( + [ + op_name, + [operand], + results, + [self.SRC_LANE_TYPE, self.LANE_TYPE], + ] + ) + + return test_data + + def gen_test_cases(self): + wast_filename = "../simd_{}_trunc_sat_{}.wast".format( + self.LANE_TYPE, self.SRC_LANE_TYPE + ) + with open(wast_filename, "w") as fp: + fp.write(self.get_all_cases()) + + def get_combine_cases(self): + return "" + + +class SimdI32x4TruncSatF32x4Case(SimdConversionCase): + LANE_TYPE = "i32x4" + SRC_LANE_TYPE = "f32x4" + UNARY_OPS = ("trunc_sat_f32x4_s", "trunc_sat_f32x4_u") + + def to_float_precision(self, value): + fop = FloatingPointOp() + return fop.to_single_precision(value) + + def to_results(self, value: str): + return [value] + + +class SimdI32x4TruncSatF64x2Case(SimdConversionCase): + LANE_TYPE = "i32x4" + SRC_LANE_TYPE = "f64x2" + UNARY_OPS = ("trunc_sat_f64x2_s_zero", "trunc_sat_f64x2_u_zero") + + def to_results(self, value: str): + return ["0", value] + + +def gen_test_cases(): + i32x4_trunc_sat = SimdI32x4TruncSatF32x4Case() + i32x4_trunc_sat.gen_test_cases() + i32x4_trunc_sat = SimdI32x4TruncSatF64x2Case() + i32x4_trunc_sat.gen_test_cases() + + +if __name__ == "__main__": + gen_test_cases() diff --git a/test/core/simd/meta/simd_integer_op.py b/test/core/simd/meta/simd_integer_op.py index 8f1d4d2f9..55272edaf 100644 --- a/test/core/simd/meta/simd_integer_op.py +++ b/test/core/simd/meta/simd_integer_op.py @@ -120,6 +120,12 @@ def unary_op(self, operand, lane): elif self.op == 'popcnt': result = self.get_valid_value(v, lane) return str(bin(result % lane.mod).count('1')) + elif self.op == 'sat_s': + # Don't call get_valid_value, it will truncate results. + return max(lane.min, min(v, lane.max)) + elif self.op == 'sat_u': + # Don't call get_valid_value, it will truncate results. + return max(0, min(v, lane.mask)) else: raise Exception('Unknown unary operation') diff --git a/test/core/simd/simd_conversions.wast b/test/core/simd/simd_conversions.wast index b24a6643e..404bfa01e 100644 --- a/test/core/simd/simd_conversions.wast +++ b/test/core/simd/simd_conversions.wast @@ -1,12 +1,6 @@ ;; Web Assembly SIMD-related type conversion tests (module - ;; Floating point to integer with saturation - (func (export "i32x4.trunc_sat_f32x4_s") (param v128) (result v128) - (i32x4.trunc_sat_f32x4_s (local.get 0))) - (func (export "i32x4.trunc_sat_f32x4_u") (param v128) (result v128) - (i32x4.trunc_sat_f32x4_u (local.get 0))) - ;; Integer to floating point (func (export "f32x4.convert_i32x4_s") (param v128) (result v128) (f32x4.convert_i32x4_s (local.get 0))) @@ -25,179 +19,6 @@ ) -;; Floating point to integer with saturation -;; i32x4.trunc_sat_f32x4_s - -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0.0 0.0 0.0 0.0)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0.0 -0.0 -0.0 -0.0)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 1.5 1.5 1.5 1.5)) - (v128.const i32x4 1 1 1 1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -1.5 -1.5 -1.5 -1.5)) - (v128.const i32x4 -1 -1 -1 -1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 1.9 1.9 1.9 1.9)) - (v128.const i32x4 1 1 1 1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 2.0 2.0 2.0 2.0)) - (v128.const i32x4 2 2 2 2)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -1.9 -1.9 -1.9 -1.9)) - (v128.const i32x4 -1 -1 -1 -1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -2.0 -2.0 -2.0 -2.0)) - (v128.const i32x4 -2 -2 -2 -2)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 2147483520.0 2147483520.0 2147483520.0 2147483520.0)) - (v128.const i32x4 2147483520 2147483520 2147483520 2147483520)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -2147483520.0 -2147483520.0 -2147483520.0 -2147483520.0)) - (v128.const i32x4 -2147483520 -2147483520 -2147483520 -2147483520)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 2147483648.0 2147483648.0 2147483648.0 2147483648.0)) - (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -2147483648.0 -2147483648.0 -2147483648.0 -2147483648.0)) - (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 3000000000.0 3000000000.0 3000000000.0 3000000000.0)) - (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -3000000000.0 -3000000000.0 -3000000000.0 -3000000000.0)) - (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 2147483647.0 2147483647.0 2147483647.0 2147483647.0)) - (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -2147483647.0 -2147483647.0 -2147483647.0 -2147483647.0)) - (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1p-149 0x1p-149 0x1p-149 0x1p-149)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1p-149 -0x1p-149 -0x1p-149 -0x1p-149)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1p-126 0x1p-126 0x1p-126 0x1p-126)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1p-126 -0x1p-126 -0x1p-126 -0x1p-126)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1p-1 0x1p-1 0x1p-1 0x1p-1)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1p-1 -0x1p-1 -0x1p-1 -0x1p-1)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1p+0 0x1p+0 0x1p+0 0x1p+0)) - (v128.const i32x4 1 1 1 1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1p+0 -0x1p+0 -0x1p+0 -0x1p+0)) - (v128.const i32x4 -1 -1 -1 -1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.19999ap+0 0x1.19999ap+0 0x1.19999ap+0 0x1.19999ap+0)) - (v128.const i32x4 1 1 1 1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.19999ap+0 -0x1.19999ap+0 -0x1.19999ap+0 -0x1.19999ap+0)) - (v128.const i32x4 -1 -1 -1 -1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2)) - (v128.const i32x4 6 6 6 6)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2)) - (v128.const i32x4 -6 -6 -6 -6)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127)) - (v128.const i32x4 0x7fffffff 0x7fffffff 0x7fffffff 0x7fffffff)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127)) - (v128.const i32x4 0x80000000 0x80000000 0x80000000 0x80000000)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 +inf +inf +inf +inf)) - (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -inf -inf -inf -inf)) - (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 +nan +nan +nan +nan)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -nan -nan -nan -nan)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 nan:0x444444 nan:0x444444 nan:0x444444 nan:0x444444)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -nan:0x444444 -nan:0x444444 -nan:0x444444 -nan:0x444444)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 42 nan inf -inf)) - (v128.const i32x4 42 0 2147483647 -2147483648)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -42 3.14 nan inf)) - (v128.const i32x4 -42 3 0 2147483647)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0123456792.0 0123456792.0 0123456792.0 0123456792.0)) - (v128.const i32x4 123456792 123456792 123456792 123456792)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 01234567890.0 01234567890.0 01234567890.0 01234567890.0)) - (v128.const i32x4 0x49960300 0x49960300 0x49960300 0x49960300)) -;; i32x4.trunc_sat_f32x4_u - -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0.0 0.0 0.0 0.0)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0.0 -0.0 -0.0 -0.0)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 1.5 1.5 1.5 1.5)) - (v128.const i32x4 1 1 1 1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -1.5 -1.5 -1.5 -1.5)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 1.9 1.9 1.9 1.9)) - (v128.const i32x4 1 1 1 1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 2.0 2.0 2.0 2.0)) - (v128.const i32x4 2 2 2 2)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -1.9 -1.9 -1.9 -1.9)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -2.0 -2.0 -2.0 -2.0)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 2147483648.0 2147483648.0 2147483648.0 2147483648.0)) - (v128.const i32x4 2147483648 2147483648 2147483648 2147483648)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -2147483648.0 -2147483648.0 -2147483648.0 -2147483648.0)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 3000000000.0 3000000000.0 3000000000.0 3000000000.0)) - (v128.const i32x4 3000000000 3000000000 3000000000 3000000000)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -3000000000.0 -3000000000.0 -3000000000.0 -3000000000.0)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 2147483647.0 2147483647.0 2147483647.0 2147483647.0)) - (v128.const i32x4 2147483648 2147483648 2147483648 2147483648)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 4294967295.0 4294967295.0 4294967295.0 4294967295.0)) - (v128.const i32x4 0xffffffff 0xffffffff 0xffffffff 0xffffffff)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 4294967296.0 4294967296.0 4294967296.0 4294967296.0)) - (v128.const i32x4 0xffffffff 0xffffffff 0xffffffff 0xffffffff)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 4294967040.0 4294967040.0 4294967040.0 4294967040.0)) - (v128.const i32x4 -256 -256 -256 -256)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1p-149 0x1p-149 0x1p-149 0x1p-149)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1p-149 -0x1p-149 -0x1p-149 -0x1p-149)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1p-126 0x1p-126 0x1p-126 0x1p-126)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1p-126 -0x1p-126 -0x1p-126 -0x1p-126)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1p-1 0x1p-1 0x1p-1 0x1p-1)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1p-1 -0x1p-1 -0x1p-1 -0x1p-1)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1p+0 0x1p+0 0x1p+0 0x1p+0)) - (v128.const i32x4 1 1 1 1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1p+0 -0x1p+0 -0x1p+0 -0x1p+0)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.19999ap+0 0x1.19999ap+0 0x1.19999ap+0 0x1.19999ap+0)) - (v128.const i32x4 1 1 1 1)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.19999ap+0 -0x1.19999ap+0 -0x1.19999ap+0 -0x1.19999ap+0)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.ccccccp-1 0x1.ccccccp-1 0x1.ccccccp-1 0x1.ccccccp-1)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.ccccccp-1 -0x1.ccccccp-1 -0x1.ccccccp-1 -0x1.ccccccp-1)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.fffffep-1 0x1.fffffep-1 0x1.fffffep-1 0x1.fffffep-1)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.fffffep-1 -0x1.fffffep-1 -0x1.fffffep-1 -0x1.fffffep-1)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2)) - (v128.const i32x4 6 6 6 6)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127)) - (v128.const i32x4 0xffffffff 0xffffffff 0xffffffff 0xffffffff)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 +nan +nan +nan +nan)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -nan -nan -nan -nan)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 +inf +inf +inf +inf)) - (v128.const i32x4 0xffffffff 0xffffffff 0xffffffff 0xffffffff)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -inf -inf -inf -inf)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 nan:0x444444 nan:0x444444 nan:0x444444 nan:0x444444)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -nan:0x444444 -nan:0x444444 -nan:0x444444 -nan:0x444444)) - (v128.const i32x4 0 0 0 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 42 nan inf -inf)) - (v128.const i32x4 42 0 0xffffffff 0)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -42 3.14 nan inf)) - (v128.const i32x4 0 3 0 0xffffffff)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0123456792.0 0123456792.0 0123456792.0 0123456792.0)) - (v128.const i32x4 123456792 123456792 123456792 123456792)) -(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0123456789.0 -0123456789.0 -0123456789.0 -0123456789.0)) - (v128.const i32x4 0 0 0 0)) ;; Integer to floating point ;; f32x4.convert_i32x4_s @@ -691,10 +512,6 @@ ;; Type mismatch -(assert_invalid (module (func (result v128) (i32x4.trunc_sat_f32x4_s (i32.const 0)))) "type mismatch") -(assert_invalid (module (func (result v128) (i32x4.trunc_sat_f32x4_s (i64.const 0)))) "type mismatch") -(assert_invalid (module (func (result v128) (i32x4.trunc_sat_f32x4_u (i32.const 0)))) "type mismatch") -(assert_invalid (module (func (result v128) (i32x4.trunc_sat_f32x4_u (i64.const 0)))) "type mismatch") (assert_invalid (module (func (result v128) (f32x4.convert_i32x4_s (i32.const 0)))) "type mismatch") (assert_invalid (module (func (result v128) (f32x4.convert_i32x4_s (i64.const 0)))) "type mismatch") (assert_invalid (module (func (result v128) (f32x4.convert_i32x4_u (i32.const 0)))) "type mismatch") @@ -813,22 +630,6 @@ ;; Test operation with empty argument -(assert_invalid - (module - (func $i32x4.trunc_sat_f32x4_s-arg-empty (result v128) - (i32x4.trunc_sat_f32x4_s) - ) - ) - "type mismatch" -) -(assert_invalid - (module - (func $i32x4.trunc_sat_f32x4_u-arg-empty (result v128) - (i32x4.trunc_sat_f32x4_u) - ) - ) - "type mismatch" -) (assert_invalid (module (func $f32x4.convert_i32x4_s-arg-empty (result v128) diff --git a/test/core/simd/simd_i32x4_trunc_sat_f32x4.wast b/test/core/simd/simd_i32x4_trunc_sat_f32x4.wast new file mode 100644 index 000000000..40af590f5 --- /dev/null +++ b/test/core/simd/simd_i32x4_trunc_sat_f32x4.wast @@ -0,0 +1,239 @@ +;; Tests for i32x4 trunc sat conversions from float. + +(module + (func (export "i32x4.trunc_sat_f32x4_s") (param v128) (result v128) (i32x4.trunc_sat_f32x4_s (local.get 0))) + (func (export "i32x4.trunc_sat_f32x4_u") (param v128) (result v128) (i32x4.trunc_sat_f32x4_u (local.get 0))) +) + + +;; i32x4.trunc_sat_f32x4_s +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0.0 0.0 0.0 0.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0.0 -0.0 -0.0 -0.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 1.5 1.5 1.5 1.5)) + (v128.const i32x4 1 1 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -1.5 -1.5 -1.5 -1.5)) + (v128.const i32x4 -1 -1 -1 -1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 1.9 1.9 1.9 1.9)) + (v128.const i32x4 1 1 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 2.0 2.0 2.0 2.0)) + (v128.const i32x4 2 2 2 2)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -1.9 -1.9 -1.9 -1.9)) + (v128.const i32x4 -1 -1 -1 -1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -2.0 -2.0 -2.0 -2.0)) + (v128.const i32x4 -2 -2 -2 -2)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 2147483520.0 2147483520.0 2147483520.0 2147483520.0)) + (v128.const i32x4 2147483520 2147483520 2147483520 2147483520)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -2147483520.0 -2147483520.0 -2147483520.0 -2147483520.0)) + (v128.const i32x4 -2147483520 -2147483520 -2147483520 -2147483520)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 2147483648.0 2147483648.0 2147483648.0 2147483648.0)) + (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -2147483648.0 -2147483648.0 -2147483648.0 -2147483648.0)) + (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 4294967294.0 4294967294.0 4294967294.0 4294967294.0)) + (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -4294967294.0 -4294967294.0 -4294967294.0 -4294967294.0)) + (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 2147483647.0 2147483647.0 2147483647.0 2147483647.0)) + (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -2147483647.0 -2147483647.0 -2147483647.0 -2147483647.0)) + (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 4294967294.0 4294967294.0 4294967294.0 4294967294.0)) + (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 4294967295.0 4294967295.0 4294967295.0 4294967295.0)) + (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 4294967296.0 4294967296.0 4294967296.0 4294967296.0)) + (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1p-149 0x1p-149 0x1p-149 0x1p-149)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1p-149 -0x1p-149 -0x1p-149 -0x1p-149)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1p-126 0x1p-126 0x1p-126 0x1p-126)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1p-126 -0x1p-126 -0x1p-126 -0x1p-126)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1p-1 0x1p-1 0x1p-1 0x1p-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1p-1 -0x1p-1 -0x1p-1 -0x1p-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1p+0 0x1p+0 0x1p+0 0x1p+0)) + (v128.const i32x4 1 1 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1p+0 -0x1p+0 -0x1p+0 -0x1p+0)) + (v128.const i32x4 -1 -1 -1 -1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.19999ap+0 0x1.19999ap+0 0x1.19999ap+0 0x1.19999ap+0)) + (v128.const i32x4 1 1 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.19999ap+0 -0x1.19999ap+0 -0x1.19999ap+0 -0x1.19999ap+0)) + (v128.const i32x4 -1 -1 -1 -1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2)) + (v128.const i32x4 6 6 6 6)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2)) + (v128.const i32x4 -6 -6 -6 -6)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127)) + (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127)) + (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.ccccccp-1 0x1.ccccccp-1 0x1.ccccccp-1 0x1.ccccccp-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.ccccccp-1 -0x1.ccccccp-1 -0x1.ccccccp-1 -0x1.ccccccp-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.fffffep-1 0x1.fffffep-1 0x1.fffffep-1 0x1.fffffep-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.fffffep-1 -0x1.fffffep-1 -0x1.fffffep-1 -0x1.fffffep-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2)) + (v128.const i32x4 6 6 6 6)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2)) + (v128.const i32x4 -6 -6 -6 -6)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127)) + (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127)) + (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 +inf +inf +inf +inf)) + (v128.const i32x4 2147483647 2147483647 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -inf -inf -inf -inf)) + (v128.const i32x4 -2147483648 -2147483648 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 +nan +nan +nan +nan)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -nan -nan -nan -nan)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 nan:0x444444 nan:0x444444 nan:0x444444 nan:0x444444)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -nan:0x444444 -nan:0x444444 -nan:0x444444 -nan:0x444444)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 42 42 42 42)) + (v128.const i32x4 42 42 42 42)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 -42 -42 -42 -42)) + (v128.const i32x4 -42 -42 -42 -42)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 0123456792.0 0123456792.0 0123456792.0 0123456792.0)) + (v128.const i32x4 123456792 123456792 123456792 123456792)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_s" (v128.const f32x4 01234567890.0 01234567890.0 01234567890.0 01234567890.0)) + (v128.const i32x4 1234567936 1234567936 1234567936 1234567936)) + +;; i32x4.trunc_sat_f32x4_u +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0.0 0.0 0.0 0.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0.0 -0.0 -0.0 -0.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 1.5 1.5 1.5 1.5)) + (v128.const i32x4 1 1 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -1.5 -1.5 -1.5 -1.5)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 1.9 1.9 1.9 1.9)) + (v128.const i32x4 1 1 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 2.0 2.0 2.0 2.0)) + (v128.const i32x4 2 2 2 2)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -1.9 -1.9 -1.9 -1.9)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -2.0 -2.0 -2.0 -2.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 2147483520.0 2147483520.0 2147483520.0 2147483520.0)) + (v128.const i32x4 2147483520 2147483520 2147483520 2147483520)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -2147483520.0 -2147483520.0 -2147483520.0 -2147483520.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 2147483648.0 2147483648.0 2147483648.0 2147483648.0)) + (v128.const i32x4 2147483648 2147483648 2147483648 2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -2147483648.0 -2147483648.0 -2147483648.0 -2147483648.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 4294967294.0 4294967294.0 4294967294.0 4294967294.0)) + (v128.const i32x4 4294967295 4294967295 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -4294967294.0 -4294967294.0 -4294967294.0 -4294967294.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 2147483647.0 2147483647.0 2147483647.0 2147483647.0)) + (v128.const i32x4 2147483648 2147483648 2147483648 2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -2147483647.0 -2147483647.0 -2147483647.0 -2147483647.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 4294967294.0 4294967294.0 4294967294.0 4294967294.0)) + (v128.const i32x4 4294967295 4294967295 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 4294967295.0 4294967295.0 4294967295.0 4294967295.0)) + (v128.const i32x4 4294967295 4294967295 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 4294967296.0 4294967296.0 4294967296.0 4294967296.0)) + (v128.const i32x4 4294967295 4294967295 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1p-149 0x1p-149 0x1p-149 0x1p-149)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1p-149 -0x1p-149 -0x1p-149 -0x1p-149)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1p-126 0x1p-126 0x1p-126 0x1p-126)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1p-126 -0x1p-126 -0x1p-126 -0x1p-126)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1p-1 0x1p-1 0x1p-1 0x1p-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1p-1 -0x1p-1 -0x1p-1 -0x1p-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1p+0 0x1p+0 0x1p+0 0x1p+0)) + (v128.const i32x4 1 1 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1p+0 -0x1p+0 -0x1p+0 -0x1p+0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.19999ap+0 0x1.19999ap+0 0x1.19999ap+0 0x1.19999ap+0)) + (v128.const i32x4 1 1 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.19999ap+0 -0x1.19999ap+0 -0x1.19999ap+0 -0x1.19999ap+0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2)) + (v128.const i32x4 6 6 6 6)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127)) + (v128.const i32x4 4294967295 4294967295 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.ccccccp-1 0x1.ccccccp-1 0x1.ccccccp-1 0x1.ccccccp-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.ccccccp-1 -0x1.ccccccp-1 -0x1.ccccccp-1 -0x1.ccccccp-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.fffffep-1 0x1.fffffep-1 0x1.fffffep-1 0x1.fffffep-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.fffffep-1 -0x1.fffffep-1 -0x1.fffffep-1 -0x1.fffffep-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2 0x1.921fb6p+2)) + (v128.const i32x4 6 6 6 6)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2 -0x1.921fb6p+2)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127 0x1.fffffep+127)) + (v128.const i32x4 4294967295 4294967295 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127 -0x1.fffffep+127)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 +inf +inf +inf +inf)) + (v128.const i32x4 4294967295 4294967295 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -inf -inf -inf -inf)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 +nan +nan +nan +nan)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -nan -nan -nan -nan)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 nan:0x444444 nan:0x444444 nan:0x444444 nan:0x444444)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -nan:0x444444 -nan:0x444444 -nan:0x444444 -nan:0x444444)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 42 42 42 42)) + (v128.const i32x4 42 42 42 42)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 -42 -42 -42 -42)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 0123456792.0 0123456792.0 0123456792.0 0123456792.0)) + (v128.const i32x4 123456792 123456792 123456792 123456792)) +(assert_return (invoke "i32x4.trunc_sat_f32x4_u" (v128.const f32x4 01234567890.0 01234567890.0 01234567890.0 01234567890.0)) + (v128.const i32x4 1234567936 1234567936 1234567936 1234567936)) + +;; type check +(assert_invalid (module (func (result v128) (i32x4.trunc_sat_f32x4_s (i32.const 0)))) "type mismatch") +(assert_invalid (module (func (result v128) (i32x4.trunc_sat_f32x4_u (i32.const 0)))) "type mismatch") + +;; Test operation with empty argument + +(assert_invalid + (module + (func $i32x4.trunc_sat_f32x4_s-arg-empty (result v128) + (i32x4.trunc_sat_f32x4_s) + ) + ) + "type mismatch" +) +(assert_invalid + (module + (func $i32x4.trunc_sat_f32x4_u-arg-empty (result v128) + (i32x4.trunc_sat_f32x4_u) + ) + ) + "type mismatch" +) + diff --git a/test/core/simd/simd_i32x4_trunc_sat_f64x2.wast b/test/core/simd/simd_i32x4_trunc_sat_f64x2.wast new file mode 100644 index 000000000..d232bb075 --- /dev/null +++ b/test/core/simd/simd_i32x4_trunc_sat_f64x2.wast @@ -0,0 +1,239 @@ +;; Tests for i32x4 trunc sat conversions from float. + +(module + (func (export "i32x4.trunc_sat_f64x2_s_zero") (param v128) (result v128) (i32x4.trunc_sat_f64x2_s_zero (local.get 0))) + (func (export "i32x4.trunc_sat_f64x2_u_zero") (param v128) (result v128) (i32x4.trunc_sat_f64x2_u_zero (local.get 0))) +) + + +;; i32x4.trunc_sat_f64x2_s_zero +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0.0 0.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0.0 -0.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 1.5 1.5)) + (v128.const i32x4 0 0 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -1.5 -1.5)) + (v128.const i32x4 0 0 -1 -1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 1.9 1.9)) + (v128.const i32x4 0 0 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 2.0 2.0)) + (v128.const i32x4 0 0 2 2)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -1.9 -1.9)) + (v128.const i32x4 0 0 -1 -1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -2.0 -2.0)) + (v128.const i32x4 0 0 -2 -2)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 2147483520.0 2147483520.0)) + (v128.const i32x4 0 0 2147483520 2147483520)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -2147483520.0 -2147483520.0)) + (v128.const i32x4 0 0 -2147483520 -2147483520)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 2147483648.0 2147483648.0)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -2147483648.0 -2147483648.0)) + (v128.const i32x4 0 0 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 4294967294.0 4294967294.0)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -4294967294.0 -4294967294.0)) + (v128.const i32x4 0 0 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 2147483647.0 2147483647.0)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -2147483647.0 -2147483647.0)) + (v128.const i32x4 0 0 -2147483647 -2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 4294967294.0 4294967294.0)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 4294967295.0 4294967295.0)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 4294967296.0 4294967296.0)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1p-149 0x1p-149)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1p-149 -0x1p-149)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1p-126 0x1p-126)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1p-126 -0x1p-126)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1p-1 0x1p-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1p-1 -0x1p-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1p+0 0x1p+0)) + (v128.const i32x4 0 0 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1p+0 -0x1p+0)) + (v128.const i32x4 0 0 -1 -1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1.19999ap+0 0x1.19999ap+0)) + (v128.const i32x4 0 0 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1.19999ap+0 -0x1.19999ap+0)) + (v128.const i32x4 0 0 -1 -1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1.921fb6p+2 0x1.921fb6p+2)) + (v128.const i32x4 0 0 6 6)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1.921fb6p+2 -0x1.921fb6p+2)) + (v128.const i32x4 0 0 -6 -6)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1.fffffep+127 0x1.fffffep+127)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1.fffffep+127 -0x1.fffffep+127)) + (v128.const i32x4 0 0 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1.ccccccp-1 0x1.ccccccp-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1.ccccccp-1 -0x1.ccccccp-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1.fffffep-1 0x1.fffffep-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1.fffffep-1 -0x1.fffffep-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1.921fb6p+2 0x1.921fb6p+2)) + (v128.const i32x4 0 0 6 6)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1.921fb6p+2 -0x1.921fb6p+2)) + (v128.const i32x4 0 0 -6 -6)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0x1.fffffep+127 0x1.fffffep+127)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -0x1.fffffep+127 -0x1.fffffep+127)) + (v128.const i32x4 0 0 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 +inf +inf)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -inf -inf)) + (v128.const i32x4 0 0 -2147483648 -2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 +nan +nan)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -nan -nan)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 nan:0x444444 nan:0x444444)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -nan:0x444444 -nan:0x444444)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 42 42)) + (v128.const i32x4 0 0 42 42)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 -42 -42)) + (v128.const i32x4 0 0 -42 -42)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 0123456792.0 0123456792.0)) + (v128.const i32x4 0 0 123456792 123456792)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_s_zero" (v128.const f64x2 01234567890.0 01234567890.0)) + (v128.const i32x4 0 0 1234567890 1234567890)) + +;; i32x4.trunc_sat_f64x2_u_zero +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0.0 0.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0.0 -0.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 1.5 1.5)) + (v128.const i32x4 0 0 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -1.5 -1.5)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 1.9 1.9)) + (v128.const i32x4 0 0 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 2.0 2.0)) + (v128.const i32x4 0 0 2 2)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -1.9 -1.9)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -2.0 -2.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 2147483520.0 2147483520.0)) + (v128.const i32x4 0 0 2147483520 2147483520)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -2147483520.0 -2147483520.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 2147483648.0 2147483648.0)) + (v128.const i32x4 0 0 2147483648 2147483648)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -2147483648.0 -2147483648.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 4294967294.0 4294967294.0)) + (v128.const i32x4 0 0 4294967294 4294967294)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -4294967294.0 -4294967294.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 2147483647.0 2147483647.0)) + (v128.const i32x4 0 0 2147483647 2147483647)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -2147483647.0 -2147483647.0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 4294967294.0 4294967294.0)) + (v128.const i32x4 0 0 4294967294 4294967294)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 4294967295.0 4294967295.0)) + (v128.const i32x4 0 0 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 4294967296.0 4294967296.0)) + (v128.const i32x4 0 0 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1p-149 0x1p-149)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1p-149 -0x1p-149)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1p-126 0x1p-126)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1p-126 -0x1p-126)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1p-1 0x1p-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1p-1 -0x1p-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1p+0 0x1p+0)) + (v128.const i32x4 0 0 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1p+0 -0x1p+0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1.19999ap+0 0x1.19999ap+0)) + (v128.const i32x4 0 0 1 1)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1.19999ap+0 -0x1.19999ap+0)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1.921fb6p+2 0x1.921fb6p+2)) + (v128.const i32x4 0 0 6 6)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1.921fb6p+2 -0x1.921fb6p+2)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1.fffffep+127 0x1.fffffep+127)) + (v128.const i32x4 0 0 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1.fffffep+127 -0x1.fffffep+127)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1.ccccccp-1 0x1.ccccccp-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1.ccccccp-1 -0x1.ccccccp-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1.fffffep-1 0x1.fffffep-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1.fffffep-1 -0x1.fffffep-1)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1.921fb6p+2 0x1.921fb6p+2)) + (v128.const i32x4 0 0 6 6)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1.921fb6p+2 -0x1.921fb6p+2)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0x1.fffffep+127 0x1.fffffep+127)) + (v128.const i32x4 0 0 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -0x1.fffffep+127 -0x1.fffffep+127)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 +inf +inf)) + (v128.const i32x4 0 0 4294967295 4294967295)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -inf -inf)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 +nan +nan)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -nan -nan)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 nan:0x444444 nan:0x444444)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -nan:0x444444 -nan:0x444444)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 42 42)) + (v128.const i32x4 0 0 42 42)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 -42 -42)) + (v128.const i32x4 0 0 0 0)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 0123456792.0 0123456792.0)) + (v128.const i32x4 0 0 123456792 123456792)) +(assert_return (invoke "i32x4.trunc_sat_f64x2_u_zero" (v128.const f64x2 01234567890.0 01234567890.0)) + (v128.const i32x4 0 0 1234567890 1234567890)) + +;; type check +(assert_invalid (module (func (result v128) (i32x4.trunc_sat_f64x2_s_zero (i32.const 0)))) "type mismatch") +(assert_invalid (module (func (result v128) (i32x4.trunc_sat_f64x2_u_zero (i32.const 0)))) "type mismatch") + +;; Test operation with empty argument + +(assert_invalid + (module + (func $i32x4.trunc_sat_f64x2_s_zero-arg-empty (result v128) + (i32x4.trunc_sat_f64x2_s_zero) + ) + ) + "type mismatch" +) +(assert_invalid + (module + (func $i32x4.trunc_sat_f64x2_u_zero-arg-empty (result v128) + (i32x4.trunc_sat_f64x2_u_zero) + ) + ) + "type mismatch" +) + From 6bd1fc44ba445aa343536d88e78dc729c4723b96 Mon Sep 17 00:00:00 2001 From: Ng Zhi An Date: Fri, 12 Feb 2021 14:11:39 -0800 Subject: [PATCH 2/3] Add encode/decode --- interpreter/binary/decode.ml | 2 ++ interpreter/binary/encode.ml | 2 ++ interpreter/text/arrange.ml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/interpreter/binary/decode.ml b/interpreter/binary/decode.ml index 0ff11197e..321db6146 100644 --- a/interpreter/binary/decode.ml +++ b/interpreter/binary/decode.ml @@ -304,6 +304,8 @@ let simd_prefix s = | 0x50l -> v128_or | 0x51l -> v128_xor | 0x52l -> v128_bitselect + | 0x55l -> i32x4_trunc_sat_f64x2_s_zero + | 0x56l -> i32x4_trunc_sat_f64x2_u_zero | 0x58l -> let a, o = memop s in let lane = u8 s in diff --git a/interpreter/binary/encode.ml b/interpreter/binary/encode.ml index 56e3d9370..88981d1db 100644 --- a/interpreter/binary/encode.ml +++ b/interpreter/binary/encode.ml @@ -381,6 +381,8 @@ let encode m = | Unary (V128 V128Op.(F64x2 Sqrt)) -> simd_op 0xefl | Unary (V128 V128Op.(I32x4 TruncSatF32x4S)) -> simd_op 0xf8l | Unary (V128 V128Op.(I32x4 TruncSatF32x4U)) -> simd_op 0xf9l + | Unary (V128 V128Op.(I32x4 TruncSatF64x2SZero)) -> simd_op 0x55l + | Unary (V128 V128Op.(I32x4 TruncSatF64x2UZero)) -> simd_op 0x56l | Unary (V128 V128Op.(F32x4 ConvertI32x4S)) -> simd_op 0xfal | Unary (V128 V128Op.(F32x4 ConvertI32x4U)) -> simd_op 0xfbl | Unary (V128 _) -> failwith "unimplemented V128 Unary op" diff --git a/interpreter/text/arrange.ml b/interpreter/text/arrange.ml index 73422b6b0..0de67644c 100644 --- a/interpreter/text/arrange.ml +++ b/interpreter/text/arrange.ml @@ -217,6 +217,8 @@ struct | I32x4 WidenHighU -> "i32x4.widen_high_i16x8_u" | I32x4 TruncSatF32x4S -> "i32x4.trunc_sat_f32x4_s" | I32x4 TruncSatF32x4U -> "i32x4.trunc_sat_f32x4_u" + | I32x4 TruncSatF64x2SZero -> "i32x4.trunc_sat_f64x2_s_zero" + | I32x4 TruncSatF64x2UZero -> "i32x4.trunc_sat_f64x2_u_zero" | I64x2 Abs -> "i64x2.abs" | I64x2 Neg -> "i64x2.neg" | I64x2 WidenLowS -> "i64x2.widen_low_i32x4_s" From 0846c437244801fc4bcccc14cda6fd296b5ac062 Mon Sep 17 00:00:00 2001 From: Ng Zhi An Date: Wed, 17 Feb 2021 10:03:24 -0800 Subject: [PATCH 3/3] Update interpreter/exec/simd.ml Co-authored-by: Andreas Rossberg --- interpreter/exec/simd.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interpreter/exec/simd.ml b/interpreter/exec/simd.ml index 892ee24d3..9209aaa2d 100644 --- a/interpreter/exec/simd.ml +++ b/interpreter/exec/simd.ml @@ -446,7 +446,8 @@ struct let trunc_sat_f32x4_s = convert I32_convert.trunc_sat_f32_s let trunc_sat_f32x4_u = convert I32_convert.trunc_sat_f32_u - let convert_zero f v = Rep.of_i32x4 (I32.zero :: I32.zero :: (List.map f (Rep.to_f64x2 v))) + let convert_zero f v = + Rep.(of_i32x4 I32.(zero :: zero :: (List.map f (to_f64x2 v))) let trunc_sat_f64x2_s_zero = convert_zero I32_convert.trunc_sat_f64_s let trunc_sat_f64x2_u_zero = convert_zero I32_convert.trunc_sat_f64_u