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]

Re: [C++11] Reclaiming fixed-point suffixes for user-defined literals.


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.


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