diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:52:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:52:19 +0000 |
commit | 5c909fa013fc285f010a95e8d387e0ef3412da9c (patch) | |
tree | 1059d068ad281f4776ff44cd414574f99a460023 /test/builtins/Unit | |
parent | f31bcc68c72371a2bf63aead9f3373a1ff2053b6 (diff) |
Notes
Diffstat (limited to 'test/builtins/Unit')
25 files changed, 921 insertions, 18 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 0000000000000..ce8b0a4313fb4 --- /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 0000000000000..afc7014936947 --- /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 0000000000000..fe0166485e696 --- /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 0000000000000..aebe4257e29ef --- /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 0000000000000..7d867ef2c95a3 --- /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 0000000000000..b8b21b96e3b1c --- /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 0000000000000..b5e154cff31f1 --- /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 0000000000000..54438413e5811 --- /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 diff --git a/test/builtins/Unit/divtc3_test.c b/test/builtins/Unit/divtc3_test.c index ad2c96dc0409d..a1f0613441da7 100644 --- a/test/builtins/Unit/divtc3_test.c +++ b/test/builtins/Unit/divtc3_test.c @@ -13,8 +13,6 @@ #include <stdio.h> -#if _ARCH_PPC - #include "int_lib.h" #include <math.h> #include <complex.h> @@ -104,7 +102,7 @@ int test__divtc3(long double a, long double b, long double c, long double d) { long double _Complex z = (a * c + b * d) / (c * c + d * d) + (b * c - a * d) / (c * c + d * d) * _Complex_I; - if (cabs((r - z)/r) > 1.e-6) + if (cabsl((r - z)/r) > 1.e-6) return 1; } break; @@ -358,11 +356,8 @@ long double x[][2] = }; -#endif - int main() { -#if _ARCH_PPC const unsigned N = sizeof(x) / sizeof(x[0]); unsigned i, j; for (i = 0; i < N; ++i) @@ -373,11 +368,7 @@ int main() return 1; } } - -// printf("No errors found.\n"); -#else - printf("skipped\n"); -#endif +// printf("No errors found.\n"); return 0; } diff --git a/test/builtins/Unit/fixtfdi_test.c b/test/builtins/Unit/fixtfdi_test.c new file mode 100644 index 0000000000000..cc25becb2f7c1 --- /dev/null +++ b/test/builtins/Unit/fixtfdi_test.c @@ -0,0 +1,71 @@ +//===--------------- fixtfdi_test.c - Test __fixtfdi ----------------------===// +// +// 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 __fixtfdi for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" +#include <stdio.h> + +#if __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +di_int __fixtfdi(long double a); + +int test__fixtfdi(long double a, di_int expected) +{ + di_int x = __fixtfdi(a); + int ret = (x != expected); + + if (ret) + { + printf("error in test__fixtfdi(%.20Lf) = %llX, " + "expected %llX\n", a, x, expected); + } + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LDBL_MANT_DIG__ == 113 + if (test__fixtfdi(makeInf128(), 0x7fffffffffffffffLL)) + return 1; + if (test__fixtfdi(0, 0x0)) + return 1; + if (test__fixtfdi(0x1.23456789abcdefp+5L, 0x24LL)) + return 1; + if (test__fixtfdi(0x1.23456789abcdefp-3L, 0x0LL)) + return 1; + if (test__fixtfdi(0x1.23456789abcdef12345678p+20L, 0x123456LL)) + return 1; + if (test__fixtfdi(0x1.23456789abcdef12345678p+40L, 0x123456789abLL)) + return 1; + if (test__fixtfdi(0x1.23456789abcdef12345678p+60L, 0x123456789abcdef1LL)) + return 1; + if (test__fixtfdi(0x1.23456789abcdefp+256L, 0x7fffffffffffffffLL)) + return 1; + if (test__fixtfdi(-0x1.23456789abcdefp+20L, 0xffffffffffedcbaaLL)) + return 1; + if (test__fixtfdi(-0x1.23456789abcdefp+40L, 0xfffffedcba987655LL)) + return 1; + if (test__fixtfdi(-0x1.23456789abcdefp+256L, 0x8000000000000000LL)) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/test/builtins/Unit/fixtfsi_test.c b/test/builtins/Unit/fixtfsi_test.c index 45ad0d243785f..1da516bd07e6a 100644 --- a/test/builtins/Unit/fixtfsi_test.c +++ b/test/builtins/Unit/fixtfsi_test.c @@ -54,7 +54,7 @@ int main() return 1; if (test__fixtfsi(-0x1.23456789abcdefp+20, 0xffedcbaa)) return 1; - if (test__fixtfsi(-0x1.23456789abcdefp+40, 0x80000001)) + if (test__fixtfsi(-0x1.23456789abcdefp+40, 0x80000000)) return 1; #else diff --git a/test/builtins/Unit/fixtfti_test.c b/test/builtins/Unit/fixtfti_test.c new file mode 100644 index 0000000000000..52184ca624e19 --- /dev/null +++ b/test/builtins/Unit/fixtfti_test.c @@ -0,0 +1,83 @@ +//===--------------- fixtfti_test.c - Test __fixtfti ----------------------===// +// +// 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 __fixtfti for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" +#include <stdio.h> + +#if __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +ti_int __fixtfti(long double a); + +int test__fixtfti(long double a, ti_int expected) +{ + ti_int x = __fixtfti(a); + int ret = (x != expected); + + if (ret) + { + twords xt; + xt.all = x; + + twords expectedt; + expectedt.all = expected; + + printf("error in test__fixtfti(%.20Lf) = 0x%.16llX%.16llX, " + "expected 0x%.16llX%.16llX\n", + a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); + } + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LDBL_MANT_DIG__ == 113 + if (test__fixtfti(makeInf128(), make_ti(0x7fffffffffffffffLL, + 0xffffffffffffffffLL))) + return 1; + if (test__fixtfti(0, make_ti(0x0LL, 0x0LL))) + return 1; + if (test__fixtfti(0x1.23456789abcdefp+5L, make_ti(0x0LL, 0x24LL))) + return 1; + if (test__fixtfti(0x1.23456789abcdefp-3L, make_ti(0x0LL, 0x0LL))) + return 1; + if (test__fixtfti(0x1.23456789abcdef12345678p+20L, + make_ti(0x0LL, 0x123456LL))) + return 1; + if (test__fixtfti(0x1.23456789abcdef123456789abcdep+112L, + make_ti(0x123456789abcdLL, 0xef123456789abcdeLL))) + return 1; + if (test__fixtfti(-0x1.23456789abcdef123456789abcdep+112L, + make_ti(0xFFFEDCBA98765432LL, 0x10EDCBA987654322LL))) + return 1; + if (test__fixtfti(0x1.23456789abcdefp+256L, make_ti(0x7fffffffffffffffLL, + 0xffffffffffffffffLL))) + return 1; + if (test__fixtfti(-0x1.23456789abcdefp+20L, make_ti(0xffffffffffffffffLL, + 0xffffffffffedcbaaLL))) + return 1; + if (test__fixtfti(-0x1.23456789abcdefp+256L, make_ti(0x8000000000000000LL, + 0x0))) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/test/builtins/Unit/fixunsdfdi_test.c b/test/builtins/Unit/fixunsdfdi_test.c index 3998482876f38..1ddc5340b03dd 100644 --- a/test/builtins/Unit/fixunsdfdi_test.c +++ b/test/builtins/Unit/fixunsdfdi_test.c @@ -95,6 +95,9 @@ int main() if (test__fixunsdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL)) return 1; + if (test__fixunsdfdi(0x1.p+64, 0xFFFFFFFFFFFFFFFFLL)) + return 1; + #if !TARGET_LIBGCC if (test__fixunsdfdi(-0x1.FFFFFFFFFFFFFp+62, 0)) return 1; diff --git a/test/builtins/Unit/fixunsdfsi_test.c b/test/builtins/Unit/fixunsdfsi_test.c index 551fc88a5241f..8d3d6304f473d 100644 --- a/test/builtins/Unit/fixunsdfsi_test.c +++ b/test/builtins/Unit/fixunsdfsi_test.c @@ -75,6 +75,8 @@ int main() if (test__fixunsdfsi(0x1.000000p+31, 0x80000000)) return 1; + if (test__fixunsdfsi(0x1.000000p+32, 0xFFFFFFFF)) + return 1; if (test__fixunsdfsi(0x1.FFFFFEp+31, 0xFFFFFF00)) return 1; if (test__fixunsdfsi(0x1.FFFFFEp+30, 0x7FFFFF80)) diff --git a/test/builtins/Unit/fixunsdfti_test.c b/test/builtins/Unit/fixunsdfti_test.c index e1aa56d7631ec..0298fb9e94474 100644 --- a/test/builtins/Unit/fixunsdfti_test.c +++ b/test/builtins/Unit/fixunsdfti_test.c @@ -115,6 +115,9 @@ int main() return 1; if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, make_ti(0x7FFFFFFFFFFFF800LL, 0))) return 1; + if (test__fixunsdfti(0x1.0000000000000p+128, make_ti(0xFFFFFFFFFFFFFFFFLL, + 0xFFFFFFFFFFFFFFFFLL))) + return 1; #if !TARGET_LIBGCC if (test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0)) diff --git a/test/builtins/Unit/fixunssfdi_test.c b/test/builtins/Unit/fixunssfdi_test.c index 812457a002dee..166153cb5b51b 100644 --- a/test/builtins/Unit/fixunssfdi_test.c +++ b/test/builtins/Unit/fixunssfdi_test.c @@ -79,6 +79,8 @@ int main() return 1; if (test__fixunssfdi(0x1.000000p+63F, 0x8000000000000000LL)) return 1; + if (test__fixunssfdi(0x1.000000p+64F, 0xFFFFFFFFFFFFFFFFLL)) + return 1; if (test__fixunssfdi(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL)) return 1; if (test__fixunssfdi(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL)) diff --git a/test/builtins/Unit/fixunssfsi_test.c b/test/builtins/Unit/fixunssfsi_test.c index 94a8b0867ecaf..17293e4385288 100644 --- a/test/builtins/Unit/fixunssfsi_test.c +++ b/test/builtins/Unit/fixunssfsi_test.c @@ -75,6 +75,8 @@ int main() if (test__fixunssfsi(0x1.000000p+31F, 0x80000000)) return 1; + if (test__fixunssfsi(0x1.000000p+32F, 0xFFFFFFFF)) + return 1; if (test__fixunssfsi(0x1.FFFFFEp+31F, 0xFFFFFF00)) return 1; if (test__fixunssfsi(0x1.FFFFFEp+30F, 0x7FFFFF80)) diff --git a/test/builtins/Unit/fixunstfdi_test.c b/test/builtins/Unit/fixunstfdi_test.c index 60ea503d27789..817c59b2d5d47 100644 --- a/test/builtins/Unit/fixunstfdi_test.c +++ b/test/builtins/Unit/fixunstfdi_test.c @@ -13,14 +13,14 @@ #include <stdio.h> -#if _ARCH_PPC +#if _ARCH_PPC || __aarch64__ #include "int_lib.h" // Returns: convert a to a unsigned long long, rounding toward zero. // Negative values all become zero. -// Assumption: long double is a ppc 128 bit floating point type +// Assumption: long double is a 128 bit floating point type // du_int is a 64 bit integral type // value in long double is representable in du_int or is negative // (no range checking performed) @@ -44,7 +44,7 @@ char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; int main() { -#if _ARCH_PPC +#if _ARCH_PPC || __aarch64__ if (test__fixunstfdi(0.0, 0)) return 1; @@ -107,6 +107,8 @@ int main() return 1; if (test__fixunstfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL)) return 1; + if (test__fixunstfdi(0x1.p+64L, 0xFFFFFFFFFFFFFFFFLL)) + return 1; if (test__fixunstfdi(-0x1.0000000000000000p+63L, 0)) return 1; diff --git a/test/builtins/Unit/fixunstfsi_test.c b/test/builtins/Unit/fixunstfsi_test.c index 4bf8fdec607c3..13ed779522485 100644 --- a/test/builtins/Unit/fixunstfsi_test.c +++ b/test/builtins/Unit/fixunstfsi_test.c @@ -56,6 +56,9 @@ int main() if (test__fixunstfsi(-0x1.23456789abcdefp+3, UINT32_C(0x0))) return 1; + if (test__fixunstfsi(0x1.p+32, 0xFFFFFFFFLL)) + return 1; + #else printf("skipped\n"); diff --git a/test/builtins/Unit/fixunstfti_test.c b/test/builtins/Unit/fixunstfti_test.c new file mode 100644 index 0000000000000..60a0982b62663 --- /dev/null +++ b/test/builtins/Unit/fixunstfti_test.c @@ -0,0 +1,103 @@ +//===-- fixunstfti_test.c - Test __fixunstfti -----------------------------===// +// +// 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 __fixunstfti for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +#if __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" +#include "int_lib.h" + +// Returns: convert a to a unsigned long long, rounding toward zero. +// Negative values all become zero. + +// Assumption: long double is a 128 bit floating point type +// tu_int is a 128 bit integral type +// value in long double is representable in tu_int or is negative +// (no range checking performed) + +COMPILER_RT_ABI tu_int __fixunstfti(long double a); + +int test__fixunstfti(long double a, tu_int expected) +{ + tu_int x = __fixunstfti(a); + if (x != expected) + { + twords xt; + xt.all = x; + + twords expectedt; + expectedt.all = expected; + + printf("error in __fixunstfti(%.20Lf) = 0x%.16llX%.16llX, " + "expected 0x%.16llX%.16llX\n", + a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); + } + return x != expected; +} + +char assumption_1[sizeof(tu_int) == 4*sizeof(su_int)] = {0}; +char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0}; +char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LDBL_MANT_DIG__ == 113 + if (test__fixunstfti(makeInf128(), make_ti(0xffffffffffffffffLL, + 0xffffffffffffffffLL))) + return 1; + + if (test__fixunstfti(0.0, 0)) + return 1; + + if (test__fixunstfti(0.5, 0)) + return 1; + if (test__fixunstfti(0.99, 0)) + return 1; + if (test__fixunstfti(1.0, 1)) + return 1; + if (test__fixunstfti(1.5, 1)) + return 1; + if (test__fixunstfti(1.99, 1)) + return 1; + if (test__fixunstfti(2.0, 2)) + return 1; + if (test__fixunstfti(2.01, 2)) + return 1; + if (test__fixunstfti(-0.01, 0)) + return 1; + if (test__fixunstfti(-0.99, 0)) + return 1; + + if (test__fixunstfti(0x1.p+128, make_ti(0xffffffffffffffffLL, + 0xffffffffffffffffLL))) + return 1; + + if (test__fixunstfti(0x1.FFFFFEp+126, make_ti(0x7fffff8000000000LL, 0x0))) + return 1; + if (test__fixunstfti(0x1.FFFFFEp+127, make_ti(0xffffff0000000000LL, 0x0))) + return 1; + if (test__fixunstfti(0x1.FFFFFEp+128, make_ti(0xffffffffffffffffLL, + 0xffffffffffffffffLL))) + return 1; + if (test__fixunstfti(0x1.FFFFFEp+129, make_ti(0xffffffffffffffffLL, + 0xffffffffffffffffLL))) + return 1; + +#else + printf("skipped\n"); +#endif + return 0; +} diff --git a/test/builtins/Unit/floatditf_test.c b/test/builtins/Unit/floatditf_test.c new file mode 100644 index 0000000000000..8cf8a0859e685 --- /dev/null +++ b/test/builtins/Unit/floatditf_test.c @@ -0,0 +1,69 @@ +//===-- floatditf_test.c - Test __floatditf -------------------------------===// +// +// 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 __floatditf for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" +#include <math.h> +#include <complex.h> +#include <stdio.h> + +#if __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +// Returns: long integer converted to long double + +COMPILER_RT_ABI long double __floatditf(long long a); + +int test__floatditf(long long a, uint64_t expectedHi, uint64_t expectedLo) +{ + long double x = __floatditf(a); + int ret = compareResultLD(x, expectedHi, expectedLo); + + if (ret) + printf("error in __floatditf(%Ld) = %.20Lf, " + "expected %.20Lf\n", a, x, fromRep128(expectedHi, expectedLo)); + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LDBL_MANT_DIG__ == 113 + if (test__floatditf(0x7fffffffffffffff, UINT64_C(0x403dffffffffffff), UINT64_C(0xfffc000000000000))) + return 1; + if (test__floatditf(0x123456789abcdef1, UINT64_C(0x403b23456789abcd), UINT64_C(0xef10000000000000))) + return 1; + if (test__floatditf(0x2, UINT64_C(0x4000000000000000), UINT64_C(0x0))) + return 1; + if (test__floatditf(0x1, UINT64_C(0x3fff000000000000), UINT64_C(0x0))) + return 1; + if (test__floatditf(0x0, UINT64_C(0x0), UINT64_C(0x0))) + return 1; + if (test__floatditf(0xffffffffffffffff, UINT64_C(0xbfff000000000000), UINT64_C(0x0))) + return 1; + if (test__floatditf(0xfffffffffffffffe, UINT64_C(0xc000000000000000), UINT64_C(0x0))) + return 1; + if (test__floatditf(-0x123456789abcdef1, UINT64_C(0xc03b23456789abcd), UINT64_C(0xef10000000000000))) + return 1; + if (test__floatditf(0x8000000000000000, UINT64_C(0xc03e000000000000), UINT64_C(0x0))) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/test/builtins/Unit/floatsitf_test.c b/test/builtins/Unit/floatsitf_test.c index 8373c7d96e263..6f98721b0a549 100644 --- a/test/builtins/Unit/floatsitf_test.c +++ b/test/builtins/Unit/floatsitf_test.c @@ -40,6 +40,8 @@ char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; int main() { #if __LDBL_MANT_DIG__ == 113 + if (test__floatsitf(0x80000000, UINT64_C(0xc01e000000000000), UINT64_C(0x0))) + return 1; if (test__floatsitf(0x7fffffff, UINT64_C(0x401dfffffffc0000), UINT64_C(0x0))) return 1; if (test__floatsitf(0, UINT64_C(0x0), UINT64_C(0x0))) diff --git a/test/builtins/Unit/floatunditf_test.c b/test/builtins/Unit/floatunditf_test.c new file mode 100644 index 0000000000000..b66a174a3f47a --- /dev/null +++ b/test/builtins/Unit/floatunditf_test.c @@ -0,0 +1,67 @@ +//===-- floatunditf_test.c - Test __floatunditf ---------------------------===// +// +// 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 __floatunditf for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#include "int_lib.h" +#include <math.h> +#include <complex.h> +#include <stdio.h> + +#if __LDBL_MANT_DIG__ == 113 + +#include "fp_test.h" + +// Returns: long integer converted to long double + +COMPILER_RT_ABI long double __floatunditf(unsigned long long a); + +int test__floatunditf(unsigned long long a, uint64_t expectedHi, uint64_t expectedLo) +{ + long double x = __floatunditf(a); + int ret = compareResultLD(x, expectedHi, expectedLo); + + if (ret) + printf("error in __floatunditf(%Lu) = %.20Lf, " + "expected %.20Lf\n", a, x, fromRep128(expectedHi, expectedLo)); + return ret; +} + +char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0}; + +#endif + +int main() +{ +#if __LDBL_MANT_DIG__ == 113 + if (test__floatunditf(0xffffffffffffffffULL, UINT64_C(0x403effffffffffff), UINT64_C(0xfffe000000000000))) + return 1; + if (test__floatunditf(0xfffffffffffffffeULL, UINT64_C(0x403effffffffffff), UINT64_C(0xfffc000000000000))) + return 1; + if (test__floatunditf(0x8000000000000000ULL, UINT64_C(0x403e000000000000), UINT64_C(0x0))) + return 1; + if (test__floatunditf(0x7fffffffffffffffULL, UINT64_C(0x403dffffffffffff), UINT64_C(0xfffc000000000000))) + return 1; + if (test__floatunditf(0x123456789abcdef1ULL, UINT64_C(0x403b23456789abcd), UINT64_C(0xef10000000000000))) + return 1; + if (test__floatunditf(0x2ULL, UINT64_C(0x4000000000000000), UINT64_C(0x0))) + return 1; + if (test__floatunditf(0x1ULL, UINT64_C(0x3fff000000000000), UINT64_C(0x0))) + return 1; + if (test__floatunditf(0x0ULL, UINT64_C(0x0), UINT64_C(0x0))) + return 1; + +#else + printf("skipped\n"); + +#endif + return 0; +} diff --git a/test/builtins/Unit/multc3_test.c b/test/builtins/Unit/multc3_test.c index b1482638a913f..f6cf4ca875be4 100644 --- a/test/builtins/Unit/multc3_test.c +++ b/test/builtins/Unit/multc3_test.c @@ -13,7 +13,7 @@ #include <stdio.h> -#if _ARCH_PPC +#if _ARCH_PPC || __aarch64__ #include "int_lib.h" #include <math.h> @@ -357,7 +357,7 @@ long double x[][2] = int main() { -#if _ARCH_PPC +#if _ARCH_PPC || __aarch64__ const unsigned N = sizeof(x) / sizeof(x[0]); unsigned i, j; for (i = 0; i < N; ++i) diff --git a/test/builtins/Unit/multf3_test.c b/test/builtins/Unit/multf3_test.c index 98a8f7a3231ed..42147550c702a 100644 --- a/test/builtins/Unit/multf3_test.c +++ b/test/builtins/Unit/multf3_test.c @@ -82,7 +82,7 @@ int main() return 1; // underflow if (test__multf3(0x1.23456734245345p-10000L, - 0x1.edcba524498724p-6383L, + 0x1.edcba524498724p-6497L, UINT64_C(0x0), UINT64_C(0x0))) return 1; |