spin2cpp icon indicating copy to clipboard operation
spin2cpp copied to clipboard

Fix 16 bit multiplication optimization

Open Wuerfel21 opened this issue 2 years ago • 1 comments

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.

Wuerfel21 avatar Dec 12 '22 16:12 Wuerfel21

And because VSC had a very normal one, I've also fixed some indentation that wasn't 4-space

Wuerfel21 avatar Dec 12 '22 16:12 Wuerfel21

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.

totalspectrum avatar Dec 14 '22 23:12 totalspectrum

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);
}

Wuerfel21 avatar Dec 16 '22 21:12 Wuerfel21

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!

totalspectrum avatar Dec 17 '22 02:12 totalspectrum