diff --git a/numpy/core/setup.py b/numpy/core/setup.py index 92dcacede412..6095d147454f 100644 --- a/numpy/core/setup.py +++ b/numpy/core/setup.py @@ -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', diff --git a/numpy/core/src/npymath/call_emms.asm b/numpy/core/src/npymath/call_emms.asm new file mode 100644 index 000000000000..5fd3c17101a2 --- /dev/null +++ b/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 + diff --git a/numpy/core/src/npymath/call_emms.obj b/numpy/core/src/npymath/call_emms.obj new file mode 100644 index 000000000000..482ad42cd900 Binary files /dev/null and b/numpy/core/src/npymath/call_emms.obj differ diff --git a/numpy/core/src/npymath/npy_math_internal.h.src b/numpy/core/src/npymath/npy_math_internal.h.src index 18b6d1434ef4..2181a35a9574 100644 --- a/numpy/core/src/npymath/npy_math_internal.h.src +++ b/numpy/core/src/npymath/npy_math_internal.h.src @@ -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# @@ -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@ @@ -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 @@ -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) @@ -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) { @@ -757,3 +791,4 @@ npy_rshift@u@@c@(npy_@u@@type@ a, npy_@u@@type@ b) } /**end repeat1**/ /**end repeat**/ + diff --git a/numpy/distutils/command/build_clib.py b/numpy/distutils/command/build_clib.py index 87345adbc2a0..cb88440ed8bc 100644 --- a/numpy/distutils/command/build_clib.py +++ b/numpy/distutils/command/build_clib.py @@ -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: @@ -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 +