Commit 63851f85 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

Add helper for lossless conversion of 31-bit pattern to Smi

R=sigurds@chromium.org

Change-Id: Ia6874ba5a705dda3a6f2b971cf50618a2229a40f
Reviewed-on: https://chromium-review.googlesource.com/c/1466502Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59525}
parent f4b7d442
......@@ -749,11 +749,7 @@ bool FeedbackNexus::ConfigureLexicalVarMode(int script_context_index,
SlotIndexBits::encode(context_slot_index) |
ImmutabilityBit::encode(immutable);
// Force {config} to be in Smi range by propagating the most significant Smi
// bit. This does not change any of the bitfield's bits.
config = (config << (32 - kSmiValueSize)) >> (32 - kSmiValueSize);
SetFeedback(Smi::FromInt(config));
SetFeedback(Smi::From31BitPattern(config));
Isolate* isolate = GetIsolate();
SetFeedbackExtra(*FeedbackVector::UninitializedSentinel(isolate),
SKIP_WRITE_BARRIER);
......
......@@ -57,6 +57,13 @@ class Smi : public Object {
return Smi((static_cast<Address>(value) << smi_shift_bits) | kSmiTag);
}
// Given {value} in [0, 2^31-1], force it into Smi range by changing at most
// the MSB (leaving the lower 31 bit unchanged).
static inline Smi From31BitPattern(int value) {
return Smi::FromInt((value << (32 - kSmiValueSize)) >>
(32 - kSmiValueSize));
}
template <typename E,
typename = typename std::enable_if<std::is_enum<E>::value>::type>
static inline Smi FromEnum(E value) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment