summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/APFloatTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [APFloat] Fix checked error assert failuresEhud Katz2020-01-091-4/+7
| | | | | | | | | | | `APFLoat::convertFromString` returns `Expected` result, which must be "checked" if the LLVM_ENABLE_ABI_BREAKING_CHECKS preprocessor flag is set. To mark an `Expected` result as "checked" we must consume the `Error` within. In many cases, we are only interested in knowing if an error occured, without the need to examine the error info. This is achieved, easily, with the `errorToBool()` API.
* [APFloat] Fix fusedMultiplyAdd when `this` equals to `Addend`Ehud Katz2020-01-071-0/+8
| | | | | | | | | | | | | Up until now, the arguments to `fusedMultiplyAdd` are passed by reference. We must save the `Addend` value on the beginning of the function, before we modify `this`, as they may be the same reference. To fix this, we now pass the `addend` parameter of `multiplySignificand` by value (instead of by-ref), and have a default value of zero. Fix PR44051. Differential Revision: https://reviews.llvm.org/D70422
* [APFloat] Fix compilation warningsEhud Katz2020-01-061-20/+6
|
* [APFloat] Add recoverable string parsing errors to APFloatEhud Katz2020-01-061-122/+130
| | | | | | Implementing the APFloat part in PR4745. Differential Revision: https://reviews.llvm.org/D69770
* [APFloat] Prevent construction of APFloat with Semantics and FP valueEhud Katz2019-12-041-13/+13
| | | | | | | | | | | | | | | | | Constructor invocations such as `APFloat(APFloat::IEEEdouble(), 0.0)` may seem like they accept a FP (floating point) value, but the overload they reach is actually the `integerPart` one, not a `float` or `double` overload (which only exists when `fltSemantics` isn't passed). This may lead to possible loss of data, by the conversion from `float` or `double` to `integerPart`. To prevent future mistakes, a new constructor overload, which accepts any FP value and marked with `delete`, to prevent its usage. Fixes PR34095. Differential Revision: https://reviews.llvm.org/D70425
* [APFloat] Enlarge ExponentType to 32bit integerEhud Katz2019-11-221-15/+117
| | | | | | | | | | | | Enlarge the size of ExponentType from 16bit integer to 32bit. This is required to prevent exponent overflow/underflow. Note that IEEEFloat size and alignment don't change in 64bit or 32bit compilation targets (and in turn, neither does APFloat). Fixes PR34851. Differential Revision: https://reviews.llvm.org/D69771
* [APFloat] Fix subtraction of subnormal numbersEhud Katz2019-11-221-0/+9
| | | | | | | | Fix incorrect determination of the bigger number out of the two subtracted, while subnormal numbers are involved. Fixes PR44010. Differential Revision: https://reviews.llvm.org/D69772
* [MC] Fix floating-point literal lexing.Eli Friedman2019-03-281-30/+27
| | | | | | | | | | | | | | | | | | | | | This patch has three related fixes to improve float literal lexing: 1. Make AsmLexer::LexDigit handle floats without a decimal point more consistently. 2. Make AsmLexer::LexFloatLiteral print an error for floats which are apparently missing an "e". 3. Make APFloat::convertFromString use binutils-compatible exponent parsing. Together, this fixes some cases where a float would be incorrectly rejected, fixes some cases where the compiler would crash, and improves diagnostics in some cases. Patch by Brandon Jones. Differential Revision: https://reviews.llvm.org/D57321 llvm-svn: 357214
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* APFloat: allow 64-bit of payloadJF Bastien2018-12-101-22/+38
| | | | | | | | | | | | | | | | | | | | Summary: The APFloat and Constant APIs taking an APInt allow arbitrary payloads, and that's great. There's a convenience API which takes an unsigned, and that's silly because it then directly creates a 64-bit APInt. Just change it to 64-bits directly. At the same time, add ConstantFP NaN getters which match the APFloat ones (with getQNaN / getSNaN and APInt parameters). Improve the APFloat testing to set more payload bits. Reviewers: scanon, rjmccall Subscribers: jkorous, dexonsmith, kristina, llvm-commits Differential Revision: https://reviews.llvm.org/D55460 llvm-svn: 348791
* [Intrinsic] Add llvm.minimum and llvm.maximum instrinsic functionsThomas Lively2018-10-131-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | Summary: These new intrinsics have the semantics of the `minimum` and `maximum` operations specified by the latest draft of IEEE 754-2018. Unlike llvm.minnum and llvm.maxnum, these new intrinsics propagate NaNs and always treat -0.0 as less than 0.0. `minimum` and `maximum` lower directly to the existing `fminnan` and `fmaxnan` ISel DAG nodes. It is safe to reuse these DAG nodes because before this patch were only emitted in situations where there were known to be no NaN arguments or where NaN propagation was correct and there were known to be no zero arguments. I know of only four backends that lower fminnan and fmaxnan: WebAssembly, ARM, AArch64, and SystemZ, and each of these lowers fminnan and fmaxnan to instructions that are compatible with the IEEE 754-2018 semantics. Reviewers: aheejin, dschuff, sunfish, javed.absar Subscribers: kristof.beyls, dexonsmith, kristina, llvm-commits Differential Revision: https://reviews.llvm.org/D52764 llvm-svn: 344437
* APFloat/x87: Fix string conversion for "unnormal" values (pr35860)Pavel Labath2018-05-091-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: Unnormal values are a feature of some very old x87 processors. We handle them correctly for the most part -- the only exception was an unnormal value whose significand happened to be zero. In this case the APFloat was still initialized as normal number (category = fcNormal), but a subsequent toString operation would assert because the math would produce nonsensical values for the zero significand. During review, it was decided that the correct way to fix this is to treat all unnormal values as NaNs (as that is what any >=386 processor will do). The issue was discovered because LLDB would crash when trying to print some "long double" values. Reviewers: skatkov, scanon, gottesmm Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41868 llvm-svn: 331884
* Fix APFloat from string conversion for InfSerguei Katkov2017-12-191-0/+17
| | | | | | | | | | | | | | | | | | The method IEEEFloat::convertFromStringSpecials() does not recognize the "+Inf" and "-Inf" strings but these strings are printed for the double Infinities by the IEEEFloat::toString(). This patch adds the "+Inf" and "-Inf" strings to the list of recognized patterns in IEEEFloat::convertFromStringSpecials(). Re-landing after fix. Reviewers: sberg, bogner, majnemer, timshen, rnk, skatkov, gottesmm, bkramer, scanon, anna Reviewed By: anna Subscribers: mkazantsev, FlameTop, llvm-commits, reames, apilipenko Differential Revision: https://reviews.llvm.org/D38030 llvm-svn: 321054
* Fix APFloat mod signSerguei Katkov2017-11-011-0/+14
| | | | | | | | | | | | fmod specification requires the sign of the remainder is the same as numerator in case remainder is zero. Reviewers: gottesmm, scanon, arsenm, davide, craig.topper Reviewed By: scanon Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D39225 llvm-svn: 317081
* Revert rL316156 due to failure on APFloatTest.fromToStringSpecialsMax Kazantsev2017-10-191-16/+0
| | | | llvm-svn: 316158
* Fix APFloat from string conversion for InfSerguei Katkov2017-10-191-0/+16
| | | | | | | | | | | | | | | | The method IEEEFloat::convertFromStringSpecials() does not recognize the "+Inf" and "-Inf" strings but these strings are printed for the double Infinities by the IEEEFloat::toString(). This patch adds the "+Inf" and "-Inf" strings to the list of recognized patterns in IEEEFloat::convertFromStringSpecials(). Reviewers: sberg, bogner, majnemer, timshen, rnk, skatkov, gottesmm, bkramer, scanon Reviewed By: skatkov Subscribers: apilipenko, reames, llvm-commits Differential Revision: https://reviews.llvm.org/D38030 llvm-svn: 316156
* Untabify.NAKAMURA Takumi2017-10-181-2/+2
| | | | llvm-svn: 316079
* Untabify.NAKAMURA Takumi2017-08-281-1/+1
| | | | llvm-svn: 311875
* [APFloat] Fix IsInteger() for DoubleAPFloat.Davide Italiano2017-08-211-0/+18
| | | | | | | | Previously, we would just assert instead. Differential Revision: https://reviews.llvm.org/D36961 llvm-svn: 311351
* [ADT] Fix another "oops" spotted by eddyb and reported in IRC.Chandler Carruth2017-07-101-1/+1
| | | | | | This test pretty clearly should be calling 'maxnum' here. =] llvm-svn: 307519
* [ADT] Fix a test case to use a correct escape for a null byte followedChandler Carruth2017-07-091-7/+7
| | | | | | | | | | by a valid octal digit. The length argument shows that this was in fact the intent. This was pointed out in IRC, thanks to eddyb! llvm-svn: 307496
* [AsmWriter/APFloat] FP constant printing: Avoid usage of locale dependent ↵Serguei Katkov2017-04-211-2/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | snprinf This should fix the bug https://bugs.llvm.org/show_bug.cgi?id=12906 To print the FP constant AsmWriter does the following: 1) convert FP value to String (actually using snprintf function which is locale dependent). 2) Convert String back to FP Value 3) Compare original and got FP values. If they are not equal just dump as hex. The problem happens on the 2nd step when APFloat does not expect group delimiter or fraction delimiter other than period symbol and so on, which can be produced on the first step if LLVM library is used in an environment with corresponding locale set. To fix this issue the locale independent APFloat:toString function is used. However it prints FP values slightly differently than snprintf does. Specifically it suppress trailing zeros in significant, use capital E and so on. It results in 117 test failures during make check. To avoid this I've also updated APFloat.toString a bit to pass make check at least. Reviewers: sberg, bogner, majnemer, sanjoy, timshen, rnk Reviewed By: timshen, rnk Subscribers: rnk, llvm-commits Differential Revision: https://reviews.llvm.org/D32276 llvm-svn: 300943
* Fix 80-column violation in previous commit.Stephen Canon2017-03-311-1/+2
| | | | llvm-svn: 299257
* Fix APFloat mod (committing for simonbyrne)Stephen Canon2017-03-311-2/+65
| | | | | | | | The previous version was prone to intermediate rounding or overflow. Differential Revision: https://reviews.llvm.org/D29346 llvm-svn: 299256
* DAGCombiner: Allow negating ConstantFP after legalizeMatt Arsenault2017-01-251-0/+22
| | | | llvm-svn: 293019
* [APFloat] Add PPCDoubleDouble multiplicationTim Shen2017-01-241-34/+173
| | | | | | | | | | Reviewers: echristo, hfinkel, kbarton, iteratee Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D28382 llvm-svn: 292860
* [APFloat] Switch from (PPCDoubleDoubleImpl, IEEEdouble) layout to ↵Tim Shen2017-01-231-17/+114
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (IEEEdouble, IEEEdouble) Summary: This patch changes the layout of DoubleAPFloat, and adjust all operations to do either: 1) (IEEEdouble, IEEEdouble) -> (uint64_t, uint64_t) -> PPCDoubleDoubleImpl, then run the old algorithm. 2) Do the right thing directly. 1) includes multiply, divide, remainder, mod, fusedMultiplyAdd, roundToIntegral, convertFromString, next, convertToInteger, convertFromAPInt, convertFromSignExtendedInteger, convertFromZeroExtendedInteger, convertToHexString, toString, getExactInverse. 2) includes makeZero, makeLargest, makeSmallest, makeSmallestNormalized, compare, bitwiseIsEqual, bitcastToAPInt, isDenormal, isSmallest, isLargest, isInteger, ilogb, scalbn, frexp, hash_value, Profile. I could split this into two patches, e.g. use 1) for all operatoins first, then incrementally change some of them to 2). I didn't do that, because 1) involves code that converts data between PPCDoubleDoubleImpl and (IEEEdouble, IEEEdouble) back and forth, and may pessimize the compiler. Instead, I find easy functions and use approach 2) for them directly. Next step is to implement move multiply and divide from 1) to 2). I don't have plans for other functions in 1). Differential Revision: https://reviews.llvm.org/D27872 llvm-svn: 292839
* [APFloatTest] Add tests for various operationsTim Shen2017-01-051-4/+271
| | | | | | Differential Revision: https://reviews.llvm.org/D27833 llvm-svn: 291189
* [APFloatTest] Log when test fails. NFCTim Shen2016-12-161-7/+21
| | | | | | | | | | Reviewers: iteratee Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D27828 llvm-svn: 289904
* Adapt to recent APFloat changeStephan Bergmann2016-12-141-6/+6
| | | | llvm-svn: 289649
* Replace APFloatBase static fltSemantics data members with getter functionsStephan Bergmann2016-12-141-820/+820
| | | | | | | | | | | | | At least the plugin used by the LibreOffice build (<https://wiki.documentfoundation.org/Development/Clang_plugins>) indirectly uses those members (through inline functions in LLVM/Clang include files in turn using them), but they are not exported by utils/extract_symbols.py on Windows, and accessing data across DLL/EXE boundaries on Windows is generally problematic. Differential Revision: https://reviews.llvm.org/D26671 llvm-svn: 289647
* [APFloatTest] Use std::make_tuple to make GCC 4.8 happyTim Shen2016-12-121-35/+38
| | | | | | Differential Revision: https://reviews.llvm.org/D26817 llvm-svn: 289474
* [APFloat] Implement PPCDoubleDouble add and subtract.Tim Shen2016-12-121-16/+119
| | | | | | | | | | | | Summary: I looked at libgcc's implementation (which is based on the paper, Software for Doubled-Precision Floating-Point Computations", by Seppo Linnainmaa, ACM TOMS vol 7 no 3, September 1981, pages 272-283.) and made it generic to arbitrary IEEE floats. Differential Revision: https://reviews.llvm.org/D26817 llvm-svn: 289472
* [APFloat] Make functions that produce APFloaat objects use correct semantics.Tim Shen2016-11-061-0/+28
| | | | | | | | | | | | | | | | | Summary: Fixes PR30869. In D25977 I meant to change all functions that care about lifetime. I changed constructors, factory functions, but I missed member/free functions that return new instances. This patch changes them. Reviewers: hfinkel, kbarton, echristo, joerg Subscribers: llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D26269 llvm-svn: 286060
* [NFC] Header cleanupMehdi Amini2016-04-181-1/+0
| | | | | | | | | | | | | | Removed some unused headers, replaced some headers with forward class declarations. Found using simple scripts like this one: clear && ack --cpp -l '#include "llvm/ADT/IndexedMap.h"' | xargs grep -L 'IndexedMap[<]' | xargs grep -n --color=auto 'IndexedMap' Patch by Eugene Kosov <claprix@yandex.ru> Differential Revision: http://reviews.llvm.org/D19219 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266595
* APFloat: Fix signalling nans for scalbnMatt Arsenault2016-03-231-1/+16
| | | | llvm-svn: 264219
* APFloat: Add frexpMatt Arsenault2016-03-211-1/+127
| | | | llvm-svn: 263950
* APFloat: Fix ilogb for denormalsMatt Arsenault2016-03-131-2/+16
| | | | llvm-svn: 263370
* APFloat: Fix scalbn handling of denormalsMatt Arsenault2016-03-131-22/+135
| | | | | | | This was incorrect for denormals, and also failed on longer exponent ranges. llvm-svn: 263369
* Add isInteger() to APFloat.Stephen Canon2015-11-161-1/+15
| | | | | | | | Useful utility function; this wasn't too hard to do before, but also wasn't obviously discoverable. Make it explicit. Reviewed offline by Michael Gottesman. llvm-svn: 253254
* Drop the hacks used for partial C99 math libraries.Benjamin Kramer2015-03-091-3/+4
| | | | | | All supported platforms have half-way decent C99 support. llvm-svn: 231679
* [APFloat][ADT] Fix sign handling logic for FMA results that truncate to zero.Lang Hames2015-01-041-0/+41
| | | | | | | | | | | | | | This patch adds a check for underflow when truncating results back to lower precision at the end of an FMA. The additional sign handling logic in APFloat::fusedMultiplyAdd should only be performed when the result of the addition step of the FMA (in full precision) is exactly zero, not when the result underflows to zero. Unit tests for this case and related signed zero FMA results are included. Fixes <rdar://problem/18925551>. llvm-svn: 225123
* [ADT] Fix PR20728 - Incorrect APFloat::fusedMultiplyAdd results for x86_fp80.Lang Hames2014-11-191-0/+12
| | | | | | | | | | | | | | As detailed at http://llvm.org/PR20728, due to an internal overflow in APFloat::multiplySignificand the APFloat::fusedMultiplyAdd method can return incorrect results for x87DoubleExtended (x86_fp80) values. This commonly manifests as incorrect constant folding of libm fmal calls on x86. E.g. fmal(1.0L, 1.0L, 3.0L) == 0.0L (should be 4.0L) This patch fixes PR20728 by adding an extra bit to the significand for intermediate results of APFloat::multiplySignificand, avoiding the overflow. llvm-svn: 222374
* [ADT] Add an (ADL-friendly) abs free function for APFloat that returnsChandler Carruth2014-10-101-0/+38
| | | | | | by value having cleared the sign bit. llvm-svn: 219485
* Add minnum / maxnum to APFloatMatt Arsenault2014-10-101-0/+22
| | | | llvm-svn: 219475
* [ADT] Replace the logb implementation with the simpler and much closerChandler Carruth2014-10-101-49/+27
| | | | | | | | to what we actually want ilogb implementation. This makes everything *much* easier to deal with and is actually what we want when using it anyways. llvm-svn: 219474
* [ADT] Add the scalbn function for APFloat.Chandler Carruth2014-10-101-0/+43
| | | | llvm-svn: 219473
* [ADT] Implement the 'logb' functionality for APFloat. This is necessaryChandler Carruth2014-10-101-0/+51
| | | | | | to implement complex division in the constant folder of Clang. llvm-svn: 219471
* [ADT] Add basic operator overloads for arithmetic to APFloat to makeChandler Carruth2014-10-091-0/+20
| | | | | | | | | | | | code using it more readable. Also add a copySign static function that works more like the standard function by accepting the value and sign-carying value as arguments. No interesting logic here, but tests added to cover the basic API additions and make sure they do something plausible. llvm-svn: 219453
* [C++11] Use 'nullptr'.Craig Topper2014-06-081-3/+3
| | | | llvm-svn: 210442
OpenPOWER on IntegriCloud