Skip to content

Commit

Permalink
[simd/jit]: Implement v128.const (#83 from haoyu-zc/jit-const)
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer authored Jul 21, 2023
2 parents 301e52a + ba1643c commit 42891db
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 33 deletions.
5 changes: 5 additions & 0 deletions src/engine/compiler/SinglePassCompiler.v3
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,11 @@ class SinglePassCompiler(xenv: SpcExecEnv, masm: MacroAssembler, regAlloc: RegAl
state.push(KIND_F64 | IN_REG, reg, 0);
}
}
def visit_V128_CONST(low: u64, high: u64) {
var reg = allocRegTos(ValueKind.V128);
masm.emit_mov_r_q(reg, low, high);
state.push(KIND_V128 | IN_REG, reg, 0);
}

def visit_REF_NULL(ht_index: u31) {
state.push(KIND_REF | IS_CONST, NO_REG, 0);
Expand Down
7 changes: 7 additions & 0 deletions src/engine/x86-64/X86_64MacroAssembler.v3
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ class X86_64MacroAssembler extends MacroAssembler {
asm.movq_r_l(scratch, long.view(val));
asm.movq_s_r(X(reg), scratch);
}
def emit_mov_r_q(reg: Reg, low: u64, high: u64) {
var x = X(reg);
asm.movq_r_l(scratch, long.view(low));
asm.pinsrq_s_r_i(x, scratch, 0);
asm.movq_r_l(scratch, long.view(high));
asm.pinsrq_s_r_i(x, scratch, 1);
}
def emit_mov_r_trap(reg: Reg, reason: TrapReason) {
var ptr = Pointer.atObject(Execute.trapObjects[reason.tag]);
asm.movq_r_l(G(reg), ptr - Pointer.NULL);
Expand Down
26 changes: 26 additions & 0 deletions test/regress/simd/simd_f32x4_arith.bin.wast
Original file line number Diff line number Diff line change
Expand Up @@ -13935,6 +13935,32 @@
-0x1.2345_68p+37
)
)
(module binary
"\00\61\73\6d\01\00\00\00\01\85\80\80\80\00\01\60"
"\00\01\7b\03\84\80\80\80\00\03\00\00\00\07\ba\80"
"\80\80\00\03\10\66\33\32\78\34\5f\73\71\72\74\5f"
"\61\72\69\74\68\00\00\10\66\33\32\78\34\5f\73\71"
"\72\74\5f\63\61\6e\6f\6e\00\01\10\66\33\32\78\34"
"\5f\73\71\72\74\5f\6d\69\78\65\64\00\02\0a\d5\80"
"\80\80\00\03\97\80\80\80\00\00\fd\0c\00\00\a0\7f"
"\00\00\a0\ff\00\00\80\41\00\00\c8\41\fd\e3\01\0b"
"\97\80\80\80\00\00\fd\0c\00\00\80\bf\00\00\c0\7f"
"\00\00\80\40\00\00\10\41\fd\e3\01\0b\97\80\80\80"
"\00\00\fd\0c\00\00\80\ff\00\00\a0\7f\00\00\10\42"
"\00\00\44\42\fd\e3\01\0b"
)
(assert_return
(invoke "f32x4_sqrt_arith")
(v128.const f32x4 nan:arithmetic nan:arithmetic 0x1p+2 0x1.4p+2)
)
(assert_return
(invoke "f32x4_sqrt_canon")
(v128.const f32x4 nan:canonical nan:canonical 0x1p+1 0x1.8p+1)
)
(assert_return
(invoke "f32x4_sqrt_mixed")
(v128.const f32x4 nan:canonical nan:arithmetic 0x1.8p+2 0x1.cp+2)
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\85\80\80\80\00\01\60"
Expand Down
23 changes: 11 additions & 12 deletions test/regress/simd/simd_f32x4_arith.wast
Original file line number Diff line number Diff line change
Expand Up @@ -5277,20 +5277,19 @@


;; Mixed f32x4 tests when some lanes are NaNs
;; todo: uncomment this after jit:v128.const is implemented
;; (module
(module

;; (func (export "f32x4_sqrt_arith") (result v128)
;; (f32x4.sqrt (v128.const f32x4 nan:0x200000 -nan:0x200000 16.0 25.0)))
;; (func (export "f32x4_sqrt_canon") (result v128)
;; (f32x4.sqrt (v128.const f32x4 -1.0 nan 4.0 9.0)))
;; (func (export "f32x4_sqrt_mixed") (result v128)
;; (f32x4.sqrt (v128.const f32x4 -inf nan:0x200000 36.0 49.0)))
;; )
(func (export "f32x4_sqrt_arith") (result v128)
(f32x4.sqrt (v128.const f32x4 nan:0x200000 -nan:0x200000 16.0 25.0)))
(func (export "f32x4_sqrt_canon") (result v128)
(f32x4.sqrt (v128.const f32x4 -1.0 nan 4.0 9.0)))
(func (export "f32x4_sqrt_mixed") (result v128)
(f32x4.sqrt (v128.const f32x4 -inf nan:0x200000 36.0 49.0)))
)

;; (assert_return (invoke "f32x4_sqrt_arith") (v128.const f32x4 nan:arithmetic nan:arithmetic 4.0 5.0))
;; (assert_return (invoke "f32x4_sqrt_canon") (v128.const f32x4 nan:canonical nan:canonical 2.0 3.0))
;; (assert_return (invoke "f32x4_sqrt_mixed") (v128.const f32x4 nan:canonical nan:arithmetic 6.0 7.0))
(assert_return (invoke "f32x4_sqrt_arith") (v128.const f32x4 nan:arithmetic nan:arithmetic 4.0 5.0))
(assert_return (invoke "f32x4_sqrt_canon") (v128.const f32x4 nan:canonical nan:canonical 2.0 3.0))
(assert_return (invoke "f32x4_sqrt_mixed") (v128.const f32x4 nan:canonical nan:arithmetic 6.0 7.0))

;; type check
(assert_invalid (module (func (result v128) (f32x4.neg (i32.const 0)))) "type mismatch")
Expand Down
51 changes: 51 additions & 0 deletions test/regress/simd/simd_f64x2_arith.bin.wast
Original file line number Diff line number Diff line change
Expand Up @@ -12349,6 +12349,57 @@
)
(v128.const f64x2 -0x1.2345_6789_abcd_fp+61 -0x1.2345_6789_abcd_fp+61)
)
(module binary
"\00\61\73\6d\01\00\00\00\01\85\80\80\80\00\01\60"
"\00\01\7b\03\87\80\80\80\00\06\00\00\00\00\00\00"
"\07\ee\80\80\80\00\06\0f\66\36\34\78\32\5f\61\64"
"\64\5f\61\72\69\74\68\00\00\0f\66\36\34\78\32\5f"
"\64\69\76\5f\6d\69\78\65\64\00\01\0f\66\36\34\78"
"\32\5f\6d\75\6c\5f\6d\69\78\65\64\00\02\0f\66\36"
"\34\78\32\5f\6e\65\67\5f\63\61\6e\6f\6e\00\03\10"
"\66\36\34\78\32\5f\73\71\72\74\5f\63\61\6e\6f\6e"
"\00\04\0f\66\36\34\78\32\5f\73\75\62\5f\61\72\69"
"\74\68\00\05\0a\f1\81\80\80\00\06\a9\80\80\80\00"
"\00\fd\0c\00\00\00\00\00\00\f8\7f\00\00\00\00\00"
"\00\f0\3f\fd\0c\00\00\00\00\00\00\f8\7f\00\00\00"
"\00\00\00\f0\3f\fd\f0\01\0b\a9\80\80\80\00\00\fd"
"\0c\00\00\00\00\00\00\f8\7f\00\00\00\00\00\00\f0"
"\3f\fd\0c\00\00\00\00\00\00\00\40\00\00\00\00\00"
"\00\f8\ff\fd\f3\01\0b\a9\80\80\80\00\00\fd\0c\00"
"\00\00\00\00\00\f8\7f\00\00\00\00\00\00\f0\3f\fd"
"\0c\00\00\00\00\00\00\00\40\00\00\00\00\00\00\f8"
"\7f\fd\f2\01\0b\97\80\80\80\00\00\fd\0c\00\00\00"
"\00\00\00\f8\7f\00\00\00\00\00\00\f0\3f\fd\ed\01"
"\0b\97\80\80\80\00\00\fd\0c\00\00\00\00\00\00\10"
"\40\00\00\00\00\00\00\f8\ff\fd\ef\01\0b\a9\80\80"
"\80\00\00\fd\0c\00\00\00\00\00\00\f0\3f\00\00\00"
"\00\00\00\f0\bf\fd\0c\00\00\00\00\00\00\f8\ff\00"
"\00\00\00\00\00\f0\3f\fd\f1\01\0b"
)
(assert_return
(invoke "f64x2_add_arith")
(v128.const f64x2 nan:arithmetic 0x1p+1)
)
(assert_return
(invoke "f64x2_div_mixed")
(v128.const f64x2 nan:canonical nan:arithmetic)
)
(assert_return
(invoke "f64x2_mul_mixed")
(v128.const f64x2 nan:arithmetic nan:canonical)
)
(assert_return
(invoke "f64x2_neg_canon")
(v128.const f64x2 nan:canonical -0x1p+0)
)
(assert_return
(invoke "f64x2_sqrt_canon")
(v128.const f64x2 0x1p+1 nan:canonical)
)
(assert_return
(invoke "f64x2_sub_arith")
(v128.const f64x2 nan:canonical -0x1p+1)
)
(assert_invalid
(module binary
"\00\61\73\6d\01\00\00\00\01\85\80\80\80\00\01\60"
Expand Down
41 changes: 20 additions & 21 deletions test/regress/simd/simd_f64x2_arith.wast
Original file line number Diff line number Diff line change
Expand Up @@ -5276,28 +5276,27 @@
(v128.const f64x2 -0x1.23456789abcdfp+61 -0x1.23456789abcdfp+61))

;; Mixed f64x2 tests when some lanes are NaNs
;; todo: uncomment this after jit:v128.const is implemented
;; (module
;; (func (export "f64x2_add_arith") (result v128)
;; (f64x2.add (v128.const f64x2 nan:0x8000000000000 1.0) (v128.const f64x2 nan 1.0)))
;; (func (export "f64x2_div_mixed") (result v128)
;; (f64x2.div (v128.const f64x2 nan 1.0) (v128.const f64x2 2.0 -nan:0x8000000000000)))
;; (func (export "f64x2_mul_mixed") (result v128)
;; (f64x2.mul (v128.const f64x2 nan:0x8000000000000 1.0) (v128.const f64x2 2.0 nan)))
;; (func (export "f64x2_neg_canon") (result v128)
;; (f64x2.neg (v128.const f64x2 nan 1.0)))
;; (func (export "f64x2_sqrt_canon") (result v128)
;; (f64x2.sqrt (v128.const f64x2 4.0 -nan)))
;; (func (export "f64x2_sub_arith") (result v128)
;; (f64x2.sub (v128.const f64x2 1.0 -1.0) (v128.const f64x2 -nan 1.0)))
;; )
(module
(func (export "f64x2_add_arith") (result v128)
(f64x2.add (v128.const f64x2 nan:0x8000000000000 1.0) (v128.const f64x2 nan 1.0)))
(func (export "f64x2_div_mixed") (result v128)
(f64x2.div (v128.const f64x2 nan 1.0) (v128.const f64x2 2.0 -nan:0x8000000000000)))
(func (export "f64x2_mul_mixed") (result v128)
(f64x2.mul (v128.const f64x2 nan:0x8000000000000 1.0) (v128.const f64x2 2.0 nan)))
(func (export "f64x2_neg_canon") (result v128)
(f64x2.neg (v128.const f64x2 nan 1.0)))
(func (export "f64x2_sqrt_canon") (result v128)
(f64x2.sqrt (v128.const f64x2 4.0 -nan)))
(func (export "f64x2_sub_arith") (result v128)
(f64x2.sub (v128.const f64x2 1.0 -1.0) (v128.const f64x2 -nan 1.0)))
)

;; (assert_return (invoke "f64x2_add_arith") (v128.const f64x2 nan:arithmetic 2.0))
;; (assert_return (invoke "f64x2_div_mixed") (v128.const f64x2 nan:canonical nan:arithmetic))
;; (assert_return (invoke "f64x2_mul_mixed") (v128.const f64x2 nan:arithmetic nan:canonical))
;; (assert_return (invoke "f64x2_neg_canon") (v128.const f64x2 nan:canonical -1.0))
;; (assert_return (invoke "f64x2_sqrt_canon") (v128.const f64x2 2.0 nan:canonical))
;; (assert_return (invoke "f64x2_sub_arith") (v128.const f64x2 nan:canonical -2.0))
(assert_return (invoke "f64x2_add_arith") (v128.const f64x2 nan:arithmetic 2.0))
(assert_return (invoke "f64x2_div_mixed") (v128.const f64x2 nan:canonical nan:arithmetic))
(assert_return (invoke "f64x2_mul_mixed") (v128.const f64x2 nan:arithmetic nan:canonical))
(assert_return (invoke "f64x2_neg_canon") (v128.const f64x2 nan:canonical -1.0))
(assert_return (invoke "f64x2_sqrt_canon") (v128.const f64x2 2.0 nan:canonical))
(assert_return (invoke "f64x2_sub_arith") (v128.const f64x2 nan:canonical -2.0))

;; type check
(assert_invalid (module (func (result v128) (f64x2.neg (i64.const 0)))) "type mismatch")
Expand Down

0 comments on commit 42891db

Please sign in to comment.