Skip to content

[arm] bitwise manipulation instructions #29

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

Merged
merged 7 commits into from
Sep 21, 2017

Conversation

gnzlbg
Copy link
Contributor

@gnzlbg gnzlbg commented Sep 20, 2017

This adds ARM's rev, rbit, clz and cls intrinsics.

The cls intrinsic currently generates bad code due to an LLVM bug, I've filled issue #30 to track it.

Closes #35 .

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 21, 2017

The code-gen tests for abm, bmi and bmi2 where failing so i've fixed those here.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 21, 2017

I don't have llc for arm installed, could somebody run:

llc -march=arm -mattr=help
llc -march=armv7 -mattr=help
llc -march=aarch64 -mattr=help

and post the output here? I don't know if its possible to use #[target_feautre] to force the generation of the arm intrinsics, but if that's possible, the answer will be there.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 21, 2017

@alexcrichton the tests are failing on travis, but they pass on my machine (MacOSX). Could we also test on Mac? The problem seems to be, that on linux the assembler emits, for example, tzcnt, but on MacOS it emits tzcntw (16bit), tzcntl (32bit), tzcntq (64bit), etc. Maybe the test plugin could handle those?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 21, 2017

The last commit truncates the instructions in the assert-instr macro with the length of the expected instruction to omit the w/l/q/etc suffixes when present.

When comparing the assembly instructions against
the expected instruction, depending on the platform,
we might end up with `tzcntl != tzcnt`. This
commit truncates the instructions to the length
of the expected instruction, such that `tzcntl => tzcnt`
and the comparison succeeds.
@BurntSushi
Copy link
Member

@gnzlbg Thanks! So I think before we bring non-x86 intrinsics in, I'd really like to try to get CI setup to be able to test them. That's tracked in #13.

It also looks like the codegen tests are failing on Windows?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 21, 2017

It also looks like the codegen tests are failing on Windows?

Were they working on windows before?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 21, 2017

So I think before we bring non-x86 intrinsics in, I'd really like to try to get CI setup to be able to test them. That's tracked in #13.

I agree that CI for this is important. The now removed python script used to do CI for ARM by cross-compiling to arm archs and verifying the assembly. IIUC @alexcrichton will look into improving the codegen testing macros to test the codegen for arm features via cross-compiling from all hosts (even if one cannot run the run-time tests, this is better than nothing). I wanted to look next into using #[target_feature] for these ARM features but can look into fixing #13 afterward (run-time testing on ARM targets is something we want anyways).

I think that for these three things (improving the code gen testing macros), using #[target_feature] for minor ARM features, and setting up full ARM CI, having some ARM code merged that we can actually test our approaches against will be very helpful.

@BurntSushi
Copy link
Member

having some ARM code merged that we can actually test our approaches against will be very helpful.

Ah yeah good point! I can be sold on that. I think I would like to make sure the CI we do have is green though. I thought Windows was green at one point? Let's wait to hear from @alexcrichton (or I can look into it, but might be a bit).

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 21, 2017

@alexcrichton this is the backtrace on appveyor:

---- x86::bmi::assert_instr__mm_tzcnt_u64 stdout ----
	thread 'x86::bmi::assert_instr__mm_tzcnt_u64' panicked at 'failed to find disassembly of stdsimd::x86::bmi::_tzcnt_u64', src\libcore\option.rs:839:4
stack backtrace:
---- x86::bmi::assert_instr__tzcnt_u32 stdout ----
	thread 'x86::bmi::assert_instr__tzcnt_u32' panicked at 'failed to get symbol of function pointer: 140698179428704', assert-instr\src\lib.rs:233:16
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys_common::backtrace::_print
             at C:\projects\rust\src\libstd\sys_common\backtrace.rs:94
   1: std::panicking::default_hook::{{closure}}
             at C:\projects\rust\src\libstd\panicking.rs:380
   2: std::panicking::default_hook
             at C:\projects\rust\src\libstd\panicking.rs:391
   3: std::panicking::rust_panic_with_hook
             at C:\projects\rust\src\libstd\panicking.rs:577
   4: std::panicking::begin_panic<alloc::string::String>
             at C:\projects\rust\src\libstd\panicking.rs:538
   5: std::panicking::begin_panic_fmt
             at C:\projects\rust\src\libstd\panicking.rs:522
   6: assert_instr::assert
             at .\assert-instr\src\lib.rs:233
   7: test::{{impl}}::call_box<(),closure>
             at C:\projects\rust\src\libtest\lib.rs:141
   8: panic_unwind::__rust_maybe_catch_panic
             at C:\projects\rust\src\libpanic_unwind\lib.rs:99
---- x86::bmi::assert_instr__tzcnt_u64 stdout ----

It seems that backtrace::resolve is failing to find the symbol of a function pointer.

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 21, 2017

@BurntSushi appveyor seems to be broken on master as well, I've enabled backtraces on appveyor for now, maybe we should do the same on travis.

return
// Truncates the instruction with the length of the expected
// instruction: tzcntl => tzcnt and compares that.
if let Some(part) = part.get(0..expected.len()) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this could be part.starts_with(expected)

(also thanksfor doing this!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I looked a lot for something like that (or contains) in the docs but couldn't find it so thought it maybe wasn't part of std. I am learning a lot with your code reviews, thank you!

@alexcrichton
Copy link
Member

Hm windows is indeed previously green

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 21, 2017 via email

@alexcrichton
Copy link
Member

Ok with the most recent logs it looks like:

  • x86::bmi::assert_instr__mm_tzcnt_u32 - backtrace failed, but the symbol looks present
  • x86::bmi::assert_instr__tzcnt_u32 - symbol not actually present, I think it was folded into _mm_tzcnt_u32
  • x86::bmi::assert_instr__tzcnt_u64 - symbol not actually present, I think it was folded into _mm_tzcnt_u64
  • x86::sse2::assert_instr__mm_adds_epi16 - backtrace failed, but the symbol looks present

Testing more...

@alexcrichton
Copy link
Member

@BurntSushi also yeah I'll work on ARM CI once we get this merged, it'll be helpful to have a few examples locally to test with

@alexcrichton
Copy link
Member

Alright all green now! I'll add some comments then merge

Pass the `/OPT:NOICF` flag to the linker to ensure that all functions don't get
eliminated (somethign we don't want in this scenario)
@alexcrichton alexcrichton merged commit 453e170 into rust-lang:master Sep 21, 2017
# We don't want to do identical comdat folding as it messes up the ability to
# generate lossless backtraces in some cases. This is enabled by rustc by
# default so pass a flag to disable it to ensure our tests work ok.
RUSTFLAGS: -Clink-args=/OPT:NOICF
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 would have never thought of this.

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.

3 participants