72c50e51a5
It seems there have only been a small amount to the compiler-rt source code in the mean time. I'd rather have the code in sync as much as possible by the time we release 9.0. Changes: - The libcompiler_rt library is now dual licensed under both the University of Illinois "BSD-Like" license and the MIT license. - Our local modifications for using .hidden instead of .private_extern have been upstreamed, meaning our changes to lib/assembly.h can now be reverted. - A possible endless recursion in __modsi3() has been fixed. - Support for ARM EABI has been added, but it has no effect on FreeBSD (yet). - The functions __udivmodsi4 and __divmodsi4 have been added. Requested by: many, including bf@ and Pedro Giffuni
51 lines
1.8 KiB
C
51 lines
1.8 KiB
C
//===-- lib/fixdfsi.c - Double-precision -> integer 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.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements double-precision to integer conversion for the
|
|
// compiler-rt library. No range checking is performed; the behavior of this
|
|
// conversion is undefined for out of range values in the C standard.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
#include "abi.h"
|
|
|
|
#define DOUBLE_PRECISION
|
|
#include "fp_lib.h"
|
|
|
|
#include "int_lib.h"
|
|
|
|
ARM_EABI_FNALIAS(d2iz, fixdfsi);
|
|
|
|
int __fixdfsi(fp_t a) {
|
|
|
|
// Break a into sign, exponent, significand
|
|
const rep_t aRep = toRep(a);
|
|
const rep_t aAbs = aRep & absMask;
|
|
const int sign = aRep & signBit ? -1 : 1;
|
|
const int exponent = (aAbs >> significandBits) - exponentBias;
|
|
const rep_t significand = (aAbs & significandMask) | implicitBit;
|
|
|
|
// If 0 < exponent < significandBits, right shift to get the result.
|
|
if ((unsigned int)exponent < significandBits) {
|
|
return sign * (significand >> (significandBits - exponent));
|
|
}
|
|
|
|
// If exponent is negative, the result is zero.
|
|
else if (exponent < 0) {
|
|
return 0;
|
|
}
|
|
|
|
// If significandBits < exponent, left shift to get the result. This shift
|
|
// may end up being larger than the type width, which incurs undefined
|
|
// behavior, but the conversion itself is undefined in that case, so
|
|
// whatever the compiler decides to do is fine.
|
|
else {
|
|
return sign * (significand << (exponent - significandBits));
|
|
}
|
|
}
|