summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/MathExtrasTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Alignment][NFC] Support compile time constantsGuillaume Chatelet2019-10-141-0/+19
| | | | | | | | | | | | | | | | | Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68936 llvm-svn: 374758
* Revert "[Alignment][NFC] Allow constexpr Align"Guillaume Chatelet2019-10-031-19/+0
| | | | | | This reverts commit b3af236fb5fc6e50fcc1b54d868f0bff557f3fb1. llvm-svn: 373619
* [Alignment][NFC] Allow constexpr AlignGuillaume Chatelet2019-10-031-0/+19
| | | | | | | | | | | | | | | | | Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D68329 llvm-svn: 373580
* [Support] Added overflow checking add, sub and mul.JF Bastien2019-07-311-0/+127
| | | | | | | | Added AddOverflow, SubOverflow and MulOverflow to compute truncated results and return a flag indicating whether overflow occured. Differential Revision: https://reviews.llvm.org/D65494 llvm-svn: 367470
* 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
* MathExtras UnitTest: Assert that isPowerOf2(0) is false. NFC.Zvi Rackover2017-07-031-0/+2
| | | | | | | | | | | | | | | | | Summary: This is a follow-up on D34077. Elena observed that the correctness of the code relies on isPowerOf2(0) returning false. Adding a test to cover this corner-case. Reviewers: delena, davide, craig.topper Reviewed By: davide Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D34939 llvm-svn: 307046
* Re-sort #include lines for unittests. This uses a slightly modifiedChandler Carruth2017-06-061-1/+1
| | | | | | | | | | | | | | | clang-format (https://reviews.llvm.org/D33932) to keep primary headers at the top and handle new utility headers like 'gmock' consistently with other utility headers. No other change was made. I did no manual edits, all of this is clang-format. This should allow other changes to have more clear and focused diffs, and is especially motivated by moving some headers into more focused libraries. llvm-svn: 304786
* [MathExtras] Fix undefined behavior (shift by bit width)Benjamin Kramer2017-04-191-0/+5
| | | | | | While there add some unit tests for uint64_t. Found by ubsan. llvm-svn: 300721
* [Support] Add some helpers to generate bitmasks.Zachary Turner2017-04-191-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | Frequently you you want a bitmask consisting of a specified number of 1s, either at the beginning or end of a word. The naive way to do this is to write template<typename T> T leadingBitMask(unsigned N) { return (T(1) << N) - 1; } but using this function you cannot produce a word with every bit set to 1 (i.e. leadingBitMask<uint8_t>(8)) because left shift is undefined when N is greater than or equal to the number of bits in the word. This patch provides an efficient, branch-free implementation that works for all values of N in [0, CHAR_BIT*sizeof(T)] Differential Revision: https://reviews.llvm.org/D32212 llvm-svn: 300710
* [ADT/MathExtras] Make buildbot happy again.Davide Italiano2016-11-111-6/+6
| | | | llvm-svn: 286559
* [ADT/MathExtras] Add tests for PowerOf2Floor (previously untested).Davide Italiano2016-11-111-0/+6
| | | | llvm-svn: 286551
* [ADT/MathExtras] Introduce PowerOf2Ceil.Davide Italiano2016-11-111-0/+6
| | | | | | | | To be used in lld (and probably somewhere else in llvm). Differential Revision: https://reviews.llvm.org/D26538 llvm-svn: 286549
* Add tests for max/minIntN(64).Justin Lebar2016-07-171-0/+4
| | | | | | | | | | | | | | Summary: Given that we had a bug on max/minUIntN(64), these should have tests too. Reviewers: rnk Subscribers: dylanmckay, llvm-commits Differential Revision: https://reviews.llvm.org/D22443 llvm-svn: 275723
* Fix isShiftedInt and isShiftedUint for widths > 32.Justin Lebar2016-07-171-0/+38
| | | | | | | | | | | | | | | | | Summary: Previously we were doing 1 << S. "1" is an int, so this doesn't work when S >= 32. This patch also adds some static_asserts to these functions to ensure that we don't hit UB by shifting left too much. Reviewers: rnk Subscribers: llvm-commits, dylanmckay Differential Revision: https://reviews.llvm.org/D22441 llvm-svn: 275719
* Don't do uint64_t(1) << 64 in maxUIntN.Justin Lebar2016-07-161-0/+1
| | | | | | | | | | | | | | Summary: This shift is undefined behavior (and, as compiled by clang, gives the wrong answer for maxUIntN(64)). Reviewers: mkuper Subscribers: llvm-commits, jroelofs, rsmith Differential Revision: https://reviews.llvm.org/D22430 llvm-svn: 275656
* Add tests to Support/MathExtrasDylan McKay2016-06-021-0/+29
| | | | | | | | | In r271380, I added several functions to get the minimum/maximum values of n-width integers. This just adds tests for them. llvm-svn: 271505
* MathExtrasTest.cpp: Use EXPECT_DOUBLE_EQ here, instead of EXPECT_FLOAT_EQ.NAKAMURA Takumi2016-03-141-1/+1
| | | | llvm-svn: 263508
* Update to use new name alignTo().Rui Ueyama2016-01-141-9/+9
| | | | llvm-svn: 257804
* [Support] Add saturating multiply-add support functionNathan Slingerland2016-01-121-0/+54
| | | | | | | | | | | | Summary: Add SaturatingMultiplyAdd convenience function template since A + (X * Y) comes up frequently when doing weighted arithmetic. Reviewers: davidxl, silvas Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D15385 llvm-svn: 257532
* [Support] Change SaturatingAdd()/SaturatingMultiply() to use pointer for ↵Nathan Slingerland2015-12-091-17/+17
| | | | | | | | | | | | | | | | returning overflow state Summary: Improve SaturatingAdd()/SaturatingMultiply() to use bool * to optionally return overflow result. This should make it clearer that the value is returned at callsites and reduces the size of the implementation. Reviewers: davidxl, silvas Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D15219 llvm-svn: 255128
* [Support] Add optional argument to SaturatingAdd() and SaturatingMultiply() ↵Nathan Slingerland2015-11-231-1/+50
| | | | | | | | | | | | | | to indicate that overflow occurred Summary: Adds the ability for callers to detect when saturation occurred on the result of saturating addition/multiplication. Reviewers: davidxl, silvas, rsmith Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D14931 llvm-svn: 253921
* [Support] Fix SaturatingMultiply<T>() to be correct (and fast), Re-enable ↵Nathan Slingerland2015-11-231-0/+48
| | | | | | | | | | | | | | | | | | Unit Tests Summary: This change fixes the SaturatingMultiply<T>() function template to not cause undefined behavior with T=uint16_t. Thanks to Richard Smith's contribution, it also no longer requires an integer division. Patch by Richard Smith. Reviewers: silvas, davidxl Subscribers: rsmith, davidxl, llvm-commits Differential Revision: http://reviews.llvm.org/D14845 llvm-svn: 253870
* Revert the revert 253497 and 253539 - These commits aren't the cause of the ↵Daniel Sanders2015-11-201-0/+17
| | | | | | | | clang-cmake-mips failures. Sorry for the noise. llvm-svn: 253662
* Revert 253497 and 253539 to try to fix clang-cmake-mips buildbot.Daniel Sanders2015-11-201-17/+0
| | | | | | | | | | It caused link errors of the form: InstrProfiling.c:(.text.__llvm_profile_instrument_target+0x1c0): undefined reference to `__sync_fetch_and_add_8' We had a network outage at the time of the commit so the first build to show a problem is http://lab.llvm.org:8011/builders/clang-cmake-mips/builds/10827 llvm-svn: 253656
* [Support] Disable SaturatingMultiply() unit test while investigatingNathan Slingerland2015-11-191-19/+0
| | | | | | | | Ubsan detected undefined behavior in the MathExtras SaturatingMultiply test. This change disables the test while it is being investigated. llvm-svn: 253539
* [llvm-profdata] Add SaturatingAdd/SaturatingMultiply Helper Functions (2nd try)Nathan Slingerland2015-11-181-0/+36
| | | | | | | | | | | | | Summary: This change adds MathExtras helper functions for handling unsigned, saturating addition and multiplication. It also updates the instrumentation and sample profile merge implementations to use them. Reviewers: dnovillo, bogner, davidxl Subscribers: davidxl, llvm-commits Differential Revision: http://reviews.llvm.org/D14720 llvm-svn: 253497
* Revert "[llvm-profdata] Add SaturatingAdd/SaturatingMultiply Helper Functions"Nathan Slingerland2015-11-181-48/+0
| | | | | | Not ready for merge. llvm-svn: 253415
* [llvm-profdata] Add SaturatingAdd/SaturatingMultiply Helper FunctionsNathan Slingerland2015-11-181-0/+48
| | | | | | | | | | | | | | | Summary: This change adds MathExtras helper functions for handling unsigned, saturating addition and multiplication. It also updates the instrumentation and sample profile merge implementations to use them. No functional changes. Reviewers: dnovillo, bogner, davidxl Subscribers: davidxl, llvm-commits Differential Revision: http://reviews.llvm.org/D14720 llvm-svn: 253412
* HHVM calling conventions.Maksim Panchenko2015-09-291-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | HHVM calling convention, hhvmcc, is used by HHVM JIT for functions in translated cache. We currently support LLVM back end to generate code for X86-64 and may support other architectures in the future. In HHVM calling convention any GP register could be used to pass and return values, with the exception of R12 which is reserved for thread-local area and is callee-saved. Other than R12, we always pass RBX and RBP as args, which are our virtual machine's stack pointer and frame pointer respectively. When we enter translation cache via hhvmcc function, we expect the stack to be aligned at 16 bytes, i.e. skewed by 8 bytes as opposed to standard ABI alignment. This affects stack object alignment and stack adjustments for function calls. One extra calling convention, hhvm_ccc, is used to call C++ helpers from HHVM's translation cache. It is almost identical to standard C calling convention with an exception of first argument which is passed in RBP (before we use RDI, RSI, etc.) Differential Revision: http://reviews.llvm.org/D12681 llvm-svn: 248832
* Try to fix the MSVC build.Benjamin Kramer2015-02-121-1/+1
| | | | | | | 0xFFFFFFFFFFFFFFFFLL doesn't fit in a long long so it should have type 'unsigned long long'. MSVC thinks it's a (signed) __int64. llvm-svn: 228950
* MathExtras: Bring Count(Trailing|Leading)Ones and CountPopulation in line ↵Benjamin Kramer2015-02-121-7/+4
| | | | | | | | with countTrailingZeros Update all callers. llvm-svn: 228930
* [Support] Remove Count{Leading,Trailing}Zeros_{32,64}.Michael J. Spencer2013-05-241-16/+12
| | | | llvm-svn: 182690
* [Support][MathExtras] Fix literal type issues.Michael J. Spencer2013-05-241-36/+36
| | | | llvm-svn: 182679
* [Support] Add type generic bit utilities to MathExtras.hMichael J. Spencer2013-05-241-0/+91
| | | | llvm-svn: 182667
* Fixes warnings emitted by Visual Studio 2010 compiler.Oscar Fuentes2011-03-011-1/+1
| | | | | | Patch by Erik Olofsson! llvm-svn: 126796
* Fixed header comment.Misha Brukman2009-08-201-1/+1
| | | | llvm-svn: 79536
* Make the constants fit.Bill Wendling2009-04-011-5/+5
| | | | llvm-svn: 68258
* Added tests for math utility functions; fixed another test's header comment.Misha Brukman2009-04-011-0/+104
llvm-svn: 68249
OpenPOWER on IntegriCloud