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

Winch: x64 atomic CAS #10039

Merged

Conversation

MarinPostma
Copy link
Contributor

This PR implements atomic CAS operations for winch x64 backend:

  • i32.atomic.rmw8.cmpxchg_u
  • i32.atomic.rmw16.cmpxchg_u
  • i32.atomic.rmw.cmpxchg
  • i64.atomic.rmw8.cmpxchg_u
  • i64.atomic.rmw16.cmpxchg_u
  • i64.atomic.rmw32.cmpxchg_u
  • i64.atomic.rmw.cmpxchg

#9734

@MarinPostma MarinPostma requested review from a team as code owners January 17, 2025 13:23
@MarinPostma MarinPostma requested review from fitzgen and removed request for a team January 17, 2025 13:23
@MarinPostma MarinPostma force-pushed the winch-x64-rmw-cmpxchg branch from ec5d429 to d86981b Compare January 17, 2025 13:33
@github-actions github-actions bot added the winch Winch issues or pull requests label Jan 17, 2025
Copy link

Subscribe to Label Action

cc @saulecabrera

This issue or pull request has been labeled: "winch"

Thus the following users have been cc'd because of the following labels:

  • saulecabrera: winch

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@saulecabrera
Copy link
Member

I'll take a look at this one.

@saulecabrera saulecabrera requested review from saulecabrera and removed request for a team and fitzgen January 17, 2025 21:30
@MarinPostma MarinPostma force-pushed the winch-x64-rmw-cmpxchg branch from d86981b to 02ff251 Compare January 19, 2025 17:32
Copy link
Member

@saulecabrera saulecabrera left a comment

Choose a reason for hiding this comment

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

I believe we can now enable the remaining spec tests?

"spec_testsuite/proposals/threads/atomic.wast",

Comment on lines 1423 to 1433
// pop the args
let replacement = self
.context
.stack
.pop()
.ok_or_else(CodeGenError::missing_values_in_stack)?;
let expected = self
.context
.stack
.pop()
.ok_or_else(CodeGenError::missing_values_in_stack)?;
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest materializing these values to registers via pop_to_reg instead of popping the raw value here: if these values are memory addresses, the push that happens below has the potential to break the stack ordering invariant if any spills happen during self.emit_compute_heap_address_align_checked. Meaning that values will no longer be stored from oldest to newest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i didn't think about that. It seems quite wasteful now that I think about it. If i understand correctly, rax will always be allocated by the time we pop expected: either by replacement or by a previous instruction. This means that xcmpchg will unconditionally spill all registers to the stack.

Comment on lines 1468 to 1577
if let Some(extend) = extend {
self.asm
.movzx_rr(expected.reg, writable!(expected.reg), extend);
}

Copy link
Member

Choose a reason for hiding this comment

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

I believe we need to check if we actually need to make the zero extension? Similar to all the other cases?

if !(extend.from_bits() == 32 && extend.to_bits() == 64) {..}

@MarinPostma MarinPostma force-pushed the winch-x64-rmw-cmpxchg branch 2 times, most recently from c9ec0de to 564d774 Compare January 20, 2025 21:43
@MarinPostma
Copy link
Contributor Author

a test is failing with the newly enabled atomic.wast spec test. Looking into it.

@MarinPostma
Copy link
Contributor Author

@saulecabrera we need to merge this one first: #10060

@MarinPostma MarinPostma force-pushed the winch-x64-rmw-cmpxchg branch 4 times, most recently from b931624 to 219b11e Compare January 21, 2025 23:22
@MarinPostma MarinPostma force-pushed the winch-x64-rmw-cmpxchg branch from 219b11e to 348299a Compare January 21, 2025 23:41
@MarinPostma
Copy link
Contributor Author

@saulecabrera fixed the tests here, but I ultimately had to disable atomic.wast, because we're missing notify

@saulecabrera
Copy link
Member

@saulecabrera fixed the tests here, but I ultimately had to disable atomic.wast, because we're missing notify

Right, I forgot to include those in the issue. It should now be up to date.

Copy link
Member

@saulecabrera saulecabrera left a comment

Choose a reason for hiding this comment

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

LGTM!

@saulecabrera saulecabrera added this pull request to the merge queue Jan 22, 2025
Merged via the queue into bytecodealliance:main with commit 3ab865a Jan 22, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
winch Winch issues or pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants