Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wazevo(amd64): support for atomic loads #2110

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions internal/engine/wazevo/backend/isa/amd64/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,29 @@ func (m *machine) LowerInstr(instr *ssa.Instruction) {
}
m.insert(m.allocateInstr().asMovzxRmR(extModeLQ, rn, rd))

case ssa.OpcodeAtomicLoad:
ptr := instr.Arg()
size := instr.AtomicTargetSize()
dst := m.c.VRegOf(instr.Return())

// At this point, the ptr is ensured to be aligned, so using a normal load is atomic.
// https://github.com/golang/go/blob/adead1a93f472affa97c494ef19f2f492ee6f34a/src/runtime/internal/atomic/atomic_amd64.go#L30
mem := newOperandMem(m.lowerToAddressMode(ptr, 0))
load := m.allocateInstr()
switch size {
case 8:
load.asMov64MR(mem, dst)
case 4:
load.asMovzxRmR(extModeLQ, mem, dst)
case 2:
load.asMovzxRmR(extModeWQ, mem, dst)
case 1:
load.asMovzxRmR(extModeBQ, mem, dst)
default:
panic("BUG")
}
m.insert(load)

default:
panic("TODO: lowering " + op.String())
}
Expand Down
21 changes: 9 additions & 12 deletions internal/engine/wazevo/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,9 @@ func TestE2E(t *testing.T) {
},
},
{
name: "memory_wait32",
m: testcases.MemoryWait32.Module,
features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
skipAMD64: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah low implementation, high return :P

name: "memory_wait32",
m: testcases.MemoryWait32.Module,
features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
calls: []callCase{
{params: []uint64{0x0, 0xbeef, 0xffffffff}, expResults: []uint64{1}}, // exp not equal, returns 1
{params: []uint64{0x1, 0xbeef, 0xffffffff}, expErr: "unaligned atomic"},
Expand All @@ -615,10 +614,9 @@ func TestE2E(t *testing.T) {
},
},
{
name: "memory_wait64",
m: testcases.MemoryWait64.Module,
features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
skipAMD64: true,
name: "memory_wait64",
m: testcases.MemoryWait64.Module,
features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
calls: []callCase{
{params: []uint64{0x0, 0xbeef, 0xffffffff}, expResults: []uint64{1}}, // exp not equal, returns 1
{params: []uint64{0x1, 0xbeef, 0xffffffff}, expErr: "unaligned atomic"},
Expand All @@ -634,10 +632,9 @@ func TestE2E(t *testing.T) {
},
},
{
name: "memory_notify",
m: testcases.MemoryNotify.Module,
features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
skipAMD64: true,
name: "memory_notify",
m: testcases.MemoryNotify.Module,
features: api.CoreFeaturesV2 | experimental.CoreFeaturesThreads,
calls: []callCase{
{params: []uint64{0x0, 0x1}, expResults: []uint64{0}}, // no waiters, returns 0
{params: []uint64{0x1, 0x1}, expErr: "unaligned atomic"},
Expand Down
Loading