Skip to content

Commit

Permalink
wazevo: fuzz, fix Fcopysign (#1826)
Browse files Browse the repository at this point in the history
Signed-off-by: Edoardo Vacchi <evacchi@users.noreply.github.com>
  • Loading branch information
evacchi authored Oct 31, 2023
1 parent 928fce8 commit 9841c5f
Show file tree
Hide file tree
Showing 5 changed files with 389 additions and 6 deletions.
10 changes: 8 additions & 2 deletions internal/engine/wazevo/backend/isa/arm64/lower_instr.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,13 +1231,19 @@ func (m *machine) lowerFcopysignImpl(rd, rn, rm, tmpI, tmpF operand, _64bit bool
}
m.insert(setMSB)

tmpReg := operandNR(m.compiler.AllocateVReg(ssa.TypeF64))

mov := m.allocateInstr()
mov.asFpuMov64(rd.nr(), rn.nr())
mov.asFpuMov64(tmpReg.nr(), rn.nr())
m.insert(mov)

vbit := m.allocateInstr()
vbit.asVecRRR(vecOpBit, rd, rm, tmpF, vecArrangement8B)
vbit.asVecRRR(vecOpBit, tmpReg, rm, tmpF, vecArrangement8B)
m.insert(vbit)

movDst := m.allocateInstr()
movDst.asFpuMov64(rd.nr(), tmpReg.nr())
m.insert(movDst)
}

func (m *machine) lowerBitcast(instr *ssa.Instruction) {
Expand Down
10 changes: 6 additions & 4 deletions internal/engine/wazevo/backend/isa/arm64/lower_instr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,17 +861,19 @@ func TestMachine_lowerFcopysign(t *testing.T) {
exp: `
movz w1?, #0x8000, lsl 16
ins v2?.s[0], w1?
mov v5?.8b, v3?.8b
bit v5?.8b, v4?.8b, v2?.8b
mov v6?.8b, v3?.8b
bit v6?.8b, v4?.8b, v2?.8b
mov v5?.8b, v6?.8b
`,
},
{
_64bit: true,
exp: `
movz x1?, #0x8000, lsl 48
ins v2?.d[0], x1?
mov v5?.8b, v3?.8b
bit v5?.8b, v4?.8b, v2?.8b
mov v6?.8b, v3?.8b
bit v6?.8b, v4?.8b, v2?.8b
mov v5?.8b, v6?.8b
`,
},
} {
Expand Down
16 changes: 16 additions & 0 deletions internal/integration_test/fuzzcases/fuzzcases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,19 @@ func Test1825(t *testing.T) {
require.Equal(t, uint64(18446744073709551615), m.Globals[6].ValHi)
})
}

// Test1825 tests that lowerFcopysignImpl allocates correctly the temporary registers.
func Test1826(t *testing.T) {
if !platform.CompilerSupported() {
return
}
run(t, func(t *testing.T, r wazero.Runtime) {
mod, err := r.Instantiate(ctx, getWasmBinary(t, "1826"))
require.NoError(t, err)
m := mod.(*wasm.ModuleInstance)
_, err = m.ExportedFunction("3").Call(ctx, 0, 0)
require.NoError(t, err)
require.Equal(t, uint64(1608723901141126568), m.Globals[0].Val)
require.Equal(t, uint64(0), m.Globals[0].ValHi)
})
}
Binary file added internal/integration_test/fuzzcases/testdata/1826.wasm
Binary file not shown.
Loading

0 comments on commit 9841c5f

Please sign in to comment.