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