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

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

Closed
nodakai opened this issue Oct 9, 2014 · 4 comments
Closed

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

nodakai opened this issue Oct 9, 2014 · 4 comments
Labels
A-inline-assembly Area: inline asm!(..)

Comments

@nodakai
Copy link
Contributor

nodakai commented Oct 9, 2014

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
@huonw
Copy link
Member

huonw commented Oct 9, 2014

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

@nodakai
Copy link
Contributor Author

nodakai commented Oct 9, 2014

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

@nodakai nodakai changed the title x86_64 asm!: some types of constraints don't work asm!: constraints to select specific registers are undocumented Oct 9, 2014
@nagisa
Copy link
Member

nagisa commented Dec 21, 2014

This needs A-inline-assembly.

@jdm jdm added the A-inline-assembly Area: inline asm!(..) label Dec 22, 2014
@alexcrichton
Copy link
Member

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

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 29, 2024
minor: Add a doc comment for OpQueue

Add an explanatory sentence and some sample code to help readers understand why this struct exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: inline asm!(..)
Projects
None yet
Development

No branches or pull requests

5 participants