11.1Sjoerg//===-- floattixf.c - Test __floattixf ------------------------------------===//
21.1Sjoerg//
31.1Sjoerg//                     The LLVM Compiler Infrastructure
41.1Sjoerg//
51.1Sjoerg// This file is dual licensed under the MIT and the University of Illinois Open
61.1Sjoerg// Source Licenses. See LICENSE.TXT for details.
71.1Sjoerg//
81.1Sjoerg//===----------------------------------------------------------------------===//
91.1Sjoerg//
101.1Sjoerg// This file tests __floattixf for the compiler_rt library.
111.1Sjoerg//
121.1Sjoerg//===----------------------------------------------------------------------===//
131.1Sjoerg
141.1Sjoerg#if __x86_64
151.1Sjoerg
161.1Sjoerg#include "int_lib.h"
171.1Sjoerg#include <float.h>
181.1Sjoerg#include <stdio.h>
191.1Sjoerg
201.1Sjoerg// Returns: convert a to a long double, rounding toward even.
211.1Sjoerg
221.1Sjoerg// Assumption: long double is a IEEE 80 bit floating point type padded to 128 bits
231.1Sjoerg//             ti_int is a 128 bit integral type
241.1Sjoerg
251.1Sjoerg// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
261.1Sjoerg// 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
271.1Sjoerg
281.1Sjoerglong double __floattixf(ti_int a);
291.1Sjoerg
301.1Sjoergint test__floattixf(ti_int a, long double expected)
311.1Sjoerg{
321.1Sjoerg    long double x = __floattixf(a);
331.1Sjoerg    if (x != expected)
341.1Sjoerg    {
351.1Sjoerg        twords at;
361.1Sjoerg        at.all = a;
371.1Sjoerg        printf("error in __floattixf(0x%.16llX%.16llX) = %LA, expected %LA\n",
381.1Sjoerg               at.s.high, at.s.low, x, expected);
391.1Sjoerg    }
401.1Sjoerg    return x != expected;
411.1Sjoerg}
421.1Sjoerg
431.1Sjoergchar assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0};
441.1Sjoergchar assumption_2[sizeof(ti_int)*CHAR_BIT == 128] = {0};
451.1Sjoergchar assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
461.1Sjoerg
471.1Sjoerg#endif
481.1Sjoerg
491.1Sjoergint main()
501.1Sjoerg{
511.1Sjoerg#if __x86_64
521.1Sjoerg    if (test__floattixf(0, 0.0))
531.1Sjoerg        return 1;
541.1Sjoerg
551.1Sjoerg    if (test__floattixf(1, 1.0))
561.1Sjoerg        return 1;
571.1Sjoerg    if (test__floattixf(2, 2.0))
581.1Sjoerg        return 1;
591.1Sjoerg    if (test__floattixf(20, 20.0))
601.1Sjoerg        return 1;
611.1Sjoerg    if (test__floattixf(-1, -1.0))
621.1Sjoerg        return 1;
631.1Sjoerg    if (test__floattixf(-2, -2.0))
641.1Sjoerg        return 1;
651.1Sjoerg    if (test__floattixf(-20, -20.0))
661.1Sjoerg        return 1;
671.1Sjoerg
681.1Sjoerg    if (test__floattixf(0x7FFFFF8000000000LL, 0x1.FFFFFEp+62))
691.1Sjoerg        return 1;
701.1Sjoerg    if (test__floattixf(0x7FFFFFFFFFFFF800LL, 0x1.FFFFFFFFFFFFEp+62))
711.1Sjoerg        return 1;
721.1Sjoerg    if (test__floattixf(0x7FFFFF0000000000LL, 0x1.FFFFFCp+62))
731.1Sjoerg        return 1;
741.1Sjoerg    if (test__floattixf(0x7FFFFFFFFFFFF000LL, 0x1.FFFFFFFFFFFFCp+62))
751.1Sjoerg        return 1;
761.1Sjoerg
771.1Sjoerg    if (test__floattixf(make_ti(0x8000008000000000LL, 0), -0x1.FFFFFEp+126))
781.1Sjoerg        return 1;
791.1Sjoerg    if (test__floattixf(make_ti(0x8000000000000800LL, 0), -0x1.FFFFFFFFFFFFEp+126))
801.1Sjoerg        return 1;
811.1Sjoerg    if (test__floattixf(make_ti(0x8000010000000000LL, 0), -0x1.FFFFFCp+126))
821.1Sjoerg        return 1;
831.1Sjoerg    if (test__floattixf(make_ti(0x8000000000001000LL, 0), -0x1.FFFFFFFFFFFFCp+126))
841.1Sjoerg        return 1;
851.1Sjoerg
861.1Sjoerg    if (test__floattixf(make_ti(0x8000000000000000LL, 0), -0x1.000000p+127))
871.1Sjoerg        return 1;
881.1Sjoerg    if (test__floattixf(make_ti(0x8000000000000001LL, 0), -0x1.FFFFFFFFFFFFFFFCp+126L))
891.1Sjoerg        return 1;
901.1Sjoerg
911.1Sjoerg    if (test__floattixf(0x0007FB72E8000000LL, 0x1.FEDCBAp+50))
921.1Sjoerg        return 1;
931.1Sjoerg
941.1Sjoerg    if (test__floattixf(0x0007FB72EA000000LL, 0x1.FEDCBA8p+50))
951.1Sjoerg        return 1;
961.1Sjoerg    if (test__floattixf(0x0007FB72EB000000LL, 0x1.FEDCBACp+50))
971.1Sjoerg        return 1;
981.1Sjoerg    if (test__floattixf(0x0007FB72EBFFFFFFLL, 0x1.FEDCBAFFFFFFCp+50))
991.1Sjoerg        return 1;
1001.1Sjoerg    if (test__floattixf(0x0007FB72EC000000LL, 0x1.FEDCBBp+50))
1011.1Sjoerg        return 1;
1021.1Sjoerg    if (test__floattixf(0x0007FB72E8000001LL, 0x1.FEDCBA0000004p+50))
1031.1Sjoerg        return 1;
1041.1Sjoerg
1051.1Sjoerg    if (test__floattixf(0x0007FB72E6000000LL, 0x1.FEDCB98p+50))
1061.1Sjoerg        return 1;
1071.1Sjoerg    if (test__floattixf(0x0007FB72E7000000LL, 0x1.FEDCB9Cp+50))
1081.1Sjoerg        return 1;
1091.1Sjoerg    if (test__floattixf(0x0007FB72E7FFFFFFLL, 0x1.FEDCB9FFFFFFCp+50))
1101.1Sjoerg        return 1;
1111.1Sjoerg    if (test__floattixf(0x0007FB72E4000001LL, 0x1.FEDCB90000004p+50))
1121.1Sjoerg        return 1;
1131.1Sjoerg    if (test__floattixf(0x0007FB72E4000000LL, 0x1.FEDCB9p+50))
1141.1Sjoerg        return 1;
1151.1Sjoerg
1161.1Sjoerg    if (test__floattixf(0x023479FD0E092DC0LL, 0x1.1A3CFE870496Ep+57))
1171.1Sjoerg        return 1;
1181.1Sjoerg    if (test__floattixf(0x023479FD0E092DA1LL, 0x1.1A3CFE870496D08p+57L))
1191.1Sjoerg        return 1;
1201.1Sjoerg    if (test__floattixf(0x023479FD0E092DB0LL, 0x1.1A3CFE870496D8p+57L))
1211.1Sjoerg        return 1;
1221.1Sjoerg    if (test__floattixf(0x023479FD0E092DB8LL, 0x1.1A3CFE870496DCp+57L))
1231.1Sjoerg        return 1;
1241.1Sjoerg    if (test__floattixf(0x023479FD0E092DB6LL, 0x1.1A3CFE870496DBp+57L))
1251.1Sjoerg        return 1;
1261.1Sjoerg    if (test__floattixf(0x023479FD0E092DBFLL, 0x1.1A3CFE870496DF8p+57L))
1271.1Sjoerg        return 1;
1281.1Sjoerg    if (test__floattixf(0x023479FD0E092DC1LL, 0x1.1A3CFE870496E08p+57L))
1291.1Sjoerg        return 1;
1301.1Sjoerg    if (test__floattixf(0x023479FD0E092DC7LL, 0x1.1A3CFE870496E38p+57L))
1311.1Sjoerg        return 1;
1321.1Sjoerg    if (test__floattixf(0x023479FD0E092DC8LL, 0x1.1A3CFE870496E4p+57L))
1331.1Sjoerg        return 1;
1341.1Sjoerg    if (test__floattixf(0x023479FD0E092DCFLL, 0x1.1A3CFE870496E78p+57L))
1351.1Sjoerg        return 1;
1361.1Sjoerg    if (test__floattixf(0x023479FD0E092DD0LL, 0x1.1A3CFE870496E8p+57L))
1371.1Sjoerg        return 1;
1381.1Sjoerg    if (test__floattixf(0x023479FD0E092DD1LL, 0x1.1A3CFE870496E88p+57L))
1391.1Sjoerg        return 1;
1401.1Sjoerg    if (test__floattixf(0x023479FD0E092DD8LL, 0x1.1A3CFE870496ECp+57L))
1411.1Sjoerg        return 1;
1421.1Sjoerg    if (test__floattixf(0x023479FD0E092DDFLL, 0x1.1A3CFE870496EF8p+57L))
1431.1Sjoerg        return 1;
1441.1Sjoerg    if (test__floattixf(0x023479FD0E092DE0LL, 0x1.1A3CFE870496Fp+57))
1451.1Sjoerg        return 1;
1461.1Sjoerg
1471.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DC0LL, 0), 0x1.1A3CFE870496Ep+121L))
1481.1Sjoerg        return 1;
1491.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DA1LL, 1), 0x1.1A3CFE870496D08p+121L))
1501.1Sjoerg        return 1;
1511.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DB0LL, 2), 0x1.1A3CFE870496D8p+121L))
1521.1Sjoerg        return 1;
1531.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DB8LL, 3), 0x1.1A3CFE870496DCp+121L))
1541.1Sjoerg        return 1;
1551.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DB6LL, 4), 0x1.1A3CFE870496DBp+121L))
1561.1Sjoerg        return 1;
1571.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DBFLL, 5), 0x1.1A3CFE870496DF8p+121L))
1581.1Sjoerg        return 1;
1591.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DC1LL, 6), 0x1.1A3CFE870496E08p+121L))
1601.1Sjoerg        return 1;
1611.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DC7LL, 7), 0x1.1A3CFE870496E38p+121L))
1621.1Sjoerg        return 1;
1631.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DC8LL, 8), 0x1.1A3CFE870496E4p+121L))
1641.1Sjoerg        return 1;
1651.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DCFLL, 9), 0x1.1A3CFE870496E78p+121L))
1661.1Sjoerg        return 1;
1671.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DD0LL, 0), 0x1.1A3CFE870496E8p+121L))
1681.1Sjoerg        return 1;
1691.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DD1LL, 11), 0x1.1A3CFE870496E88p+121L))
1701.1Sjoerg        return 1;
1711.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DD8LL, 12), 0x1.1A3CFE870496ECp+121L))
1721.1Sjoerg        return 1;
1731.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DDFLL, 13), 0x1.1A3CFE870496EF8p+121L))
1741.1Sjoerg        return 1;
1751.1Sjoerg    if (test__floattixf(make_ti(0x023479FD0E092DE0LL, 14), 0x1.1A3CFE870496Fp+121L))
1761.1Sjoerg        return 1;
1771.1Sjoerg
1781.1Sjoerg    if (test__floattixf(make_ti(0, 0xFFFFFFFFFFFFFFFFLL), 0x1.FFFFFFFFFFFFFFFEp+63L))
1791.1Sjoerg        return 1;
1801.1Sjoerg
1811.1Sjoerg    if (test__floattixf(make_ti(0x0000123456789012LL, 0x3456100000000001LL),
1821.1Sjoerg                        0x1.2345678901234562p+108L))
1831.1Sjoerg        return 1;
1841.1Sjoerg    if (test__floattixf(make_ti(0x0000123456789012LL, 0x3456200000000000LL),
1851.1Sjoerg                        0x1.2345678901234562p+108L))
1861.1Sjoerg        return 1;
1871.1Sjoerg    if (test__floattixf(make_ti(0x0000123456789012LL, 0x34562FFFFFFFFFFFLL),
1881.1Sjoerg                        0x1.2345678901234562p+108L))
1891.1Sjoerg        return 1;
1901.1Sjoerg    if (test__floattixf(make_ti(0x0000123456789012LL, 0x3456300000000000LL),
1911.1Sjoerg                        0x1.2345678901234564p+108L))
1921.1Sjoerg        return 1;
1931.1Sjoerg    if (test__floattixf(make_ti(0x0000123456789012LL, 0x3456400000000000LL),
1941.1Sjoerg                        0x1.2345678901234564p+108L))
1951.1Sjoerg        return 1;
1961.1Sjoerg    if (test__floattixf(make_ti(0x0000123456789012LL, 0x34564FFFFFFFFFFFLL),
1971.1Sjoerg                        0x1.2345678901234564p+108L))
1981.1Sjoerg        return 1;
1991.1Sjoerg    if (test__floattixf(make_ti(0x0000123456789012LL, 0x3456500000000000LL),
2001.1Sjoerg                        0x1.2345678901234564p+108L))
2011.1Sjoerg        return 1;
2021.1Sjoerg    if (test__floattixf(make_ti(0x0000123456789012LL, 0x3456500000000001LL),
2031.1Sjoerg                        0x1.2345678901234566p+108L))
2041.1Sjoerg        return 1;
2051.1Sjoerg    if (test__floattixf(make_ti(0x0000123456789012LL, 0x34566FFFFFFFFFFFLL),
2061.1Sjoerg                        0x1.2345678901234566p+108L))
2071.1Sjoerg        return 1;
2081.1Sjoerg#else
2091.1Sjoerg    printf("skipped\n");
2101.1Sjoerg#endif
2111.1Sjoerg   return 0;
2121.1Sjoerg}
213