aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/math
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-13 19:06:37 +0200
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-13 19:06:37 +0200
commitb19288248802ec3f3e1adbf734655068c5559052 (patch)
tree2a4a4724ff9c00726287fb5e5aaae7fda3b10ef0 /test/monniaux/math
parent814090921e6c3b6a61b9328f01d7bad475bdeaf6 (diff)
downloadcompcert-kvx-b19288248802ec3f3e1adbf734655068c5559052.tar.gz
compcert-kvx-b19288248802ec3f3e1adbf734655068c5559052.zip
experiments with rounding modes
Diffstat (limited to 'test/monniaux/math')
-rw-r--r--test/monniaux/math/rounding.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/test/monniaux/math/rounding.c b/test/monniaux/math/rounding.c
index 4831c3d1..c2ce85e3 100644
--- a/test/monniaux/math/rounding.c
+++ b/test/monniaux/math/rounding.c
@@ -1,20 +1,36 @@
#include <stdio.h>
#include <fenv.h>
+#ifdef __K1C__
+#include <mppa_bare_runtime/k1c/registers.h>
+int fesetround(int rounding_mode) {
+ if (rounding_mode < 0 || rounding_mode > 3) return 1;
+ unsigned long long cs = __builtin_k1_get(K1_SFR_CS);
+ cs = (cs & ~(3 << 16)) | (rounding_mode << 16);
+ __builtin_k1_set(K1_SFR_CS, cs);
+ return 0;
+}
+
+int fegetround(void) {
+ unsigned long long cs = __builtin_k1_get(K1_SFR_CS);
+ return (cs >> 16) & 3;
+}
+#endif
+
#pragma STDC FENV_ACCESS ON
-double inverse(double x) {
- return 1.0 / x;
+double add(double x) {
+ return x+0.1;
}
int main() {
if (fesetround(FE_DOWNWARD)) {
printf("fesetround(FE_DOWNWARD) unsuccessful\n");
}
- double low = inverse(3.0);
+ double low = add(3.0);
if (fesetround(FE_UPWARD)) {
printf("fesetround(FE_UPWARD) unsuccessful\n");
}
- double high = inverse(3.0);
- printf("%d %a\n", low==high, high-low);
+ double high = add(3.0);
+ printf("%d %a %d\n", low==high, high-low, fegetround());
}