diff --git a/daz/__init__.py b/daz/__init__.py index b76dc1f..d23fb78 100644 --- a/daz/__init__.py +++ b/daz/__init__.py @@ -1,5 +1,7 @@ from daz._core import set_daz # NOQA from daz._core import set_ftz # NOQA +from daz._core import get_daz # NOQA +from daz._core import get_ftz # NOQA from daz._core import unset_daz # NOQA from daz._core import unset_ftz # NOQA from daz._version import __version__ # NOQA diff --git a/daz/_core.c b/daz/_core.c index a0ce206..c3b7e8d 100644 --- a/daz/_core.c +++ b/daz/_core.c @@ -19,6 +19,22 @@ static PyObject* set_ftz(void) return Py_None; } +static PyObject* get_daz(void) +{ + unsigned int mxcsr = _mm_getcsr(); + if((1<<6)&mxcsr) + Py_RETURN_TRUE; + Py_RETURN_FALSE; +} + +static PyObject* get_ftz(void) +{ + unsigned int mxcsr = _mm_getcsr(); + if((1<<15)&mxcsr) + Py_RETURN_TRUE; + Py_RETURN_FALSE; +} + static PyObject* unset_daz(void) { unsigned int mxcsr = _mm_getcsr(); @@ -40,6 +56,8 @@ static PyObject* unset_ftz(void) static PyMethodDef methods[] = { {"set_ftz", (PyCFunction)set_ftz, METH_NOARGS, 0}, {"set_daz", (PyCFunction)set_daz, METH_NOARGS, 0}, + {"get_ftz", (PyCFunction)get_ftz, METH_NOARGS, 0}, + {"get_daz", (PyCFunction)get_daz, METH_NOARGS, 0}, {"unset_ftz", (PyCFunction)unset_ftz, METH_NOARGS, 0}, {"unset_daz", (PyCFunction)unset_daz, METH_NOARGS, 0}, {NULL, NULL, 0, NULL} diff --git a/tests/test_daz.py b/tests/test_daz.py index c770a55..54f93cb 100644 --- a/tests/test_daz.py +++ b/tests/test_daz.py @@ -16,12 +16,16 @@ def setUp(self): def check_normal(self): assert self.normal == self.denormal * self.scale assert self.normal / self.scale == self.denormal + assert not daz.get_daz() + assert not daz.get_ftz() def test_normal(self): self.check_normal() def test_daz(self): daz.set_daz() + assert daz.get_daz() + assert not daz.get_ftz() assert self.normal / self.scale == 0 assert self.denormal * self.scale == 0 assert self.denormal == 0 @@ -30,6 +34,8 @@ def test_daz(self): def test_ftz(self): daz.set_ftz() + assert daz.get_ftz() + assert not daz.get_daz() assert self.normal / self.scale == 0 assert self.denormal * self.scale == self.normal assert self.denormal != 0