Inline Assembly and Preprocessor

Ravishankar S ravishankar.s@hathway.com
Sun Sep 17 04:58:00 GMT 2006


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@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Ian Lance Taylor
Sent: Wednesday, September 13, 2006 10:14 PM
To: Ravishankar S
Cc: gcc-help@gcc.gnu.org
Subject: Re: Inline Assembly and Preprocessor


Ravishankar S <ravishankar.s@hathway.com> 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




More information about the Gcc-help mailing list