#include <stdint.h>
#include <stdio.h>

uint16_t size, i;

// occhio che usi SMLAL
// https://community.arm.com/developer/tools-software/tools/f/keil-forum/28937/can-t-efficiently-use-smlal-instruction-in-cortex-m4
int main(void){
	size = 7;
	i = 0;
	printf("inline q31_t hb_fir%d(q31_t * samples_ringbuf, uint8_t sample_index, uint8_t buff_size_mask, q31_t * coefficients){\n",size);
	printf("\tq63_t sum0 = 0;\n");
	while(i <= (size/2)){
		if((!(i%2)) || (i==(size/2))) {
			printf("\tsum0 += (q63_t) samples_ringbuf[(sample_index - %d) & buff_size_mask] * coefficients[%d];\n", i, i);
			if(i != (size/2)) printf("\tsum0 += (q63_t) samples_ringbuf[(sample_index - %d) & buff_size_mask] * coefficients[%d];\n", (size - (i+1)), i);
//			printf("\tsum0 += (q63_t) samples_ringbuf[(sample_index - %d)] * coefficients[%d];\n", i, i);
//			if(i != (size/2)) printf("\tsum0 += (q63_t) samples_ringbuf[(sample_index - %d)] * coefficients[%d];\n", (size - (i+1)), i);
		}
		i++;
	}
	printf("\treturn (q31_t) (sum0 >> 31);\n");
	printf("}\n");
}
