diff options
author | Joerg Sonnenberger <joerg@bec.de> | 2014-05-29 00:54:26 +0000 |
---|---|---|
committer | Joerg Sonnenberger <joerg@bec.de> | 2014-05-29 00:54:26 +0000 |
commit | 9883e32ad6650a978c7602ba32ed39cac03d3270 (patch) | |
tree | 2f1022ffe334c759cc25663f6b3e1bf85d3b9d98 /lib/builtins/fp_extend.h | |
parent | b8e9b024681dee9e4391166815e5887c99d2c85e (diff) | |
download | compiler-rt-9883e32ad6650a978c7602ba32ed39cac03d3270.tar.gz |
Refactor extendsfdf2.
Patch by: GuanHong Liu
Differential Revision: http://reviews.llvm.org/D3887
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@209781 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/builtins/fp_extend.h')
-rw-r--r-- | lib/builtins/fp_extend.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lib/builtins/fp_extend.h b/lib/builtins/fp_extend.h new file mode 100644 index 000000000..fff676eec --- /dev/null +++ b/lib/builtins/fp_extend.h @@ -0,0 +1,76 @@ +//===-lib/fp_extend.h - low precision -> high precision conversion -*- C -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Set source and destination setting +// +//===----------------------------------------------------------------------===// + +#ifndef FP_EXTEND_HEADER +#define FP_EXTEND_HEADER + +#include "int_lib.h" + +#if defined SRC_SINGLE +typedef float src_t; +typedef uint32_t src_rep_t; +#define SRC_REP_C UINT32_C +static const int srcSigBits = 23; +#define src_rep_t_clz __builtin_clz + +#elif defined SRC_DOUBLE +typedef double src_t; +typedef uint64_t src_rep_t; +#define SRC_REP_C UINT64_C +static const int srcSigBits = 52; +static inline int src_rep_t_clz(src_rep_t a) { +#if defined __LP64__ + return __builtin_clzl(a); +#else + if (a & REP_C(0xffffffff00000000)) + return __builtin_clz(a >> 32); + else + return 32 + __builtin_clz(a & REP_C(0xffffffff)); +#endif +} + +#else +#error Source should be single precision or double precision! +#endif //end source precision + +#if defined DST_DOUBLE +typedef double dst_t; +typedef uint64_t dst_rep_t; +#define DST_REP_C UINT64_C +static const int dstSigBits = 52; + +#elif defined DST_QUAD +typedef long double dst_t; +typedef __uint128_t dst_rep_t; +#define DST_REP_C (__uint128_t) +static const int dstSigBits = 112; + +#else +#error Destination should be double precision or quad precision! +#endif //end destination precision + +// End of specialization parameters. Two helper routines for conversion to and +// from the representation of floating-point data as integer values follow. + +static inline src_rep_t srcToRep(src_t x) { + const union { src_t f; src_rep_t i; } rep = {.f = x}; + return rep.i; +} + +static inline dst_t dstFromRep(dst_rep_t x) { + const union { dst_t f; dst_rep_t i; } rep = {.i = x}; + return rep.f; +} +// End helper routines. Conversion implementation follows. + +#endif //FP_EXTEND_HEADER |