diff options
author | David Monniaux <david.monniaux@univ-grenoble-alpes.fr> | 2019-04-05 15:13:33 +0200 |
---|---|---|
committer | David Monniaux <david.monniaux@univ-grenoble-alpes.fr> | 2019-04-05 15:13:33 +0200 |
commit | cba7f5e13ccea83e60ccfdf1895bef18bf50fe0a (patch) | |
tree | 9cb6f8ec6ae0eb86811e2aacf51d6fb3e76c512d /test/monniaux | |
parent | 27d1525b819cf4f82e4a2f2943596001b50c44b7 (diff) | |
download | compcert-kvx-cba7f5e13ccea83e60ccfdf1895bef18bf50fe0a.tar.gz compcert-kvx-cba7f5e13ccea83e60ccfdf1895bef18bf50fe0a.zip |
implement using our "pattern matching"
Diffstat (limited to 'test/monniaux')
-rw-r--r-- | test/monniaux/ternary/ternary.c | 15 |
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; } |