Skip to content

Commit

Permalink
[WTF] Remove countTrailingZeros
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264041

Reviewed by Yusuke Suzuki.

In addition to being redundant because of ctz existing, the lookup table
in itself is slower due to the operations happening to the variable v
before retrieving the value. Source: https://godbolt.org/z/Pnd9nPPbo

* Source/JavaScriptCore/b3/B3ReduceStrength.cpp: Switch to WTF:ctz.
* Source/WTF/wtf/MathExtras.h:
  (WTF::countTrailingZeros): Deleted.

Canonical link: https://commits.webkit.org/270076@main
  • Loading branch information
AtariDreams authored and Constellation committed Nov 1, 2023
1 parent 3a66f00 commit 37c77f4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Source/JavaScriptCore/b3/B3ReduceStrength.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ class ReduceStrength {
&& m_value->child(1)->hasInt()) {
uint64_t shiftAmount = m_value->child(0)->child(1)->asInt();
uint64_t maskShift = m_value->child(1)->asInt();
uint64_t maskShiftAmount = WTF::countTrailingZeros(maskShift);
uint64_t maskShiftAmount = WTF::ctz(maskShift);
uint64_t mask = maskShift >> maskShiftAmount;
uint64_t width = WTF::bitCount(mask);
uint64_t datasize = m_value->child(0)->child(0)->type() == Int64 ? 64 : 32;
Expand Down Expand Up @@ -1600,7 +1600,7 @@ class ReduceStrength {
&& m_value->child(1)->asInt() >= 0) {
uint64_t shiftAmount = m_value->child(1)->asInt();
uint64_t maskShift = m_value->child(0)->child(1)->asInt();
uint64_t maskShiftAmount = WTF::countTrailingZeros(maskShift);
uint64_t maskShiftAmount = WTF::ctz(maskShift);
uint64_t mask = maskShift >> maskShiftAmount;
uint64_t width = WTF::bitCount(mask);
uint64_t datasize = m_value->child(0)->child(0)->type() == Int64 ? 64 : 32;
Expand Down
22 changes: 0 additions & 22 deletions Source/WTF/wtf/MathExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,28 +732,6 @@ constexpr unsigned getMSBSetConstexpr(T t)
return bitSize - 1 - clzConstexpr(t);
}

inline size_t countTrailingZeros(uint32_t v)
{
static const unsigned Mod37BitPosition[] = {
32, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13,
4, 7, 17, 0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9,
5, 20, 8, 19, 18
};
return Mod37BitPosition[((1 + ~v) & v) % 37];
}

inline size_t countTrailingZeros(uint64_t v)
{
static const unsigned Mod67Position[] = {
64, 0, 1, 39, 2, 15, 40, 23, 3, 12, 16, 59, 41, 19, 24, 54,
4, 64, 13, 10, 17, 62, 60, 28, 42, 30, 20, 51, 25, 44, 55,
47, 5, 32, 65, 38, 14, 22, 11, 58, 18, 53, 63, 9, 61, 27,
29, 50, 43, 46, 31, 37, 21, 57, 52, 8, 26, 49, 45, 36, 56,
7, 48, 35, 6, 34, 33, 0
};
return Mod67Position[((1 + ~v) & v) % 67];
}

inline uint32_t reverseBits32(uint32_t value)
{
#if COMPILER(GCC_COMPATIBLE) && CPU(ARM64)
Expand Down

0 comments on commit 37c77f4

Please sign in to comment.