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

Prefer asm! over llvm_asm! in core #76669

Merged
merged 2 commits into from Sep 16, 2020
Merged

Prefer asm! over llvm_asm! in core #76669

merged 2 commits into from Sep 16, 2020

Conversation

tesuji
Copy link
Contributor

@tesuji tesuji commented Sep 13, 2020

Replace llvm_asm! with asm! in core.

x86 asm compare (in somecases I replaced generic type with String).

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 13, 2020
@tesuji
Copy link
Contributor Author

tesuji commented Sep 13, 2020

on llvm8 builder,

 LLVM ERROR: Bad $ operand number in inline asm string: '/* ${0:q} */'

@Amanieu
Copy link
Member

Amanieu commented Sep 13, 2020

I think that this is because the new asm! requires LLVM 10. Older LLVM don't support operand modifiers in intel syntax.

@tesuji
Copy link
Contributor Author

tesuji commented Sep 13, 2020

I guess I should close this PR and create an issue to track updating to asm! after LLVM 10 ?

@Amanieu
Copy link
Member

Amanieu commented Sep 13, 2020

Yes, I think that would be the best approach for now.

@tesuji tesuji marked this pull request as ready for review September 13, 2020 14:59
@tesuji
Copy link
Contributor Author

tesuji commented Sep 13, 2020

Yes, I think that would be the best approach for now.

I added a FIXME in core::hint::black_box instead.

@Amanieu
Copy link
Member

Amanieu commented Sep 13, 2020

The same issue applies to the other asm!. You're not getting a CI error because CI only tests x86_64 and not x86.

library/core/src/num/dec2flt/algorithm.rs Outdated Show resolved Hide resolved
library/core/src/num/dec2flt/algorithm.rs Outdated Show resolved Hide resolved
@jyn514 jyn514 added A-inline-assembly Area: inline asm!(..) F-asm `#![feature(asm)]` (not `llvm_asm`) T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 13, 2020
@tesuji
Copy link
Contributor Author

tesuji commented Sep 14, 2020

I think that this is because the new asm! requires LLVM 10. Older LLVM don't support operand modifiers in intel syntax.

If so, do you think would it be better to document it elsewhere?
And a check for LLVM version to error out sooner ?
Does at&t syntax have the same problem ? If not, is switching to ATT syntax acceptable ?

@tesuji tesuji force-pushed the core_asm branch 2 times, most recently from 6922019 to d5a12d2 Compare September 14, 2020 05:47
@Amanieu
Copy link
Member

Amanieu commented Sep 14, 2020

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 asm! tests are disabled when compiled with system LLVM.

library/core/src/hint.rs Outdated Show resolved Hide resolved
library/core/src/num/dec2flt/algorithm.rs Show resolved Hide resolved
{
asm!(
"/* {0} */",
in(reg32) &dummy,
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this table correct ?
image

Copy link
Member

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.

Copy link
Contributor Author

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 ?

library/core/src/hint.rs Outdated Show resolved Hide resolved
@Amanieu
Copy link
Member

Amanieu commented Sep 15, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Sep 15, 2020

📌 Commit 1c7204f has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 15, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 16, 2020
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
@jyn514
Copy link
Member

jyn514 commented Sep 16, 2020

Failed in rollup (#76774 (comment)):

error[E0472]: asm! is unsupported on this target
   --> library/core/src/hint.rs:143:13
    |
143 | /             asm!(
144 | |                 "/* {0} */",
145 | |                 in(reg) &mut dummy,
146 | |                 options(nostack, preserves_flags),
147 | |             );
    | |______________^

error: aborting due to previous error

[RUSTC-TIMING] core test:false 5.850
error: could not compile `core`.

To learn more, run the command again with --verbose.
command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "mipsel-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "16" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/library/test/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit code: 101
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap dist --host mipsel-unknown-linux-gnu --target mipsel-unknown-linux-gnu

@jyn514
Copy link
Member

jyn514 commented Sep 16, 2020

@bors rollup=iffy

@tesuji

This comment has been minimized.

@tesuji

This comment has been minimized.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 16, 2020
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 16, 2020
@tesuji
Copy link
Contributor Author

tesuji commented Sep 16, 2020

I removed the black_box changes and added a FIXME there.

@@ -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));
Copy link
Member

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>
@Amanieu
Copy link
Member

Amanieu commented Sep 16, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Sep 16, 2020

📌 Commit 4dc4e9f has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 16, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 16, 2020
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`
@bors bors merged commit d1b0504 into rust-lang:master Sep 16, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 16, 2020
@tesuji tesuji deleted the core_asm branch September 17, 2020 02:25
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Sep 28, 2020
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
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 30, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: inline asm!(..) F-asm `#![feature(asm)]` (not `llvm_asm`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants