From 98383707438a3e31ffd86a82b57fbe439945f777 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Fri, 5 Apr 2019 15:18:50 +0200 Subject: move patterns to include file --- test/monniaux/ternary.h | 23 +++++++++++++++++++++++ test/monniaux/ternary/ternary.c | 16 ++-------------- 2 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 test/monniaux/ternary.h (limited to 'test') diff --git a/test/monniaux/ternary.h b/test/monniaux/ternary.h new file mode 100644 index 00000000..43cdbd12 --- /dev/null +++ b/test/monniaux/ternary.h @@ -0,0 +1,23 @@ +#include + +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); +} + +static inline int64_t ternary_int64(int64_t a, int64_t b, int64_t c) { + return (((-((a) == 0)) & (c)) | ((-((a) != 0)) & (b))); +} +static inline uint64_t ternary_uint64(uint64_t a, uint64_t b, uint64_t c) { + return ternary_int64(a, b, c); +} + +#if defined(__COMPCERT__) && defined(__K1C__) +#define TERNARY32(a, b, c) ternary_uint32((a), (b), (c)) +#define TERNARY64(a, b, c) ternary_uint64((a), (b), (c)) +#else +#define TERNARY32(a, b, c) ((a) ? (b) : (c)) +#define TERNARY64(a, b, c) ((a) ? (b) : (c)) +#endif diff --git a/test/monniaux/ternary/ternary.c b/test/monniaux/ternary/ternary.c index 61da9597..ed7de156 100644 --- a/test/monniaux/ternary/ternary.c +++ b/test/monniaux/ternary/ternary.c @@ -2,26 +2,14 @@ #include #include #include "../clock.h" +#include "../ternary.h" typedef uint32_t data; -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) : (c)) -#endif - data silly_computation(void) { data x = 1; for(int i=0; i<10000; i++) { - x = x * TERNARY(x & 0x100, 45561U, 337777U); + x = x * TERNARY32(x & 0x100, 45561U, 337777U); } return x; } -- cgit