Skip to content

asm!: constraints to select specific registers are undocumented #17885

Closed

Description

@nodakai

None of the "a" -- "d" constraints (to use the eax -- edx registers) works as expected.

#![feature(asm)]

fn main() {
    let x: u32;
    unsafe {
        asm!( "xor $0, $0" : "=r"(x) );
//      asm!( "xor $0, $0" : "=a"(x) );
    };
    println!("{}", x);
}

If I enable the commented-out line, I get:

error: couldn't allocate output register for constraint 'a' at line 20

But Clang/LLVM 3.0 (Ubuntu 12.04 package) understands them:

int main(void) {
    int x;
    __asm__ __volatile__ ( "xor %0, %0" : "=a"(x) );
    __asm__ __volatile__ ( "xor %0, %0" : "=b"(x) );
    __asm__ __volatile__ ( "xor %0, %0" : "=c"(x) );
    __asm__ __volatile__ ( "xor %0, %0" : "=d"(x) );
    return 0;
}
00000000004004c0 <main>:
  4004c0:       53                      push   %rbx
  4004c1:       31 c0                   xor    %eax,%eax
  4004c3:       31 db                   xor    %ebx,%ebx
  4004c5:       31 c9                   xor    %ecx,%ecx
  4004c7:       31 d2                   xor    %edx,%edx
  4004c9:       31 c0                   xor    %eax,%eax
  4004cb:       5b                      pop    %rbx
  4004cc:       c3                      retq   
  4004cd:       90                      nop
  4004ce:       90                      nop
  4004cf:       90                      nop

Activity

  1. huonw commented on Oct 9, 2014

    @huonw
    Contributor

    You can get specific registers via {...}, e.g. "={eax}"(x).

  2. nodakai commented on Oct 9, 2014

    @nodakai
    ContributorAuthor

    @huonw Great! I thought it was a bug similar to #16337

  3. changed the title [-]x86_64 asm!: some types of constraints don't work[/-] [+]asm!: constraints to select specific registers are undocumented[/+] on Oct 9, 2014
  4. nagisa commented on Dec 21, 2014

    @nagisa
    Member

    This needs A-inline-assembly.

  5. alexcrichton commented on Sep 28, 2015

    @alexcrichton
    Member

    This is now documented!. We're just using LLVM syntax, so their documentation suffices for ours now at least.

  6. added a commit that references this issue on Aug 29, 2024
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!(…)`)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions