diff options
Diffstat (limited to 'test/monniaux/ternary/ternary.c')
-rw-r--r-- | test/monniaux/ternary/ternary.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/monniaux/ternary/ternary.c b/test/monniaux/ternary/ternary.c new file mode 100644 index 00000000..79025639 --- /dev/null +++ b/test/monniaux/ternary/ternary.c @@ -0,0 +1,29 @@ +#include <stdint.h> +#include <stdio.h> +#include <inttypes.h> +#include "../clock.h" + +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 * TERNARY(((x & 0x100) != 0), 45561U, 337777U); + } + return x; +} + +int main() { + clock_prepare(); + clock_start(); + data result = silly_computation(); + clock_stop(); + printf("result=%" PRIu32 "\ncycles=%" PRIu64 "\n", result, get_total_clock()); + return 0; +} |