Home | History | Annotate | Download | only in builtins
      1 //=== lib/fp_trunc.h - high precision -> low precision conversion *- C -*-===//
      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 // Set source and destination precision setting
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef FP_TRUNC_HEADER
     15 #define FP_TRUNC_HEADER
     16 
     17 #include "int_lib.h"
     18 
     19 #if defined SRC_SINGLE
     20 typedef float src_t;
     21 typedef uint32_t src_rep_t;
     22 #define SRC_REP_C UINT32_C
     23 static const int srcSigBits = 23;
     24 
     25 #elif defined SRC_DOUBLE
     26 typedef double src_t;
     27 typedef uint64_t src_rep_t;
     28 #define SRC_REP_C UINT64_C
     29 static const int srcSigBits = 52;
     30 
     31 #elif defined SRC_QUAD
     32 typedef long double src_t;
     33 typedef __uint128_t src_rep_t;
     34 #define SRC_REP_C (__uint128_t)
     35 static const int srcSigBits = 112;
     36 
     37 #else
     38 #error Source should be double precision or quad precision!
     39 #endif //end source precision
     40 
     41 #if defined DST_DOUBLE
     42 typedef double dst_t;
     43 typedef uint64_t dst_rep_t;
     44 #define DST_REP_C UINT64_C
     45 static const int dstSigBits = 52;
     46 
     47 #elif defined DST_SINGLE
     48 typedef float dst_t;
     49 typedef uint32_t dst_rep_t;
     50 #define DST_REP_C UINT32_C
     51 static const int dstSigBits = 23;
     52 
     53 #elif defined DST_HALF
     54 typedef uint16_t dst_t;
     55 typedef uint16_t dst_rep_t;
     56 #define DST_REP_C UINT16_C
     57 static const int dstSigBits = 10;
     58 
     59 #else
     60 #error Destination should be single precision or double precision!
     61 #endif //end destination precision
     62 
     63 // End of specialization parameters.  Two helper routines for conversion to and
     64 // from the representation of floating-point data as integer values follow.
     65 
     66 static __inline src_rep_t srcToRep(src_t x) {
     67     const union { src_t f; src_rep_t i; } rep = {.f = x};
     68     return rep.i;
     69 }
     70 
     71 static __inline dst_t dstFromRep(dst_rep_t x) {
     72     const union { dst_t f; dst_rep_t i; } rep = {.i = x};
     73     return rep.f;
     74 }
     75 
     76 #endif // FP_TRUNC_HEADER
     77