aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/math
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-13 20:34:45 +0200
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-13 20:34:45 +0200
commit14cb39a563f56c852d8dacbbfa9604a722079e49 (patch)
treeafa7442f8e95071d0bcac3c1344d8cf9140c6cf8 /test/monniaux/math
parentb19288248802ec3f3e1adbf734655068c5559052 (diff)
downloadcompcert-kvx-14cb39a563f56c852d8dacbbfa9604a722079e49.tar.gz
compcert-kvx-14cb39a563f56c852d8dacbbfa9604a722079e49.zip
code for checking IEEE-754 exceptions
Diffstat (limited to 'test/monniaux/math')
-rw-r--r--test/monniaux/math/exceptions.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/monniaux/math/exceptions.c b/test/monniaux/math/exceptions.c
new file mode 100644
index 00000000..d4a6a26b
--- /dev/null
+++ b/test/monniaux/math/exceptions.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <fenv.h>
+#include <float.h>
+
+#ifdef __K1C__
+#include <mppa_bare_runtime/k1c/registers.h>
+int fetestexcept(int excepts) {
+ int mask = (K1_SFR_CS_IO_MASK | K1_SFR_CS_DZ_MASK | K1_SFR_CS_OV_MASK | K1_SFR_CS_UN_MASK | K1_SFR_CS_IN_MASK) & excepts;
+ unsigned long long cs = __builtin_k1_get(K1_SFR_CS);
+ return cs & mask;
+}
+
+int feclearexcept(int excepts) {
+ int mask = (K1_SFR_CS_IO_MASK | K1_SFR_CS_DZ_MASK | K1_SFR_CS_OV_MASK | K1_SFR_CS_UN_MASK | K1_SFR_CS_IN_MASK) & excepts;
+ __builtin_k1_wfxl(K1_SFR_CS, mask);
+ return 0;
+}
+#endif
+
+#pragma STDC FENV_ACCESS ON
+
+double add(double x, double y) {
+ return x+y;
+}
+
+double mul(double x, double y) {
+ return x*y;
+}
+
+int main() {
+ printf("%x\n", fetestexcept(FE_ALL_EXCEPT));
+ double v1 = add(3.0, 0.1);
+ printf("%x\n", fetestexcept(FE_ALL_EXCEPT));
+ feclearexcept(FE_INEXACT);
+ printf("%x\n", fetestexcept(FE_ALL_EXCEPT));
+ double v2 = mul(DBL_MAX, DBL_MAX);
+ printf("%g %x\n", v2, fetestexcept(FE_ALL_EXCEPT));
+ feclearexcept(FE_ALL_EXCEPT);
+ double v3 = mul(DBL_MIN, DBL_MIN);
+ printf("%g %x\n", v3, fetestexcept(FE_ALL_EXCEPT));
+}