kermit esea
kermit esea

Reputation: 41

MSVC inline assembly to GCC (with parameter and return)

inline float sqrt2(float sqr)
{
    float root = 0;

    __asm
    {
    sqrtss xmm0, sqr
    movss root, xmm0
    }

    return root;
}

here is MSVC compilator inline assembly which I want to compile with gcc x86, what I know that gcc inline assembly is getting called with asm("asm here"); but I completely don't know how to include parameter in that, the result is obtained by "=r" I know only.

Which should result in something like that:

asm("sqrtss xmm0, %1\n\t"
        "movss %0, xmm0"
        : "=r" (root)
        : "r" (sqr));

Upvotes: 2

Views: 269

Answers (1)

Jester
Jester

Reputation: 58822

The r constraint is for general purpose registers. x is for xmm. Consult the manual for more details. Also, if you are using a mov in inline asm, you are likely doing it wrong.

inline float sqrt2(float sqr)
{
    float root = 0;

    __asm__("sqrtss %1, %0" : "=x" (root) : "x" (sqr));

    return root;
}

Note that gcc is entirely capable of generating sqrtss instruction from sqrtf library function call. You may use -fno-math-errno to get rid of some minor error checking overhead.

Upvotes: 3

Related Questions