summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSayed Adel <seiko@imavr.com>2021-05-21 04:40:29 +0200
committerSayed Adel <seiko@imavr.com>2021-05-21 05:23:13 +0200
commitf74f5003090a4c7ec83dead46567bd96de6dfce8 (patch)
tree594732a1987ab4313cec668b9344694d93998c87 /numpy
parent4619081d1faca58dd3e25db76164c1c7ad928a0f (diff)
downloadnumpy-f74f5003090a4c7ec83dead46567bd96de6dfce8.tar.gz
SIMD: Fix computing the fast int32 division parameters
When the divisor is equal to the minimum integer value, It was affected by gcc 9.3 only and under certain conditions of aggressive optimization.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/common/simd/intdiv.h24
1 files changed, 12 insertions, 12 deletions
diff --git a/numpy/core/src/common/simd/intdiv.h b/numpy/core/src/common/simd/intdiv.h
index 1ce3b4df8..f6ea9abf2 100644
--- a/numpy/core/src/common/simd/intdiv.h
+++ b/numpy/core/src/common/simd/intdiv.h
@@ -368,18 +368,18 @@ NPY_FINLINE npyv_s32x3 npyv_divisor_s32(npy_int32 d)
{
npy_int32 d1 = abs(d);
npy_int32 sh, m;
- if (d1 > 1) {
+ // Handel abs overflow
+ if ((npy_uint32)d == 0x80000000U) {
+ m = 0x80000001;
+ sh = 30;
+ }
+ else if (d1 > 1) {
sh = npyv__bitscan_revnz_u32(d1 - 1); // ceil(log2(abs(d))) - 1
m = (1ULL << (32 + sh)) / d1 + 1; // multiplier
}
else if (d1 == 1) {
sh = 0; m = 1;
}
- // fix abs overflow
- else if (d == (1 << 31)) {
- m = d + 1;
- sh = 30;
- }
else {
// raise arithmetic exception for d == 0
sh = m = 1 / ((npy_int32 volatile *)&d)[0]; // LCOV_EXCL_LINE
@@ -445,18 +445,18 @@ NPY_FINLINE npyv_s64x3 npyv_divisor_s64(npy_int64 d)
#else
npy_int64 d1 = llabs(d);
npy_int64 sh, m;
- if (d1 > 1) {
+ // Handel abs overflow
+ if ((npy_uint64)d == 0x8000000000000000ULL) {
+ m = 0x8000000000000001LL;
+ sh = 62;
+ }
+ else if (d1 > 1) {
sh = npyv__bitscan_revnz_u64(d1 - 1); // ceil(log2(abs(d))) - 1
m = npyv__divh128_u64(1ULL << sh, d1) + 1; // multiplier
}
else if (d1 == 1) {
sh = 0; m = 1;
}
- // fix abs overflow
- else if (d == (1LL << 63)) {
- m = d + 1;
- sh = 62;
- }
else {
// raise arithmetic exception for d == 0
sh = m = 1 / ((npy_int64 volatile *)&d)[0]; // LCOV_EXCL_LINE