8000 ENH: Added libdivide for floor divide by ganesh-k13 · Pull Request #17727 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Added libdivide for floor divide #17727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
179038f
ENH: Added libdiv
ganesh-k13 Nov 7, 2020
e89175b
ENH: Fixed typos in header | use in2 over ip2
ganesh-k13 Nov 7, 2020
565759b
ENH: Added optimal divisor
ganesh-k13 Nov 8, 2020
d0c934c
ENH: Added libdivide header
ganesh-k13 Nov 8, 2020
b02399a
ENH: Made libdivide default
ganesh-k13 Nov 8, 2020
f0ddb7c
ENH: Handled divide by 0 case
ganesh-k13 Nov 8, 2020
72dcc04
ENH: Added libdivide zlib license
ganesh-k13 Nov 9, 2020
19835d2
ENH: Removed empty structure
ganesh-k13 Nov 10, 2020
3975a28
ENH: Auto generate libdivide structs
ganesh-k13 Nov 11, 2020
90e6cf5
ENH: Logic to optimize %
ganesh-k13 Nov 11, 2020
969aa03
ENH: Fix breaking case
ganesh-k13 Nov 11, 2020
44a3a31
ENH: Change comments
ganesh-k13 Nov 11, 2020
b3d70ef
ENH: Improved floor division (#17727)
ganesh-k13 Nov 11, 2020
931134b
ENH: Added asv benchmarks
ganesh-k13 Nov 11, 2020
6e2e281
ENH: Change comments
ganesh-k13 Nov 12, 2020
90a84af
ENH: Linting
ganesh-k13 Nov 12, 2020
61c3d38
MAINT: Added libdivide as linguist-vendored
ganesh-k13 Nov 12, 2020
827bc38
ENH: Removed legacy division
ganesh-k13 Nov 12, 2020
0ce0ebd
ENH: Improved floor division (#17727)
ganesh-k13 Nov 12, 2020
c85c44a
ENH: Added libdivide to timedelta
ganesh-k13 Nov 13, 2020
0517f13
TST: Added UT for floor divide
ganesh-k13 Nov 20, 2020
a769d6f
ENH: Improved floor division (#17727)
ganesh-k13 Nov 21, 2020
0e2116f
ENH: Optimized 0 divisor cases
ganesh-k13 Nov 21, 2020
f93ca93
TST: Minor changes to floor divide | Added cases for timedelta divide
ganesh-k13 Nov 21, 2020
285d810
ENH: Remove looping definitions | Renamed fast loop macros
ganesh-k13 Nov 22, 2020
9825795
ENH: Removed unsed macro check
ganesh-k13 Nov 22, 2020
1f104fd
BUG: Added better 0 checks
ganesh-k13 Nov 23, 2020
2fde590
BENCH: Added floor divide benchmarks (#17727)
ganesh-k13 Nov 23, 2020
8912ffd
DOC: Improved floor division (#17727)
ganesh-k13 Nov 23, 2020
a5e1235
BENCH: Improve floor divide benchmarks (#17727)
ganesh-k13 Nov 23, 2020
ca4ba20
BUG,TST: Fixed division by 0 status setting
ganesh-k13 Nov 23, 2020
28aa883
MAINT: Linting fixes
ganesh-k13 Dec 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: Made libdivide default
  • Loading branch information
ganesh-k13 committed Nov 8, 2020
commit b02399ac1c0838a84c6d966ef2c34cd60c82c30c
14 changes: 4 additions & 10 deletions numpy/core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,8 @@ def check_mathlib(config_cmd):
"MATHLIB env variable")
return mathlibs

def check_libdivide():
return os.environ.get('NPY_USE_LIBDIVIDE') is not None

def check_optimal_divisor():
return os.environ.get('NPY_USE_OPTIMAL_DIVISOR') is not None
def check_use_legacy_division():
return os.environ.get('NPY_USE_LEGACY_DIVISION') is not None

def visibility_define(config):
"""Return the define value to use for NPY_VISIBILITY_HIDDEN (may be empty
Expand Down Expand Up @@ -448,11 +445,8 @@ def generate_config_h(ext, build_dir):
mathlibs = check_mathlib(config_cmd)
moredefs.append(('MATHLIB', ','.join(mathlibs)))

# Check if libdivide needs to be used
check_libdivide() and moredefs.append('USE_LIBDIVIDE')

# Check if optimal divisor code needs to be used
check_optimal_divisor() and moredefs.append('USE_OPTIMAL_DIVISOR')
# Check if legacy division needs to be used
check_use_legacy_division() and moredefs.append('USE_LEGACY_DIVISION')

check_math_capabilities(config_cmd, ext, moredefs, mathlibs)
moredefs.extend(cocache.check_ieee_macros(config_cmd)[0])
Expand Down
58 changes: 2 additions & 56 deletions numpy/core/src/umath/loops.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/* Use Libdivide for faster division */
/* TODO Explore placing specialised versions in `numpy/core/src/common/simd` */
#ifdef USE_LIBDIVIDE
#ifndef USE_LEGACY_DIVISION
#include "numpy/libdivide.h"
#endif

Expand Down Expand Up @@ -847,7 +847,7 @@ NPY_NO_EXPORT NPY_GCC_OPT_3 void
UNARY_LOOP_FAST(@type@, @type@, *out = in > 0 ? 1 : (in < 0 ? -1 : 0));
}

#ifdef USE_LIBDIVIDE
#ifndef USE_LEGACY_DIVISION
NPY_NO_EXPORT void
@TYPE@_divide(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func))
{
Expand Down Expand Up @@ -901,60 +901,6 @@ NPY_NO_EXPORT void
}
}
}
#elif defined(USE_OPTIMAL_DIVISOR)
NPY_NO_EXPORT void
@TYPE@_divide(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func))
{
BINARY_LOOP_BASE

if(!is2) {
const @type@ in2 = *(@type@ *)ip2;
const float in2_f = (float) in2;
BINARY_LOOP_FIXED {
const @type@ in1 = *(@type@ *)ip1;
/*
* FIXME: On x86 at least, dividing the smallest representable integer
* by -1 causes a SIFGPE (division overflow). We treat this case here
* (to avoid a SIGFPE crash at python level), but a good solution would
* be to treat integer division problems separately from FPU exceptions
* (i.e. a different approach than npy_set_floatstatus_divbyzero()).
*/
if (in2 == 0 || (in1 == NPY_MIN_@TYPE@ && in2 == -1)) {
npy_set_floatstatus_divbyzero();
*((@type@ *)op1) = 0;
}
else if ((in1 > 0) != (in2 > 0)) {
*((@type@ *)op1) = floor(in1/in2_f);
}
else {
*((@type@ *)op1) = in1/in2;
}
}
}
else {
BINARY_LOOP_SLIDING { // XXX Lot of repeated code
const @type@ in1 = *(@type@ *)ip1;
const @type@ in2 = *(@type@ *)ip2;
/*
* FIXME: On x86 at least, dividing the smallest representable integer
* by -1 causes a SIFGPE (division overflow). We treat this case here
* (to avoid a SIGFPE crash at python level), but a good solution would
* be to treat integer division problems separately from FPU exceptions
* (i.e. a different approach than npy_set_floatstatus_divbyzero()).
*/
if (in2 == 0 || (in1 == NPY_MIN_@TYPE@ && in2 == -1)) {
npy_set_floatstatus_divbyzero();
*((@type@ *)op1) = 0;
}
else if (((in1 > 0) != (in2 > 0)) && (in1 % in2 != 0)) {
*((@type@ *)op1) = in1/in2 - 1;
}
else {
*((@type@ *)op1) = in1/in2;
}
}
}
}
#else
NPY_NO_EXPORT void
@TYPE@_divide(char **args, npy_intp const *dimensions, npy_intp const *steps, void *NPY_UNUSED(func))
Expand Down
0