diff options
author | Pauli Virtanen <pav@iki.fi> | 2017-08-16 18:00:18 +0200 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2017-08-16 18:16:14 +0200 |
commit | b5f472d450522a701fa526f8c85f7eb467d65c1a (patch) | |
tree | 8f825384891abfb3c2459aa19ff9460b765b9345 /numpy/core | |
parent | 441c082c881455a1149fa14ab7de2b91286da554 (diff) | |
download | numpy-b5f472d450522a701fa526f8c85f7eb467d65c1a.tar.gz |
ENH: check for FPU mode changes in the test suite
Emit a test failure if the FPU mode changes when running a test case,
allowing to pinpoint what test caused the mode change.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarray/multiarray_tests.c.src | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/multiarray_tests.c.src b/numpy/core/src/multiarray/multiarray_tests.c.src index f5be52d74..657c4064e 100644 --- a/numpy/core/src/multiarray/multiarray_tests.c.src +++ b/numpy/core/src/multiarray/multiarray_tests.c.src @@ -1560,6 +1560,37 @@ extint_ceildiv_128_64(PyObject *NPY_UNUSED(self), PyObject *args) { } +static char get_fpu_mode_doc[] = ( + "get_fpu_mode()\n" + "\n" + "Get the current FPU control word, in a platform-dependent format.\n" + "Returns None if not implemented on current platform."); + +static PyObject * +get_fpu_mode(PyObject *NPY_UNUSED(self), PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) { + return NULL; + } + +#if defined(_MSC_VER) + { + unsigned int result = 0; + result = _controlfp(0, 0); + return PyLong_FromLongLong(result); + } +#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) + { + unsigned short cw = 0; + __asm__("fstcw %w0" : "=m" (cw)); + return PyLong_FromLongLong(cw); + } +#else + return Py_RETURN_NONE; +#endif +} + + static PyMethodDef Multiarray_TestsMethods[] = { {"IsPythonScalar", IsPythonScalar, @@ -1650,6 +1681,9 @@ static PyMethodDef Multiarray_TestsMethods[] = { {"extint_ceildiv_128_64", extint_ceildiv_128_64, METH_VARARGS, NULL}, + {"get_fpu_mode", + get_fpu_mode, + METH_VARARGS, get_fpu_mode_doc}, {NULL, NULL, 0, NULL} /* Sentinel */ }; |