-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Prefer asm! over llvm_asm! in core #76669
Conversation
on llvm8 builder,
|
I think that this is because the new |
I guess I should close this PR and create an issue to track updating to asm! after LLVM 10 ? |
Yes, I think that would be the best approach for now. |
I added a FIXME in |
The same issue applies to the other |
If so, do you think would it be better to document it elsewhere? |
6922019
to
d5a12d2
Compare
I double-checked the LLVM patches, I think that as long as you stick to AT&T syntax and stick to general-purpose registers you should be fine. Obviously this hasn't been tested since the |
library/core/src/hint.rs
Outdated
{ | ||
asm!( | ||
"/* {0} */", | ||
in(reg32) &dummy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVPTX is a 64-bit architecture so pointers need to be in reg64
, not reg32
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this table correct ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the table is correct. However r
is only valid for use with pointers on 32-bit NVPTX. Our NVPTX target is 64-bit so you need to use l
for pointers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we document NVPTX64 then ?
@bors r+ |
📌 Commit 1c7204f has been approved by |
Prefer asm! over llvm_asm! in core Replace llvm_asm! with asm! in core. x86 asm compare (in somecases I replaced generic type with String). * https://rust.godbolt.org/z/59eEMv * https://rust.godbolt.org/z/v78s6q * https://rust.godbolt.org/z/7qYY41
Failed in rollup (#76774 (comment)):
|
@bors rollup=iffy |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I removed the black_box changes and added a FIXME there. |
library/core/src/hint.rs
Outdated
@@ -121,7 +121,8 @@ pub fn black_box<T>(dummy: T) -> T { | |||
#[cfg(not(miri))] // This is just a hint, so it is fine to skip in Miri. | |||
// SAFETY: the inline assembly is a no-op. | |||
unsafe { | |||
llvm_asm!("" : : "r"(&dummy)); | |||
// FIXME: Cannot use `asm!` because it doesn't support MIPS and other architectures. | |||
llvm_asm!("" : : "r"(&mut dummy)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incidentally the old asm had bugs: you need volatile
and memory
clobbers to have the proper black_box
effect. Currently rustc automatically adds volatile
and LLVM adds memory
when volatile
is set, but we probably shouldn't rely on this.
Co-authored-by: Amanieu <amanieu@gmail.com>
@bors r+ |
📌 Commit 4dc4e9f has been approved by |
Rollup of 10 pull requests Successful merges: - rust-lang#76669 (Prefer asm! over llvm_asm! in core) - rust-lang#76675 (Small improvements to asm documentation) - rust-lang#76681 (remove orphaned files) - rust-lang#76694 (Introduce a PartitioningCx struct) - rust-lang#76695 (fix syntax error in suggesting generic constraint in trait parameter) - rust-lang#76699 (improve const infer error) - rust-lang#76707 (Simplify iter flatten struct doc) - rust-lang#76710 (:arrow_up: rust-analyzer) - rust-lang#76714 (Small docs improvements) - rust-lang#76717 (Fix generating rustc docs with non-default lib directory.) Failed merges: r? `@ghost`
Prefer asm! in std - all in sgx module Similar to the change in rust-lang#76669 but all `llvm_asm!` is gate in x86/x86_64 target. Godbolt: - https://rust.godbolt.org/z/h7nG1h - https://rust.godbolt.org/z/xx39hW r? @ghost
Prefer asm! in std - all in sgx module Similar to the change in rust-lang#76669 but all `llvm_asm!` is gate in x86/x86_64 target. Godbolt: - https://rust.godbolt.org/z/h7nG1h - https://rust.godbolt.org/z/xx39hW
Replace llvm_asm! with asm! in core.
x86 asm compare (in somecases I replaced generic type with String).