Home | History | Annotate | Line # | Download | only in Unit
      1  1.1  joerg //===-- fixunssfti_test.c - Test __fixunssfti -----------------------------===//
      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 __fixunssfti 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 unsigned long long, rounding toward zero.
     20  1.1  joerg //          Negative values all become zero.
     21  1.1  joerg 
     22  1.1  joerg // Assumption: float is a IEEE 32 bit floating point type
     23  1.1  joerg //             tu_int is a 64 bit integral type
     24  1.1  joerg //             value in float is representable in tu_int or is negative
     25  1.1  joerg //                 (no range checking performed)
     26  1.1  joerg 
     27  1.1  joerg // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
     28  1.1  joerg 
     29  1.1  joerg tu_int __fixunssfti(float a);
     30  1.1  joerg 
     31  1.1  joerg int test__fixunssfti(float a, tu_int expected)
     32  1.1  joerg {
     33  1.1  joerg     tu_int x = __fixunssfti(a);
     34  1.1  joerg     if (x != expected)
     35  1.1  joerg     {
     36  1.1  joerg         utwords xt;
     37  1.1  joerg         xt.all = x;
     38  1.1  joerg         utwords expectedt;
     39  1.1  joerg         expectedt.all = expected;
     40  1.1  joerg         printf("error in __fixunssfti(%A) = 0x%.16llX%.16llX, expected 0x%.16llX%.16llX\n",
     41  1.1  joerg                a, xt.s.high, xt.s.low, expectedt.s.high, expectedt.s.low);
     42  1.1  joerg     }
     43  1.1  joerg     return x != expected;
     44  1.1  joerg }
     45  1.1  joerg 
     46  1.1  joerg char assumption_1[sizeof(tu_int) == 2*sizeof(di_int)] = {0};
     47  1.1  joerg char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
     48  1.1  joerg char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
     49  1.1  joerg 
     50  1.1  joerg #endif
     51  1.1  joerg 
     52  1.1  joerg int main()
     53  1.1  joerg {
     54  1.1  joerg #if __x86_64
     55  1.1  joerg     if (test__fixunssfti(0.0F, 0))
     56  1.1  joerg         return 1;
     57  1.1  joerg 
     58  1.1  joerg     if (test__fixunssfti(0.5F, 0))
     59  1.1  joerg         return 1;
     60  1.1  joerg     if (test__fixunssfti(0.99F, 0))
     61  1.1  joerg         return 1;
     62  1.1  joerg     if (test__fixunssfti(1.0F, 1))
     63  1.1  joerg         return 1;
     64  1.1  joerg     if (test__fixunssfti(1.5F, 1))
     65  1.1  joerg         return 1;
     66  1.1  joerg     if (test__fixunssfti(1.99F, 1))
     67  1.1  joerg         return 1;
     68  1.1  joerg     if (test__fixunssfti(2.0F, 2))
     69  1.1  joerg         return 1;
     70  1.1  joerg     if (test__fixunssfti(2.01F, 2))
     71  1.1  joerg         return 1;
     72  1.1  joerg     if (test__fixunssfti(-0.5F, 0))
     73  1.1  joerg         return 1;
     74  1.1  joerg     if (test__fixunssfti(-0.99F, 0))
     75  1.1  joerg         return 1;
     76  1.1  joerg #if !TARGET_LIBGCC
     77  1.1  joerg     if (test__fixunssfti(-1.0F, 0))  // libgcc ignores "returns 0 for negative input" spec
     78  1.1  joerg         return 1;
     79  1.1  joerg     if (test__fixunssfti(-1.5F, 0))
     80  1.1  joerg         return 1;
     81  1.1  joerg     if (test__fixunssfti(-1.99F, 0))
     82  1.1  joerg         return 1;
     83  1.1  joerg     if (test__fixunssfti(-2.0F, 0))
     84  1.1  joerg         return 1;
     85  1.1  joerg     if (test__fixunssfti(-2.01F, 0))
     86  1.1  joerg         return 1;
     87  1.1  joerg #endif
     88  1.1  joerg 
     89  1.1  joerg     if (test__fixunssfti(0x1.FFFFFEp+63F, 0xFFFFFF0000000000LL))
     90  1.1  joerg         return 1;
     91  1.1  joerg     if (test__fixunssfti(0x1.000000p+63F, 0x8000000000000000LL))
     92  1.1  joerg         return 1;
     93  1.1  joerg     if (test__fixunssfti(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL))
     94  1.1  joerg         return 1;
     95  1.1  joerg     if (test__fixunssfti(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL))
     96  1.1  joerg         return 1;
     97  1.1  joerg 
     98  1.1  joerg     if (test__fixunssfti(0x1.FFFFFEp+127F, make_ti(0xFFFFFF0000000000LL, 0)))
     99  1.1  joerg         return 1;
    100  1.1  joerg     if (test__fixunssfti(0x1.000000p+127F, make_ti(0x8000000000000000LL, 0)))
    101  1.1  joerg         return 1;
    102  1.1  joerg     if (test__fixunssfti(0x1.FFFFFEp+126F, make_ti(0x7FFFFF8000000000LL, 0)))
    103  1.1  joerg         return 1;
    104  1.1  joerg     if (test__fixunssfti(0x1.FFFFFCp+126F, make_ti(0x7FFFFF0000000000LL, 0)))
    105  1.1  joerg         return 1;
    106  1.1  joerg 
    107  1.1  joerg #if !TARGET_LIBGCC
    108  1.1  joerg     if (test__fixunssfti(-0x1.FFFFFEp+62F, 0x0000000000000000LL))
    109  1.1  joerg         return 1;
    110  1.1  joerg     if (test__fixunssfti(-0x1.FFFFFCp+62F, 0x0000000000000000LL))
    111  1.1  joerg         return 1;
    112  1.1  joerg     if (test__fixunssfti(-0x1.FFFFFEp+126F, 0x0000000000000000LL))
    113  1.1  joerg         return 1;
    114  1.1  joerg     if (test__fixunssfti(-0x1.FFFFFCp+126F, 0x0000000000000000LL))
    115  1.1  joerg         return 1;
    116  1.1  joerg #endif
    117  1.1  joerg 
    118  1.1  joerg #endif
    119  1.1  joerg    return 0;
    120  1.1  joerg }
    121