[compiler-rt] r252180 - [compiler-rt][aarch64] New tests for 128-bit floating-point builtins, fixes of tests and __fixuint
Sergey Dmitrouk via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 5 10:36:42 PST 2015
Author: sdmitrouk
Date: Thu Nov 5 12:36:42 2015
New Revision: 252180
URL: http://llvm.org/viewvc/llvm-project?rev=252180&view=rev
Log:
[compiler-rt][aarch64] New tests for 128-bit floating-point builtins, fixes of tests and __fixuint
Summary:
The following tests for 128-bit floating-point type behaved in a strange way, thought it were bugs, but seem to be mistakes in tests:
* `fixtfsi` test checked for `0x80000001` as a value returned for number less than can be represented, while `LONG_MIN` should be returned on saturation;
* `fixunstfdi` wasn't enabled for AArch64, only for PPC, but there is nothing PPC specific in that test;
* `multf3` tried to underflow multiplication by producing result with 16383 exponent, while there are still 112 bits of fraction plus implicit bit, so resultant exponent should be 16497.
Tests for some other builtins didn't exist:
* `fixtfdi`
* `fixtfti`
* `fixunstfti`
They were made by copying similar files and adjusting for wider types and adding/removing some reasonable/extra checks.
Also `__fixuint` seems to have off by one error, updated tests to catch this case.
Reviewers: rengolin, zatrazz, howard.hinnant, t.p.northover, jmolloy, enefaim
Subscribers: aemerson, llvm-commits, rengolin
Differential Revision: http://reviews.llvm.org/D14187
Added:
compiler-rt/trunk/test/builtins/Unit/fixtfdi_test.c
compiler-rt/trunk/test/builtins/Unit/fixtfti_test.c
compiler-rt/trunk/test/builtins/Unit/fixunstfti_test.c
Modified:
compiler-rt/trunk/lib/builtins/fp_fixuint_impl.inc
compiler-rt/trunk/test/builtins/Unit/fixtfsi_test.c
compiler-rt/trunk/test/builtins/Unit/fixunsdfdi_test.c
compiler-rt/trunk/test/builtins/Unit/fixunsdfsi_test.c
compiler-rt/trunk/test/builtins/Unit/fixunsdfti_test.c
compiler-rt/trunk/test/builtins/Unit/fixunssfdi_test.c
compiler-rt/trunk/test/builtins/Unit/fixunssfsi_test.c
compiler-rt/trunk/test/builtins/Unit/fixunstfdi_test.c
compiler-rt/trunk/test/builtins/Unit/fixunstfsi_test.c
compiler-rt/trunk/test/builtins/Unit/multf3_test.c
Modified: compiler-rt/trunk/lib/builtins/fp_fixuint_impl.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/fp_fixuint_impl.inc?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/fp_fixuint_impl.inc (original)
+++ compiler-rt/trunk/lib/builtins/fp_fixuint_impl.inc Thu Nov 5 12:36:42 2015
@@ -27,7 +27,7 @@ static __inline fixuint_t __fixuint(fp_t
return 0;
// If the value is too large for the integer type, saturate.
- if ((unsigned)exponent > sizeof(fixuint_t) * CHAR_BIT)
+ if ((unsigned)exponent >= sizeof(fixuint_t) * CHAR_BIT)
return ~(fixuint_t)0;
// If 0 <= exponent < significandBits, right shift to get the result.
Added: compiler-rt/trunk/test/builtins/Unit/fixtfdi_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixtfdi_test.c?rev=252180&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixtfdi_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/fixtfdi_test.c Thu Nov 5 12:36:42 2015
@@ -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;
+}
Modified: compiler-rt/trunk/test/builtins/Unit/fixtfsi_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixtfsi_test.c?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixtfsi_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/fixtfsi_test.c Thu Nov 5 12:36:42 2015
@@ -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
Added: compiler-rt/trunk/test/builtins/Unit/fixtfti_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixtfti_test.c?rev=252180&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixtfti_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/fixtfti_test.c Thu Nov 5 12:36:42 2015
@@ -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;
+}
Modified: compiler-rt/trunk/test/builtins/Unit/fixunsdfdi_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixunsdfdi_test.c?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixunsdfdi_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/fixunsdfdi_test.c Thu Nov 5 12:36:42 2015
@@ -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;
Modified: compiler-rt/trunk/test/builtins/Unit/fixunsdfsi_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixunsdfsi_test.c?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixunsdfsi_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/fixunsdfsi_test.c Thu Nov 5 12:36:42 2015
@@ -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))
Modified: compiler-rt/trunk/test/builtins/Unit/fixunsdfti_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixunsdfti_test.c?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixunsdfti_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/fixunsdfti_test.c Thu Nov 5 12:36:42 2015
@@ -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))
Modified: compiler-rt/trunk/test/builtins/Unit/fixunssfdi_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixunssfdi_test.c?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixunssfdi_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/fixunssfdi_test.c Thu Nov 5 12:36:42 2015
@@ -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))
Modified: compiler-rt/trunk/test/builtins/Unit/fixunssfsi_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixunssfsi_test.c?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixunssfsi_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/fixunssfsi_test.c Thu Nov 5 12:36:42 2015
@@ -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))
Modified: compiler-rt/trunk/test/builtins/Unit/fixunstfdi_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixunstfdi_test.c?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixunstfdi_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/fixunstfdi_test.c Thu Nov 5 12:36:42 2015
@@ -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)*CH
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;
Modified: compiler-rt/trunk/test/builtins/Unit/fixunstfsi_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixunstfsi_test.c?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixunstfsi_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/fixunstfsi_test.c Thu Nov 5 12:36:42 2015
@@ -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");
Added: compiler-rt/trunk/test/builtins/Unit/fixunstfti_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/fixunstfti_test.c?rev=252180&view=auto
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/fixunstfti_test.c (added)
+++ compiler-rt/trunk/test/builtins/Unit/fixunstfti_test.c Thu Nov 5 12:36:42 2015
@@ -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;
+}
Modified: compiler-rt/trunk/test/builtins/Unit/multf3_test.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/multf3_test.c?rev=252180&r1=252179&r2=252180&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/multf3_test.c (original)
+++ compiler-rt/trunk/test/builtins/Unit/multf3_test.c Thu Nov 5 12:36:42 2015
@@ -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;
More information about the llvm-commits
mailing list