S
Samuel Stearley
I have a question about the ~ operator in C. In some code I compare
an eight bit value to an inverted 8 bit value, but when I run they are
never equal. So I disassembled the code and saw that the inversion is
a 32 bit operation, followed by a 32 bit compare.
So is my code wrong or is this a compiler bug? I'm using gcc 3.3.2
eg
typedef struct blob
{
UINT8 x;
UINT8 y;
}BLOB;
BLOB temp;
if (temp.x == ~temp.y)
{
/* snip */
}
resulted in the following powerpc assembly:
3e7c8: 89 21 00 11 lbz r9,17(r1) /* get byte y and clear upper 24
bits */
3e7cc: 3c 60 05 15 lis r3,1301
3e7d0: 88 01 00 10 lbz r0,16(r1) /* get byte x and clear upper 24
bits */
3e7d4: 60 63 01 01 ori r3,r3,257
3e7d8: 7d 29 48 f8 not r9,r9 /* 32 bit inversion, upper bits
are now set */
3e7dc: 7f 80 48 00 cmpw cr7,r0,r9 /* 32 bit compare */
an eight bit value to an inverted 8 bit value, but when I run they are
never equal. So I disassembled the code and saw that the inversion is
a 32 bit operation, followed by a 32 bit compare.
So is my code wrong or is this a compiler bug? I'm using gcc 3.3.2
eg
typedef struct blob
{
UINT8 x;
UINT8 y;
}BLOB;
BLOB temp;
if (temp.x == ~temp.y)
{
/* snip */
}
resulted in the following powerpc assembly:
3e7c8: 89 21 00 11 lbz r9,17(r1) /* get byte y and clear upper 24
bits */
3e7cc: 3c 60 05 15 lis r3,1301
3e7d0: 88 01 00 10 lbz r0,16(r1) /* get byte x and clear upper 24
bits */
3e7d4: 60 63 01 01 ori r3,r3,257
3e7d8: 7d 29 48 f8 not r9,r9 /* 32 bit inversion, upper bits
are now set */
3e7dc: 7f 80 48 00 cmpw cr7,r0,r9 /* 32 bit compare */