From cc65063de9adb38f9e3d5ccc8a85135ae269124b Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Sun, 24 Mar 2019 18:10:43 +0100 Subject: another ternary implementation --- test/monniaux/ternary/ternary.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test/monniaux/ternary') diff --git a/test/monniaux/ternary/ternary.c b/test/monniaux/ternary/ternary.c index 45201ff8..79025639 100644 --- a/test/monniaux/ternary/ternary.c +++ b/test/monniaux/ternary/ternary.c @@ -5,10 +5,16 @@ typedef uint32_t data; +#if 0 +#define TERNARY(a, b, c) ((a) ? (b) : (c)) +#else +#define TERNARY(a, b, c) (((-(a)) & (b)) | ((-1+(a)) & (c))) +#endif + data silly_computation(void) { data x = 1; for(int i=0; i<10000; i++) { - x = x * (((x & 0x100) != 0) ? 45561U : 337777U); + x = x * TERNARY(((x & 0x100) != 0), 45561U, 337777U); } return x; } -- cgit