WebKit Bugzilla
Attachment 372861 Details for
Bug 199203
: Add B3 Strength Reduction to turn multiply-immediate to adds and shifts
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-199203-20190625135929.patch (text/plain), 4.67 KB, created by
Justin Michaud
on 2019-06-25 13:59:29 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Justin Michaud
Created:
2019-06-25 13:59:29 PDT
Size:
4.67 KB
patch
obsolete
>Subversion Revision: 246642 >diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog >index 10940f37a1f8fe59ad14b87261354c6ac9601853..3c66652b8c128dfda51f1e450bee46f8b7e6f969 100644 >--- a/Source/JavaScriptCore/ChangeLog >+++ b/Source/JavaScriptCore/ChangeLog >@@ -1,3 +1,12 @@ >+2019-06-25 Justin Michaud <justin_michaud@apple.com> >+ >+ Add B3 Strength Reduction to turn multiply-immediate to adds and shifts >+ https://bugs.webkit.org/show_bug.cgi?id=199203 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * b3/B3ReduceStrength.cpp: >+ > 2019-06-18 Darin Adler <darin@apple.com> > > Tidy up the remaining bits of the AtomicString to AtomString rename >diff --git a/Source/JavaScriptCore/b3/B3ReduceStrength.cpp b/Source/JavaScriptCore/b3/B3ReduceStrength.cpp >index 102478f38045e9688fe89cc330655db4e346a918..0a306151e0585fd4733a66220a7412ac1e50a6ef 100644 >--- a/Source/JavaScriptCore/b3/B3ReduceStrength.cpp >+++ b/Source/JavaScriptCore/b3/B3ReduceStrength.cpp >@@ -734,14 +734,58 @@ private: > } > > // Turn this: Mul(value, constant) >- // Into this: Shl(value, log2(constant)) >- if (hasOneBitSet(factor)) { >- unsigned shiftAmount = WTF::fastLog2(static_cast<uint64_t>(factor)); >- replaceWithNewValue( >- m_proc.add<Value>( >- Shl, m_value->origin(), m_value->child(0), >+ // Into this: Add/Sub(Shl(value, log2(constant1)), ...) >+ ASSERT(factor > 0); >+ constexpr unsigned cutoff = 1; >+ >+ unsigned bitCount = bitCount64(factor); >+ int64_t invertedBase = factor; >+ // Set all bits to the right of the msb >+ invertedBase |= invertedBase >> 32; >+ invertedBase |= invertedBase >> 16; >+ invertedBase |= invertedBase >> 8; >+ invertedBase |= invertedBase >> 4; >+ invertedBase |= invertedBase >> 2; >+ invertedBase |= invertedBase >> 1; >+ // No sign bit, so unsigned overflow should not happen >+ invertedBase += 1; >+ >+ int64_t invertedFactor = ((~factor) & (invertedBase - 1)) + 1; >+ ASSERT(invertedFactor > 0); >+ unsigned invertedBitCount = bitCount64(invertedFactor) + 1; >+ ASSERT(invertedBase - invertedFactor == factor); >+ >+ if ((bitCount > 0 && bitCount <= cutoff) || (invertedBitCount > 0 && invertedBitCount <= cutoff)) { >+ Value* add = nullptr; >+ int64_t value = bitCount <= invertedBitCount ? factor : invertedFactor; >+ >+ for (unsigned shiftAmount = 0; shiftAmount < 63; ++shiftAmount) { >+ if (!(value&(1ul << shiftAmount))) >+ continue; >+ >+ Value* thisBit = shiftAmount == 0 ? m_value->child(0) : m_insertionSet.insert<Value>( >+ m_index, Shl, m_value->origin(), m_value->child(0), >+ m_insertionSet.insert<Const32Value>( >+ m_index, m_value->origin(), shiftAmount)); >+ >+ if (!add) >+ add = thisBit; >+ else >+ add = m_insertionSet.insert<Value>(m_index, Add, m_value->origin(), thisBit, add); >+ } >+ >+ if (value == invertedFactor) { >+ unsigned shiftAmount = WTF::fastLog2(static_cast<uint64_t>(invertedBase)); >+ >+ Value* thisBit = m_insertionSet.insert<Value>( >+ m_index, Shl, m_value->origin(), m_value->child(0), > m_insertionSet.insert<Const32Value>( >- m_index, m_value->origin(), shiftAmount))); >+ m_index, m_value->origin(), shiftAmount)); >+ >+ add = m_insertionSet.insert<Value>(m_index, Sub, m_value->origin(), thisBit, add); >+ } >+ >+ replaceWithIdentity(add); > break; > } > } else if (m_value->child(1)->hasDouble()) { >@@ -2176,6 +2220,14 @@ private: > } > } > >+ inline static unsigned bitCount64(uint64_t value) { >+ unsigned bitCount = 0; >+ for (unsigned shiftAmount = 0; shiftAmount < 63; ++shiftAmount) >+ if (value&(1ul << shiftAmount)) >+ ++bitCount; >+ return bitCount; >+ } >+ > // Find a node that: > // - functor(node) returns true. > // - it's reachable from the given node via children.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 199203
:
372861
|
372880
|
372881
|
373928