Skip to content

Commit

Permalink
Fix floating point conversions 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 ea09733 commit 6e0f345
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/jit/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ static void emitReinterpretOperation(sljit_compiler* compiler, Instruction* inst
type = instr->opcode() == ByteCode::F32ReinterpretI32Opcode ? Instruction::Int32Operand : Instruction::Int64Operand;
}
emitMove(compiler, type, src, dst);
return;
}

sljit_sw floatReg;
Expand Down
2 changes: 2 additions & 0 deletions src/jit/FloatConvInl.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ static void emitConvertUnsigned32FromFloat(sljit_compiler* compiler, Instruction
sljit_s32 sourceReg = GET_SOURCE_REG(srcArg.arg, instr->requiredReg(0));
sljit_s32 resultReg = GET_TARGET_REG(dstArg.arg, instr->requiredReg(1));

floatOperandToArg(compiler, operands, srcArg, sourceReg);
MOVE_TO_FREG(compiler, SLJIT_MOV_F64 | (opcode & SLJIT_32), sourceReg, srcArg.arg, srcArg.argw);
sljit_emit_fop1(compiler, opcode, resultReg, 0, sourceReg, 0);

Expand Down Expand Up @@ -420,6 +421,7 @@ static void emitSaturatedConvertUnsigned32FromFloat(sljit_compiler* compiler, In
sljit_s32 resultReg = GET_TARGET_REG(dstArg.arg, instr->requiredReg(1));
sljit_s32 tmpFReg = SLJIT_TMP_DEST_FREG;

floatOperandToArg(compiler, operands, srcArg, sourceReg);
MOVE_TO_FREG(compiler, SLJIT_MOV_F64 | (opcode & SLJIT_32), sourceReg, srcArg.arg, srcArg.argw);
sljit_emit_fop1(compiler, opcode, resultReg, 0, sourceReg, 0);

Expand Down
20 changes: 20 additions & 0 deletions test/jit/convert.wast
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@

(; 2147483649, 18446744071562067969, 2147483649 ;)
)

(func (export "test2") (result i32)
f32.const 1234
i32.trunc_f32_u
)

(func (export "test3") (result i32)
f32.const 4567
i32.trunc_sat_f32_u
)

(func (export "test4") (param i32) (result f32 i32)
local.get 0
f32.reinterpret_i32
i32.const 0xaaaa
i32.popcnt
)
)

(assert_return (invoke "test1") (i32.const 2147483649) (i64.const 18446744071562067969) (i64.const 2147483649))
(assert_return (invoke "test2") (i32.const 1234))
(assert_return (invoke "test3") (i32.const 4567))
(assert_return (invoke "test4" (i32.const 0x45580000)) (f32.const 3456.0) (i32.const 8))

0 comments on commit 6e0f345

Please sign in to comment.