Skip to content

Inline assembly doesn't work with FP constraint #20213

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

Closed
alexchandel opened this issue Dec 25, 2014 · 9 comments
Closed

Inline assembly doesn't work with FP constraint #20213

alexchandel opened this issue Dec 25, 2014 · 9 comments

Comments

@alexchandel
Copy link

The following code:

pub fn log(x: f64) -> f64
{
    let out: f64;
    unsafe {
    asm!("fldln2
        fldl $1
        fyl2x" : "=t"(out) : "m"(x));}
    out
}

errors with the message:

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

The constraint t refers to the top of the floating point stack in GCC's inline assembly, and the unsafe guide says our constraints mirror theirs.

@huonw
Copy link
Member

huonw commented Dec 25, 2014

Our constraints do not duplicate GCC; its just that we implement several of the same constraints GCC supports.

t is evidently one of the ones that is not implemented.

It is a bug in the unsafe guide if it says that we match GCC entirely.

@alexchandel
Copy link
Author

I wish constraints were documented somewhere.

How do we implement constraints for registers on the floating point stack?

@klutzy
Copy link
Contributor

klutzy commented Dec 25, 2014

We currently just translates asm! into llvm inline asm.

Clang-3.4 translates "=t" to "={st}". So we can use "={st}" as well, but I think we may have to do what clang does..

@klutzy
Copy link
Contributor

klutzy commented Dec 25, 2014

Relevant clang code

@kmcallister kmcallister added the A-inline-assembly Area: Inline assembly (`asm!(…)`) label Jan 16, 2015
@steveklabnik
Copy link
Member

The chapter of the book says that we're "Like GCC and Clang" and points to the LLVM inline asm stuff, so I'm going to give this one a close.

@klutzy
Copy link
Contributor

klutzy commented Feb 12, 2016

@steveklabnik This is still an issue; we currently don't do like "GCC and Clang". We do like llvm IR which is different from GCC/Clang.

For given GCC/Clang inline asm:

__asm__("fldln2; fldl %1; fyl2x" : "=t"(out) : "m"(x));

Clang-3.7 emits the following LLVM IR:

%2 = call double asm "fldln2; fldl $1; fyl2x",
"={st},*m,~{dirflag},~{fpsr},~{flags}"(double* %1) #2, !srcloc !1

where "=t" (GCC x86 constraint) is converted to "={st}" (LLVM IR constraint; undocumented?).

Currently we simply pass asm!() arguments without such conversion, so only "={st}" works.

@alexchandel
Copy link
Author

@steveklabnik I agree with @klutzy, this is exactly what I found confusing initially.

We could actually be "Like GCC and Clang" and translate "=t" to "={st}", which is what I'd assume after reading the phrase "Like GCC and Clang", or we could say we're like LLVM IR.

@steveklabnik steveklabnik reopened this Feb 15, 2016
@steveklabnik steveklabnik added A-docs and removed A-inline-assembly Area: Inline assembly (`asm!(…)`) labels Feb 15, 2016
@steveklabnik
Copy link
Member

Okay, sorry for missing the boat here.

@alexchandel
Copy link
Author

@steveklabnik nw. I don't even know whether rustc should support GCC/Clang inline assembly, though it might improve ease of use. It just felt like a papercut to find out the hard way that it doesn't.

steveklabnik added a commit to steveklabnik/rust that referenced this issue Mar 9, 2016
steveklabnik added a commit to steveklabnik/rust that referenced this issue Mar 10, 2016
Remove inaccurate claim about inline assembly

It's not like GCC's.

Fixes rust-lang#20213
steveklabnik added a commit to steveklabnik/rust that referenced this issue Mar 10, 2016
Remove inaccurate claim about inline assembly

It's not like GCC's.

Fixes rust-lang#20213
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

No branches or pull requests

5 participants