This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Modulus by constant
- From: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- To: gcc at gcc dot gnu dot org
- Date: Sat, 17 Apr 04 21:16:25 EDT
- Subject: Modulus by constant
Does anybody understand the code that Torbjorn wrote to do divides and modulus
operations as multiplies?
Consider the following:
unsigned short r2286 () { return 2286;}
extern unsigned short r2286 (void);
int
main ()
{
unsigned short x = r2286 () % 255;
printf ("x = %d\n", x);
}
(The first line should be in a different file to avoid inlining.)
This should print 246. But, at least on x86-64, it prints a different value.
This is the cause of least one Ada ACATS failure.