11.1Sjoerg//===-- fixxfti_test.c - Test __fixxfti -----------------------------------===// 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 __fixxfti 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 <stdio.h> 181.1Sjoerg 191.1Sjoerg// Returns: convert a to a signed long long, rounding toward zero. 201.1Sjoerg 211.1Sjoerg// Assumption: long double is an intel 80 bit floating point type padded with 6 bytes 221.1Sjoerg// su_int is a 32 bit integral type 231.1Sjoerg// value in long double is representable in ti_int (no range checking performed) 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.1Sjoergti_int __fixxfti(long double a); 291.1Sjoerg 301.1Sjoergint test__fixxfti(long double a, ti_int expected) 311.1Sjoerg{ 321.1Sjoerg ti_int x = __fixxfti(a); 331.1Sjoerg if (x != expected) 341.1Sjoerg { 351.1Sjoerg utwords xt; 361.1Sjoerg xt.all = x; 371.1Sjoerg utwords expectedt; 381.1Sjoerg expectedt.all = expected; 391.1Sjoerg printf("error in __fixxfti(%LA) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n", 401.1Sjoerg a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); 411.1Sjoerg } 421.1Sjoerg return x != expected; 431.1Sjoerg} 441.1Sjoerg 451.1Sjoergchar assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; 461.1Sjoergchar assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0}; 471.1Sjoergchar assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0}; 481.1Sjoerg 491.1Sjoerg#endif 501.1Sjoerg 511.1Sjoergint main() 521.1Sjoerg{ 531.1Sjoerg#if __x86_64 541.1Sjoerg if (test__fixxfti(0.0, 0)) 551.1Sjoerg return 1; 561.1Sjoerg 571.1Sjoerg if (test__fixxfti(0.5, 0)) 581.1Sjoerg return 1; 591.1Sjoerg if (test__fixxfti(0.99, 0)) 601.1Sjoerg return 1; 611.1Sjoerg if (test__fixxfti(1.0, 1)) 621.1Sjoerg return 1; 631.1Sjoerg if (test__fixxfti(1.5, 1)) 641.1Sjoerg return 1; 651.1Sjoerg if (test__fixxfti(1.99, 1)) 661.1Sjoerg return 1; 671.1Sjoerg if (test__fixxfti(2.0, 2)) 681.1Sjoerg return 1; 691.1Sjoerg if (test__fixxfti(2.01, 2)) 701.1Sjoerg return 1; 711.1Sjoerg if (test__fixxfti(-0.5, 0)) 721.1Sjoerg return 1; 731.1Sjoerg if (test__fixxfti(-0.99, 0)) 741.1Sjoerg return 1; 751.1Sjoerg if (test__fixxfti(-1.0, -1)) 761.1Sjoerg return 1; 771.1Sjoerg if (test__fixxfti(-1.5, -1)) 781.1Sjoerg return 1; 791.1Sjoerg if (test__fixxfti(-1.99, -1)) 801.1Sjoerg return 1; 811.1Sjoerg if (test__fixxfti(-2.0, -2)) 821.1Sjoerg return 1; 831.1Sjoerg if (test__fixxfti(-2.01, -2)) 841.1Sjoerg return 1; 851.1Sjoerg 861.1Sjoerg if (test__fixxfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL)) 871.1Sjoerg return 1; 881.1Sjoerg if (test__fixxfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL)) 891.1Sjoerg return 1; 901.1Sjoerg 911.1Sjoerg if (test__fixxfti(-0x1.FFFFFEp+62, make_ti(0xFFFFFFFFFFFFFFFFLL, 921.1Sjoerg 0x8000008000000000LL))) 931.1Sjoerg return 1; 941.1Sjoerg if (test__fixxfti(-0x1.FFFFFCp+62, make_ti(0xFFFFFFFFFFFFFFFFLL, 951.1Sjoerg 0x8000010000000000LL))) 961.1Sjoerg return 1; 971.1Sjoerg 981.1Sjoerg if (test__fixxfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL)) 991.1Sjoerg return 1; 1001.1Sjoerg if (test__fixxfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL)) 1011.1Sjoerg return 1; 1021.1Sjoerg 1031.1Sjoerg if (test__fixxfti(-0x1.FFFFFFFFFFFFFp+62, make_ti(0xFFFFFFFFFFFFFFFFLL, 1041.1Sjoerg 0x8000000000000400LL))) 1051.1Sjoerg return 1; 1061.1Sjoerg if (test__fixxfti(-0x1.FFFFFFFFFFFFEp+62, make_ti(0xFFFFFFFFFFFFFFFFLL, 1071.1Sjoerg 0x8000000000000800LL))) 1081.1Sjoerg return 1; 1091.1Sjoerg 1101.1Sjoerg if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL)) 1111.1Sjoerg return 1; 1121.1Sjoerg if (test__fixxfti(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL)) 1131.1Sjoerg return 1; 1141.1Sjoerg 1151.1Sjoerg if (test__fixxfti(-0x1.0000000000000000p+63L, make_ti(0xFFFFFFFFFFFFFFFFLL, 1161.1Sjoerg 0x8000000000000000LL))) 1171.1Sjoerg return 1; 1181.1Sjoerg if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp+62L, make_ti(0xFFFFFFFFFFFFFFFFLL, 1191.1Sjoerg 0x8000000000000001LL))) 1201.1Sjoerg return 1; 1211.1Sjoerg if (test__fixxfti(-0x1.FFFFFFFFFFFFFFF8p+62L, make_ti(0xFFFFFFFFFFFFFFFFLL, 1221.1Sjoerg 0x8000000000000002LL))) 1231.1Sjoerg return 1; 1241.1Sjoerg 1251.1Sjoerg if (test__fixxfti(0x1.FFFFFFFFFFFFFFFEp+126L, make_ti(0x7FFFFFFFFFFFFFFFLL, 1261.1Sjoerg 0x8000000000000000LL))) 1271.1Sjoerg return 1; 1281.1Sjoerg if (test__fixxfti(0x1.FFFFFFFFFFFFFFFCp+126L, make_ti(0x7FFFFFFFFFFFFFFFLL, 1291.1Sjoerg 0x0000000000000000LL))) 1301.1Sjoerg 1311.1Sjoerg return 1; 1321.1Sjoerg 1331.1Sjoerg if (test__fixxfti(-0x1.0000000000000000p+127L, make_ti(0x8000000000000000LL, 1341.1Sjoerg 0x0000000000000000LL))) 1351.1Sjoerg return 1; 1361.1Sjoerg if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFEp+126L, make_ti(0x8000000000000000LL, 1371.1Sjoerg 0x8000000000000000LL))) 1381.1Sjoerg return 1; 1391.1Sjoerg if (test__fixxfti(-0x1.FFFFFFFFFFFFFFFCp+126L, make_ti(0x8000000000000001LL, 1401.1Sjoerg 0x0000000000000000LL))) 1411.1Sjoerg return 1; 1421.1Sjoerg#else 1431.1Sjoerg printf("skipped\n"); 1441.1Sjoerg#endif 1451.1Sjoerg return 0; 1461.1Sjoerg} 147