Skip to content

Commit

Permalink
ENH, BUG: use emms assembly call after calling fmod on windows 64-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip committed Oct 14, 2020
1 parent 18da0ef commit 3fe6989
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
6 changes: 6 additions & 0 deletions numpy/core/setup.py
Expand Up @@ -674,6 +674,12 @@ def get_mathlib_info(*args):
# Intel and Clang also don't seem happy with /GL
is_msvc = (platform.platform().startswith('Windows') and
platform.python_compiler().startswith('MS'))

# issue 16744: remove this code and the call to call_emms in nypmath
# when there is a fix from microsoft
if platform.platform().startswith('Windows') and sys.maxsize > 2**32:
npymath_sources.append(join('src', 'npymath', 'call_emms.obj'))

config.add_installed_library('npymath',
sources=npymath_sources + [get_mathlib_info],
install_dir='lib',
Expand Down
8 changes: 8 additions & 0 deletions numpy/core/src/npymath/call_emms.asm
@@ -0,0 +1,8 @@
.code
call_emms proc
emms
mov eax, 0
ret ; Return EAX
call_emms endp
end

Binary file added numpy/core/src/npymath/call_emms.obj
Binary file not shown.
43 changes: 39 additions & 4 deletions numpy/core/src/npymath/npy_math_internal.h.src
Expand Up @@ -371,6 +371,10 @@ NPY_INPLACE double npy_log2(double x)
* instead test for the macro, but I am lazy to do that for now.
*/

#ifdef _WIN64
int call_emms(void);
#endif

/**begin repeat
* #type = npy_longdouble, npy_float#
* #TYPE = NPY_LONGDOUBLE, FLOAT#
Expand Down Expand Up @@ -398,8 +402,8 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
/**end repeat1**/

/**begin repeat1
* #kind = atan2,hypot,pow,fmod,copysign#
* #KIND = ATAN2,HYPOT,POW,FMOD,COPYSIGN#
* #kind = atan2,hypot,pow,copysign#
* #KIND = ATAN2,HYPOT,POW,COPYSIGN#
*/
#ifdef @kind@@c@
#undef @kind@@c@
Expand All @@ -412,6 +416,21 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
#endif
/**end repeat1**/

#ifdef fmod@c@
#undef fmod@c@
#endif
#ifndef HAVE_FMOD@C@

NPY_INPLACE @type@ npy_fmod@c@(@type@ x, @type@ y)
{
@type@ ret = (@type@)npy_fmod((double)x, (double) y);
#ifdef _WIN64
call_emms();
#endif
return ret;
}
#endif

#ifdef modf@c@
#undef modf@c@
#endif
Expand Down Expand Up @@ -473,8 +492,8 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
/**end repeat1**/

/**begin repeat1
* #kind = atan2,hypot,pow,fmod,copysign#
* #KIND = ATAN2,HYPOT,POW,FMOD,COPYSIGN#
* #kind = atan2,hypot,pow,copysign#
* #KIND = ATAN2,HYPOT,POW,COPYSIGN#
*/
#ifdef HAVE_@KIND@@C@
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
Expand All @@ -484,6 +503,21 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
#endif
/**end repeat1**/

#ifdef HAVE_FMOD@C@

NPY_INPLACE @type@ npy_fmod@c@(@type@ x, @type@ y)
{
@type@ ret = fmod@c@(x, y);
#ifdef _WIN64
call_emms();
#endif
return ret;
}
#endif




#ifdef HAVE_MODF@C@
NPY_INPLACE @type@ npy_modf@c@(@type@ x, @type@ *iptr)
{
Expand Down Expand Up @@ -757,3 +791,4 @@ npy_rshift@u@@c@(npy_@u@@type@ a, npy_@u@@type@ b)
}
/**end repeat1**/
/**end repeat**/

13 changes: 10 additions & 3 deletions numpy/distutils/command/build_clib.py
Expand Up @@ -289,16 +289,22 @@ def build_a_library(self, build_info, lib_name, libraries):
# problem, msvc uses its own convention :(
c_sources += cxx_sources
cxx_sources = []
obj_ext = '.obj'
else:
obj_ext = '.o'

objects = []
# c_sources collects all the default sources, including pre-compiled
# object files
objects = [c_sources.pop(c_sources.index(c)) for c in c_sources[:]
if c.endswith(obj_ext)]
if c_sources:
log.info("compiling C sources")
objects = compiler.compile(c_sources,
objects.extend(compiler.compile(c_sources,
output_dir=self.build_temp,
macros=macros,
include_dirs=include_dirs,
debug=self.debug,
extra_postargs=extra_args_baseopt)
extra_postargs=extra_args_baseopt))
objects.extend(dispatch_objects)

if cxx_sources:
Expand Down Expand Up @@ -392,3 +398,4 @@ def build_a_library(self, build_info, lib_name, libraries):
clib_libraries.extend(binfo.get('libraries', []))
if clib_libraries:
build_info['libraries'] = clib_libraries

0 comments on commit 3fe6989

Please sign in to comment.