This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
modulus question
- From: Pat Haugen <pthaugen at us dot ibm dot com>
- To: gcc at gcc dot gnu dot org
- Date: Mon, 9 Aug 2004 15:31:57 -0500
- Subject: modulus question
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
{
}
}