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]

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.


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