[C++11] Reclaiming fixed-point suffixes for user-defined literals.
Joern Rennecke
amylaar@spamcop.net
Mon Nov 7 01:41:00 GMT 2011
Quoting David Brown <david.brown@hesbynett.no>:
> Take an example using a processor I know well, the AVR (it is an 8-bit
> device, which is a little unusual for gcc). It has an instruction will
> multiply two "1.7" signed 8-bit integers to get a single 1.15 signed
> 16-bit integer - basically combining an 8-bit x 8-bit to 16-bit
> multiply with a left shift. So to do a "signed short _Fract" multiply,
> you have a single instruction and discard the least significant byte.
>
> Simulating the same operation in generic C would be something like :
>
> int8_t multShortFract(int8_t a, int8_t b) {
> int16_t c = (int16_t) a * b;
> return (c >> 7);
> }
If you can make up your mind if the result is 8 or 16 bit, generating the
instruction should be standard fare for the combiner pass.
More information about the Gcc
mailing list