modulus question
Pat Haugen
pthaugen@us.ibm.com
Mon Aug 9 20:35:00 GMT 2004
Wondering if someone could explain why I'm seeing the following difference
when doing a mod by 2. The final generated code ends up with the 'xor/and'
sequence for mod by 2 but the simpler 'and' for mod by 4 (or 8, or 16,
...). This is from mainline, powerpc64-unknown-linux-gnu.
int i;
void test1(unsigned int u, unsigned int u2)
{
if ((u % 2) == 0)
i = 1;
if ((u2 % 4) == 0)
i = 2;
}
>From dump file t04.generic:
test1 (u, u2)
{
unsigned int T.0;
int T.1;
int T.2;
_Bool T.3;
unsigned int T.4;
T.0 = u ^ 1;
T.1 = (int)T.0;
T.2 = T.1 & 1;
T.3 = (_Bool)T.2;
if (T.3)
{
i = 1;
}
else
{
}
T.4 = u2 & 3;
if (T.4 == 0)
{
i = 2;
}
else
{
}
}
More information about the Gcc
mailing list