Home | History | Annotate | Line # | Download | only in Unit
      1  1.1  joerg //===-- floatuntisf.c - Test __floatuntisf --------------------------------===//
      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 __floatuntisf 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 <float.h>
     18  1.1  joerg #include <stdio.h>
     19  1.1  joerg 
     20  1.1  joerg // Returns: convert a to a float, rounding toward even.
     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 128 bit integral type
     24  1.1  joerg 
     25  1.1  joerg // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
     26  1.1  joerg 
     27  1.1  joerg float __floatuntisf(tu_int a);
     28  1.1  joerg 
     29  1.1  joerg int test__floatuntisf(tu_int a, float expected)
     30  1.1  joerg {
     31  1.1  joerg     float x = __floatuntisf(a);
     32  1.1  joerg     if (x != expected)
     33  1.1  joerg     {
     34  1.1  joerg         utwords at;
     35  1.1  joerg         at.all = a;
     36  1.1  joerg         printf("error in __floatuntisf(0x%.16llX%.16llX) = %a, expected %a\n",
     37  1.1  joerg                at.s.high, at.s.low, x, expected);
     38  1.1  joerg     }
     39  1.1  joerg     return x != expected;
     40  1.1  joerg }
     41  1.1  joerg 
     42  1.1  joerg char assumption_1[sizeof(tu_int) == 2*sizeof(du_int)] = {0};
     43  1.1  joerg char assumption_2[sizeof(tu_int)*CHAR_BIT == 128] = {0};
     44  1.1  joerg char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
     45  1.1  joerg 
     46  1.1  joerg #endif
     47  1.1  joerg 
     48  1.1  joerg int main()
     49  1.1  joerg {
     50  1.1  joerg #if __x86_64
     51  1.1  joerg     if (test__floatuntisf(0, 0.0F))
     52  1.1  joerg         return 1;
     53  1.1  joerg 
     54  1.1  joerg     if (test__floatuntisf(1, 1.0F))
     55  1.1  joerg         return 1;
     56  1.1  joerg     if (test__floatuntisf(2, 2.0F))
     57  1.1  joerg         return 1;
     58  1.1  joerg     if (test__floatuntisf(20, 20.0F))
     59  1.1  joerg         return 1;
     60  1.1  joerg 
     61  1.1  joerg     if (test__floatuntisf(0x7FFFFF8000000000LL, 0x1.FFFFFEp+62F))
     62  1.1  joerg         return 1;
     63  1.1  joerg     if (test__floatuntisf(0x7FFFFF0000000000LL, 0x1.FFFFFCp+62F))
     64  1.1  joerg         return 1;
     65  1.1  joerg 
     66  1.1  joerg     if (test__floatuntisf(make_ti(0x8000008000000000LL, 0), 0x1.000001p+127F))
     67  1.1  joerg         return 1;
     68  1.1  joerg     if (test__floatuntisf(make_ti(0x8000000000000800LL, 0), 0x1.0p+127F))
     69  1.1  joerg         return 1;
     70  1.1  joerg     if (test__floatuntisf(make_ti(0x8000010000000000LL, 0), 0x1.000002p+127F))
     71  1.1  joerg         return 1;
     72  1.1  joerg 
     73  1.1  joerg     if (test__floatuntisf(make_ti(0x8000000000000000LL, 0), 0x1.000000p+127F))
     74  1.1  joerg         return 1;
     75  1.1  joerg 
     76  1.1  joerg     if (test__floatuntisf(0x0007FB72E8000000LL, 0x1.FEDCBAp+50F))
     77  1.1  joerg         return 1;
     78  1.1  joerg 
     79  1.1  joerg     if (test__floatuntisf(0x0007FB72EA000000LL, 0x1.FEDCBA8p+50F))
     80  1.1  joerg         return 1;
     81  1.1  joerg     if (test__floatuntisf(0x0007FB72EB000000LL, 0x1.FEDCBACp+50F))
     82  1.1  joerg         return 1;
     83  1.1  joerg 
     84  1.1  joerg     if (test__floatuntisf(0x0007FB72EC000000LL, 0x1.FEDCBBp+50F))
     85  1.1  joerg         return 1;
     86  1.1  joerg 
     87  1.1  joerg     if (test__floatuntisf(0x0007FB72E6000000LL, 0x1.FEDCB98p+50F))
     88  1.1  joerg         return 1;
     89  1.1  joerg     if (test__floatuntisf(0x0007FB72E7000000LL, 0x1.FEDCB9Cp+50F))
     90  1.1  joerg         return 1;
     91  1.1  joerg     if (test__floatuntisf(0x0007FB72E4000000LL, 0x1.FEDCB9p+50F))
     92  1.1  joerg         return 1;
     93  1.1  joerg 
     94  1.1  joerg     if (test__floatuntisf(0xFFFFFFFFFFFFFFFELL, 0x1p+64F))
     95  1.1  joerg         return 1;
     96  1.1  joerg     if (test__floatuntisf(0xFFFFFFFFFFFFFFFFLL, 0x1p+64F))
     97  1.1  joerg         return 1;
     98  1.1  joerg 
     99  1.1  joerg     if (test__floatuntisf(0x0007FB72E8000000LL, 0x1.FEDCBAp+50F))
    100  1.1  joerg         return 1;
    101  1.1  joerg 
    102  1.1  joerg     if (test__floatuntisf(0x0007FB72EA000000LL, 0x1.FEDCBAp+50F))
    103  1.1  joerg         return 1;
    104  1.1  joerg     if (test__floatuntisf(0x0007FB72EB000000LL, 0x1.FEDCBAp+50F))
    105  1.1  joerg         return 1;
    106  1.1  joerg     if (test__floatuntisf(0x0007FB72EBFFFFFFLL, 0x1.FEDCBAp+50F))
    107  1.1  joerg         return 1;
    108  1.1  joerg     if (test__floatuntisf(0x0007FB72EC000000LL, 0x1.FEDCBCp+50F))
    109  1.1  joerg         return 1;
    110  1.1  joerg     if (test__floatuntisf(0x0007FB72E8000001LL, 0x1.FEDCBAp+50F))
    111  1.1  joerg         return 1;
    112  1.1  joerg 
    113  1.1  joerg     if (test__floatuntisf(0x0007FB72E6000000LL, 0x1.FEDCBAp+50F))
    114  1.1  joerg         return 1;
    115  1.1  joerg     if (test__floatuntisf(0x0007FB72E7000000LL, 0x1.FEDCBAp+50F))
    116  1.1  joerg         return 1;
    117  1.1  joerg     if (test__floatuntisf(0x0007FB72E7FFFFFFLL, 0x1.FEDCBAp+50F))
    118  1.1  joerg         return 1;
    119  1.1  joerg     if (test__floatuntisf(0x0007FB72E4000001LL, 0x1.FEDCBAp+50F))
    120  1.1  joerg         return 1;
    121  1.1  joerg     if (test__floatuntisf(0x0007FB72E4000000LL, 0x1.FEDCB8p+50F))
    122  1.1  joerg         return 1;
    123  1.1  joerg 
    124  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCB90000000000001LL),
    125  1.1  joerg                           0x1.FEDCBAp+76F))
    126  1.1  joerg         return 1;
    127  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBA0000000000000LL),
    128  1.1  joerg                           0x1.FEDCBAp+76F))
    129  1.1  joerg         return 1;
    130  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBAFFFFFFFFFFFFFLL),
    131  1.1  joerg                           0x1.FEDCBAp+76F))
    132  1.1  joerg         return 1;
    133  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBB0000000000000LL),
    134  1.1  joerg                           0x1.FEDCBCp+76F))
    135  1.1  joerg         return 1;
    136  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBB0000000000001LL),
    137  1.1  joerg                           0x1.FEDCBCp+76F))
    138  1.1  joerg         return 1;
    139  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBBFFFFFFFFFFFFFLL),
    140  1.1  joerg                           0x1.FEDCBCp+76F))
    141  1.1  joerg         return 1;
    142  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBC0000000000000LL),
    143  1.1  joerg                           0x1.FEDCBCp+76F))
    144  1.1  joerg         return 1;
    145  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBC0000000000001LL),
    146  1.1  joerg                           0x1.FEDCBCp+76F))
    147  1.1  joerg         return 1;
    148  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBD0000000000000LL),
    149  1.1  joerg                           0x1.FEDCBCp+76F))
    150  1.1  joerg         return 1;
    151  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBD0000000000001LL),
    152  1.1  joerg                           0x1.FEDCBEp+76F))
    153  1.1  joerg         return 1;
    154  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBDFFFFFFFFFFFFFLL),
    155  1.1  joerg                           0x1.FEDCBEp+76F))
    156  1.1  joerg         return 1;
    157  1.1  joerg     if (test__floatuntisf(make_ti(0x0000000000001FEDLL, 0xCBE0000000000000LL),
    158  1.1  joerg                           0x1.FEDCBEp+76F))
    159  1.1  joerg         return 1;
    160  1.1  joerg 
    161  1.1  joerg #else
    162  1.1  joerg     printf("skipped\n");
    163  1.1  joerg #endif
    164  1.1  joerg    return 0;
    165  1.1  joerg }
    166