83 lines · c
1//===-- int_to_fp.h - integer to floating point conversion ----------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// Set source and destination defines in order to use a correctly10// parameterised floatXiYf implementation.11//12//===----------------------------------------------------------------------===//13 14#ifndef INT_TO_FP_H15#define INT_TO_FP_H16 17#include "int_lib.h"18 19#if defined SRC_I6420typedef int64_t src_t;21typedef uint64_t usrc_t;22static __inline int clzSrcT(usrc_t x) { return __builtin_clzll(x); }23 24#elif defined SRC_U6425typedef uint64_t src_t;26typedef uint64_t usrc_t;27static __inline int clzSrcT(usrc_t x) { return __builtin_clzll(x); }28 29#elif defined SRC_I12830typedef __int128_t src_t;31typedef __uint128_t usrc_t;32static __inline int clzSrcT(usrc_t x) { return __clzti2(x); }33 34#elif defined SRC_U12835typedef __uint128_t src_t;36typedef __uint128_t usrc_t;37static __inline int clzSrcT(usrc_t x) { return __clzti2(x); }38 39#else40#error Source should be a handled integer type.41#endif42 43#if defined DST_SINGLE44typedef float dst_t;45typedef uint32_t dst_rep_t;46#define DST_REP_C UINT32_C47 48enum {49 dstSigBits = 23,50};51 52#elif defined DST_DOUBLE53typedef double dst_t;54typedef uint64_t dst_rep_t;55#define DST_REP_C UINT64_C56 57enum {58 dstSigBits = 52,59};60 61#elif defined DST_QUAD62typedef tf_float dst_t;63typedef __uint128_t dst_rep_t;64#define DST_REP_C (__uint128_t)65 66enum {67 dstSigBits = 112,68};69 70#else71#error Destination should be a handled floating point type72#endif73 74static __inline dst_t dstFromRep(dst_rep_t x) {75 const union {76 dst_t f;77 dst_rep_t i;78 } rep = {.i = x};79 return rep.f;80}81 82#endif // INT_TO_FP_H83