This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: modulus question



On Aug 9, 2004, at 1:31 PM, Pat Haugen wrote:
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;

}

Fold is changing (u%2)==0 into (u&1)==0 which gets changed to ((u^1) & 1) != 0.
Why it does this is unknown to me.



-- Pinski



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]