Multiplying two shorts...

Dan Kegel dan at srs.UUCP
Thu Aug 11 04:18:51 AEST 1988


Sun's compilers seem to let you multiply two short integers and get all 
32 product bits, if you code like this:
    register short x, y;
    register long z;

    z = x * y;

If the compiler is nice, it emits the correct (16x16=32) multiply instruction.
If it isn't nice, it emits the slower (32x32=64) instruction and throws
away the top 32 bits.

Do most modern compilers perform this optimization?
It would be nice to be able to depend on it.
-- 
  Dan Kegel   "We had to get it passed before the columnists attacked!"
  srs!dan at cs.rochester.edu  rochester!srs!dan dan%srs.uucp at harvard.harvard.edu



More information about the Comp.lang.c mailing list