开发者

Macro asm inline error

I am trying to use following macro:

#define M_MA(out, L_v, var1, var2)({ \
    asm volatile(  \
    "movswl %2, %%edi\n\t" \
    "movswl %3, %%ebx\n\t" \
    "imull %%edi, %%ebx\n\t" \
    "sall $1,%%ebx\n\t" \
    "cmpl %4,%%ebx\n\t" \
    "cmove %5,%%ebx\n\t" \
    "addl %1, %%ebx\n\t" \
    "jno out%=\n\t" \
    "cmovg %5, %%ebx\n\t" \
    "cmovl %4, %%ebx\n\t" \
    "out%=: nop\n\t" \
    "movl %%ebx, %0\n\t" : "=r"(out) : "r"(L_v), "m"(var1), "m"(var2), "r"(-2147483648), "r"(+2147483647) : "%ebx","%edi");  })

When it is used inside a file compiled using optimizations I get:

error: ‘asm’ operand has impossible constraints

var1 and var2 are 16 bits words. out and L_v are 32 bits words.

After some reading I think the problem is that the compiler need more registers than available but I am not sure about it. If that is the problem I have no idea how to use less registers than now or how to mend the mistak开发者_StackOverflow社区e.

I am using gcc over Linux in a 32 bits platform.

Anyone could clarify something about that?

Regards


"I have no idea how to use less registers than now" -- how about using immediates instead of registers for the two maxint/minint constants? (Ah, cmov does not take immediates. But you can store the constants in %edi for yourself instead of requiring the compiler to set it up in a different register in advance).

Also, why do you want to construct everything in %ebx and then copy it to a different register at the very end? None of the operations are ones for which %ebx has a special meaning, so simply replacing %%ebx with %0 throughout and declaring it "&=r" instead of "=r" will be either a win or at least not a loss.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜