Skip to content

Commit

Permalink
Faster and more compact byteScatter()
Browse files Browse the repository at this point in the history
  • Loading branch information
alex65536 committed Aug 10, 2023
1 parent b5a45e4 commit f4b9a26
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/util/bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ inline constexpr uint8_t byteGather(uint64_t x) {

// Creates a 8-bit number, with all of its bytes equal to `x`
inline constexpr uint64_t byteScatter(uint8_t x) {
uint64_t r = x;
r |= r << 8;
r |= r << 16;
r |= r << 32;
return r;
return static_cast<uint64_t>(x) * 0x0101010101010101ULL;
}

// Performs a left rotation of `x` by `shift`. If `shift >= 64`, the behavior is undefined
Expand Down

0 comments on commit f4b9a26

Please sign in to comment.