Home | History | Annotate | Download | only in Unit
      1 //===-- fixunsdfti_test.c - Test __fixunsdfti -----------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file tests __fixunsdfti for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 
     17 // Returns: convert a to a unsigned long long, rounding toward zero.
     18 //          Negative values all become zero.
     19 
     20 // Assumption: double is a IEEE 64 bit floating point type
     21 //             tu_int is a 64 bit integral type
     22 //             value in double is representable in tu_int or is negative
     23 //                 (no range checking performed)
     24 
     25 // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
     26 
     27 #if __x86_64
     28 
     29 tu_int __fixunsdfti(double a);
     30 
     31 int test__fixunsdfti(double a, tu_int expected)
     32 {
     33     tu_int x = __fixunsdfti(a);
     34     if (x != expected)
     35     {
     36         utwords xt;
     37         xt.all = x;
     38         utwords expectedt;
     39         expectedt.all = expected;
     40         printf("error in __fixunsdfti(%A) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
     41                a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
     42     }
     43     return x != expected;
     44 }
     45 
     46 char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
     47 char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
     48 char assumption_3[sizeof(double)*CHAR_BIT == 64] = {0};
     49 
     50 #endif
     51 
     52 int main()
     53 {
     54 #if __x86_64
     55     if (test__fixunsdfti(0.0, 0))
     56         return 1;
     57 
     58     if (test__fixunsdfti(0.5, 0))
     59         return 1;
     60     if (test__fixunsdfti(0.99, 0))
     61         return 1;
     62     if (test__fixunsdfti(1.0, 1))
     63         return 1;
     64     if (test__fixunsdfti(1.5, 1))
     65         return 1;
     66     if (test__fixunsdfti(1.99, 1))
     67         return 1;
     68     if (test__fixunsdfti(2.0, 2))
     69         return 1;
     70     if (test__fixunsdfti(2.01, 2))
     71         return 1;
     72     if (test__fixunsdfti(-0.5, 0))
     73         return 1;
     74     if (test__fixunsdfti(-0.99, 0))
     75         return 1;
     76 #if !TARGET_LIBGCC
     77     if (test__fixunsdfti(-1.0, 0))  // libgcc ignores "returns 0 for negative input" spec
     78         return 1;
     79     if (test__fixunsdfti(-1.5, 0))
     80         return 1;
     81     if (test__fixunsdfti(-1.99, 0))
     82         return 1;
     83     if (test__fixunsdfti(-2.0, 0))
     84         return 1;
     85     if (test__fixunsdfti(-2.01, 0))
     86         return 1;
     87 #endif
     88 
     89     if (test__fixunsdfti(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
     90         return 1;
     91     if (test__fixunsdfti(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
     92         return 1;
     93 
     94 #if !TARGET_LIBGCC
     95     if (test__fixunsdfti(-0x1.FFFFFEp+62, 0))
     96         return 1;
     97     if (test__fixunsdfti(-0x1.FFFFFCp+62, 0))
     98         return 1;
     99 #endif
    100 
    101     if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+63, 0xFFFFFFFFFFFFF800LL))
    102         return 1;
    103     if (test__fixunsdfti(0x1.0000000000000p+63, 0x8000000000000000LL))
    104         return 1;
    105     if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
    106         return 1;
    107     if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
    108         return 1;
    109 
    110     if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+127, make_ti(0xFFFFFFFFFFFFF800LL, 0)))
    111         return 1;
    112     if (test__fixunsdfti(0x1.0000000000000p+127, make_ti(0x8000000000000000LL, 0)))
    113         return 1;
    114     if (test__fixunsdfti(0x1.FFFFFFFFFFFFFp+126, make_ti(0x7FFFFFFFFFFFFC00LL, 0)))
    115         return 1;
    116     if (test__fixunsdfti(0x1.FFFFFFFFFFFFEp+126, make_ti(0x7FFFFFFFFFFFF800LL, 0)))
    117         return 1;
    118 
    119 #if !TARGET_LIBGCC
    120     if (test__fixunsdfti(-0x1.FFFFFFFFFFFFFp+62, 0))
    121         return 1;
    122     if (test__fixunsdfti(-0x1.FFFFFFFFFFFFEp+62, 0))
    123         return 1;
    124 #endif
    125 
    126 #endif
    127    return 0;
    128 }
    129