Merge remote-tracking branch 'origin/issue-955' into integration_2025_w31 (!3545)

Fix overflow when negating minimum int16_t value in precoding

This closes #955

It prevents undefined behavior caused by the minimum int16_t value
(-32768) in two's complement representation. Because possible negation
by multiplying with -1 during precoding cause an overflows since +32768
cannot be represented in 16-bit signed integers and end up again in
-32768 because of overflow, here reveald by using the SIMD functions.

Workaround we use a slightly smaller number than 1 in Q15 Format to
prevent this error. Q15 representation of (integer value -32767) -1 +
2^-15 = -0.999969482421875
This commit is contained in:
Robert Schmidt
2025-07-31 15:26:21 +02:00
7 changed files with 231 additions and 11 deletions
+1 -7
View File
@@ -61,13 +61,7 @@
c16_t convert_precoder_weight(double complex c_in)
{
double cr = creal(c_in) * 32768 + 0.5;
if (cr < 0)
cr -= 1;
double ci = cimag(c_in) * 32768 + 0.5;
if (ci < 0)
ci -= 1;
return (c16_t) {.r = (short)cr, .i = (short)ci};
return (c16_t) {.r = round(SHRT_MAX*creal(c_in)), .i = round(SHRT_MAX*cimag(c_in))};
}
void get_K1_K2(int N1, int N2, int *K1, int *K2, int layers)