Home | History | Annotate | Line # | Download | only in Unit
      1  1.1  joerg //===-- fixunssfdi_test.c - Test __fixunssfdi -----------------------------===//
      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 __fixunssfdi for the compiler_rt library.
     11  1.1  joerg //
     12  1.1  joerg //===----------------------------------------------------------------------===//
     13  1.1  joerg 
     14  1.1  joerg #include "int_lib.h"
     15  1.1  joerg #include <stdio.h>
     16  1.1  joerg 
     17  1.1  joerg // Returns: convert a to a unsigned long long, rounding toward zero.
     18  1.1  joerg //          Negative values all become zero.
     19  1.1  joerg 
     20  1.1  joerg // Assumption: float is a IEEE 32 bit floating point type
     21  1.1  joerg //             du_int is a 64 bit integral type
     22  1.1  joerg //             value in float is representable in du_int or is negative
     23  1.1  joerg //                 (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 du_int __fixunssfdi(float a);
     28  1.1  joerg 
     29  1.1  joerg int test__fixunssfdi(float a, du_int expected)
     30  1.1  joerg {
     31  1.1  joerg     du_int x = __fixunssfdi(a);
     32  1.1  joerg     if (x != expected)
     33  1.1  joerg         printf("error in __fixunssfdi(%A) = %llX, expected %llX\n",
     34  1.1  joerg                a, x, expected);
     35  1.1  joerg     return x != expected;
     36  1.1  joerg }
     37  1.1  joerg 
     38  1.1  joerg char assumption_1[sizeof(du_int) == 2*sizeof(si_int)] = {0};
     39  1.1  joerg char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
     40  1.1  joerg char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
     41  1.1  joerg 
     42  1.1  joerg int main()
     43  1.1  joerg {
     44  1.1  joerg     if (test__fixunssfdi(0.0F, 0))
     45  1.1  joerg         return 1;
     46  1.1  joerg 
     47  1.1  joerg     if (test__fixunssfdi(0.5F, 0))
     48  1.1  joerg         return 1;
     49  1.1  joerg     if (test__fixunssfdi(0.99F, 0))
     50  1.1  joerg         return 1;
     51  1.1  joerg     if (test__fixunssfdi(1.0F, 1))
     52  1.1  joerg         return 1;
     53  1.1  joerg     if (test__fixunssfdi(1.5F, 1))
     54  1.1  joerg         return 1;
     55  1.1  joerg     if (test__fixunssfdi(1.99F, 1))
     56  1.1  joerg         return 1;
     57  1.1  joerg     if (test__fixunssfdi(2.0F, 2))
     58  1.1  joerg         return 1;
     59  1.1  joerg     if (test__fixunssfdi(2.01F, 2))
     60  1.1  joerg         return 1;
     61  1.1  joerg     if (test__fixunssfdi(-0.5F, 0))
     62  1.1  joerg         return 1;
     63  1.1  joerg     if (test__fixunssfdi(-0.99F, 0))
     64  1.1  joerg         return 1;
     65  1.1  joerg #if !TARGET_LIBGCC
     66  1.1  joerg     if (test__fixunssfdi(-1.0F, 0))  // libgcc ignores "returns 0 for negative input" spec
     67  1.1  joerg         return 1;
     68  1.1  joerg     if (test__fixunssfdi(-1.5F, 0))
     69  1.1  joerg         return 1;
     70  1.1  joerg     if (test__fixunssfdi(-1.99F, 0))
     71  1.1  joerg         return 1;
     72  1.1  joerg     if (test__fixunssfdi(-2.0F, 0))
     73  1.1  joerg         return 1;
     74  1.1  joerg     if (test__fixunssfdi(-2.01F, 0))
     75  1.1  joerg         return 1;
     76  1.1  joerg #endif
     77  1.1  joerg 
     78  1.1  joerg     if (test__fixunssfdi(0x1.FFFFFEp+63F, 0xFFFFFF0000000000LL))
     79  1.1  joerg         return 1;
     80  1.1  joerg     if (test__fixunssfdi(0x1.000000p+63F, 0x8000000000000000LL))
     81  1.1  joerg         return 1;
     82  1.1  joerg     if (test__fixunssfdi(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL))
     83  1.1  joerg         return 1;
     84  1.1  joerg     if (test__fixunssfdi(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL))
     85  1.1  joerg         return 1;
     86  1.1  joerg 
     87  1.1  joerg #if !TARGET_LIBGCC
     88  1.1  joerg     if (test__fixunssfdi(-0x1.FFFFFEp+62F, 0x0000000000000000LL))
     89  1.1  joerg         return 1;
     90  1.1  joerg     if (test__fixunssfdi(-0x1.FFFFFCp+62F, 0x0000000000000000LL))
     91  1.1  joerg         return 1;
     92  1.1  joerg #endif
     93  1.1  joerg 
     94  1.1  joerg    return 0;
     95  1.1  joerg }
     96