Skip to content

Commit

Permalink
[ptr-compr] Add a switch for branchless/branchful decompression
Browse files Browse the repository at this point in the history
Bug: v8:7703
Change-Id: Ic6cd8b337813ecff2a0d030aa3a57304e784378a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1511486
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60391}
  • Loading branch information
isheludko authored and Commit Bot committed Mar 21, 2019
1 parent 64a9420 commit 39fca64
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/globals.h
Expand Up @@ -225,6 +225,10 @@ using AtomicTagged_t = base::AtomicWord;

#endif // V8_COMPRESS_POINTERS

// Defines whether the branchless or branchful implementation of pointer
// decompression should be used.
constexpr bool kUseBranchlessPtrDecompression = true;

STATIC_ASSERT(kTaggedSize == (1 << kTaggedSizeLog2));

using AsAtomicTagged = base::AsAtomicPointerImpl<AtomicTagged_t>;
Expand Down
14 changes: 10 additions & 4 deletions src/ptr-compr-inl.h
Expand Up @@ -42,10 +42,16 @@ V8_INLINE Address DecompressTaggedAny(Address on_heap_addr,
// Current compression scheme requires |raw_value| to be sign-extended
// from int32_t to intptr_t.
intptr_t value = static_cast<intptr_t>(static_cast<int32_t>(raw_value));
// |root_mask| is 0 if the |value| was a smi or -1 otherwise.
Address root_mask = static_cast<Address>(-(value & kSmiTagMask));
Address root_or_zero = root_mask & GetRootFromOnHeapAddress(on_heap_addr);
return root_or_zero + static_cast<Address>(value);
if (kUseBranchlessPtrDecompression) {
// |root_mask| is 0 if the |value| was a smi or -1 otherwise.
Address root_mask = static_cast<Address>(-(value & kSmiTagMask));
Address root_or_zero = root_mask & GetRootFromOnHeapAddress(on_heap_addr);
return root_or_zero + static_cast<Address>(value);
} else {
return HAS_SMI_TAG(value) ? static_cast<Address>(value)
: (GetRootFromOnHeapAddress(on_heap_addr) +
static_cast<Address>(value));
}
}

#ifdef V8_COMPRESS_POINTERS
Expand Down
29 changes: 18 additions & 11 deletions src/x64/macro-assembler-x64.cc
Expand Up @@ -307,17 +307,24 @@ void TurboAssembler::DecompressAnyTagged(Register destination,
DCHECK(!AreAliased(destination, scratch));
RecordComment("[ DecompressAnyTagged");
movsxlq(destination, field_operand);
// Branchlessly compute |masked_root|:
// masked_root = HAS_SMI_TAG(destination) ? 0 : kRootRegister;
STATIC_ASSERT((kSmiTagSize == 1) && (kSmiTag < 32));
Register masked_root = scratch;
movl(masked_root, destination);
andl(masked_root, Immediate(kSmiTagMask));
negq(masked_root);
andq(masked_root, kRootRegister);
// Now this add operation will either leave the value unchanged if it is a smi
// or add the isolate root if it is a heap object.
addq(destination, masked_root);
if (kUseBranchlessPtrDecompression) {
// Branchlessly compute |masked_root|:
// masked_root = HAS_SMI_TAG(destination) ? 0 : kRootRegister;
STATIC_ASSERT((kSmiTagSize == 1) && (kSmiTag < 32));
Register masked_root = scratch;
movl(masked_root, destination);
andl(masked_root, Immediate(kSmiTagMask));
negq(masked_root);
andq(masked_root, kRootRegister);
// Now this add operation will either leave the value unchanged if it is
// a smi or add the isolate root if it is a heap object.
addq(destination, masked_root);
} else {
Label done;
JumpIfSmi(destination, &done);
addq(destination, kRootRegister);
bind(&done);
}
RecordComment("]");
}

Expand Down

0 comments on commit 39fca64

Please sign in to comment.