forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_fpumode.c
76 lines (59 loc) · 1.3 KB
/
_fpumode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <Python.h>
#include <stdio.h>
#ifdef _MSC_VER
#pragma float_control(precise, on)
#pragma fenv_access (on)
#endif
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 *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
Py_RETURN_NONE;
#endif
}
static struct PyMethodDef methods[] = {
{"get_fpu_mode", get_fpu_mode, METH_VARARGS, get_fpu_mode_doc},
{NULL, NULL, 0, NULL}
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"_fpumode",
NULL,
-1,
methods,
NULL,
NULL,
NULL,
NULL
};
PyObject *PyInit__fpumode(void)
{
return PyModule_Create(&moduledef);
}
#else
PyMODINIT_FUNC init_fpumode(void)
{
Py_InitModule("_fpumode", methods);
}
#endif