-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-41687: [C++] bit_util: Trying to remove pre-compute table #41690
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,15 +282,19 @@ static inline int Log2(uint64_t x) { | |
|
||
// Bitmask selecting the k-th bit in a byte | ||
// static constexpr uint8_t kBitmask[] = {1, 2, 4, 8, 16, 32, 64, 128}; | ||
static constexpr uint8_t GetBitMask(uint8_t index) { | ||
template <typename T> | ||
static constexpr uint8_t GetBitMask(T index) { | ||
// DCHECK(index >= 0 && index <= 7); | ||
ARROW_COMPILER_ASSUME(index >= 0 && index <= 7); | ||
return static_cast<uint8_t>(1) << index; | ||
} | ||
|
||
// the bitwise complement version of kBitmask | ||
// static constexpr uint8_t kFlippedBitmask[] = {254, 253, 251, 247, 239, 223, 191, 127}; | ||
static constexpr uint8_t GetFlippedBitMask(uint8_t index) { | ||
template <typename T> | ||
static constexpr uint8_t GetFlippedBitMask(T index) { | ||
// DCHECK(index >= 0 && index <= 7); | ||
ARROW_COMPILER_ASSUME(index >= 0 && index <= 7); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting the assumption here doesn't have the same effect. Because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not fully understand this, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or from the godbolt link, do you mean change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, tried in godbolt, I'll add this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha, I use |
||
return ~(static_cast<uint8_t>(1) << index); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler will generate code that performs the
<<
on a 32-bit integer. A more honest implementation (in the sense that it gives more freedom to the compiler [1]):And since indices in arrow are rarely
uint8_t
, I would keep the index type unconstrained like this:[1] might matter more for
rustc
thanclang
because C/C++ compilers already have a lot of freedom even when your code contains many type constraints