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

Add spin_loop_hint intrinsic #58870

Closed
wants to merge 1 commit into from

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Mar 2, 2019

This removes one occurrence of inline assembly in libcore, leaving only:

src/libcore/num/dec2flt/algorithm.rs
61:        unsafe { asm!("fldcw $0" :: "m" (cw) :: "volatile") }
77:        unsafe { asm!("fnstcw $0" : "=*m" (&cw) ::: "volatile") }

This makes life easier for alternative codegen backends which don't (yet) support inline asm by not needing to patch libcore to remove it.

cc https://github.com/bjorn3/rustc_codegen_cranelift/issues/337

@rust-highfive
Copy link
Collaborator

r? @estebank

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 2, 2019
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:0fff643e:start=1551528449638587671,finish=1551528450524937519,duration=886349848
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[00:26:25]    Compiling env_logger v0.5.13
[00:26:29]    Compiling flate2 v1.0.6
[00:26:29]    Compiling backtrace v0.3.11
[00:26:35]    Compiling tempfile v3.0.5
[00:26:36] error: internal compiler error: src/librustc_codegen_llvm/intrinsic.rs:709: broken spin_loop_hint
[00:26:36] thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:620:9
[00:26:36] note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
[00:26:36] error: aborting due to previous error
[00:26:36] 
[00:26:36] 
[00:26:36] 
[00:26:36] note: the compiler unexpectedly panicked. this is a bug.
[00:26:36] 
[00:26:36] note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
[00:26:36] 
[00:26:36] note: rustc 1.34.0-dev running on x86_64-unknown-linux-gnu
[00:26:36] 
[00:26:36] note: compiler flags: -Z external-macro-backtrace -Z force-unstable-if-unmarked -C opt-level=2 -C prefer-dynamic -C debug-assertions=y -C link-args=-Wl,-rpath,$ORIGIN/../lib --crate-type lib
[00:26:36] note: some of the compiler flags provided by cargo are hidden
[00:26:36] 
[00:26:36] error: Could not compile `parking_lot_core`.
[00:26:36] warning: build failed, waiting for other jobs to finish...
---
181352 ./obj/build/x86_64-unknown-linux-gnu/stage0-rustc
156416 ./src/llvm-project/clang
156004 ./obj/build/bootstrap/debug/incremental
141232 ./obj/build/bootstrap/debug/incremental/bootstrap-3i6jt5nchoxcn
141228 ./obj/build/bootstrap/debug/incremental/bootstrap-3i6jt5nchoxcn/s-f9yyeooc9d-1jcjbmg-3r437gq9en0c0
139296 ./obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release
136416 ./obj/build/x86_64-unknown-linux-gnu/stage0-rustc/x86_64-unknown-linux-gnu/release/deps
123628 ./src/llvm-project/llvm/test/CodeGen
108532 ./src/llvm-project/lldb

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 2, 2019

What did I do wrong?

@@ -689,6 +690,27 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
return;
}

"spin_loop_hint" => {
Copy link
Member

Choose a reason for hiding this comment

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

This can (should) be implemented as a call to @llvm.x86.sse2.pause() on x86/x86_64.

Copy link
Member

Choose a reason for hiding this comment

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

(i.e. __mm_pause on x86 and an equivalent on Aarch still needs to be implemented(?))

@nagisa
Copy link
Member

nagisa commented Mar 2, 2019

I have a feeling that these instructions should be exposed by coresimd instead.

@estebank
Copy link
Contributor

estebank commented Mar 2, 2019

r? @nagisa

@rust-highfive rust-highfive assigned nagisa and unassigned estebank Mar 2, 2019
@bjorn3
Copy link
Member Author

bjorn3 commented Mar 2, 2019

I think this should remain in core::hint as multiple archs have a similar instruction and it is just a hint, so it should just compile on archs which don't have such an instruction without having to use #[cfg].

@nagisa
Copy link
Member

nagisa commented Mar 2, 2019

I don’t mind them being exposed by core::hint, but I think they should be implemented in terms of coresimd, which is responsible for implementing all such instructions either way.

@bjorn3
Copy link
Member Author

bjorn3 commented Mar 2, 2019

I see. Maybe I will send coresimd a PR tomorrow.

@bjorn3 bjorn3 closed this Mar 2, 2019
@bjorn3 bjorn3 deleted the spin_loop_hint_intrinsic branch March 2, 2019 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants