RE: Inline Assembly and Preprocessor

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

 



That's exactly the problem. When pos is not a constant. "K" constraint
is for a unsigned constant. The code works perfecty fine when pos is a
constant. I would like to optimize that case. But that seems not
possible. 

I didn't capture the error message. But there was something like
"impossible constraint for operand 2 (i.e %2". Since it's a port of gcc
to TriCore by HighTec EDV, it can give error messages tailored to the
environment.

The only way to solve this problem as I see is if the preprocessor
provided a way to see if a macro argument is a integer constant. Then at
preprocessor time, the code can be optimized!

Like:

#define PutBit(var,pos,val) {\
#if INTEGER_CONSTANT(val) \
        uint32_t temp = (val == 0);\
        __asm__ __volatile__("ins.t %0,%1,%2,%3,0": "=d"(val) : \
 "d"(val) , "K"(pos) , "d"(temp));\
#else \
...

#endif

 

Regards,
Ravishankar

-----Original Message-----
From: gcc-help-owner@xxxxxxxxxxx [mailto:gcc-help-owner@xxxxxxxxxxx] On
Behalf Of Ian Lance Taylor
Sent: Wednesday, September 13, 2006 10:14 PM
To: Ravishankar S
Cc: gcc-help@xxxxxxxxxxx
Subject: Re: Inline Assembly and Preprocessor


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

__________ NOD32 1.1454 (20060321) Information __________

This message was checked by NOD32 antivirus system. http://www.eset.com



[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