Modulus by constant
Richard Kenner
kenner@vlsi1.ultra.nyu.edu
Sun Apr 18 02:00:00 GMT 2004
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.
More information about the Gcc
mailing list