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

Switch from llvm_asm!() to new asm!() macro #304

Merged
merged 2 commits into from Nov 16, 2021

Conversation

coolreader18
Copy link
Contributor

To be honest I'm not the most familiar with inline assembly, but afaict the new version is correct. The assembly output is identical, at least, checking RawRwLock::bump_shared_slow (which calls both elision impls) using cargo asm.

This should be ready for use when asm!() is stabilized, cf (well, your own stabilization report I guess) rust-lang/rust#72016 (comment)

@Amanieu
Copy link
Owner

Amanieu commented Nov 11, 2021

This code is actually incorrect on the x32 ABI: you need to force the use of the :e modifier for both registers so that a 32-bit cmpxchg is used instead of a 64-bit one.

@coolreader18
Copy link
Contributor Author

coolreader18 commented Nov 11, 2021

Not that I'd know more about this than you, but are you sure? The unstable book looks like it implies that eax will be chosen on x86 32-bit (https://doc.rust-lang.org/unstable-book/library-features/asm.html)

Architecture Register class Modifier Example output LLVM modifier
x86-32 reg None eax k
x86-64 reg None rax q

Is it just by chance that it's picking the correct e registers?

@Amanieu
Copy link
Owner

Amanieu commented Nov 12, 2021

x32 is not the same as x86. It's the 32-bit ABI for x86_64 where it uses the x86_64 ISA but with 32-bit pointers. You can try it yourself with the x86_64-unknown-linux-gnux32 target.

asm!(
"xrelease",
"lock",
"xadd [{}], {}",
Copy link
Owner

Choose a reason for hiding this comment

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

You also need :e here for 32-bit pointer size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants