This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch branch-1.17.x
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/branch-1.17.x by this push:
new c8c8ad38b [ARM] Fix CountOnes() function
c8c8ad38b is described below
commit c8c8ad38b3dbf0cc2bf0f5bd612109615faf068d
Author: Zoltan Martonka <[email protected]>
AuthorDate: Fri Dec 1 17:55:36 2023 +0000
[ARM] Fix CountOnes() function
This function is only used on arms. It does not work on numbers
greater than 255:
For some reason ULL suffix was added to 2 masks, that should be
32bit, and losing the higher bits are actually the desired
behaviour.
Change-Id: Ia4b78b5c1df9547548fc7980cec4b84349e868bc
Reviewed-on: http://gerrit.cloudera.org:8080/20736
Reviewed-by: Alexey Serbin <[email protected]>
Tested-by: Kudu Jenkins
(cherry picked from commit cda230197d9b25bf635facb29215fcfbdd09c415)
Reviewed-on: http://gerrit.cloudera.org:8080/21981
Reviewed-by: Abhishek Chennaka <[email protected]>
Tested-by: Alexey Serbin <[email protected]>
---
src/kudu/gutil/bits.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/src/kudu/gutil/bits.h b/src/kudu/gutil/bits.h
index 1c3c71417..f9fc2e412 100644
--- a/src/kudu/gutil/bits.h
+++ b/src/kudu/gutil/bits.h
@@ -13,19 +13,21 @@ class Bits {
// Return the number of one bits in the given integer.
static int CountOnesInByte(unsigned char n);
+ ATTRIBUTE_NO_SANITIZE_INTEGER
static int CountOnes(uint32 n) {
n -= ((n >> 1) & 0x55555555);
n = ((n >> 2) & 0x33333333) + (n & 0x33333333);
- return static_cast<int>((((n + (n >> 4)) & 0xF0F0F0FULL) * 0x1010101ULL)
>> 24);
+ return static_cast<int>((((n + (n >> 4)) & 0x0F0F0F0F) * 0x01010101) >>
24);
}
// Count bits using sideways addition [WWG'57]. See Knuth TAOCP v4 7.1.3(59)
+ ATTRIBUTE_NO_SANITIZE_INTEGER
static inline int CountOnes64(uint64 n) {
-#if defined(__x86_64__)
+#if defined(__x86_64__) || defined(__aarch64__)
n -= (n >> 1) & 0x5555555555555555ULL;
n = ((n >> 2) & 0x3333333333333333ULL) + (n & 0x3333333333333333ULL);
- return (((n + (n >> 4)) & 0xF0F0F0F0F0F0F0FULL)
- * 0x101010101010101ULL) >> 56;
+ return static_cast<int>((((n + (n >> 4)) & 0xF0F0F0F0F0F0F0FULL)
+ * 0x101010101010101ULL) >> 56);
#else
return CountOnes(n >> 32) + CountOnes(n & 0xffffffff);
#endif