summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorIsuru Fernando <isuruf@gmail.com>2021-03-07 13:06:08 -0800
committerIsuru Fernando <isuruf@gmail.com>2021-03-07 13:06:08 -0800
commit31e172ee5b34acd3243441480a8f431d5689fbc4 (patch)
treeff4d37e9ade62c9465e74c4c3ef1cfda80bcc54d /numpy/core/src
parent0bcf690951899608db2ab8aa6aebebbe6723b307 (diff)
downloadnumpy-31e172ee5b34acd3243441480a8f431d5689fbc4.tar.gz
Fix overflow warning on apple silicon
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/umath/loops.c.src15
1 files changed, 15 insertions, 0 deletions
diff --git a/numpy/core/src/umath/loops.c.src b/numpy/core/src/umath/loops.c.src
index 570b3ec04..bd8c78d2d 100644
--- a/numpy/core/src/umath/loops.c.src
+++ b/numpy/core/src/umath/loops.c.src
@@ -2526,6 +2526,21 @@ NPY_NO_EXPORT void
const @ftype@ in1i = ((@ftype@ *)ip1)[1];
const @ftype@ in2r = ((@ftype@ *)ip2)[0];
const @ftype@ in2i = ((@ftype@ *)ip2)[1];
+#if defined(__APPLE__) && defined(__aarch64__)
+ // On macos-arm64, if this block of code was not there,
+ // when branch prediction goes wrong, the floating point exception
+ // register does not get cleared and an exception for the
+ // wrong branch is thrown.
+ if (in2i == 0) {
+ ((@ftype@ *)op1)[0] = npy_floor@c@(in1r/in2r);
+ ((@ftype@ *)op1)[1] = 0;
+ }
+ else if (in2r == 0) {
+ ((@ftype@ *)op1)[0] = npy_floor@c@(in1i/in2i);
+ ((@ftype@ *)op1)[1] = 0;
+ }
+ else
+#endif
if (npy_fabs@c@(in2r) >= npy_fabs@c@(in2i)) {
const @ftype@ rat = in2i/in2r;
((@ftype@ *)op1)[0] = npy_floor@c@((in1r + in1i*rat)/(in2r + in2i*rat));