1 1.1 joerg //===-- fixsfti_test.c - Test __fixsfti -----------------------------------===// 2 1.1 joerg // 3 1.1 joerg // The LLVM Compiler Infrastructure 4 1.1 joerg // 5 1.1 joerg // This file is dual licensed under the MIT and the University of Illinois Open 6 1.1 joerg // Source Licenses. See LICENSE.TXT for details. 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg // 10 1.1 joerg // This file tests __fixsfti for the compiler_rt library. 11 1.1 joerg // 12 1.1 joerg //===----------------------------------------------------------------------===// 13 1.1 joerg 14 1.1 joerg #if __x86_64 15 1.1 joerg 16 1.1 joerg #include "int_lib.h" 17 1.1 joerg #include <stdio.h> 18 1.1 joerg 19 1.1 joerg // Returns: convert a to a signed long long, rounding toward zero. 20 1.1 joerg 21 1.1 joerg // Assumption: float is a IEEE 32 bit floating point type 22 1.1 joerg // su_int is a 32 bit integral type 23 1.1 joerg // value in float is representable in ti_int (no range checking performed) 24 1.1 joerg 25 1.1 joerg // seee eeee emmm mmmm mmmm mmmm mmmm mmmm 26 1.1 joerg 27 1.1 joerg ti_int __fixsfti(float a); 28 1.1 joerg 29 1.1 joerg int test__fixsfti(float a, ti_int expected) 30 1.1 joerg { 31 1.1 joerg ti_int x = __fixsfti(a); 32 1.1 joerg if (x != expected) 33 1.1 joerg { 34 1.1 joerg twords xt; 35 1.1 joerg xt.all = x; 36 1.1 joerg twords expectedt; 37 1.1 joerg expectedt.all = expected; 38 1.1 joerg printf("error in __fixsfti(%A) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n", 39 1.1 joerg a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low); 40 1.1 joerg } 41 1.1 joerg return x != expected; 42 1.1 joerg } 43 1.1 joerg 44 1.1 joerg char assumption_1[sizeof(ti_int) == 2*sizeof(di_int)] = {0}; 45 1.1 joerg char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0}; 46 1.1 joerg char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0}; 47 1.1 joerg 48 1.1 joerg #endif 49 1.1 joerg 50 1.1 joerg int main() 51 1.1 joerg { 52 1.1 joerg #if __x86_64 53 1.1 joerg if (test__fixsfti(0.0F, 0)) 54 1.1 joerg return 1; 55 1.1 joerg 56 1.1 joerg if (test__fixsfti(0.5F, 0)) 57 1.1 joerg return 1; 58 1.1 joerg if (test__fixsfti(0.99F, 0)) 59 1.1 joerg return 1; 60 1.1 joerg if (test__fixsfti(1.0F, 1)) 61 1.1 joerg return 1; 62 1.1 joerg if (test__fixsfti(1.5F, 1)) 63 1.1 joerg return 1; 64 1.1 joerg if (test__fixsfti(1.99F, 1)) 65 1.1 joerg return 1; 66 1.1 joerg if (test__fixsfti(2.0F, 2)) 67 1.1 joerg return 1; 68 1.1 joerg if (test__fixsfti(2.01F, 2)) 69 1.1 joerg return 1; 70 1.1 joerg if (test__fixsfti(-0.5F, 0)) 71 1.1 joerg return 1; 72 1.1 joerg if (test__fixsfti(-0.99F, 0)) 73 1.1 joerg return 1; 74 1.1 joerg if (test__fixsfti(-1.0F, -1)) 75 1.1 joerg return 1; 76 1.1 joerg if (test__fixsfti(-1.5F, -1)) 77 1.1 joerg return 1; 78 1.1 joerg if (test__fixsfti(-1.99F, -1)) 79 1.1 joerg return 1; 80 1.1 joerg if (test__fixsfti(-2.0F, -2)) 81 1.1 joerg return 1; 82 1.1 joerg if (test__fixsfti(-2.01F, -2)) 83 1.1 joerg return 1; 84 1.1 joerg 85 1.1 joerg if (test__fixsfti(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL)) 86 1.1 joerg return 1; 87 1.1 joerg if (test__fixsfti(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL)) 88 1.1 joerg return 1; 89 1.1 joerg 90 1.1 joerg if (test__fixsfti(-0x1.FFFFFEp+62F, make_ti(0xFFFFFFFFFFFFFFFFLL, 91 1.1 joerg 0x8000008000000000LL))) 92 1.1 joerg return 1; 93 1.1 joerg if (test__fixsfti(-0x1.FFFFFCp+62F, make_ti(0xFFFFFFFFFFFFFFFFLL, 94 1.1 joerg 0x8000010000000000LL))) 95 1.1 joerg return 1; 96 1.1 joerg 97 1.1 joerg if (test__fixsfti(0x1.FFFFFEp+126F, make_ti(0x7FFFFF8000000000LL, 0))) 98 1.1 joerg return 1; 99 1.1 joerg if (test__fixsfti(0x1.FFFFFCp+126F, make_ti(0x7FFFFF0000000000LL, 0))) 100 1.1 joerg return 1; 101 1.1 joerg 102 1.1 joerg if (test__fixsfti(-0x1.FFFFFEp+126F, make_ti(0x8000008000000000LL, 0))) 103 1.1 joerg return 1; 104 1.1 joerg if (test__fixsfti(-0x1.FFFFFCp+126F, make_ti(0x8000010000000000LL, 0))) 105 1.1 joerg return 1; 106 1.1 joerg 107 1.1 joerg #else 108 1.1 joerg printf("skipped\n"); 109 1.1 joerg #endif 110 1.1 joerg return 0; 111 1.1 joerg } 112