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

Support .insn directive in asm! #90558

Closed
piegamesde opened this issue Nov 4, 2021 · 6 comments · Fixed by #91528
Closed

Support .insn directive in asm! #90558

piegamesde opened this issue Nov 4, 2021 · 6 comments · Fixed by #91528
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-asm `#![feature(asm)]` (not `llvm_asm`)

Comments

@piegamesde
Copy link
Contributor

Tracking issue: #72016.

The .insn assembler directive allows to treat data as instructions. This allows to generate CPU instructions that are otherwise not possible using assembler commands. It is platform specific and mostly relevant for RISC-V platforms, but I could also find uses for it on MIPS targets as well.

More generally speaking, any solution that allows me to produce custom machine code instructions without a performance overhead will be okay for me. The current best workaround is to write the assembler code externally and then link to it. However, this adds the overhead of a function call that cannot be inlined due to the FFI boundary, so this is not acceptable in the long term.

See also https://users.rust-lang.org/t/custom-cpu-instructions-with-asm/66637 for some more discussion of my problem.

@hkratz
Copy link
Contributor

hkratz commented Nov 4, 2021

This will likely work automatically once LLVM supports it. A commit has recently landed (https://reviews.llvm.org/D108602?id=369214) but is not yet in any released version.

@asquared31415
Copy link
Contributor

@rustbot label +A-inline-assembly +F-asm

@rustbot rustbot added A-inline-assembly Area: Inline assembly (`asm!(…)`) F-asm `#![feature(asm)]` (not `llvm_asm`) labels Nov 5, 2021
@sanxiyn sanxiyn added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Nov 10, 2021
@piegamesde
Copy link
Contributor Author

piegamesde commented Nov 12, 2021

I tried building rust+cargo from source with llvm/llvm-project@2838797 cherry-picked. Sadly it did not make the error message go away. However I don't have a good way to check if the correct LLVM is being used (I could however check that rustc and cargo are the ones I want) A good way to check is to use clang on a minimal example instead. Turns out that I somehow wasn't.

@piegamesde
Copy link
Contributor Author

Okay, it actually does work. What is the procedure around Rust's LLVM dependency? How often is it bumped? Is this a candidate for cherry-picking onto rust-llvm?

@sanxiyn
Copy link
Member

sanxiyn commented Nov 19, 2021

LLVM procedure is at https://rustc-dev-guide.rust-lang.org/backend/updating-llvm.html. I think this is a candidate for cherry-picking but someone needs to do the work.

@piegamesde
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. F-asm `#![feature(asm)]` (not `llvm_asm`)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants