Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fixtfti.c
Go to the documentation of this file.
1/* ===-- fixtfti.c - Implement __fixtfti -----------------------------------===
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
11#include "fp128.h"
12
14 const __int128 fixint_max = (__int128)((~(unsigned __int128)0) / 2);
15 const __int128 fixint_min = -fixint_max - 1;
16 // Break a into sign, exponent, significand
17 const __int128 aRep = toRep(a);
18 const __int128 aAbs = aRep & absMask;
19 const __int128 sign = aRep & signBit ? -1 : 1;
20 const int exponent = (aAbs >> significandBits) - exponentBias;
21 const __int128 significand = (aAbs & significandMask) | implicitBit;
22
23 // If exponent is negative, the result is zero.
24 if (exponent < 0)
25 return 0;
26
27 // If the value is too large for the integer type, saturate.
28 if ((unsigned)exponent >= sizeof(__int128) * CHAR_BIT)
29 return sign == 1 ? fixint_max : fixint_min;
30
31 // If 0 <= exponent < significandBits, right shift to get the result.
32 // Otherwise, shift left.
33 if (exponent < significandBits)
34 return sign * (significand >> (significandBits - exponent));
35 else
36 return sign * ((__int128)significand << (exponent - significandBits));
37}
__int128 ___fixtfti(float128_t a)
Definition fixtfti.c:13
#define implicitBit
Definition fp128.h:15
#define signBit
Definition fp128.h:17
#define exponentBias
Definition fp128.h:13
#define significandBits
Definition fp128.h:9
#define significandMask
Definition fp128.h:16
#define absMask
Definition fp128.h:18
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181