diff options
author | Jorg Brown <jorg@google.com> | 2019-11-04 19:00:23 -0800 |
---|---|---|
committer | Jorg Brown <jorg@google.com> | 2019-11-04 19:00:23 -0800 |
commit | 586952f4cefd809b7becd16c6d1e751ea923adfd (patch) | |
tree | 7974e57b1d60ce17931991d9fcf0bdb5caa6bbea /lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h | |
parent | 610f80f7baea5e46c0ccd4cbb905a679c7c56a05 (diff) | |
download | llvm-586952f4cefd809b7becd16c6d1e751ea923adfd.zip llvm-586952f4cefd809b7becd16c6d1e751ea923adfd.tar.gz llvm-586952f4cefd809b7becd16c6d1e751ea923adfd.tar.bz2 |
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
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPythonImpl.h')
0 files changed, 0 insertions, 0 deletions