Hi,
I need to multiply two fixed point numbers in an IQ31 format. The MSP430I2031 supports neither 32x32 nor fractional multiplication, hence I need to roll my own function.
The best I came up with is:
int32_t __iq31mpy(int32_t a, int32_t b) { return ((int32_t)(((int64_t)(a) * (int64_t)(b)) >> 31)); }
However this has quite significant overhead. All intermediate 64 bit values that will be discarded (we're only interested in top 32 bits) take up registers/stack, also there are 4-level-deep nested internal __mspabi functions.
There got to be an easier route by directly using MPY16 in 4 multiplies of 16x16=32 type using MACS, but I just can't figure it out.
Greetings
Michał