2015-03-12 05:13:56 +08:00
|
|
|
//===-- 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 float to unsigned integer conversion for the
|
|
|
|
// compiler-rt library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "fp_lib.h"
|
|
|
|
|
2015-10-11 05:21:28 +08:00
|
|
|
static __inline fixuint_t __fixuint(fp_t a) {
|
2015-03-12 05:13:56 +08:00
|
|
|
// 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 either the value or the exponent is negative, the result is zero.
|
|
|
|
if (sign == -1 || exponent < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// If the value is too large for the integer type, saturate.
|
[compiler-rt][aarch64] New tests for 128-bit floating-point builtins, fixes of tests and __fixuint
Summary:
The following tests for 128-bit floating-point type behaved in a strange way, thought it were bugs, but seem to be mistakes in tests:
* `fixtfsi` test checked for `0x80000001` as a value returned for number less than can be represented, while `LONG_MIN` should be returned on saturation;
* `fixunstfdi` wasn't enabled for AArch64, only for PPC, but there is nothing PPC specific in that test;
* `multf3` tried to underflow multiplication by producing result with 16383 exponent, while there are still 112 bits of fraction plus implicit bit, so resultant exponent should be 16497.
Tests for some other builtins didn't exist:
* `fixtfdi`
* `fixtfti`
* `fixunstfti`
They were made by copying similar files and adjusting for wider types and adding/removing some reasonable/extra checks.
Also `__fixuint` seems to have off by one error, updated tests to catch this case.
Reviewers: rengolin, zatrazz, howard.hinnant, t.p.northover, jmolloy, enefaim
Subscribers: aemerson, llvm-commits, rengolin
Differential Revision: http://reviews.llvm.org/D14187
llvm-svn: 252180
2015-11-06 02:36:42 +08:00
|
|
|
if ((unsigned)exponent >= sizeof(fixuint_t) * CHAR_BIT)
|
2015-03-12 05:13:56 +08:00
|
|
|
return ~(fixuint_t)0;
|
|
|
|
|
|
|
|
// If 0 <= exponent < significandBits, right shift to get the result.
|
|
|
|
// Otherwise, shift left.
|
|
|
|
if (exponent < significandBits)
|
|
|
|
return significand >> (significandBits - exponent);
|
|
|
|
else
|
|
|
|
return (fixuint_t)significand << (exponent - significandBits);
|
|
|
|
}
|