aboutsummaryrefslogtreecommitdiffstats
path: root/test/regression/builtins-common.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@college-de-france.fr>2020-07-25 17:13:05 +0200
committerXavier Leroy <xavierleroy@users.noreply.github.com>2020-07-27 16:30:28 +0200
commit70f105e623dddeb27be258fedb56bd0e9a59d190 (patch)
tree4c6130620108ec3b2d42f476986fe2896f0dae4a /test/regression/builtins-common.c
parentbc20d7c0d16d07790fb6eb608bf608237b0abbc3 (diff)
downloadcompcert-kvx-70f105e623dddeb27be258fedb56bd0e9a59d190.tar.gz
compcert-kvx-70f105e623dddeb27be258fedb56bd0e9a59d190.zip
Refactor regression testing of built-in functions
Share the testing code for built-in functions that are available on all target platforms. Improve testing of __builtin_clz* and __builtin_ctz*
Diffstat (limited to 'test/regression/builtins-common.c')
-rw-r--r--test/regression/builtins-common.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/regression/builtins-common.c b/test/regression/builtins-common.c
new file mode 100644
index 00000000..7d975f0a
--- /dev/null
+++ b/test/regression/builtins-common.c
@@ -0,0 +1,52 @@
+/* Builtin functions that are implemented on all target processors */
+
+#include <stdio.h>
+
+unsigned int x = 0x12345678;
+unsigned int y = 0xDEADBEEF;
+unsigned long long xx = 0x123456789ABCDEF0ULL;
+double a = 3.14159;
+double b = 2.718;
+double c = 1.414;
+unsigned short s = 0x1234;
+
+int main(int argc, char ** argv)
+{
+ printf("bswap(%x) = %x\n", x, __builtin_bswap(x));
+ printf("bswap16(%x) = %x\n", s, __builtin_bswap16(s));
+ printf("bswap64(%llx) = %llx\n", xx, __builtin_bswap64(xx));
+ for (int i = 0; i < 32; i++) {
+ unsigned z = 0xFFFFFFFFU >> i;
+ printf("clz(%08x) = %d\n", z, __builtin_clz(z));
+ z = 0x80000000U >> i;
+ printf("clz(%08x) = %d\n", z, __builtin_clz(z));
+ }
+ for (int i = 0; i < 64; i++) {
+ unsigned long long z = 0xFFFFFFFFFFFFFFFFULL >> i;
+ printf("clzll(%016llx) = %d\n", z, __builtin_clzll(z));
+ z = 0x8000000000000000ULL >> i;
+ printf("clzll(%016llx) = %d\n", z, __builtin_clzll(z));
+ }
+ for (int i = 0; i < 32; i++) {
+ unsigned z = 1U << i;
+ printf("ctz(%08x) = %d\n", z, __builtin_ctz(z));
+ z = 0xFFFFFFFFU << i;
+ printf("ctz(%08x) = %d\n", z, __builtin_ctz(z));
+ }
+ for (int i = 0; i < 64; i++) {
+ unsigned long long z = 1ULL << i;
+ printf("ctzll(%016llx) = %d\n", z, __builtin_ctzll(z));
+ z = 0xFFFFFFFFFFFFFFFFULL << i;
+ printf("ctzll(%016llx) = %d\n", z, __builtin_ctzll(z));
+ }
+ printf("fabs(%f) = %f\n", a, __builtin_fabs(a));
+ printf("fabs(%f) = %f\n", -a, __builtin_fabs(-a));
+ printf("fsqrt(%f) = %f\n", a, __builtin_fsqrt(a));
+
+ /* Make sure that ignoring the result of a builtin
+ doesn't cause an internal error */
+ (void) __builtin_bswap(x);
+ (void) __builtin_fsqrt(a);
+ (void) __builtin_sel(a > 0.0, x, y);
+ return 0;
+}