[ASan/Win tests] Bring back -GS- as SEH tests fail otherwise
[blocksruntime.git] / lib / builtins / fixdfsi.c
blob88b2ff5e74a07bae5bcbdb881315b8d81948c239
1 //===-- lib/fixdfsi.c - Double-precision -> integer 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 // This file implements double-precision to integer conversion for the
11 // compiler-rt library. No range checking is performed; the behavior of this
12 // conversion is undefined for out of range values in the C standard.
14 //===----------------------------------------------------------------------===//
16 #define DOUBLE_PRECISION
17 #include "fp_lib.h"
19 #include "int_lib.h"
21 ARM_EABI_FNALIAS(d2iz, fixdfsi)
23 COMPILER_RT_ABI int
24 __fixdfsi(fp_t a) {
26 // Break a into sign, exponent, significand
27 const rep_t aRep = toRep(a);
28 const rep_t aAbs = aRep & absMask;
29 const int sign = aRep & signBit ? -1 : 1;
30 const int exponent = (aAbs >> significandBits) - exponentBias;
31 const rep_t significand = (aAbs & significandMask) | implicitBit;
33 // If 0 < exponent < significandBits, right shift to get the result.
34 if ((unsigned int)exponent < significandBits) {
35 return sign * (significand >> (significandBits - exponent));
38 // If exponent is negative, the result is zero.
39 else if (exponent < 0) {
40 return 0;
43 // If significandBits < exponent, left shift to get the result. This shift
44 // may end up being larger than the type width, which incurs undefined
45 // behavior, but the conversion itself is undefined in that case, so
46 // whatever the compiler decides to do is fine.
47 else {
48 return sign * (significand << (exponent - significandBits));