Skip to content

Commit

Permalink
Merge pull request #701 from argilo/fix-8ic-multiply-conjugate
Browse files Browse the repository at this point in the history
Avoid integer overflow in volk_8ic_x2_multiply_conjugate_16ic corner case
  • Loading branch information
jdemel authored Dec 1, 2023
2 parents 10971d6 + 2c4a9b4 commit 76c421e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions kernels/volk/volk_8ic_x2_multiply_conjugate_16ic.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define INCLUDED_volk_8ic_x2_multiply_conjugate_16ic_a_H

#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <volk/volk_complex.h>

Expand Down Expand Up @@ -81,7 +82,7 @@ static inline void volk_8ic_x2_multiply_conjugate_16ic_a_avx2(lv_16sc_t* cVector
lv_32fc_t bVal = lv_cmake(bReal, -bImag);
lv_32fc_t temp = aVal * bVal;

*c16Ptr++ = (int16_t)lv_creal(temp);
*c16Ptr++ = (int16_t)(lv_creal(temp) > SHRT_MAX ? SHRT_MAX : lv_creal(temp));
*c16Ptr++ = (int16_t)lv_cimag(temp);
}
}
Expand Down Expand Up @@ -152,7 +153,7 @@ static inline void volk_8ic_x2_multiply_conjugate_16ic_a_sse4_1(lv_16sc_t* cVect
lv_32fc_t bVal = lv_cmake(bReal, -bImag);
lv_32fc_t temp = aVal * bVal;

*c16Ptr++ = (int16_t)lv_creal(temp);
*c16Ptr++ = (int16_t)(lv_creal(temp) > SHRT_MAX ? SHRT_MAX : lv_creal(temp));
*c16Ptr++ = (int16_t)lv_cimag(temp);
}
}
Expand Down Expand Up @@ -185,7 +186,7 @@ static inline void volk_8ic_x2_multiply_conjugate_16ic_generic(lv_16sc_t* cVecto
lv_32fc_t bVal = lv_cmake(bReal, -bImag);
lv_32fc_t temp = aVal * bVal;

*c16Ptr++ = (int16_t)lv_creal(temp);
*c16Ptr++ = (int16_t)(lv_creal(temp) > SHRT_MAX ? SHRT_MAX : lv_creal(temp));
*c16Ptr++ = (int16_t)lv_cimag(temp);
}
}
Expand Down Expand Up @@ -267,7 +268,7 @@ static inline void volk_8ic_x2_multiply_conjugate_16ic_u_avx2(lv_16sc_t* cVector
lv_32fc_t bVal = lv_cmake(bReal, -bImag);
lv_32fc_t temp = aVal * bVal;

*c16Ptr++ = (int16_t)lv_creal(temp);
*c16Ptr++ = (int16_t)(lv_creal(temp) > SHRT_MAX ? SHRT_MAX : lv_creal(temp));
*c16Ptr++ = (int16_t)lv_cimag(temp);
}
}
Expand Down

0 comments on commit 76c421e

Please sign in to comment.