aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/ternary
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-05 15:13:33 +0200
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-04-05 15:13:33 +0200
commitcba7f5e13ccea83e60ccfdf1895bef18bf50fe0a (patch)
tree9cb6f8ec6ae0eb86811e2aacf51d6fb3e76c512d /test/monniaux/ternary
parent27d1525b819cf4f82e4a2f2943596001b50c44b7 (diff)
downloadcompcert-kvx-cba7f5e13ccea83e60ccfdf1895bef18bf50fe0a.tar.gz
compcert-kvx-cba7f5e13ccea83e60ccfdf1895bef18bf50fe0a.zip
implement using our "pattern matching"
Diffstat (limited to 'test/monniaux/ternary')
-rw-r--r--test/monniaux/ternary/ternary.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/test/monniaux/ternary/ternary.c b/test/monniaux/ternary/ternary.c
index 79025639..61da9597 100644
--- a/test/monniaux/ternary/ternary.c
+++ b/test/monniaux/ternary/ternary.c
@@ -5,16 +5,23 @@
typedef uint32_t data;
-#if 0
-#define TERNARY(a, b, c) ((a) ? (b) : (c))
+static inline int32_t ternary_int32(int32_t a, int32_t b, int32_t c) {
+ return (((-((a) == 0)) & (c)) | ((-((a) != 0)) & (b)));
+}
+static inline uint32_t ternary_uint32(uint32_t a, uint32_t b, uint32_t c) {
+ return ternary_int32(a, b, c);
+}
+
+#if defined(__COMPCERT__) && defined(__K1C__)
+#define TERNARY(a, b, c) ternary_uint32((a), (b), (c))
#else
-#define TERNARY(a, b, c) (((-(a)) & (b)) | ((-1+(a)) & (c)))
+#define TERNARY(a, b, c) ((a) ? (b) : (c))
#endif
data silly_computation(void) {
data x = 1;
for(int i=0; i<10000; i++) {
- x = x * TERNARY(((x & 0x100) != 0), 45561U, 337777U);
+ x = x * TERNARY(x & 0x100, 45561U, 337777U);
}
return x;
}