llvm-project/libcxx
Jorg Brown 586952f4ce Optimize std::midpoint for integers
Same idea as the current algorithm, that is, add (half of the difference between a and b) to a.

But we use a different technique for computing the difference: we compute b - a into a pair of integers that are named "sign_bit" and "diff". We have to use a pair because subtracting two 32-bit integers produces a 33-bit result.

Computing half of that is a simple matter of shifting diff right by 1, and adding sign_bit shifted left by 31. llvm knows how to do that with one instruction: shld.

The only tricky part is that if the difference is odd and negative, then shifting it by one isn't the same as dividing it by two - shifting a negative one produces a negative one, for example. So there's one more adjustment: if the sign bit and the low bit of diff are one, we add one.

For a demonstration of the codegen difference, see https://godbolt.org/z/7ar3K9 , which also has a built-in test.

Differential Revision: https://reviews.llvm.org/D69459
2019-11-04 19:00:23 -08:00
..
benchmarks [libcxx][NFC] Strip trailing whitespace, fix typo. 2019-10-23 11:49:43 -07:00
cmake [libc++] Fix linker script generation 2019-10-11 04:54:35 +00:00
docs [NFC] Fix typos in libc++ documentation 2019-10-01 20:34:50 +00:00
fuzzing [NFC] Strip trailing whitespace from libc++ 2019-10-23 11:19:19 -07:00
include Optimize std::midpoint for integers 2019-11-04 19:00:23 -08:00
lib [libc++] Add missing revision number in ABI changelog 2019-10-03 16:50:05 +00:00
src [libcxx][NFC] Strip trailing whitespace, fix typo. 2019-10-23 11:49:43 -07:00
test [libc++] Add test and remove workaround for PR13592 2019-10-30 15:52:11 -07:00
utils [libcxx] Disable -Wconstant-evaluated for testsuite 2019-11-01 13:46:47 +01:00
www Add all the issues to be voted upon in Belfast 2019-10-26 07:53:15 -07:00
.arcconfig [libcxx] Set up .arcconfig to point to new Diffusion CXX repository 2017-12-04 17:55:28 +00:00
.clang-format Make clang-format use C++03 syntax 2017-04-15 02:45:43 +00:00
.gitignore
CMakeLists.txt build: avoid custom handling for C++ standard 2019-11-02 15:07:54 -04:00
CREDITS.TXT Try again, this time with the correct address 2017-12-29 19:26:53 +00:00
LICENSE.TXT Fix typos throughout the license files that somehow I and my reviewers 2019-01-21 09:52:34 +00:00
NOTES.TXT Reland "Use custom command and target to install libc++ headers" 2018-06-12 03:10:02 +00:00
TODO.TXT
appveyor-reqs-install.cmd Attempt to upgrade compiler used by appveyor builds 2019-04-03 20:40:01 +00:00
appveyor.yml disable appveyor config for MSVC 2015 2019-04-03 20:36:51 +00:00