Skip to content

Commit

Permalink
Fix float compare instruction merging
Browse files Browse the repository at this point in the history
Also fix a typo in lane extraction.

Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
  • Loading branch information
Zoltan Herczeg committed Nov 4, 2023
1 parent 9b51fb8 commit 1039450
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/jit/ByteCodeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ static void createInstructionList(JITCompiler* compiler, ModuleFunction* functio
case ByteCode::F32X4ExtractLaneOpcode:
case ByteCode::F64X2ExtractLaneOpcode: {
SIMDExtractLane* extractLane = reinterpret_cast<SIMDExtractLane*>(byteCode);
Instruction* instr = compiler->append(byteCode, Instruction::ExtractLaneSIMD, opcode, 2, 0);
Instruction* instr = compiler->append(byteCode, Instruction::ExtractLaneSIMD, opcode, 1, 1);

Operand* operands = instr->operands();
operands[0].item = nullptr;
Expand Down
48 changes: 26 additions & 22 deletions src/jit/FloatMathInl.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,34 +438,38 @@ static bool emitFloatCompare(sljit_compiler* compiler, Instruction* instr)
RELEASE_ASSERT_NOT_REACHED();
}

Instruction* nextInstr = instr->next()->asInstruction();
Instruction* nextInstr = nullptr;
bool isSelect = false;

ASSERT(nextInstr != nullptr);
ASSERT(instr->next() != nullptr);

switch (nextInstr->opcode()) {
case ByteCode::JumpIfTrueOpcode:
case ByteCode::JumpIfFalseOpcode:
if (nextInstr->getParam(0)->item == instr) {
if (nextInstr->opcode() == ByteCode::JumpIfFalseOpcode) {
type ^= 0x1;
}
if (instr->next()->isInstruction()) {
nextInstr = instr->next()->asInstruction();

type |= (opcode & SLJIT_32);
switch (nextInstr->opcode()) {
case ByteCode::JumpIfTrueOpcode:
case ByteCode::JumpIfFalseOpcode:
if (nextInstr->getParam(0)->item == instr) {
if (nextInstr->opcode() == ByteCode::JumpIfFalseOpcode) {
type ^= 0x1;
}

sljit_jump* jump = sljit_emit_fcmp(compiler, type, params[0].arg, params[0].argw,
params[1].arg, params[1].argw);
nextInstr->asExtended()->value().targetLabel->jumpFrom(jump);
return true;
}
break;
case ByteCode::SelectOpcode:
if (nextInstr->getParam(2)->item == instr) {
isSelect = true;
type |= (opcode & SLJIT_32);

sljit_jump* jump = sljit_emit_fcmp(compiler, type, params[0].arg, params[0].argw,
params[1].arg, params[1].argw);
nextInstr->asExtended()->value().targetLabel->jumpFrom(jump);
return true;
}
break;
case ByteCode::SelectOpcode:
if (nextInstr->getParam(2)->item == instr) {
isSelect = true;
}
break;
default:
break;
}
break;
default:
break;
}

sljit_emit_fop1(compiler, opcode, params[0].arg, params[0].argw,
Expand Down
41 changes: 40 additions & 1 deletion test/basic/br.wast
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,44 @@
))
i32.const 200
)
(func (export "br_if_cmp")(param i32 i32 i64 f32 f64)(result i32 i32 i32 i32)
block (result i32)
i32.const -1
local.get 0
br_if 0
drop
local.get 1
i32.const 100
i32.eq
end
block (result i32)
i32.const -1
local.get 0
br_if 0
drop
local.get 2
i64.const 100
i64.eq
end
block (result i32)
i32.const -1
local.get 0
br_if 0
drop
local.get 3
f32.const 100.0
f32.eq
end
block (result i32)
i32.const -1
local.get 0
br_if 0
drop
local.get 4
f64.const 100.0
f64.eq
end
)
)

(assert_return (invoke "br0") (i32.const 1)(i32.const 2)(i32.const 3))
Expand All @@ -41,4 +79,5 @@
(assert_return (invoke "check") (i32.const 107))
(assert_return (invoke "br0_1"(i32.const 1))(i32.const 100))
(assert_return (invoke "br0_1"(i32.const 0))(i32.const 200))

(assert_return (invoke "br_if_cmp"(i32.const 0)(i32.const 100)(i64.const 100)(f32.const 100.0)(f64.const 100.0))
(i32.const 1)(i32.const 1)(i32.const 1)(i32.const 1))

0 comments on commit 1039450

Please sign in to comment.