[bits] Make bit rotation branchless

A minor optimization to the four bit rotation functions.

Drive-by: Make them constexpr.

R=ahaas@chromium.org

Bug: v8:9810
Change-Id: Ic563310030aa487f976017032291a553705d1ec2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1903972
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64854}
This commit is contained in:
Clemens Backes 2019-11-08 09:39:11 +01:00 committed by Commit Bot
parent af608d4bd4
commit 2daa1138e3

View File

@ -182,30 +182,25 @@ inline uint32_t RoundDownToPowerOfTwo32(uint32_t value) {
// Precondition: 0 <= shift < 32 // Precondition: 0 <= shift < 32
inline uint32_t RotateRight32(uint32_t value, uint32_t shift) { inline constexpr uint32_t RotateRight32(uint32_t value, uint32_t shift) {
if (shift == 0) return value; return (value >> shift) | (value << ((32 - shift) & 31));
return (value >> shift) | (value << (32 - shift));
} }
// Precondition: 0 <= shift < 32 // Precondition: 0 <= shift < 32
inline uint32_t RotateLeft32(uint32_t value, uint32_t shift) { inline constexpr uint32_t RotateLeft32(uint32_t value, uint32_t shift) {
if (shift == 0) return value; return (value << shift) | (value >> ((32 - shift) & 31));
return (value << shift) | (value >> (32 - shift));
} }
// Precondition: 0 <= shift < 64 // Precondition: 0 <= shift < 64
inline uint64_t RotateRight64(uint64_t value, uint64_t shift) { inline constexpr uint64_t RotateRight64(uint64_t value, uint64_t shift) {
if (shift == 0) return value; return (value >> shift) | (value << ((64 - shift) & 63));
return (value >> shift) | (value << (64 - shift));
} }
// Precondition: 0 <= shift < 64 // Precondition: 0 <= shift < 64
inline uint64_t RotateLeft64(uint64_t value, uint64_t shift) { inline constexpr uint64_t RotateLeft64(uint64_t value, uint64_t shift) {
if (shift == 0) return value; return (value << shift) | (value >> ((64 - shift) & 63));
return (value << shift) | (value >> (64 - shift));
} }
// SignedAddOverflow32(lhs,rhs,val) performs a signed summation of |lhs| and // SignedAddOverflow32(lhs,rhs,val) performs a signed summation of |lhs| and
// |rhs| and stores the result into the variable pointed to by |val| and // |rhs| and stores the result into the variable pointed to by |val| and
// returns true if the signed summation resulted in an overflow. // returns true if the signed summation resulted in an overflow.