Skip to content

Tracking Issue for inline assembly (asm!) #72016

Closed

Activity

  1. added
    A-inline-assemblyArea: Inline assembly (`asm!(…)`)
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on May 8, 2020
  2. changed the title [-]Tracking Issue for inline assembly[/-] [+]Tracking Issue for inline assembly (`asm!`)[/+] on May 8, 2020
  3. added
    T-langRelevant to the language team
    F-asm`#![feature(asm)]` (not `llvm_asm`)
    on May 8, 2020
  4. joshtriplett commented on May 25, 2020

    @joshtriplett
    Member

    Note: if you'd like to report an issue in inline assembly, please report it as a separate github issue, and just link to this one. Please don't report issues in inline assembly as comments on this tracking issue.

  5. BartMassey commented on May 25, 2020

    @BartMassey
    Contributor

    Should the asm! macro be available directly from the prelude as it is now, or should it have to be imported from std::arch::$ARCH::asm? The advantage of the latter is that it would make it explicit that the asm! macro is target-specific, but it would make cross-platform code slightly longer to write.

    Definitely want the explicit import. This would also make it a bit clearer what's going on when somebody tries to compile an old-style asm! with a newer compiler, which is going to happen a lot: you'd get an unresolved symbol rather than mysterious syntax errors.

  6. joshtriplett commented on May 26, 2020

    @joshtriplett
    Member
  7. petrochenkov commented on Jun 8, 2020

    @petrochenkov
    Contributor

    Minor compatibility concern: asm! supports some LLVM-isms like C style comments /* comment */ (#73056 (comment)).

    Other backends using external assemblers may need to do some pre-processing before passing the asm text to them.

  8. programmerjake commented on Jun 9, 2020

    @programmerjake
    Member

    Minor compatibility concern: asm! supports some LLVM-isms like C style comments /* comment */ (#73056 (comment)).

    GNU Assembler (IIRC defined as the official assembly dialect by the RFC), and by extension GCC, supports C-style comments too, so they are definitely not LLVM-specific.

  9. newpavlov commented on Jun 9, 2020

    @newpavlov
    Contributor

    Namespacing the asm! macro

    I am also in favor of explicit imports from arch modules. I would suggest going even further and introduce separate macros for each supported target (e.g. asm_x86!, asm_arm!, etc.).

  10. joshtriplett commented on Jun 9, 2020

    @joshtriplett
    Member

    Some feedback from various places in response to the blog post. (I'm skipping general expressions of awesomeness, though there have been many; I'm quoting those that have specific feedback.)

    @amluto (Andy Lutomirski, prominent Linux kernel developer who works on a lot of low-level x86) at https://news.ycombinator.com/item?id=23467108 :

    Rust folks, thank you so much for making this far, far better than GCC’s asm syntax for C. Also, thank you for using Intel x86 syntax instead of AT&T.
    It would be delightful if GCC were to adopt something similar after this stabilizes in Rust.

    Several people on HN were a little confused about the backward-compatibility story here; in the future, when we talk about features that have only existed on nightly, we need to be more clear in the future about messaging around our stability policy.

    Several people wondered why this used a string constant; it'd be good to explain that in documentation. And this doesn't mean the assembly isn't parsed, it means it isn't parsed by rustc (it's parsed by LLVM in the backend).

    We really should have mentioned, in the blog post, that AT&T syntax was supported with options(att_syntax), so that people didn't think they have to translate all their assembly. I've prepared an update to the blog post mentioning that.

    Someone mentioned preferring an "explicit clobber" syntax (like clobber("ax")) rather than having to write out("ax") _. I can understand that.

    Closely related, I think we should definitely have both "clobber all function-clobbered registers" and "clobber all general-purpose registers" options.

  11. amluto commented on Jun 9, 2020

    @amluto

    I’ll add one more comment: please document what happens if you try to use not-quite-general-purpose registers as operands (clobber or otherwise). The most important case is the PIC register. GCC does not appreciate inline asm that clobbers the PIC register. IMO it should be allowed, especially for things like CPUID on x86_32.

    This also includes thinks like EBP/RBP. If I’m building with frame pointers on or I do something that forces a frame pointer, is RBP available? RSP is another example — presumably it’s not available.

  12. 245 remaining items

  13. added a commit that references this issue on Dec 17, 2021
  14. added a commit that references this issue on Jan 12, 2022
  15. bstrie commented on Jan 25, 2022

    @bstrie
    Contributor

    I see that there are some new feature flags in nightly for tracking the long tail of asm! stabilization: asm_const, asm_experimental_arch, asm_sym, and asm_unwind. Should we make dedicated tracking issues for these?

  16. Amanieu commented on Jan 26, 2022

    @Amanieu
    MemberAuthor

    I created separate tracking issues for each sub-feature:

    This tracking issue can be closed now that asm! is stable.

  17. moved this to Stabilized in Initiativeson Feb 1, 2022
  18. added a commit that references this issue on Feb 17, 2022
  19. added a commit that references this issue on Aug 31, 2022
  20. mert-kurttutan commented on Nov 1, 2023

    @mert-kurttutan

    Hi @nagisa ,
    I am still experiencing the same issue that @marysaka mentioned (in 1.73 stable and nightly) on x86 hardware, here .
    I am trying out a Rust port of some C code. The C code uses inline assembly with memory inputs which has the syntax [x] "m" (x) where x is a variable defined in the current scope, and it is able to use variables from stack memory (instead of registers).
    So, it is able to use less number of registers by loading multiple variables (from stack) to the same register in different parts of the code.

    In the reference for inline assembly for Rust, only input operand type is that of register operand. Do we have similar method use variable as input from memory rather than register ?

  21. nagisa commented on Nov 1, 2023

    @nagisa
    Member

    Next time please open a new issue, or even better, ask on Zulip, rather than commenting on one that has been closed for more than a year at this point.


    As far as I know, no, memory operands are considered a future possibility by the RFC that implemented inline assembly and would require some design & implementation work.

    Your next best bet is to pass in an address to the variable in a register.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCF-asm`#![feature(asm)]` (not `llvm_asm`)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamWG-embeddedWorking group: Embedded systemsdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions