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