summaryrefslogtreecommitdiff
path: root/lib/Support/APFloat.cpp
Commit message (Collapse)AuthorAge
* APFloat: x - NaN needs to flip the signbit of NaN when x is a number.Stephen Canon2014-06-08
| | | | | | Because we don't have a separate negate( ) function, 0 - NaN does double-duty as the IEEE-754 negate( ) operation, which (unlike most FP ops) *does* attach semantic meaning to the signbit of NaN. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210428 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper2014-04-15
| | | | | | instead of comparing to nullptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206252 91177308-0d34-0410-b5e6-96231b3b80d8
* [C++11] Make use of 'nullptr' in the Support library.Craig Topper2014-04-07
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205697 91177308-0d34-0410-b5e6-96231b3b80d8
* APFloat: Add a move ctor and operator=Benjamin Kramer2014-03-04
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202883 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix known typosAlp Toker2014-01-24
| | | | | | | Sweep the codebase for common typos. Includes some changes to visible function names that were misspelt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200018 91177308-0d34-0410-b5e6-96231b3b80d8
* Correct word hyphenationsAlp Toker2013-12-05
| | | | | | | This patch tries to avoid unrelated changes other than fixing a few hyphen-related ambiguities and contractions in nearby lines. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196471 91177308-0d34-0410-b5e6-96231b3b80d8
* Change default # of digits for APFloat::toStringEli Friedman2013-08-29
| | | | | | | | | | | | | | | | | This is a re-commit of r189442; I'll follow up with clang changes. The previous default was almost, but not quite enough digits to represent a floating-point value in a manner which preserves the representation when it's read back in. The larger default is much less confusing. I spent some time looking into printing exactly the right number of digits if a precision isn't specified, but it's kind of complicated, and I'm not really sure I understand what APFloat::toString is supposed to output for FormatPrecision != 0 (or maybe the current API specification is just silly, not sure which). I have a WIP patch if anyone is interested. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189624 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r189442 "Change default # of digits for APFloat::toString"Ted Kremenek2013-08-28
| | | | | | This is breaking numerous Clang tests on the buildbot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189447 91177308-0d34-0410-b5e6-96231b3b80d8
* Change default # of digits for APFloat::toStringEli Friedman2013-08-28
| | | | | | | | | | | | | | | The previous default was almost, but not quite enough digits to represent a floating-point value in a manner which preserves the representation when it's read back in. The larger default is much less confusing. I spent some time looking into printing exactly the right number of digits if a precision isn't specified, but it's kind of complicated, and I'm not really sure I understand what APFloat::toString is supposed to output for FormatPrecision != 0 (or maybe the current API specification is just silly, not sure which). I have a WIP patch if anyone is interested. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189442 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Make all arithmetic operations with NaN produce positive NaNs.Michael Gottesman2013-07-27
| | | | | | | | | | | | | IEEE-754R 1.4 Exclusions states that IEEE-754R does not specify the interpretation of the sign of NaNs. In order to remove an irrelevant variable that most floating point implementations do not use, standardize add, sub, mul, div, mod so that operating anything with NaN always yields a positive NaN. In a later commit I am going to update the APIs for creating NaNs so that one can not even create a negative NaN. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187314 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Move setting fcNormal in zeroSignificand() to calling code.Michael Gottesman2013-07-27
| | | | | | | | Zeroing the significand of a floating point number does not necessarily cause a floating point number to become finite non zero. For instance, if one has a NaN, zeroing the significand will cause it to become +/- infinity. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187313 91177308-0d34-0410-b5e6-96231b3b80d8
* Handle '.' correctly in hex float literal parsing.Eli Friedman2013-07-17
| | | | | | | | | | | There were a couple of different loops that were not handling '.' correctly in APFloat::convertFromHexadecimalString; these mistakes could lead to assertion failures and incorrect rounding for overlong hex float literals. Fixes PR16643. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186539 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] PR16573: Avoid losing mantissa bits in ppc_fp128 to double truncationUlrich Weigand2013-07-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When truncating to a format with fewer mantissa bits, APFloat::convert will perform a right shift of the mantissa by the difference of the precision of the two formats. Usually, this will result in just the mantissa bits needed for the target format. One special situation is if the input number is denormal. In this case, the right shift may discard significant bits. This is usually not a problem, since truncating a denormal usually results in zero (underflow) after normalization anyway, since the result format's exponent range is usually smaller than the target format's. However, there is one case where the latter property does not hold: when truncating from ppc_fp128 to double. In particular, truncating a ppc_fp128 whose first double of the pair is denormal should result in just that first double, not zero. The current code however performs an excessive right shift, resulting in lost result bits. This is then caught in the APFloat::normalize call performed by APFloat::convert and causes an assertion failure. This patch checks for the scenario of truncating a denormal, and attempts to (possibly partially) replace the initial mantissa right shift by decrementing the exponent, if doing so will still result in a valid *target format* exponent. Index: test/CodeGen/PowerPC/pr16573.ll =================================================================== --- test/CodeGen/PowerPC/pr16573.ll (revision 0) +++ test/CodeGen/PowerPC/pr16573.ll (revision 0) @@ -0,0 +1,11 @@ +; RUN: llc < %s | FileCheck %s + +target triple = "powerpc64-unknown-linux-gnu" + +define double @test() { + %1 = fptrunc ppc_fp128 0xM818F2887B9295809800000000032D000 to double + ret double %1 +} + +; CHECK: .quad -9111018957755033591 + Index: lib/Support/APFloat.cpp =================================================================== --- lib/Support/APFloat.cpp (revision 185817) +++ lib/Support/APFloat.cpp (working copy) @@ -1956,6 +1956,23 @@ X86SpecialNan = true; } + // If this is a truncation of a denormal number, and the target semantics + // has larger exponent range than the source semantics (this can happen + // when truncating from PowerPC double-double to double format), the + // right shift could lose result mantissa bits. Adjust exponent instead + // of performing excessive shift. + if (shift < 0 && isFiniteNonZero()) { + int exponentChange = significandMSB() + 1 - fromSemantics.precision; + if (exponent + exponentChange < toSemantics.minExponent) + exponentChange = toSemantics.minExponent - exponent; + if (exponentChange < shift) + exponentChange = shift; + if (exponentChange < 0) { + shift -= exponentChange; + exponent += exponentChange; + } + } + // If this is a truncation, perform the shift before we narrow the storage. if (shift < 0 && (isFiniteNonZero() || category==fcNaN)) lostFraction = shiftRight(significandParts(), oldPartCount, -shift); git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186409 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Swap an early out check so we do not dereference str.end().Michael Gottesman2013-07-02
| | | | | | | Originally if D.firstSigDigit == str.end(), we will have already dereferenced D.firstSigDigit in the first predicate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185437 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Ensure that we can properly parse strings that do not have null ↵Michael Gottesman2013-07-01
| | | | | | | | terminators. rdar://14323230 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185397 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "Revert "[APFloat] Removed APFloat constructor which initialized to ↵Michael Gottesman2013-06-27
| | | | | | | | | | | | | | | | | | | | either zero/NaN but allowed you to arbitrarily set the category of the float."" This reverts commit r185099. Looks like both the ppc-64 and mips bots are still failing after I reverted this change. Since: 1. The mips bot always performs a clean build, 2. The ppc64-bot failed again after a clean build (I asked the ppc-64 maintainers to clean the bot which they did... Thanks Will!), I think it is safe to assume that this change was not the cause of the failures that said builders were seeing. Thus I am recomitting. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185111 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert "[APFloat] Removed APFloat constructor which initialized to either ↵Michael Gottesman2013-06-27
| | | | | | | | | | | | zero/NaN but allowed you to arbitrarily set the category of the float." This reverts commit r185095. This is causing a FileCheck failure on the 3dnow intrinsics on at least the mips/ppc bots but not on the x86 bots. Reverting while I figure out what is going on. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185099 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Removed APFloat constructor which initialized to either zero/NaN ↵Michael Gottesman2013-06-27
| | | | | | | | | | | | | | but allowed you to arbitrarily set the category of the float. The category which an APFloat belongs to should be dependent on the actual value that the APFloat has, not be arbitrarily passed in by the user. This will prevent inconsistency bugs where the category and the actual value in APFloat differ. I also fixed up all of the references to this constructor (which were only in LLVM). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185095 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Convert all references to fcNormal to references to isFiniteNonZero().Michael Gottesman2013-06-26
| | | | | | | | | | | | Currently inside APFloat fcNormal still implies the old definition of Normal (i.e. isFiniteNonZero) instead of the proper IEEE-754R definition that the external method isNormal() uses. This patch prepares for the internal switch inside APFloat by converting all references that check if a category is fcNormal directly with an indirect call via isFiniteNonZero(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185036 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Added support for parsing float strings which contain ↵Michael Gottesman2013-06-24
| | | | | | {inf,-inf,NaN,-NaN}. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184713 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Added make{Zero,Inf} methods and implemented get{Zero,Inf} on top ↵Michael Gottesman2013-06-24
| | | | | | of them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184712 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Removed a assert from significandParts() which says that one can ↵Michael Gottesman2013-06-24
| | | | | | | | | | | | | | | | | only access the significand of FiniteNonZero/NaN floats. The method significandParts() is a helper method meant to ease access to APFloat's significand by allowing the user to not need to be aware of whether or not the APFloat is using memory allocated in the instance itself or in an external array. This assert says that one can only access the significand of FiniteNonZero/NaN floats. This makes it cumbersome and more importantly dangerous when one wishes to zero out the significand of a zero/infinity value since one will have to deal with the aforementioned quandary related to how the memory in APFloat is allocated. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184711 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Rename macro convolve => PackCategoriesIntoKey so that it is clear ↵Michael Gottesman2013-06-24
| | | | | | | | | | | | what APFloat is actually using said macro for. In the context of APFloat, seeing a macro called convolve suggests that APFloat is using said value in some sort of convolution somewhere in the source code. This is misleading. I also added a documentation comment to the macro. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184710 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Rename llvm::exponent_t => llvm::APFloat::ExponentType.Michael Gottesman2013-06-24
| | | | | | | | | exponent_t is only used internally in APFloat and no exponent_t values are exposed via the APFloat API. In light of such conditions it does not make any sense to gum up the llvm namespace with said type. Plus it makes it clearer that exponent_t is associated with APFloat. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184686 91177308-0d34-0410-b5e6-96231b3b80d8
* [APFloat] Converted all references to APFloat::isNormal => ↵Michael Gottesman2013-06-19
| | | | | | | | APFloat::isFiniteNonZero. Turns out all the references were in llvm and not in clang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184356 91177308-0d34-0410-b5e6-96231b3b80d8
* Fixed comment typo that causes the given comment to actually make sense.Michael Gottesman2013-06-19
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184286 91177308-0d34-0410-b5e6-96231b3b80d8
* Introduce needsCleanup() for APFloat and APInt.Manuel Klimek2013-06-03
| | | | | | | | | This is needed in clang so one can check if the object needs the destructor called after its memory was freed. This is useful when creating many APInt/APFloat objects with placement new, where the overhead of tracking the pointers for cleanup is significant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183100 91177308-0d34-0410-b5e6-96231b3b80d8
* APFloat: Use isDenormal instead of hand-rolled code to check for denormals.Benjamin Kramer2013-06-01
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183072 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement IEEE-754R 2008 nextUp/nextDown functions in the guise of the ↵Michael Gottesman2013-05-30
| | | | | | | | function APFloat::next(bool nextDown). rdar://13852078 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182945 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a bug that APFloat::fusedMultiplyAdd() mistakenly evaluate "14.5f * ↵Shuxin Yang2013-05-13
| | | | | | -14.5f + 225.0f" to 225.0f. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181715 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix AsmPrinter crashes with assertion. Bug 15318 in BugzillaHao Liu2013-03-20
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177472 91177308-0d34-0410-b5e6-96231b3b80d8
* APFloat: Make sure that we get a well-formed x87 NaN when converting from a ↵Benjamin Kramer2013-01-25
| | | | | | | | smaller type. Fixes PR15054. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173459 91177308-0d34-0410-b5e6-96231b3b80d8
* Make APFloat constructor require explicit semantics.Tim Northover2013-01-22
| | | | | | | | | Previously we tried to infer it from the bit width size, with an added IsIEEE argument for the PPC/IEEE 128-bit case, which had a default value. This default value allowed bugs to creep in, where it was inappropriate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173138 91177308-0d34-0410-b5e6-96231b3b80d8
* Add llvm::hexDigitValue to convert single characters to hex.Jordan Rose2013-01-18
| | | | | | This is duplicated in a couple places in the codebase. Adopt this in APFloat. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172851 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove redundant 'llvm::' qualificationsDmitri Gribenko2013-01-13
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172358 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement APFloat::isDenormal()Shuxin Yang2013-01-07
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171764 91177308-0d34-0410-b5e6-96231b3b80d8
* Use the new script to sort the includes of every file under lib.Chandler Carruth2012-12-03
| | | | | | | | | | | | | | | | | Sooooo many of these had incorrect or strange main module includes. I have manually inspected all of these, and fixed the main module include to be the nearest plausible thing I could find. If you own or care about any of these source files, I encourage you to take some time and check that these edits were sensible. I can't have broken anything (I strictly added headers, and reordered them, never removed), but they may not be the headers you'd really like to identify as containing the API being implemented. Many forward declarations and missing includes were added to a header files to allow them to parse cleanly when included first. The main module rule does in fact have its merits. =] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169131 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a bug in APFloat.cpp: declare APFloat after fltSemantics itAlexey Samsonov2012-11-30
| | | | | | | | | | | | uses. APFloat::convert() takes the pointer to the fltSemantics variable, which is later accessed it in ~APFloat() desctructor. That is, semantics must still be alive at the moment we delete APFloat. Found by experimental AddressSanitizer use-after-scope checker. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169047 91177308-0d34-0410-b5e6-96231b3b80d8
* Drop the limitation to IEEE floating point types from the fdiv of pow2 -> ↵Benjamin Kramer2012-11-08
| | | | | | | | fmul transform. This is safe for x87 long doubles and ppc double doubles too. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167582 91177308-0d34-0410-b5e6-96231b3b80d8
* APFloat cleanup: Remove now unused "arithmeticOK" logic.Ulrich Weigand2012-10-29
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166954 91177308-0d34-0410-b5e6-96231b3b80d8
* APFloat cleanup: Remove now unused fields "sign2" and "exponent2".Ulrich Weigand2012-10-29
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166952 91177308-0d34-0410-b5e6-96231b3b80d8
* Implement arithmetic on APFloat with PPCDoubleDouble semantics byUlrich Weigand2012-10-29
| | | | | | | | | | | | | treating it as if it were an IEEE floating-point type with 106-bit mantissa. This makes compile-time arithmetic on "long double" for PowerPC in clang (in particular parsing of floating point constants) work, and fixes all "long double" related failures in the test suite. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@166951 91177308-0d34-0410-b5e6-96231b3b80d8
* APFloat::roundToIntegral: Special values don't keep the exponent value up to ↵Benjamin Kramer2012-09-26
| | | | | | | | date, don't rely on it. Add a couple of unit tests for special floats. Fixes 13929, found by MemorySanitizer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164698 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix undefined behavior (signed integer overflow) when Clang parses a ↵Richard Smith2012-08-24
| | | | | | hexfloat with an enormous exponent. Caught by an existing unit test + -ftrapv. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162505 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix another roundToIntegral bug where very large values could become ↵Owen Anderson2012-08-15
| | | | | | infinity. Problem and solution identified by Steve Canon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161969 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix typo in comment.Owen Anderson2012-08-15
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161956 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a problem with APFloat::roundToIntegral where it would return incorrect ↵Owen Anderson2012-08-15
| | | | | | results for negative inputs to trunc. Add unit tests to verify this behavior. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161929 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix the construction of the magic constant for roundToIntegral to be 64-bit ↵Owen Anderson2012-08-14
| | | | | | safe. Fixes c-torture/execute/990826-0.c git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161885 91177308-0d34-0410-b5e6-96231b3b80d8
* Add a roundToIntegral method to APFloat, which can be parameterized over ↵Owen Anderson2012-08-13
| | | | | | various rounding modes. Use this to implement SelectionDAG constant folding of FFLOOR, FCEIL, and FTRUNC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161807 91177308-0d34-0410-b5e6-96231b3b80d8
* Don't add null characters to the end of the APFloat string buffer.David Blaikie2012-07-25
| | | | | | Report/patch inspiration by Olaf Krzikalla. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160744 91177308-0d34-0410-b5e6-96231b3b80d8