Re: Inline Assembly and Preprocessor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ravishankar S <ravishankar.s@xxxxxxxxxxx> writes:

> Im trying to write an optimized inline assembly for TriCore. I was under
> the assumtion that __builtin's were evaluated at compile time so that
> for further parsing ,the correct code is selected. This does not seem to
> be the case.
> 
> Example I want to optimize a PutBit macro as follows:
> 
> // If val == 0 then clear the bit in var at pos. Else set the bit.
> #define PutBit(var,pos,val) {\
>    if(__builtin_constant(pos)) {\
>         // Optimized version if pos is constant.\
>         uint32_t temp == (val == 0);\
>         __asm__ __volatile__("ins.t %0,%1,%2,%3,0": "=d"(val) : "d"(val)
> , "K"(pos) , "d"(temp));\
>    } else {\
>        // Normal version
> }\
> 
> The problem is when pos is not a constant  but a variable.
> 
> PutBit(var1,bitpos,bitval);
> 
> Now pos is replaced by a variable where a constant was expected.
> So compiler gives an error "improper constraint" for "K" must be a
> constant.

Your code should work, in that "pos" should be a constant in the
inline asm.  What is the exact error message that you get?  gcc does
not have any error message which says "improper constraint".  For
example, have you considered the possibility that "pos" is a constant
which does not match the constraint "K"?

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux