spin2cpp
spin2cpp copied to clipboard
Fix 16 bit multiplication optimization
Was already in place, but seems to have been broken at some point. Also I don't think it ever worked if a constant was involved.
I also added an IR-level optimization to remove extraneous mask/extend ops.
Don't have a P2 hooked up right now, so please run exec tests.
And because VSC had a very normal one, I've also fixed some indentation that wasn't 4-space
I've merged this, but it doesn't seem to make much difference on my tests. Maybe we can add some peepholes to trigger it more often.
This is the shitty little test I wrote. Compile without inlining.
#include <stdint.h>
int32_t funny1(int16_t a, int16_t b) {
return a*b;
}
uint32_t funny2(uint16_t a, uint16_t b) {
return a*b;
}
uint32_t funny3() {
uint16_t a = _INA;
return a*3;
}
uint32_t funny4(uint32_t a, uint32_t b) {
return a*b;
}
uint32_t funny5(uint8_t a, uint8_t b) {
return a*b;
}
uint32_t funny6(int8_t a, int8_t b) {
return a*b;
}
int main() {
_OUTA = funny1(1,2);
_OUTA = funny2(3,4);
_OUTA = funny3();
_OUTA = funny4(3,4);
_OUTA = funny5(3,4);
_OUTA = funny6(3,4);
}
OK, I found the problem -- I was using spin2cpp to do the test, and for some forgotten historical reason spin2cpp always turned on CSE (which messes up this optimization because the CSE results are in 32 bit temporaries). I've fixed that and the tests are looking good, thanks!