Copy C code to not have multiplication overflow

Change-Id: I9375170ce1217921a334c5b93dc3e0084f976688
This commit is contained in:
Vincent Rabaud
2024-03-05 11:33:59 +01:00
parent 1fb9f3dcf1
commit 501d9274a7
12 changed files with 109 additions and 126 deletions

View File

@@ -45,28 +45,38 @@
"ulw %[" #O2 "], " #I3 "+" XSTR(I9) "*" #I7 "(%[" #I0 "]) \n\t" \
"ulw %[" #O3 "], " #I4 "+" XSTR(I9) "*" #I8 "(%[" #I0 "]) \n\t"
// O - output
// I - input (macro doesn't change it so it should be different from I)
#define MUL_SHIFT_C1(O, I) \
"mul %[" #O "], %[" #I "], %[kC1] \n\t" \
"sra %[" #O "], %[" #O "], 16 \n\t" \
"addu %[" #O "], %[" #O "], %[" #I "] \n\t"
#define MUL_SHIFT_C2(O, I) \
"mul %[" #O "], %[" #I "], %[kC2] \n\t" \
"sra %[" #O "], %[" #O "], 16 \n\t"
// Same as #define MUL_SHIFT_C1 but I and O are the same. It stores the
// intermediary result in TMP.
#define MUL_SHIFT_C1_IO(IO, TMP) \
"mul %[" #TMP "], %[" #IO "], %[kC1] \n\t" \
"sra %[" #TMP "], %[" #TMP "], 16 \n\t" \
"addu %[" #IO "], %[" #TMP "], %[" #IO "] \n\t"
// O - output
// IO - input/output
// I - input (macro doesn't change it)
#define MUL_SHIFT_SUM(O0, O1, O2, O3, O4, O5, O6, O7, \
IO0, IO1, IO2, IO3, \
I0, I1, I2, I3, I4, I5, I6, I7) \
"mul %[" #O0 "], %[" #I0 "], %[kC2] \n\t" \
"mul %[" #O1 "], %[" #I0 "], %[kC1] \n\t" \
"mul %[" #O2 "], %[" #I1 "], %[kC2] \n\t" \
"mul %[" #O3 "], %[" #I1 "], %[kC1] \n\t" \
"mul %[" #O4 "], %[" #I2 "], %[kC2] \n\t" \
"mul %[" #O5 "], %[" #I2 "], %[kC1] \n\t" \
"mul %[" #O6 "], %[" #I3 "], %[kC2] \n\t" \
"mul %[" #O7 "], %[" #I3 "], %[kC1] \n\t" \
"sra %[" #O0 "], %[" #O0 "], 16 \n\t" \
"sra %[" #O1 "], %[" #O1 "], 16 \n\t" \
"sra %[" #O2 "], %[" #O2 "], 16 \n\t" \
"sra %[" #O3 "], %[" #O3 "], 16 \n\t" \
"sra %[" #O4 "], %[" #O4 "], 16 \n\t" \
"sra %[" #O5 "], %[" #O5 "], 16 \n\t" \
"sra %[" #O6 "], %[" #O6 "], 16 \n\t" \
"sra %[" #O7 "], %[" #O7 "], 16 \n\t" \
MUL_SHIFT_C2(O0, I0) \
MUL_SHIFT_C1(O1, I0) \
MUL_SHIFT_C2(O2, I1) \
MUL_SHIFT_C1(O3, I1) \
MUL_SHIFT_C2(O4, I2) \
MUL_SHIFT_C1(O5, I2) \
MUL_SHIFT_C2(O6, I3) \
MUL_SHIFT_C1(O7, I3) \
"addu %[" #IO0 "], %[" #IO0 "], %[" #I4 "] \n\t" \
"addu %[" #IO1 "], %[" #IO1 "], %[" #I5 "] \n\t" \
"subu %[" #IO2 "], %[" #IO2 "], %[" #I6 "] \n\t" \