From 255cee09b71255051c2b40eae0c88bffce1f6f32 Mon Sep 17 00:00:00 2001 From: xleroy Date: Sat, 20 Apr 2013 07:54:52 +0000 Subject: Big merge of the newregalloc-int64 branch. Lots of changes in two directions: 1- new register allocator (+ live range splitting, spilling&reloading, etc) based on a posteriori validation using the Rideau-Leroy algorithm 2- support for 64-bit integer arithmetic (type "long long"). git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2200 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- test/regression/int64.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 test/regression/int64.c (limited to 'test/regression/int64.c') diff --git a/test/regression/int64.c b/test/regression/int64.c new file mode 100644 index 00000000..55a4f887 --- /dev/null +++ b/test/regression/int64.c @@ -0,0 +1,115 @@ +/* Semi-random testing of 64-bit integer operations */ + +#include + +typedef unsigned long long u64; +typedef signed long long s64; + +static u64 rnd64(void) +{ + static u64 seed = 0; + seed = seed * 6364136223846793005ULL + 1442695040888963407ULL; + return seed; +} + +static inline u64 safe_udiv64(u64 x, u64 y) +{ + if (y == 0) return 0; else return x / y; +} + +static inline u64 safe_umod64(u64 x, u64 y) +{ + if (y == 0) return 0; else return x % y; +} + +static inline s64 safe_sdiv64(s64 x, s64 y) +{ + if (y == 0 || (y == -1 && x == (-1LL << 63))) return 0; else return x / y; +} + +static inline s64 safe_smod64(s64 x, s64 y) +{ + if (y == 0 || (y == -1 && x == (-1LL << 63))) return 0; else return x % y; +} + +static void test1(u64 x, u64 y) +{ + u64 y2; + s64 y3; + int i; + double f; + + printf("x = %llx\n", x); + printf("y = %llx\n", y); + printf("-x = %llx\n", -x); + printf("x + y = %llx\n", x + y); + printf("x - y = %llx\n", x - y); + printf("x * y = %llx\n", x * y); + printf("x /u y = %llx\n", safe_udiv64(x, y)); + printf("x %%u y = %llx\n", safe_umod64(x, y)); + printf("x /s y = %llx\n", safe_sdiv64(x, y)); + printf("x %%s y = %llx\n", safe_smod64(x, y)); + y2 = y >> 32; + printf("x /u y2 = %llx\n", safe_udiv64(x, y2)); + printf("x %%u y2 = %llx\n", safe_umod64(x, y2)); + y3 = ((s64)y) >> 32; + printf("x /s y3 = %llx\n", safe_sdiv64(x, y3)); + printf("x %%s y3 = %llx\n", safe_smod64(x, y3)); + printf("~x = %llx\n", ~x); + printf("x & y = %llx\n", x & y); + printf("x | y = %llx\n", x | y); + printf("x ^ y = %llx\n", x ^ y); + i = y & 63; + printf("x << i = %llx\n", x << i); + printf("x >>u i = %llx\n", x >> i); + printf("x >>s i = %llx\n", (s64) x >> i); + printf("x cmpu y = %s\n", + x == y ? "eq" : x < y ? "lt" : "gt"); + printf("x cmps y = %s\n", + x == y ? "eq" : (s64)x < (s64)y ? "lt" : "gt"); + f = (double) x; + printf("utod x = %llx\n", *((u64*) &f)); + f = f * 0.0001; + printf("dtou f = %llx\n", (u64) f); + f = (double) ((s64) x); + printf("stod x = %llx\n", *((u64*) &f)); + f = f * 0.0001; + printf("dtos f = %llx\n", (s64) f); + printf("\n"); +} + +u64 special_values[] = { + 0, + 1, + -1, + 0x7FFFFFFFLLU, + 0x80000000LLU, + 0x7FFFFFFFFFFFFFFFLLU, + 0x8000000000000000LLU +}; + +int main() +{ + int i, j; + u64 x, y; + + for (i = 0; i <= 4; i++) { + for (j = 0; j <= 4; j++) { + test1(special_values[i], special_values[j]); + } + test1(special_values[i], rnd64()); + test1(rnd64(), special_values[i]); + } + for (i = 0; i < 100; i++) { + x = rnd64(); y = rnd64(); + test1(x, y); + } + return 0; +} + + + + + + + -- cgit