Skip to content

Commit

Permalink
Fix float splat with immediate in JIT
Browse files Browse the repository at this point in the history
Signed-off-by: Zoltan Herczeg [email protected]
  • Loading branch information
zherczeg authored and clover2123 committed Nov 18, 2024
1 parent f8d10d7 commit ea09733
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/jit/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ struct JITArg {

void set(Operand* operand);

static bool isImm(Operand* operand)
{
return VARIABLE_TYPE(*operand) == Instruction::ConstPtr;
}

sljit_s32 arg;
sljit_sw argw;
};
Expand Down
10 changes: 10 additions & 0 deletions src/jit/SimdInl.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ static void emitSplatSIMD(sljit_compiler* compiler, Instruction* instr)
default:
ASSERT(instr->opcode() == ByteCode::F64X2SplatOpcode);
type = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64 | SLJIT_SIMD_FLOAT;
#if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
if (JITArg::isImm(operands)) {
type = SLJIT_SIMD_REG_128 | SLJIT_SIMD_ELEM_64;
}
#endif /* SLJIT_32BIT_ARCHITECTURE */
break;
}

Expand All @@ -241,6 +246,11 @@ static void emitSplatSIMD(sljit_compiler* compiler, Instruction* instr)
} else {
#endif /* SLJIT_32BIT_ARCHITECTURE */
args[0].set(operands);

if (SLJIT_IS_IMM(args[0].arg)) {
type &= ~SLJIT_SIMD_FLOAT;
}

sljit_emit_simd_replicate(compiler, type, dstReg, args[0].arg, args[0].argw);
#if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
}
Expand Down
16 changes: 16 additions & 0 deletions test/jit/splat.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(module
(table $t 10 externref)

(func (export "splat_f32") (result v128)
f32.const 1234.75
f32x4.splat
)

(func (export "splat_f64") (result v128)
f64.const -123456.75
f64x2.splat
)
)

(assert_return (invoke "splat_f32") (v128.const f32x4 1234.75 1234.75 1234.75 1234.75))
(assert_return (invoke "splat_f64") (v128.const f64x2 -123456.75 -123456.75))

0 comments on commit ea09733

Please sign in to comment.