aboutsummaryrefslogtreecommitdiff
path: root/test/builtins/Unit/arm
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
commit5c909fa013fc285f010a95e8d387e0ef3412da9c (patch)
tree1059d068ad281f4776ff44cd414574f99a460023 /test/builtins/Unit/arm
parentf31bcc68c72371a2bf63aead9f3373a1ff2053b6 (diff)
downloadsrc-5c909fa013fc285f010a95e8d387e0ef3412da9c.tar.gz
src-5c909fa013fc285f010a95e8d387e0ef3412da9c.zip
Vendor import of compiler-rt trunk r256633:vendor/compiler-rt/compiler-rt-trunk-r256633
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=292925 svn path=/vendor/compiler-rt/compiler-rt-trunk-r256633/; revision=292926; tag=vendor/compiler-rt/compiler-rt-trunk-r256633
Diffstat (limited to 'test/builtins/Unit/arm')
-rw-r--r--test/builtins/Unit/arm/aeabi_cdcmpeq_test.c70
-rw-r--r--test/builtins/Unit/arm/aeabi_cdcmple_test.c92
-rw-r--r--test/builtins/Unit/arm/aeabi_cfcmpeq_test.c70
-rw-r--r--test/builtins/Unit/arm/aeabi_cfcmple_test.c92
-rw-r--r--test/builtins/Unit/arm/aeabi_drsub_test.c47
-rw-r--r--test/builtins/Unit/arm/aeabi_frsub_test.c47
-rw-r--r--test/builtins/Unit/arm/call_apsr.S43
-rw-r--r--test/builtins/Unit/arm/call_apsr.h39
8 files changed, 500 insertions, 0 deletions
diff --git a/test/builtins/Unit/arm/aeabi_cdcmpeq_test.c b/test/builtins/Unit/arm/aeabi_cdcmpeq_test.c
new file mode 100644
index 000000000000..ce8b0a4313fb
--- /dev/null
+++ b/test/builtins/Unit/arm/aeabi_cdcmpeq_test.c
@@ -0,0 +1,70 @@
+//===-- aeabi_cdcmpeq.c - Test __aeabi_cdcmpeq ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __aeabi_cdcmpeq for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#if __arm__
+#include "call_apsr.h"
+
+extern __attribute__((pcs("aapcs"))) void __aeabi_cdcmpeq(double a, double b);
+
+int test__aeabi_cdcmpeq(double a, double b, int expected)
+{
+ uint32_t cpsr_value = call_apsr_d(a, b, __aeabi_cdcmpeq);
+ union cpsr cpsr = { .value = cpsr_value };
+ if (expected != cpsr.flags.z) {
+ printf("error in __aeabi_cdcmpeq(%f, %f) => Z = %d, expected %d\n",
+ a, b, cpsr.flags.z, expected);
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+int main()
+{
+#if __arm__
+ if (test__aeabi_cdcmpeq(1.0, 1.0, 1))
+ return 1;
+ if (test__aeabi_cdcmpeq(1234.567, 765.4321, 0))
+ return 1;
+ if (test__aeabi_cdcmpeq(-123.0, -678.0, 0))
+ return 1;
+ if (test__aeabi_cdcmpeq(0.0, -0.0, 1))
+ return 1;
+ if (test__aeabi_cdcmpeq(1.0, NAN, 0))
+ return 1;
+ if (test__aeabi_cdcmpeq(NAN, 1.0, 0))
+ return 1;
+ if (test__aeabi_cdcmpeq(NAN, NAN, 0))
+ return 1;
+ if (test__aeabi_cdcmpeq(INFINITY, 1.0, 0))
+ return 1;
+ if (test__aeabi_cdcmpeq(0.0, INFINITY, 0))
+ return 1;
+ if (test__aeabi_cdcmpeq(-INFINITY, 0.0, 0))
+ return 1;
+ if (test__aeabi_cdcmpeq(0.0, -INFINITY, 0))
+ return 1;
+ if (test__aeabi_cdcmpeq(INFINITY, INFINITY, 1))
+ return 1;
+ if (test__aeabi_cdcmpeq(-INFINITY, -INFINITY, 1))
+ return 1;
+#else
+ printf("skipped\n");
+#endif
+ return 0;
+}
diff --git a/test/builtins/Unit/arm/aeabi_cdcmple_test.c b/test/builtins/Unit/arm/aeabi_cdcmple_test.c
new file mode 100644
index 000000000000..afc701493694
--- /dev/null
+++ b/test/builtins/Unit/arm/aeabi_cdcmple_test.c
@@ -0,0 +1,92 @@
+//===-- aeabi_cdcmple.c - Test __aeabi_cdcmple and __aeabi_cdrcmple -------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __aeabi_cdcmple and __aeabi_cdrcmple for the compiler_rt
+// library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "call_apsr.h"
+
+#if __arm__
+
+extern __attribute__((pcs("aapcs"))) void __aeabi_cdcmple(double a, double b);
+extern __attribute__((pcs("aapcs"))) void __aeabi_cdrcmple(double a, double b);
+
+int test__aeabi_cdcmple(double a, double b, int expected)
+{
+ int32_t cpsr_value = call_apsr_d(a, b, __aeabi_cdcmple);
+ int32_t r_cpsr_value = call_apsr_d(b, a, __aeabi_cdrcmple);
+
+ if (cpsr_value != r_cpsr_value) {
+ printf("error: __aeabi_cdcmple(%f, %f) != __aeabi_cdrcmple(%f, %f)\n", a, b, b, a);
+ return 1;
+ }
+
+ int expected_z, expected_c;
+ if (expected == -1) {
+ expected_z = 0;
+ expected_c = 0;
+ } else if (expected == 0) {
+ expected_z = 1;
+ expected_c = 1;
+ } else {
+ // a or b is NaN, or a > b
+ expected_z = 0;
+ expected_c = 1;
+ }
+
+ union cpsr cpsr = { .value = cpsr_value };
+ if (expected_z != cpsr.flags.z || expected_c != cpsr.flags.c) {
+ printf("error in __aeabi_cdcmple(%f, %f) => (Z = %d, C = %d), expected (Z = %d, C = %d)\n",
+ a, b, cpsr.flags.z, cpsr.flags.c, expected_z, expected_c);
+ return 1;
+ }
+
+ cpsr.value = r_cpsr_value;
+ if (expected_z != cpsr.flags.z || expected_c != cpsr.flags.c) {
+ printf("error in __aeabi_cdrcmple(%f, %f) => (Z = %d, C = %d), expected (Z = %d, C = %d)\n",
+ a, b, cpsr.flags.z, cpsr.flags.c, expected_z, expected_c);
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+int main()
+{
+#if __arm__
+ if (test__aeabi_cdcmple(1.0, 1.0, 0))
+ return 1;
+ if (test__aeabi_cdcmple(1234.567, 765.4321, 1))
+ return 1;
+ if (test__aeabi_cdcmple(765.4321, 1234.567, -1))
+ return 1;
+ if (test__aeabi_cdcmple(-123.0, -678.0, 1))
+ return 1;
+ if (test__aeabi_cdcmple(-678.0, -123.0, -1))
+ return 1;
+ if (test__aeabi_cdcmple(0.0, -0.0, 0))
+ return 1;
+ if (test__aeabi_cdcmple(1.0, NAN, 1))
+ return 1;
+ if (test__aeabi_cdcmple(NAN, 1.0, 1))
+ return 1;
+ if (test__aeabi_cdcmple(NAN, NAN, 1))
+ return 1;
+#else
+ printf("skipped\n");
+#endif
+ return 0;
+}
diff --git a/test/builtins/Unit/arm/aeabi_cfcmpeq_test.c b/test/builtins/Unit/arm/aeabi_cfcmpeq_test.c
new file mode 100644
index 000000000000..fe0166485e69
--- /dev/null
+++ b/test/builtins/Unit/arm/aeabi_cfcmpeq_test.c
@@ -0,0 +1,70 @@
+//===-- aeabi_cfcmpeq.c - Test __aeabi_cfcmpeq ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __aeabi_cfcmpeq for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#if __arm__
+#include "call_apsr.h"
+
+extern __attribute__((pcs("aapcs"))) void __aeabi_cfcmpeq(float a, float b);
+
+int test__aeabi_cfcmpeq(float a, float b, int expected)
+{
+ uint32_t cpsr_value = call_apsr_f(a, b, __aeabi_cfcmpeq);
+ union cpsr cpsr = { .value = cpsr_value };
+ if (expected != cpsr.flags.z) {
+ printf("error in __aeabi_cfcmpeq(%f, %f) => Z = %d, expected %d\n",
+ a, b, cpsr.flags.z, expected);
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+int main()
+{
+#if __arm__
+ if (test__aeabi_cfcmpeq(1.0, 1.0, 1))
+ return 1;
+ if (test__aeabi_cfcmpeq(1234.567, 765.4321, 0))
+ return 1;
+ if (test__aeabi_cfcmpeq(-123.0, -678.0, 0))
+ return 1;
+ if (test__aeabi_cfcmpeq(0.0, -0.0, 1))
+ return 1;
+ if (test__aeabi_cfcmpeq(1.0, NAN, 0))
+ return 1;
+ if (test__aeabi_cfcmpeq(NAN, 1.0, 0))
+ return 1;
+ if (test__aeabi_cfcmpeq(NAN, NAN, 0))
+ return 1;
+ if (test__aeabi_cfcmpeq(INFINITY, 1.0, 0))
+ return 1;
+ if (test__aeabi_cfcmpeq(0.0, INFINITY, 0))
+ return 1;
+ if (test__aeabi_cfcmpeq(-INFINITY, 0.0, 0))
+ return 1;
+ if (test__aeabi_cfcmpeq(0.0, -INFINITY, 0))
+ return 1;
+ if (test__aeabi_cfcmpeq(INFINITY, INFINITY, 1))
+ return 1;
+ if (test__aeabi_cfcmpeq(-INFINITY, -INFINITY, 1))
+ return 1;
+#else
+ printf("skipped\n");
+#endif
+ return 0;
+}
diff --git a/test/builtins/Unit/arm/aeabi_cfcmple_test.c b/test/builtins/Unit/arm/aeabi_cfcmple_test.c
new file mode 100644
index 000000000000..aebe4257e29e
--- /dev/null
+++ b/test/builtins/Unit/arm/aeabi_cfcmple_test.c
@@ -0,0 +1,92 @@
+//===-- aeabi_cfcmple.c - Test __aeabi_cfcmple and __aeabi_cfrcmple -------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __aeabi_cfcmple and __aeabi_cfrcmple for the compiler_rt
+// library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "call_apsr.h"
+
+#if __arm__
+
+extern __attribute__((pcs("aapcs"))) void __aeabi_cfcmple(float a, float b);
+extern __attribute__((pcs("aapcs"))) void __aeabi_cfrcmple(float a, float b);
+
+int test__aeabi_cfcmple(float a, float b, int expected)
+{
+ int32_t cpsr_value = call_apsr_f(a, b, __aeabi_cfcmple);
+ int32_t r_cpsr_value = call_apsr_f(b, a, __aeabi_cfrcmple);
+
+ if (cpsr_value != r_cpsr_value) {
+ printf("error: __aeabi_cfcmple(%f, %f) != __aeabi_cfrcmple(%f, %f)\n", a, b, b, a);
+ return 1;
+ }
+
+ int expected_z, expected_c;
+ if (expected == -1) {
+ expected_z = 0;
+ expected_c = 0;
+ } else if (expected == 0) {
+ expected_z = 1;
+ expected_c = 1;
+ } else {
+ // a or b is NaN, or a > b
+ expected_z = 0;
+ expected_c = 1;
+ }
+
+ union cpsr cpsr = { .value = cpsr_value };
+ if (expected_z != cpsr.flags.z || expected_c != cpsr.flags.c) {
+ printf("error in __aeabi_cfcmple(%f, %f) => (Z = %d, C = %d), expected (Z = %d, C = %d)\n",
+ a, b, cpsr.flags.z, cpsr.flags.c, expected_z, expected_c);
+ return 1;
+ }
+
+ cpsr.value = r_cpsr_value;
+ if (expected_z != cpsr.flags.z || expected_c != cpsr.flags.c) {
+ printf("error in __aeabi_cfrcmple(%f, %f) => (Z = %d, C = %d), expected (Z = %d, C = %d)\n",
+ a, b, cpsr.flags.z, cpsr.flags.c, expected_z, expected_c);
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+int main()
+{
+#if __arm__
+ if (test__aeabi_cfcmple(1.0, 1.0, 0))
+ return 1;
+ if (test__aeabi_cfcmple(1234.567, 765.4321, 1))
+ return 1;
+ if (test__aeabi_cfcmple(765.4321, 1234.567, -1))
+ return 1;
+ if (test__aeabi_cfcmple(-123.0, -678.0, 1))
+ return 1;
+ if (test__aeabi_cfcmple(-678.0, -123.0, -1))
+ return 1;
+ if (test__aeabi_cfcmple(0.0, -0.0, 0))
+ return 1;
+ if (test__aeabi_cfcmple(1.0, NAN, 1))
+ return 1;
+ if (test__aeabi_cfcmple(NAN, 1.0, 1))
+ return 1;
+ if (test__aeabi_cfcmple(NAN, NAN, 1))
+ return 1;
+#else
+ printf("skipped\n");
+#endif
+ return 0;
+}
diff --git a/test/builtins/Unit/arm/aeabi_drsub_test.c b/test/builtins/Unit/arm/aeabi_drsub_test.c
new file mode 100644
index 000000000000..7d867ef2c95a
--- /dev/null
+++ b/test/builtins/Unit/arm/aeabi_drsub_test.c
@@ -0,0 +1,47 @@
+//===-- aeabi_drsub.c - Test __aeabi_drsub --------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __aeabi_drsub for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+
+#if __arm__
+extern __attribute__((pcs("aapcs"))) double __aeabi_drsub(double a, double b);
+
+int test__aeabi_drsub(double a, double b, double expected)
+{
+ double actual = __aeabi_drsub(a, b);
+ if (actual != expected)
+ printf("error in __aeabi_drsub(%f, %f) = %f, expected %f\n",
+ a, b, actual, expected);
+ return actual != expected;
+}
+#endif
+
+int main()
+{
+#if __arm__
+ if (test__aeabi_drsub(1.0, 1.0, 0.0))
+ return 1;
+ if (test__aeabi_drsub(1234.567, 765.4321, -469.134900))
+ return 1;
+ if (test__aeabi_drsub(-123.0, -678.0, -555.0))
+ return 1;
+ if (test__aeabi_drsub(0.0, -0.0, 0.0))
+ return 1;
+#else
+ printf("skipped\n");
+#endif
+ return 0;
+}
diff --git a/test/builtins/Unit/arm/aeabi_frsub_test.c b/test/builtins/Unit/arm/aeabi_frsub_test.c
new file mode 100644
index 000000000000..b8b21b96e3b1
--- /dev/null
+++ b/test/builtins/Unit/arm/aeabi_frsub_test.c
@@ -0,0 +1,47 @@
+//===-- aeabi_frsub.c - Test __aeabi_frsub --------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __aeabi_frsub for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+
+#if __arm__
+extern __attribute__((pcs("aapcs"))) float __aeabi_frsub(float a, float b);
+
+int test__aeabi_frsub(float a, float b, float expected)
+{
+ float actual = __aeabi_frsub(a, b);
+ if (actual != expected)
+ printf("error in __aeabi_frsub(%f, %f) = %f, expected %f\n",
+ a, b, actual, expected);
+ return actual != expected;
+}
+#endif
+
+int main()
+{
+#if __arm__
+ if (test__aeabi_frsub(1.0, 1.0, 0.0))
+ return 1;
+ if (test__aeabi_frsub(1234.567, 765.4321, -469.134900))
+ return 1;
+ if (test__aeabi_frsub(-123.0, -678.0, -555.0))
+ return 1;
+ if (test__aeabi_frsub(0.0, -0.0, 0.0))
+ return 1;
+#else
+ printf("skipped\n");
+#endif
+ return 0;
+}
diff --git a/test/builtins/Unit/arm/call_apsr.S b/test/builtins/Unit/arm/call_apsr.S
new file mode 100644
index 000000000000..b5e154cff31f
--- /dev/null
+++ b/test/builtins/Unit/arm/call_apsr.S
@@ -0,0 +1,43 @@
+//===-- call_apsr.S - Helpers for ARM EABI floating point tests -----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements helpers for ARM EABI floating point tests for the
+// compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include "../../../../lib/builtins/assembly.h"
+
+.syntax unified
+// __attribute__((pcs("aapcs")))
+// int32_t call_apsr_d(double a, double b, void(*fn)(double, double)) {
+// fn(a, b);
+// return apsr;
+// }
+
+DEFINE_COMPILERRT_PRIVATE_FUNCTION(call_apsr_d)
+ push {lr}
+ ldr ip, [sp, #4]
+ blx ip
+ mrs r0, apsr
+ pop {pc}
+END_COMPILERRT_FUNCTION(call_apsr_d)
+
+// __attribute__((pcs("aapcs")))
+// int32_t call_apsr_f(float a, float b, void(*fn)(float, float)) {
+// fn(a, b);
+// return apsr;
+// }
+
+DEFINE_COMPILERRT_PRIVATE_FUNCTION(call_apsr_f)
+ push {lr}
+ blx r2
+ mrs r0, apsr
+ pop {pc}
+END_COMPILERRT_FUNCTION(call_apsr_f)
diff --git a/test/builtins/Unit/arm/call_apsr.h b/test/builtins/Unit/arm/call_apsr.h
new file mode 100644
index 000000000000..54438413e581
--- /dev/null
+++ b/test/builtins/Unit/arm/call_apsr.h
@@ -0,0 +1,39 @@
+//===-- call_apsr.h - Helpers for ARM EABI floating point tests -----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares helpers for ARM EABI floating point tests for the
+// compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CALL_APSR_H
+#define CALL_APSR_H
+
+#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
+#error big endian support not implemented
+#endif
+
+union cpsr {
+ struct {
+ uint32_t filler: 28;
+ uint32_t v: 1;
+ uint32_t c: 1;
+ uint32_t z: 1;
+ uint32_t n: 1;
+ } flags;
+ uint32_t value;
+};
+
+extern __attribute__((pcs("aapcs")))
+uint32_t call_apsr_f(float a, float b, __attribute__((pcs("aapcs"))) void (*fn)(float, float));
+
+extern __attribute__((pcs("aapcs")))
+uint32_t call_apsr_d(double a, double b, __attribute__((pcs("aapcs"))) void (*fn)(double, double));
+
+#endif // CALL_APSR_H