Index: compiler-rt/lib/builtins/CMakeLists.txt =================================================================== --- compiler-rt/lib/builtins/CMakeLists.txt +++ compiler-rt/lib/builtins/CMakeLists.txt @@ -506,6 +506,7 @@ ppc/divtc3.c ppc/fixtfdi.c ppc/fixunstfdi.c + ppc/floattitf.c ppc/floatditf.c ppc/floatunditf.c ppc/gcc_qadd.c Index: compiler-rt/lib/builtins/ppc/floattitf.c =================================================================== --- /dev/null +++ compiler-rt/lib/builtins/ppc/floattitf.c @@ -0,0 +1,45 @@ +//===-- lib/builtins/ppc/floattitf.c - Convert int128->long double -*-C -*-===// +// +// 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 converting an unsigned 128 bit integer to a 128bit IBM/ +// PowerPC long double (double-double) value. +// +//===----------------------------------------------------------------------===// + +#include "DD.h" + +/* Conversions to be used for high and low parts of long double. */ +long double __floatditf (int64_t); +long double __floatunditf (uint64_t); + +long double __floattitf (__int128_t arg) { + /* 128 bit integers can be thought of as having a high and a low + * portion, each high and low portion consisting of 64 bits each. + * Split the int128 into their respective high and low parts. */ + int64_t hi_part = (int64_t)(arg >> 64); + int64_t lo_part = (int64_t) arg; + + /* Convert each 64-bit part into double-double. The high part + * must be a signed conversion to ensure the correct result. */ + long double hi_double = __floatditf(hi_part); + long double lo_double = __floatunditf(lo_part); + + /* The size of each high and low part of the 128 bit integer. + * Each 128 bit integer is constructed from two doublewords. + * This is used to ensure we have the correct high portion. */ + static const double eachDWordSize = 0x1.0p64; + + /* Multiply the high part of the long double by 2^64 to undo + * the splitting of the high and low parts of the 128bit integer. */ + long double new_hi = hi_double * ((long double) eachDWordSize); + + /* Add the high and low parts together to obtain + * the long double result. */ + return (new_hi + lo_double); +} Index: compiler-rt/test/builtins/Unit/ppc/floattitf_test.h =================================================================== --- /dev/null +++ compiler-rt/test/builtins/Unit/ppc/floattitf_test.h @@ -0,0 +1,203 @@ +/* +* Test case inputs for: long double __floattitf (__int128_t) +* Conversion from 128 bit integer to long double (IBM double-double). +*/ + +#define INFINITY __builtin_inf() +#define QNAN __builtin_nan("") + +struct testCase { + __int128_t input128; + double hi; + double lo; +}; + +struct testCase tests[] = { +{ INFINITY, 0x1p+127, -0x1p+0 }, +{ -INFINITY, -0x1p+127, 0x0p+0 }, +{ QNAN, 0x0p+0, 0x0p+0 }, +{ -QNAN, 0x0p+0, 0x0p+0 }, +{ (__int128_t) -0, 0x0p+0, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000000000, 0x0p+0, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000000001, 0x1p+0 , 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x1000000000000000, 0x1p+60 , 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xffffffffffffffff, 0x1p+64 , -0x1p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x7fffffffffffffff, 0x1p+63 , -0x1p+0 }, +{ ((__int128_t)0x0000000000000001 << 64) | 0x0000000000000000, 0x1p+64 , 0x0p+0 }, +{ ((__int128_t)0x0000000000000001 << 64) | 0x0000000000000001, 0x1p+64 , 0x1p+0 }, +{ ((__int128_t)0x0000000000000001 << 64) | 0x7fffffffffffffff, 0x1.8p+64 , -0x1p+0 }, +{ ((__int128_t)0x0000000000000001 << 64) | 0x1000000000000000, 0x1.1p+64 , 0x0p+0 }, +{ ((__int128_t)0x0000000000000001 << 64) | 0xffffffffffffffff, 0x1p+65 , -0x1p+0 }, +{ ((__int128_t)0x7fffffffffffffff << 64) | 0x0000000000000000, 0x1p+127 , -0x1p+64 }, +{ ((__int128_t)0x7fffffffffffffff << 64) | 0x0000000000000001, 0x1p+127 , -0x1p+64 }, +{ ((__int128_t)0x7fffffffffffffff << 64) | 0x7fffffffffffffff, 0x1p+127 , -0x1p+63 }, +{ ((__int128_t)0x7fffffffffffffff << 64) | 0x1000000000000000, 0x1p+127 , -0x1.ep+63 }, +{ ((__int128_t)0x7fffffffffffffff << 64) | 0xffffffffffffffff, 0x1p+127 , -0x1p+0 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000000000000, 0x1p+124 , 0x0p+0 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000000000001, 0x1p+124 , 0x1p+0 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x7fffffffffffffff, 0x1p+124 , 0x1p+63 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x1000000000000000, 0x1p+124 , 0x1p+60 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0xffffffffffffffff, 0x1p+124 , 0x1p+64 }, +{ ((__int128_t)0xffffffffffffffff << 64) | 0x0000000000000000, -0x1p+64 , 0x0p+0 }, +{ ((__int128_t)0xffffffffffffffff << 64) | 0x0000000000000001, -0x1p+64 , 0x1p+0 }, +{ ((__int128_t)0xffffffffffffffff << 64) | 0x7fffffffffffffff, -0x1p+63 , -0x1p+0 }, +{ ((__int128_t)0xffffffffffffffff << 64) | 0x1000000000000000, -0x1.ep+63 , 0x0p+0 }, +{ ((__int128_t)0xffffffffffffffff << 64) | 0xffffffffffffffff, -0x1p+0 , 0x0p+0 }, +{ ((__int128_t)0x0000000000000061 << 64) | 0x0000000000000061, 0x1.84p+70, 0x1.84p+6 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000000057, 0x1.5cp+6, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xffffffffffffff9e, 0x1p+64 , -0x1.88p+6 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000000062, 0x1.88p+6, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000000403, 0x1.00cp+10, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xfffffffffffffbfc, 0x1.fffffffffffffp+63 , 0x1.fep+9 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x000000000000040a, 0x1.028p+10, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x000000000000040c, 0x1.03p+10, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x000000000000041a, 0x1.068p+10, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000000510, 0x1.44p+10, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000000518, 0x1.46p+10, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xfffffffffffffae7, 0x1.fffffffffffffp+63 , 0x1.738p+9 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000000602, 0x1.808p+10, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xfffffffffffff9fd, 0x1.fffffffffffffp+63 , 0x1.fdp+8 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000002090, 0x1.048p+13, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xffffffffffffdbdb, 0x1.ffffffffffffbp+63 , 0x1.ed8p+9 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000002430, 0x1.218p+13, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000020202, 0x1.0101p+17, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xfffffffffffdeef7, 0x1.fffffffffffbep+63 , -0x1.09p+8 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000032004, 0x1.9002p+17, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xfffffffffffcdffb, 0x1.fffffffffff9cp+63 , -0x1.4p+2 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000032040, 0x1.902p+17, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xffffffffffbfdfbb, 0x1.ffffffffff7fcp+63 , -0x1.14p+6 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000000402088, 0x1.00822p+22, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000080080088, 0x1.0010011p+31, 0x0p+0 }, +{ ((__int128_t)0xffffffff7ff7ff77 << 64) | 0xffffffff7ff7ff77, -0x1.0010011p+95 , -0x1.00100112p+31 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000000850000008, 0x1.0a000001p+35, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000002000000448, 0x1.000000224p+37, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xffffffdfff7dbfff, 0x1.ffffffbffefb8p+63 , -0x1p+0 }, +{ ((__int128_t)0x0000004002001100 << 64) | 0x0000004002001100, 0x1.00080044p+102 , 0x1.00080044p+38 }, +{ ((__int128_t)0x000008020000000c << 64) | 0x000008020000000c, 0x1.00400000018p+107 , 0x1.00400000018p+43 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xfffff7fdfffffff3, 0x1.ffffeffcp+63 , -0x1.ap+3 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x0000800000000824, 0x1.000000001048p+47, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xfffdffffff7ffcff, 0x1.fffbffffffp+63 , -0x1.808p+9 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x4002040010000000, 0x1.000810004p+62, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xbffdfbffefffffff, 0x1.7ffbf7ffep+63 , -0x1p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x8000000000000000, 0x1p+63, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xfffffffff418c5c1, 0x1.ffffffffe8319p+63 , -0x1.1f8p+9 }, +{ ((__int128_t)0x000000000000000f << 64) | 0xffffffffffffffff, 0x1p+68 , -0x1p+0 }, +{ ((__int128_t)0x00000000000000ff << 64) | 0xffffffffffffffff, 0x1p+72 , -0x1p+0 }, +{ ((__int128_t)0x0000000000000fff << 64) | 0xffffffffffffffff, 0x1p+76 , -0x1p+0 }, +{ ((__int128_t)0x000000000000ffff << 64) | 0xffffffffffffffff, 0x1p+80 , -0x1p+0 }, +{ ((__int128_t)0x00000000000fffff << 64) | 0xffffffffffffffff, 0x1p+84 , -0x1p+0 }, +{ ((__int128_t)0x0000000000ffffff << 64) | 0xffffffffffffffff, 0x1p+88 , -0x1p+0 }, +{ ((__int128_t)0x000000000fffffff << 64) | 0xffffffffffffffff, 0x1p+92 , -0x1p+0 }, +{ ((__int128_t)0x00000000ffffffff << 64) | 0xffffffffffffffff, 0x1p+96 , -0x1p+0 }, +{ ((__int128_t)0x0000000fffffffff << 64) | 0xffffffffffffffff, 0x1p+100 , -0x1p+0 }, +{ ((__int128_t)0x000000ffffffffff << 64) | 0xffffffffffffffff, 0x1p+104 , -0x1p+0 }, +{ ((__int128_t)0x00000fffffffffff << 64) | 0xffffffffffffffff, 0x1p+108 , -0x1p+0 }, +{ ((__int128_t)0x0000ffffffffffff << 64) | 0xffffffffffffffff, 0x1p+112 , -0x1p+0 }, +{ ((__int128_t)0x000fffffffffffff << 64) | 0xffffffffffffffff, 0x1p+116 , -0x1p+0 }, +{ ((__int128_t)0x00ffffffffffffff << 64) | 0xffffffffffffffff, 0x1p+120 , -0x1p+0 }, +{ ((__int128_t)0x0fffffffffffffff << 64) | 0xffffffffffffffff, 0x1p+124 , -0x1p+0 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000000000000, 0x1p+124 , 0x0p+0 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000000000011, 0x1p+124 , 0x1.1p+4 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000000000111, 0x1p+124 , 0x1.11p+8 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000000001111, 0x1p+124 , 0x1.111p+12 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000000011111, 0x1p+124 , 0x1.1111p+16 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000000111111, 0x1p+124 , 0x1.11111p+20 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000001111111, 0x1p+124 , 0x1.111111p+24 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000011111111, 0x1p+124 , 0x1.1111111p+28 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000000111111111, 0x1p+124 , 0x1.11111111p+32 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000001111111111, 0x1p+124 , 0x1.111111111p+36 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000011111111111, 0x1p+124 , 0x1.1111111111p+40 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0000111111111111, 0x1p+124 , 0x1.11111111111p+44 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0001111111111111, 0x1p+124 , 0x1.111111111111p+48 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0011111111111111, 0x1p+124 , 0x1.1111111111111p+52 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x0111111111111111, 0x1p+124 , 0x1.11111111111111p+56 }, +{ ((__int128_t)0x1000000000000000 << 64) | 0x1111111111111111, 0x1p+124 , 0x1.111111111111111p+60 }, +{ ((__int128_t)0xffffffffffffffff << 64) | 0xf000000000000000, -0x1p+60 , 0x0p+0 }, +{ ((__int128_t)0xffffffffffffffff << 64) | 0xff00000000000000, -0x1p+56 , 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xb7ffffff77ffffff, 0x1.6ffffffefp+63, -0x1p+0 }, +{ ((__int128_t)0xb7ffffff3fffffff << 64) | 0xb7ffffff3fffffff, -0x1.20000003p+126 , -0x1.20000003p+62 }, +{ ((__int128_t)0xb7fffffefffffffe << 64) | 0xb7fffffefffffffe, -0x1.20000004p+126 , -0x1.48000001p+64 }, +{ ((__int128_t)0xb7fffffeffffefff << 64) | 0xb7fffffeffffefff, -0x1.2000000400004p+126 , -0x1.2000000400004p+62 }, +{ ((__int128_t)0x0000040000000000 << 64) | 0x0000000000000000, 0x1p+106 , 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x000000003ff00000, 0x1.ff8p+29 , 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xb7fbffffffffdfff, 0x1.6ff7ffffffffcp+63 , -0x1p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x4804000000010000, 0x1.201000000004p+62, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x4900000000001000, 0x1.2400000000004p+62, 0x0p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0xb6ffffffffffefff, 0x1.6dffffffffffep+63, -0x1p+0 }, +{ ((__int128_t)0x0000000000000000 << 64) | 0x4900000000008000, 0x1.240000000002p+62, 0x0p+0 }, +{ ((__int128_t)0xb6ffffffffff7fff << 64) | 0xb6ffffffffff7fff, -0x1.240000000002p+126, -0x1.240000000002p+62 }, +{ ((__int128_t)0x4900000000040000 << 64) | 0x4900000000040000, 0x1.24000000001p+126 , 0x1.24000000001p+62 }, +{ ((__int128_t)0xb6fffffffffbffff << 64) | 0xb6fffffffffbffff, -0x1.24000000001p+126 , -0x1.24000000001p+62 }, +{ ((__int128_t)0x4900000000200000 << 64) | 0x4900000000200000, 0x1.24000000008p+126 , 0x1.24000000008p+62 }, +{ ((__int128_t)0xb6ffffffffdfffff << 64) | 0xb6ffffffffdfffff, -0x1.24000000008p+126 , -0x1.24000000008p+62 }, +{ ((__int128_t)0x4900000000800000 << 64) | 0x4900000000800000, 0x1.2400000002p+126 , 0x1.2400000002p+62 }, +{ ((__int128_t)0xb6ffffffff7fffff << 64) | 0xb6ffffffff7fffff, -0x1.2400000002p+126 , -0x1.2400000002p+62 }, +{ ((__int128_t)0x4900000008000000 << 64) | 0x4900000008000000, 0x1.240000002p+126 , 0x1.240000002p+62 }, +{ ((__int128_t)0xb6fffffff7ffffff << 64) | 0xb6fffffff7ffffff, -0x1.240000002p+126 , -0x1.240000002p+62 }, +{ ((__int128_t)0x4900000040000000 << 64) | 0x4900000040000000, 0x1.24000001p+126 , 0x1.24000001p+62 }, +{ ((__int128_t)0xb6ffffffbfffffff << 64) | 0xb6ffffffbfffffff, -0x1.24000001p+126 , -0x1.24000001p+62 }, +{ ((__int128_t)0x4900000080000000 << 64) | 0x4900000080000000, 0x1.24000002p+126 , 0x1.24000002p+62 }, +{ ((__int128_t)0xb6ffffff7fffffff << 64) | 0xb6ffffff7fffffff, -0x1.24000002p+126 , -0x1.24000002p+62 }, +{ ((__int128_t)0x4900000400000000 << 64) | 0x4900000400000000, 0x1.2400001p+126 , 0x1.2400001p+62 }, +{ ((__int128_t)0xb6fffffbffffffff << 64) | 0xb6fffffbffffffff, -0x1.2400001p+126 , -0x1.2400001p+62 }, +{ ((__int128_t)0x4900001000000000 << 64) | 0x4900001000000000, 0x1.2400004p+126 , 0x1.2400004p+62 }, +{ ((__int128_t)0xb6ffffefffffffff << 64) | 0xb6ffffefffffffff, -0x1.2400004p+126 , -0x1.2400004p+62 }, +{ ((__int128_t)0x4900004000000000 << 64) | 0x4900004000000000, 0x1.240001p+126 , 0x1.240001p+62 }, +{ ((__int128_t)0xb6ffffbfffffffff << 64) | 0xb6ffffbfffffffff, -0x1.240001p+126 , -0x1.240001p+62 }, +{ ((__int128_t)0x4900040000000000 << 64) | 0x4900040000000000, 0x1.24001p+126 , 0x1.24001p+62 }, +{ ((__int128_t)0xb6fffbffffffffff << 64) | 0xb6fffbffffffffff, -0x1.24001p+126 , -0x1.24001p+62 }, +{ ((__int128_t)0x4900200000000000 << 64) | 0x4900200000000000, 0x1.24008p+126 , 0x1.24008p+62 }, +{ ((__int128_t)0xb6ffdfffffffffff << 64) | 0xb6ffdfffffffffff, -0x1.24008p+126 , -0x1.24008p+62 }, +{ ((__int128_t)0x4901000000000000 << 64) | 0x4901000000000000, 0x1.2404p+126 , 0x1.2404p+62 }, +{ ((__int128_t)0xb6feffffffffffff << 64) | 0xb6feffffffffffff, -0x1.2404p+126 , -0x1.2404p+62 }, +{ ((__int128_t)0x4910000000000000 << 64) | 0x4910000000000000, 0x1.244p+126 , 0x1.244p+62 }, +{ ((__int128_t)0xb6efffffffffffff << 64) | 0xb6efffffffffffff, -0x1.244p+126, -0x1.244p+62 }, +{ ((__int128_t)0x4980000000000000 << 64) | 0x4980000000000000, 0x1.26p+126 , 0x1.26p+62 }, +{ ((__int128_t)0xb67fffffffffffff << 64) | 0xb67fffffffffffff, -0x1.26p+126 , -0x1.26p+62 }, +{ ((__int128_t)0x4c00000000000000 << 64) | 0x4c00000000000000, 0x1.3p+126 , 0x1.3p+62 }, +{ ((__int128_t)0xb3ffffffffffffff << 64) | 0xb3ffffffffffffff, -0x1.3p+126 , -0x1.3p+62 }, +{ ((__int128_t)0x9fffffffffffbfff << 64) | 0x9fffffffffffbfff, -0x1.800000000001p+126 , -0x1.800000000001p+62 }, +{ ((__int128_t)0x6000000000004001 << 64) | 0x6000000000004001, 0x1.800000000001p+126 , 0x1.6000000000004p+64 }, +{ ((__int128_t)0x8fffffffffffffbf << 64) | 0x8fffffffffffffbf, -0x1.cp+126 , -0x1.01cp+70 }, +{ ((__int128_t)0x7000000000000080 << 64) | 0x7000000000000080, 0x1.cp+126 , 0x1.00ep+71 }, +{ ((__int128_t)0x8fffffffffffff7f << 64) | 0x8fffffffffffff7f, -0x1.cp+126 , -0x1.00ep+71 }, +{ ((__int128_t)0x7000000000000800 << 64) | 0x7000000000000800, 0x1.c000000000002p+126 , 0x1.c000000000002p+62 }, +{ ((__int128_t)0x8ffffffffffff7ff << 64) | 0x8ffffffffffff7ff, -0x1.c000000000002p+126 , -0x1.c000000000002p+62 }, +{ ((__int128_t)0x7000000000002000 << 64) | 0x7000000000002000, 0x1.c000000000008p+126 , 0x1.c000000000008p+62 }, +{ ((__int128_t)0x8fffffffffffdfff << 64) | 0x8fffffffffffdfff, -0x1.c000000000008p+126 , -0x1.c000000000008p+62 }, +{ ((__int128_t)0x7000000000010000 << 64) | 0x7000000000010000, 0x1.c00000000004p+126 , 0x1.c00000000004p+62 }, +{ ((__int128_t)0x8ffffffffffeffff << 64) | 0x8ffffffffffeffff, -0x1.c00000000004p+126 , -0x1.c00000000004p+62 }, +{ ((__int128_t)0x7000000000040000 << 64) | 0x7000000000040000, 0x1.c0000000001p+126 , 0x1.c0000000001p+62 }, +{ ((__int128_t)0x8ffffffffffbffff << 64) | 0x8ffffffffffbffff, -0x1.c0000000001p+126 , -0x1.c0000000001p+62 }, +{ ((__int128_t)0x7000000000080000 << 64) | 0x7000000000080000, 0x1.c0000000002p+126 , 0x1.c0000000002p+62 }, +{ ((__int128_t)0x8ffffffffff7ffff << 64) | 0x8ffffffffff7ffff, -0x1.c0000000002p+126 , -0x1.c0000000002p+62 }, +{ ((__int128_t)0x7000000000800000 << 64) | 0x7000000000800000, 0x1.c000000002p+126 , 0x1.c000000002p+62 }, +{ ((__int128_t)0x8fffffffff7fffff << 64) | 0x8fffffffff7fffff, -0x1.c000000002p+126 , -0x1.c000000002p+62 }, +{ ((__int128_t)0x7000000008000000 << 64) | 0x7000000008000000, 0x1.c00000002p+126 , 0x1.c00000002p+62 }, +{ ((__int128_t)0x8ffffffff7ffffff << 64) | 0x8ffffffff7ffffff, -0x1.c00000002p+126 , -0x1.c00000002p+62 }, +{ ((__int128_t)0x7000000010000000 << 64) | 0x7000000010000000, 0x1.c00000004p+126 , 0x1.c00000004p+62 }, +{ ((__int128_t)0x8fffffffefffffff << 64) | 0x8fffffffefffffff, -0x1.c00000004p+126 , -0x1.c00000004p+62 }, +{ ((__int128_t)0x7000000100000000 << 64) | 0x7000000100000000, 0x1.c0000004p+126 , 0x1.c0000004p+62 }, +{ ((__int128_t)0x8ffffffeffffffff << 64) | 0x8ffffffeffffffff, -0x1.c0000004p+126 , -0x1.c0000004p+62 }, +{ ((__int128_t)0x7000000200000000 << 64) | 0x7000000200000000, 0x1.c0000008p+126 , 0x1.c0000008p+62 }, +{ ((__int128_t)0x8ffffffdffffffff << 64) | 0x8ffffffdffffffff, -0x1.c0000008p+126 , -0x1.c0000008p+62 }, +{ ((__int128_t)0x7000000800000000 << 64) | 0x7000000800000000, 0x1.c000002p+126 , 0x1.c000002p+62 }, +{ ((__int128_t)0x8ffffff7ffffffff << 64) | 0x8ffffff7ffffffff, -0x1.c000002p+126 , -0x1.c000002p+62 }, +{ ((__int128_t)0x7000008000000000 << 64) | 0x7000008000000000, 0x1.c00002p+126 , 0x1.c00002p+62 }, +{ ((__int128_t)0x8fffff7fffffffff << 64) | 0x8fffff7fffffffff, -0x1.c00002p+126 , -0x1.c00002p+62 }, +{ ((__int128_t)0x7000010000000000 << 64) | 0x7000010000000000, 0x1.c00004p+126 , 0x1.c00004p+62 }, +{ ((__int128_t)0x8ffffeffffffffff << 64) | 0x8ffffeffffffffff, -0x1.c00004p+126 , -0x1.c00004p+62 }, +{ ((__int128_t)0x7000080000000000 << 64) | 0x7000080000000000, 0x1.c0002p+126 , 0x1.c0002p+62 }, +{ ((__int128_t)0x8ffff7ffffffffff << 64) | 0x8ffff7ffffffffff, -0x1.c0002p+126 , -0x1.c0002p+62 }, +{ ((__int128_t)0x7000800000000000 << 64) | 0x7000800000000000, 0x1.c002p+126 , 0x1.c002p+62 }, +{ ((__int128_t)0x8fff7fffffffffff << 64) | 0x8fff7fffffffffff, -0x1.c002p+126 , -0x1.c002p+62 }, +{ ((__int128_t)0x7002000000000000 << 64) | 0x7002000000000000, 0x1.c008p+126 , 0x1.c008p+62 }, +{ ((__int128_t)0x8ffdffffffffffff << 64) | 0x8ffdffffffffffff, -0x1.c008p+126 , -0x1.c008p+62 }, +{ ((__int128_t)0x7008000000000000 << 64) | 0x7008000000000000, 0x1.c02p+126 , 0x1.c02p+62 }, +{ ((__int128_t)0x8ff7ffffffffffff << 64) | 0x8ff7ffffffffffff, -0x1.c02p+126 , -0x1.c02p+62 }, +{ ((__int128_t)0x7080000000000000 << 64) | 0x7080000000000000, 0x1.c2p+126 , 0x1.c2p+62 }, +{ ((__int128_t)0x8f7fffffffffffff << 64) | 0x8f7fffffffffffff, -0x1.c2p+126 , -0x1.c2p+62 }, +{ ((__int128_t)0x7400000000000000 << 64) | 0x7400000000000000, 0x1.dp+126 , 0x1.dp+62 }, +}; + +static const int numTests = sizeof(tests) / sizeof(struct testCase); Index: compiler-rt/test/builtins/Unit/ppc/floattitf_test.c =================================================================== --- /dev/null +++ compiler-rt/test/builtins/Unit/ppc/floattitf_test.c @@ -0,0 +1,52 @@ +// REQUIRES: target-is-powerpc64le +// RUN: %clang_builtins %s %librt -o %t && %run %t + +/* +* Test case execution for: long double __floattitf (__int128_t) +* Conversion from 128 bit integer to long double (IBM double-double). +*/ + +#include +#include + +long double __floattitf(__int128_t); + +#include "floattitf_test.h" +#include "DD.h" + +int main(int argc, char *argv[]) { + /* Necessary long double and 128 bit integer declarations used to + * compare computed and expected high and low portions of the + * IBM double-double. */ + DD expected_ld; + DD computed_ld; + __int128_t result128; + + for (int i = 0; i < numTests; ++i) { + /* Set the expected high and low values of the long double, + * and the 128 bit integer input to be converted. */ + expected_ld.hi = tests[i].hi; + expected_ld.lo = tests[i].lo; + result128 = tests[i].input128; + + /* Get the computed long double from the int128->long double conversion + * and check for errors between high and low portions. */ + computed_ld.ld = __floattitf(result128); + + if ((computed_ld.hi != expected_ld.hi) || + (computed_ld.lo != expected_ld.lo)) { + + printf("Error on __floattitf( 0x%016llx 0x%016llx ):\n", + (long long) (tests[i].input128 >> 64), + (long long) tests[i].input128); + printf("\tExpected value - %La = ( %a, %a )\n", + expected_ld.ld, expected_ld.hi, expected_ld.lo); + printf("\tComputed value - %La = ( %a, %a )\n\n", + computed_ld.ld, computed_ld.hi, computed_ld.lo); + + return 1; + } + } + + return 0; +}