[cleanup] Split out bit-field.h and bounds.h from utils/utils.h
utils.h itself is fairly large and contains lots of unrelated functions as well as having a fair number of dependencies itself, so this splits bounds checking and bit field operations into their own headers in base and replaces uses of utils.h with the more appropriate header where possible. (Also fixes some cases where other headers were previously brought in transitively). Bug: v8:9810, v8:8912 Change-Id: I76c53f953848a57e2c5bfad6ce45abcd6d2a4f1b Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1916604 Reviewed-by: Clemens Backes <clemensb@chromium.org> Reviewed-by: Ross McIlroy <rmcilroy@chromium.org> Commit-Queue: Dan Elphick <delphick@chromium.org> Cr-Commit-Position: refs/heads/master@{#64983}
This commit is contained in:
parent
28f3229a30
commit
84f3877c15
6
BUILD.gn
6
BUILD.gn
@ -1398,7 +1398,9 @@ v8_source_set("v8_snapshot") {
|
||||
# Do not publicize any header to remove build dependency.
|
||||
public = []
|
||||
|
||||
sources = [ "src/init/setup-isolate-deserialize.cc" ]
|
||||
sources = [
|
||||
"src/init/setup-isolate-deserialize.cc",
|
||||
]
|
||||
if (emit_builtins_as_inline_asm) {
|
||||
deps += [ ":asm_to_inline_asm_default" ]
|
||||
sources += [ "$target_gen_dir/embedded.cc" ]
|
||||
@ -3422,10 +3424,12 @@ v8_component("v8_libbase") {
|
||||
"src/base/atomicops_internals_portable.h",
|
||||
"src/base/atomicops_internals_std.h",
|
||||
"src/base/base-export.h",
|
||||
"src/base/bit-field.h",
|
||||
"src/base/bits.cc",
|
||||
"src/base/bits.h",
|
||||
"src/base/bounded-page-allocator.cc",
|
||||
"src/base/bounded-page-allocator.h",
|
||||
"src/base/bounds.h",
|
||||
"src/base/build_config.h",
|
||||
"src/base/compiler-specific.h",
|
||||
"src/base/cpu.cc",
|
||||
|
@ -424,7 +424,8 @@ void AsmJsScanner::ConsumeCompareOrShift(uc32 ch) {
|
||||
}
|
||||
|
||||
bool AsmJsScanner::IsIdentifierStart(uc32 ch) {
|
||||
return IsInRange(AsciiAlphaToLower(ch), 'a', 'z') || ch == '_' || ch == '$';
|
||||
return base::IsInRange(AsciiAlphaToLower(ch), 'a', 'z') || ch == '_' ||
|
||||
ch == '$';
|
||||
}
|
||||
|
||||
bool AsmJsScanner::IsIdentifierPart(uc32 ch) { return IsAsciiIdentifier(ch); }
|
||||
|
@ -170,7 +170,7 @@ class AstNode: public ZoneObject {
|
||||
void* operator new(size_t size);
|
||||
|
||||
int position_;
|
||||
using NodeTypeField = BitField<NodeType, 0, 6>;
|
||||
using NodeTypeField = base::BitField<NodeType, 0, 6>;
|
||||
|
||||
protected:
|
||||
uint32_t bit_field_;
|
||||
@ -259,7 +259,7 @@ class Expression : public AstNode {
|
||||
|
||||
bool IsPattern() {
|
||||
STATIC_ASSERT(kObjectLiteral + 1 == kArrayLiteral);
|
||||
return IsInRange(node_type(), kObjectLiteral, kArrayLiteral);
|
||||
return base::IsInRange(node_type(), kObjectLiteral, kArrayLiteral);
|
||||
}
|
||||
|
||||
bool is_parenthesized() const {
|
||||
|
@ -261,7 +261,7 @@ class Variable final : public ZoneObject {
|
||||
bit_field_ = MaybeAssignedFlagField::update(bit_field_, kMaybeAssigned);
|
||||
}
|
||||
|
||||
using VariableModeField = BitField16<VariableMode, 0, 4>;
|
||||
using VariableModeField = base::BitField16<VariableMode, 0, 4>;
|
||||
using VariableKindField = VariableModeField::Next<VariableKind, 3>;
|
||||
using LocationField = VariableKindField::Next<VariableLocation, 3>;
|
||||
using ForceContextAllocationField = LocationField::Next<bool, 1>;
|
||||
|
159
src/base/bit-field.h
Normal file
159
src/base/bit-field.h
Normal file
@ -0,0 +1,159 @@
|
||||
// Copyright 2019 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_BASE_BIT_FIELD_H_
|
||||
#define V8_BASE_BIT_FIELD_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "src/base/macros.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace base {
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// BitField is a help template for encoding and decode bitfield with
|
||||
// unsigned content.
|
||||
// Instantiate them via 'using', which is cheaper than deriving a new class:
|
||||
// using MyBitField = base::BitField<int, 4, 2, MyEnum>;
|
||||
// The BitField class is final to enforce this style over derivation.
|
||||
|
||||
template <class T, int shift, int size, class U = uint32_t>
|
||||
class BitField final {
|
||||
public:
|
||||
STATIC_ASSERT(std::is_unsigned<U>::value);
|
||||
STATIC_ASSERT(shift < 8 * sizeof(U)); // Otherwise shifts by {shift} are UB.
|
||||
STATIC_ASSERT(size < 8 * sizeof(U)); // Otherwise shifts by {size} are UB.
|
||||
STATIC_ASSERT(shift + size <= 8 * sizeof(U));
|
||||
STATIC_ASSERT(size > 0);
|
||||
|
||||
using FieldType = T;
|
||||
|
||||
// A type U mask of bit field. To use all bits of a type U of x bits
|
||||
// in a bitfield without compiler warnings we have to compute 2^x
|
||||
// without using a shift count of x in the computation.
|
||||
static constexpr int kShift = shift;
|
||||
static constexpr int kSize = size;
|
||||
static constexpr U kMask = ((U{1} << kShift) << kSize) - (U{1} << kShift);
|
||||
static constexpr int kLastUsedBit = kShift + kSize - 1;
|
||||
static constexpr U kNumValues = U{1} << kSize;
|
||||
|
||||
// Value for the field with all bits set.
|
||||
static constexpr T kMax = static_cast<T>(kNumValues - 1);
|
||||
|
||||
template <class T2, int size2>
|
||||
using Next = BitField<T2, kShift + kSize, size2, U>;
|
||||
|
||||
// Tells whether the provided value fits into the bit field.
|
||||
static constexpr bool is_valid(T value) {
|
||||
return (static_cast<U>(value) & ~static_cast<U>(kMax)) == 0;
|
||||
}
|
||||
|
||||
// Returns a type U with the bit field value encoded.
|
||||
static constexpr U encode(T value) {
|
||||
#if V8_HAS_CXX14_CONSTEXPR
|
||||
DCHECK(is_valid(value));
|
||||
#endif
|
||||
return static_cast<U>(value) << kShift;
|
||||
}
|
||||
|
||||
// Returns a type U with the bit field value updated.
|
||||
static constexpr U update(U previous, T value) {
|
||||
return (previous & ~kMask) | encode(value);
|
||||
}
|
||||
|
||||
// Extracts the bit field from the value.
|
||||
static constexpr T decode(U value) {
|
||||
return static_cast<T>((value & kMask) >> kShift);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, int shift, int size>
|
||||
using BitField8 = BitField<T, shift, size, uint8_t>;
|
||||
|
||||
template <class T, int shift, int size>
|
||||
using BitField16 = BitField<T, shift, size, uint16_t>;
|
||||
|
||||
template <class T, int shift, int size>
|
||||
using BitField64 = BitField<T, shift, size, uint64_t>;
|
||||
|
||||
// Helper macros for defining a contiguous sequence of bit fields. Example:
|
||||
// (backslashes at the ends of respective lines of this multi-line macro
|
||||
// definition are omitted here to please the compiler)
|
||||
//
|
||||
// #define MAP_BIT_FIELD1(V, _)
|
||||
// V(IsAbcBit, bool, 1, _)
|
||||
// V(IsBcdBit, bool, 1, _)
|
||||
// V(CdeBits, int, 5, _)
|
||||
// V(DefBits, MutableMode, 1, _)
|
||||
//
|
||||
// DEFINE_BIT_FIELDS(MAP_BIT_FIELD1)
|
||||
// or
|
||||
// DEFINE_BIT_FIELDS_64(MAP_BIT_FIELD1)
|
||||
//
|
||||
#define DEFINE_BIT_FIELD_RANGE_TYPE(Name, Type, Size, _) \
|
||||
k##Name##Start, k##Name##End = k##Name##Start + Size - 1,
|
||||
|
||||
#define DEFINE_BIT_RANGES(LIST_MACRO) \
|
||||
struct LIST_MACRO##_Ranges { \
|
||||
enum { LIST_MACRO(DEFINE_BIT_FIELD_RANGE_TYPE, _) kBitsCount }; \
|
||||
};
|
||||
|
||||
#define DEFINE_BIT_FIELD_TYPE(Name, Type, Size, RangesName) \
|
||||
using Name = base::BitField<Type, RangesName::k##Name##Start, Size>;
|
||||
|
||||
#define DEFINE_BIT_FIELD_64_TYPE(Name, Type, Size, RangesName) \
|
||||
using Name = base::BitField64<Type, RangesName::k##Name##Start, Size>;
|
||||
|
||||
#define DEFINE_BIT_FIELDS(LIST_MACRO) \
|
||||
DEFINE_BIT_RANGES(LIST_MACRO) \
|
||||
LIST_MACRO(DEFINE_BIT_FIELD_TYPE, LIST_MACRO##_Ranges)
|
||||
|
||||
#define DEFINE_BIT_FIELDS_64(LIST_MACRO) \
|
||||
DEFINE_BIT_RANGES(LIST_MACRO) \
|
||||
LIST_MACRO(DEFINE_BIT_FIELD_64_TYPE, LIST_MACRO##_Ranges)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// BitSetComputer is a help template for encoding and decoding information for
|
||||
// a variable number of items in an array.
|
||||
//
|
||||
// To encode boolean data in a smi array you would use:
|
||||
// using BoolComputer = BitSetComputer<bool, 1, kSmiValueSize, uint32_t>;
|
||||
//
|
||||
template <class T, int kBitsPerItem, int kBitsPerWord, class U>
|
||||
class BitSetComputer {
|
||||
public:
|
||||
static const int kItemsPerWord = kBitsPerWord / kBitsPerItem;
|
||||
static const int kMask = (1 << kBitsPerItem) - 1;
|
||||
|
||||
// The number of array elements required to embed T information for each item.
|
||||
static int word_count(int items) {
|
||||
if (items == 0) return 0;
|
||||
return (items - 1) / kItemsPerWord + 1;
|
||||
}
|
||||
|
||||
// The array index to look at for item.
|
||||
static int index(int base_index, int item) {
|
||||
return base_index + item / kItemsPerWord;
|
||||
}
|
||||
|
||||
// Extract T data for a given item from data.
|
||||
static T decode(U data, int item) {
|
||||
return static_cast<T>((data >> shift(item)) & kMask);
|
||||
}
|
||||
|
||||
// Return the encoding for a store of value for item in previous.
|
||||
static U encode(U previous, int item, T value) {
|
||||
int shift_value = shift(item);
|
||||
int set_bits = (static_cast<int>(value) << shift_value);
|
||||
return (previous & ~(kMask << shift_value)) | set_bits;
|
||||
}
|
||||
|
||||
static int shift(int item) { return (item % kItemsPerWord) * kBitsPerItem; }
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_BASE_BIT_FIELD_H_
|
54
src/base/bounds.h
Normal file
54
src/base/bounds.h
Normal file
@ -0,0 +1,54 @@
|
||||
// Copyright 2019 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_BASE_BOUNDS_H_
|
||||
#define V8_BASE_BOUNDS_H_
|
||||
|
||||
#include "include/v8config.h"
|
||||
#include "src/base/macros.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace base {
|
||||
|
||||
// Checks if value is in range [lower_limit, higher_limit] using a single
|
||||
// branch.
|
||||
template <typename T, typename U>
|
||||
inline constexpr bool IsInRange(T value, U lower_limit, U higher_limit) {
|
||||
#if V8_HAS_CXX14_CONSTEXPR
|
||||
DCHECK_LE(lower_limit, higher_limit);
|
||||
#endif
|
||||
STATIC_ASSERT(sizeof(U) <= sizeof(T));
|
||||
using unsigned_T = typename std::make_unsigned<T>::type;
|
||||
// Use static_cast to support enum classes.
|
||||
return static_cast<unsigned_T>(static_cast<unsigned_T>(value) -
|
||||
static_cast<unsigned_T>(lower_limit)) <=
|
||||
static_cast<unsigned_T>(static_cast<unsigned_T>(higher_limit) -
|
||||
static_cast<unsigned_T>(lower_limit));
|
||||
}
|
||||
|
||||
// Checks if [index, index+length) is in range [0, max). Note that this check
|
||||
// works even if {index+length} would wrap around.
|
||||
inline constexpr bool IsInBounds(size_t index, size_t length, size_t max) {
|
||||
return length <= max && index <= (max - length);
|
||||
}
|
||||
|
||||
// Checks if [index, index+length) is in range [0, max). If not, {length} is
|
||||
// clamped to its valid range. Note that this check works even if
|
||||
// {index+length} would wrap around.
|
||||
template <typename T>
|
||||
inline bool ClampToBounds(T index, T* length, T max) {
|
||||
if (index > max) {
|
||||
*length = 0;
|
||||
return false;
|
||||
}
|
||||
T avail = max - index;
|
||||
bool oob = *length > avail;
|
||||
if (oob) *length = avail;
|
||||
return !oob;
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
} // namespace v8
|
||||
|
||||
#endif // V8_BASE_BOUNDS_H_
|
@ -6,6 +6,7 @@
|
||||
#define V8_BUILTINS_ACCESSORS_H_
|
||||
|
||||
#include "include/v8.h"
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/objects/property-details.h"
|
||||
#include "src/utils/allocation.h"
|
||||
|
@ -783,10 +783,10 @@ class ArrayConcatVisitor {
|
||||
storage_ = isolate_->global_handles()->Create(storage);
|
||||
}
|
||||
|
||||
using FastElementsField = BitField<bool, 0, 1>;
|
||||
using ExceedsLimitField = BitField<bool, 1, 1>;
|
||||
using IsFixedArrayField = BitField<bool, 2, 1>;
|
||||
using HasSimpleElementsField = BitField<bool, 3, 1>;
|
||||
using FastElementsField = base::BitField<bool, 0, 1>;
|
||||
using ExceedsLimitField = base::BitField<bool, 1, 1>;
|
||||
using IsFixedArrayField = base::BitField<bool, 2, 1>;
|
||||
using HasSimpleElementsField = base::BitField<bool, 3, 1>;
|
||||
|
||||
bool fast_elements() const { return FastElementsField::decode(bit_field_); }
|
||||
void set_fast_elements(bool fast) {
|
||||
|
@ -5,9 +5,9 @@
|
||||
#ifndef V8_CODEGEN_HANDLER_TABLE_H_
|
||||
#define V8_CODEGEN_HANDLER_TABLE_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/common/assert-scope.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -129,8 +129,8 @@ class V8_EXPORT_PRIVATE HandlerTable {
|
||||
static const int kReturnEntrySize = 2;
|
||||
|
||||
// Encoding of the {handler} field.
|
||||
using HandlerPredictionField = BitField<CatchPrediction, 0, 3>;
|
||||
using HandlerOffsetField = BitField<int, 3, 29>;
|
||||
using HandlerPredictionField = base::BitField<CatchPrediction, 0, 3>;
|
||||
using HandlerOffsetField = base::BitField<int, 3, 29>;
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
@ -343,8 +343,8 @@ class Displacement {
|
||||
private:
|
||||
int data_;
|
||||
|
||||
using TypeField = BitField<Type, 0, 2>;
|
||||
using NextField = BitField<int, 2, 32 - 2>;
|
||||
using TypeField = base::BitField<Type, 0, 2>;
|
||||
using NextField = base::BitField<int, 2, 32 - 2>;
|
||||
|
||||
void init(Label* L, Type type);
|
||||
};
|
||||
|
@ -142,8 +142,8 @@ class RelocInfo {
|
||||
return COMPRESS_POINTERS_BOOL && mode == COMPRESSED_EMBEDDED_OBJECT;
|
||||
}
|
||||
static constexpr bool IsEmbeddedObjectMode(Mode mode) {
|
||||
return IsInRange(mode, FIRST_EMBEDDED_OBJECT_RELOC_MODE,
|
||||
LAST_EMBEDDED_OBJECT_RELOC_MODE);
|
||||
return base::IsInRange(mode, FIRST_EMBEDDED_OBJECT_RELOC_MODE,
|
||||
LAST_EMBEDDED_OBJECT_RELOC_MODE);
|
||||
}
|
||||
static constexpr bool IsRuntimeEntry(Mode mode) {
|
||||
return mode == RUNTIME_ENTRY;
|
||||
|
@ -27,8 +27,8 @@ namespace internal {
|
||||
namespace {
|
||||
|
||||
// Each byte is encoded as MoreBit | ValueBits.
|
||||
using MoreBit = BitField8<bool, 7, 1>;
|
||||
using ValueBits = BitField8<unsigned, 0, 7>;
|
||||
using MoreBit = base::BitField8<bool, 7, 1>;
|
||||
using ValueBits = base::BitField8<unsigned, 0, 7>;
|
||||
|
||||
// Helper: Add the offsets from 'other' to 'value'. Also set is_statement.
|
||||
void AddAndSetEntry(PositionTableEntry* value,
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "src/common/assert-scope.h"
|
||||
#include "src/common/checks.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/utils/vector.h"
|
||||
#include "src/zone/zone-containers.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
#include <ostream>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/flags/flags.h"
|
||||
#include "src/handles/handles.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -142,18 +142,18 @@ class SourcePosition final {
|
||||
|
||||
void Print(std::ostream& out, SharedFunctionInfo function) const;
|
||||
|
||||
using IsExternalField = BitField64<bool, 0, 1>;
|
||||
using IsExternalField = base::BitField64<bool, 0, 1>;
|
||||
|
||||
// The two below are only used if IsExternal() is true.
|
||||
using ExternalLineField = BitField64<int, 1, 20>;
|
||||
using ExternalFileIdField = BitField64<int, 21, 10>;
|
||||
using ExternalLineField = base::BitField64<int, 1, 20>;
|
||||
using ExternalFileIdField = base::BitField64<int, 21, 10>;
|
||||
|
||||
// ScriptOffsetField is only used if IsExternal() is false.
|
||||
using ScriptOffsetField = BitField64<int, 1, 30>;
|
||||
using ScriptOffsetField = base::BitField64<int, 1, 30>;
|
||||
|
||||
// InliningId is in the high bits for better compression in
|
||||
// SourcePositionTable.
|
||||
using InliningIdField = BitField64<int, 31, 16>;
|
||||
using InliningIdField = base::BitField64<int, 31, 16>;
|
||||
|
||||
// Leaving the highest bit untouched to allow for signed conversion.
|
||||
uint64_t value_;
|
||||
|
@ -181,8 +181,8 @@ void MacroAssembler::PushRoot(RootIndex index) {
|
||||
|
||||
void TurboAssembler::CompareRoot(Register with, RootIndex index) {
|
||||
DCHECK(root_array_available_);
|
||||
if (IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot,
|
||||
RootIndex::kLastStrongOrReadOnlyRoot)) {
|
||||
if (base::IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot,
|
||||
RootIndex::kLastStrongOrReadOnlyRoot)) {
|
||||
cmp_tagged(with,
|
||||
Operand(kRootRegister, RootRegisterOffsetForRootIndex(index)));
|
||||
} else {
|
||||
@ -195,8 +195,8 @@ void TurboAssembler::CompareRoot(Operand with, RootIndex index) {
|
||||
DCHECK(root_array_available_);
|
||||
DCHECK(!with.AddressUsesRegister(kScratchRegister));
|
||||
LoadRoot(kScratchRegister, index);
|
||||
if (IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot,
|
||||
RootIndex::kLastStrongOrReadOnlyRoot)) {
|
||||
if (base::IsInRange(index, RootIndex::kFirstStrongOrReadOnlyRoot,
|
||||
RootIndex::kLastStrongOrReadOnlyRoot)) {
|
||||
cmp_tagged(with, kScratchRegister);
|
||||
} else {
|
||||
// Some smi roots contain system pointer size values like stack limits.
|
||||
|
@ -94,7 +94,7 @@ bool PerThreadAssertScope<kType, kAllow>::IsAllowed() {
|
||||
|
||||
namespace {
|
||||
template <PerIsolateAssertType kType>
|
||||
using DataBit = BitField<bool, kType, 1>;
|
||||
using DataBit = base::BitField<bool, kType, 1>;
|
||||
}
|
||||
|
||||
template <PerIsolateAssertType kType, bool kAllow>
|
||||
|
@ -15,7 +15,8 @@ namespace internal {
|
||||
namespace compiler {
|
||||
|
||||
void AllocationBuilder::AllocateContext(int variadic_part_length, MapRef map) {
|
||||
DCHECK(IsInRange(map.instance_type(), FIRST_CONTEXT_TYPE, LAST_CONTEXT_TYPE));
|
||||
DCHECK(base::IsInRange(map.instance_type(), FIRST_CONTEXT_TYPE,
|
||||
LAST_CONTEXT_TYPE));
|
||||
DCHECK_NE(NATIVE_CONTEXT_TYPE, map.instance_type());
|
||||
int size = Context::SizeFor(variadic_part_length);
|
||||
Allocate(size, AllocationType::kYoung, Type::OtherInternal());
|
||||
|
@ -354,15 +354,15 @@ bool TryMatchLoadStoreShift(Arm64OperandGenerator* g,
|
||||
// Bitfields describing binary operator properties:
|
||||
// CanCommuteField is true if we can switch the two operands, potentially
|
||||
// requiring commuting the flags continuation condition.
|
||||
using CanCommuteField = BitField8<bool, 1, 1>;
|
||||
using CanCommuteField = base::BitField8<bool, 1, 1>;
|
||||
// MustCommuteCondField is true when we need to commute the flags continuation
|
||||
// condition in order to switch the operands.
|
||||
using MustCommuteCondField = BitField8<bool, 2, 1>;
|
||||
using MustCommuteCondField = base::BitField8<bool, 2, 1>;
|
||||
// IsComparisonField is true when the operation is a comparison and has no other
|
||||
// result other than the condition.
|
||||
using IsComparisonField = BitField8<bool, 3, 1>;
|
||||
using IsComparisonField = base::BitField8<bool, 3, 1>;
|
||||
// IsAddSubField is true when an instruction is encoded as ADD or SUB.
|
||||
using IsAddSubField = BitField8<bool, 4, 1>;
|
||||
using IsAddSubField = base::BitField8<bool, 4, 1>;
|
||||
|
||||
// Get properties of a binary operator.
|
||||
uint8_t GetBinopProperties(InstructionCode opcode) {
|
||||
|
@ -27,8 +27,8 @@
|
||||
#define TARGET_ARCH_OPCODE_LIST(V)
|
||||
#define TARGET_ADDRESSING_MODE_LIST(V)
|
||||
#endif
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/compiler/write-barrier-kind.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -267,11 +267,11 @@ using InstructionCode = uint32_t;
|
||||
// for code generation. We encode the instruction, addressing mode, and flags
|
||||
// continuation into a single InstructionCode which is stored as part of
|
||||
// the instruction.
|
||||
using ArchOpcodeField = BitField<ArchOpcode, 0, 9>;
|
||||
using AddressingModeField = BitField<AddressingMode, 9, 5>;
|
||||
using FlagsModeField = BitField<FlagsMode, 14, 3>;
|
||||
using FlagsConditionField = BitField<FlagsCondition, 17, 5>;
|
||||
using MiscField = BitField<int, 22, 10>;
|
||||
using ArchOpcodeField = base::BitField<ArchOpcode, 0, 9>;
|
||||
using AddressingModeField = base::BitField<AddressingMode, 9, 5>;
|
||||
using FlagsModeField = base::BitField<FlagsMode, 14, 3>;
|
||||
using FlagsConditionField = base::BitField<FlagsCondition, 17, 5>;
|
||||
using MiscField = base::BitField<int, 22, 10>;
|
||||
|
||||
} // namespace compiler
|
||||
} // namespace internal
|
||||
|
@ -125,7 +125,7 @@ class V8_EXPORT_PRIVATE InstructionOperand {
|
||||
|
||||
inline uint64_t GetCanonicalizedValue() const;
|
||||
|
||||
using KindField = BitField64<Kind, 0, 3>;
|
||||
using KindField = base::BitField64<Kind, 0, 3>;
|
||||
|
||||
uint64_t value_;
|
||||
};
|
||||
@ -322,24 +322,24 @@ class UnallocatedOperand final : public InstructionOperand {
|
||||
// P ... Policy
|
||||
//
|
||||
// The slot index is a signed value which requires us to decode it manually
|
||||
// instead of using the BitField utility class.
|
||||
// instead of using the base::BitField utility class.
|
||||
|
||||
STATIC_ASSERT(KindField::kSize == 3);
|
||||
|
||||
using VirtualRegisterField = BitField64<uint32_t, 3, 32>;
|
||||
using VirtualRegisterField = base::BitField64<uint32_t, 3, 32>;
|
||||
|
||||
// BitFields for all unallocated operands.
|
||||
using BasicPolicyField = BitField64<BasicPolicy, 35, 1>;
|
||||
// base::BitFields for all unallocated operands.
|
||||
using BasicPolicyField = base::BitField64<BasicPolicy, 35, 1>;
|
||||
|
||||
// BitFields specific to BasicPolicy::FIXED_SLOT.
|
||||
using FixedSlotIndexField = BitField64<int, 36, 28>;
|
||||
using FixedSlotIndexField = base::BitField64<int, 36, 28>;
|
||||
|
||||
// BitFields specific to BasicPolicy::EXTENDED_POLICY.
|
||||
using ExtendedPolicyField = BitField64<ExtendedPolicy, 36, 3>;
|
||||
using LifetimeField = BitField64<Lifetime, 39, 1>;
|
||||
using HasSecondaryStorageField = BitField64<bool, 40, 1>;
|
||||
using FixedRegisterField = BitField64<int, 41, 6>;
|
||||
using SecondaryStorageField = BitField64<int, 47, 3>;
|
||||
using ExtendedPolicyField = base::BitField64<ExtendedPolicy, 36, 3>;
|
||||
using LifetimeField = base::BitField64<Lifetime, 39, 1>;
|
||||
using HasSecondaryStorageField = base::BitField64<bool, 40, 1>;
|
||||
using FixedRegisterField = base::BitField64<int, 41, 6>;
|
||||
using SecondaryStorageField = base::BitField64<int, 47, 3>;
|
||||
|
||||
private:
|
||||
explicit UnallocatedOperand(int virtual_register)
|
||||
@ -368,7 +368,7 @@ class ConstantOperand : public InstructionOperand {
|
||||
INSTRUCTION_OPERAND_CASTS(ConstantOperand, CONSTANT)
|
||||
|
||||
STATIC_ASSERT(KindField::kSize == 3);
|
||||
using VirtualRegisterField = BitField64<uint32_t, 3, 32>;
|
||||
using VirtualRegisterField = base::BitField64<uint32_t, 3, 32>;
|
||||
};
|
||||
|
||||
class ImmediateOperand : public InstructionOperand {
|
||||
@ -401,8 +401,8 @@ class ImmediateOperand : public InstructionOperand {
|
||||
INSTRUCTION_OPERAND_CASTS(ImmediateOperand, IMMEDIATE)
|
||||
|
||||
STATIC_ASSERT(KindField::kSize == 3);
|
||||
using TypeField = BitField64<ImmediateType, 3, 1>;
|
||||
using ValueField = BitField64<int32_t, 32, 32>;
|
||||
using TypeField = base::BitField64<ImmediateType, 3, 1>;
|
||||
using ValueField = base::BitField64<int32_t, 32, 32>;
|
||||
};
|
||||
|
||||
class LocationOperand : public InstructionOperand {
|
||||
@ -503,9 +503,9 @@ class LocationOperand : public InstructionOperand {
|
||||
}
|
||||
|
||||
STATIC_ASSERT(KindField::kSize == 3);
|
||||
using LocationKindField = BitField64<LocationKind, 3, 2>;
|
||||
using RepresentationField = BitField64<MachineRepresentation, 5, 8>;
|
||||
using IndexField = BitField64<int32_t, 35, 29>;
|
||||
using LocationKindField = base::BitField64<LocationKind, 3, 2>;
|
||||
using RepresentationField = base::BitField64<MachineRepresentation, 5, 8>;
|
||||
using IndexField = base::BitField64<int32_t, 35, 29>;
|
||||
};
|
||||
|
||||
class AllocatedOperand : public LocationOperand {
|
||||
@ -909,9 +909,9 @@ class V8_EXPORT_PRIVATE Instruction final {
|
||||
// APIs to aid debugging. For general-stream APIs, use operator<<.
|
||||
void Print() const;
|
||||
|
||||
using OutputCountField = BitField<size_t, 0, 8>;
|
||||
using InputCountField = BitField<size_t, 8, 16>;
|
||||
using TempCountField = BitField<size_t, 24, 6>;
|
||||
using OutputCountField = base::BitField<size_t, 0, 8>;
|
||||
using InputCountField = base::BitField<size_t, 8, 16>;
|
||||
using TempCountField = base::BitField<size_t, 24, 6>;
|
||||
|
||||
static const size_t kMaxOutputCount = OutputCountField::kMax;
|
||||
static const size_t kMaxInputCount = InputCountField::kMax;
|
||||
@ -925,7 +925,7 @@ class V8_EXPORT_PRIVATE Instruction final {
|
||||
InstructionOperand* inputs, size_t temp_count,
|
||||
InstructionOperand* temps);
|
||||
|
||||
using IsCallField = BitField<bool, 30, 1>;
|
||||
using IsCallField = base::BitField<bool, 30, 1>;
|
||||
|
||||
InstructionCode opcode_;
|
||||
uint32_t bit_field_;
|
||||
|
@ -487,10 +487,10 @@ class V8_EXPORT_PRIVATE UsePosition final
|
||||
static UsePositionHintType HintTypeForOperand(const InstructionOperand& op);
|
||||
|
||||
private:
|
||||
using TypeField = BitField<UsePositionType, 0, 2>;
|
||||
using HintTypeField = BitField<UsePositionHintType, 2, 3>;
|
||||
using RegisterBeneficialField = BitField<bool, 5, 1>;
|
||||
using AssignedRegisterField = BitField<int32_t, 6, 6>;
|
||||
using TypeField = base::BitField<UsePositionType, 0, 2>;
|
||||
using HintTypeField = base::BitField<UsePositionHintType, 2, 3>;
|
||||
using RegisterBeneficialField = base::BitField<bool, 5, 1>;
|
||||
using AssignedRegisterField = base::BitField<int32_t, 6, 6>;
|
||||
|
||||
InstructionOperand* const operand_;
|
||||
void* hint_;
|
||||
@ -671,12 +671,12 @@ class V8_EXPORT_PRIVATE LiveRange : public NON_EXPORTED_BASE(ZoneObject) {
|
||||
void VerifyPositions() const;
|
||||
void VerifyIntervals() const;
|
||||
|
||||
using SpilledField = BitField<bool, 0, 1>;
|
||||
using SpilledField = base::BitField<bool, 0, 1>;
|
||||
// Bits (1,7[ are used by TopLevelLiveRange.
|
||||
using AssignedRegisterField = BitField<int32_t, 7, 6>;
|
||||
using RepresentationField = BitField<MachineRepresentation, 13, 8>;
|
||||
using RecombineField = BitField<bool, 21, 1>;
|
||||
using ControlFlowRegisterHint = BitField<uint8_t, 22, 6>;
|
||||
using AssignedRegisterField = base::BitField<int32_t, 7, 6>;
|
||||
using RepresentationField = base::BitField<MachineRepresentation, 13, 8>;
|
||||
using RecombineField = base::BitField<bool, 21, 1>;
|
||||
using ControlFlowRegisterHint = base::BitField<uint8_t, 22, 6>;
|
||||
// Bit 28 is used by TopLevelLiveRange.
|
||||
|
||||
// Unique among children and splinters of the same virtual register.
|
||||
@ -987,11 +987,11 @@ class V8_EXPORT_PRIVATE TopLevelLiveRange final : public LiveRange {
|
||||
friend class LiveRange;
|
||||
void SetSplinteredFrom(TopLevelLiveRange* splinter_parent);
|
||||
|
||||
using HasSlotUseField = BitField<SlotUseKind, 1, 2>;
|
||||
using IsPhiField = BitField<bool, 3, 1>;
|
||||
using IsNonLoopPhiField = BitField<bool, 4, 1>;
|
||||
using SpillTypeField = BitField<SpillType, 5, 2>;
|
||||
using DeferredFixedField = BitField<bool, 28, 1>;
|
||||
using HasSlotUseField = base::BitField<SlotUseKind, 1, 2>;
|
||||
using IsPhiField = base::BitField<bool, 3, 1>;
|
||||
using IsNonLoopPhiField = base::BitField<bool, 4, 1>;
|
||||
using SpillTypeField = base::BitField<SpillType, 5, 2>;
|
||||
using DeferredFixedField = base::BitField<bool, 28, 1>;
|
||||
|
||||
int vreg_;
|
||||
int last_child_id_;
|
||||
|
@ -85,8 +85,8 @@ class ConstructForwardVarargsParameters final {
|
||||
return p.bit_field_;
|
||||
}
|
||||
|
||||
using ArityField = BitField<size_t, 0, 16>;
|
||||
using StartIndexField = BitField<uint32_t, 16, 16>;
|
||||
using ArityField = base::BitField<size_t, 0, 16>;
|
||||
using StartIndexField = base::BitField<uint32_t, 16, 16>;
|
||||
|
||||
uint32_t const bit_field_;
|
||||
};
|
||||
@ -147,8 +147,8 @@ class CallForwardVarargsParameters final {
|
||||
return p.bit_field_;
|
||||
}
|
||||
|
||||
using ArityField = BitField<size_t, 0, 15>;
|
||||
using StartIndexField = BitField<uint32_t, 15, 15>;
|
||||
using ArityField = base::BitField<size_t, 0, 15>;
|
||||
using StartIndexField = base::BitField<uint32_t, 15, 15>;
|
||||
|
||||
uint32_t const bit_field_;
|
||||
};
|
||||
@ -209,10 +209,10 @@ class CallParameters final {
|
||||
feedback_hash(p.feedback_));
|
||||
}
|
||||
|
||||
using ArityField = BitField<size_t, 0, 27>;
|
||||
using CallFeedbackRelationField = BitField<CallFeedbackRelation, 27, 1>;
|
||||
using SpeculationModeField = BitField<SpeculationMode, 28, 1>;
|
||||
using ConvertReceiverModeField = BitField<ConvertReceiverMode, 29, 2>;
|
||||
using ArityField = base::BitField<size_t, 0, 27>;
|
||||
using CallFeedbackRelationField = base::BitField<CallFeedbackRelation, 27, 1>;
|
||||
using SpeculationModeField = base::BitField<SpeculationMode, 28, 1>;
|
||||
using ConvertReceiverModeField = base::BitField<ConvertReceiverMode, 29, 2>;
|
||||
|
||||
uint32_t const bit_field_;
|
||||
CallFrequency const frequency_;
|
||||
|
@ -157,7 +157,7 @@ class LinkageLocation {
|
||||
private:
|
||||
enum LocationType { REGISTER, STACK_SLOT };
|
||||
|
||||
using TypeField = BitField<LocationType, 0, 1>;
|
||||
using TypeField = base::BitField<LocationType, 0, 1>;
|
||||
using LocationField = TypeField::Next<int32_t, 31>;
|
||||
|
||||
static constexpr int32_t ANY_REGISTER = -1;
|
||||
|
@ -200,8 +200,8 @@ class V8_EXPORT_PRIVATE Node final {
|
||||
: reinterpret_cast<OutOfLineInputs*>(start)->node_;
|
||||
}
|
||||
|
||||
using InlineField = BitField<bool, 0, 1>;
|
||||
using InputIndexField = BitField<unsigned, 1, 31>;
|
||||
using InlineField = base::BitField<bool, 0, 1>;
|
||||
using InputIndexField = base::BitField<unsigned, 1, 31>;
|
||||
};
|
||||
|
||||
//============================================================================
|
||||
@ -285,9 +285,9 @@ class V8_EXPORT_PRIVATE Node final {
|
||||
|
||||
void ClearInputs(int start, int count);
|
||||
|
||||
using IdField = BitField<NodeId, 0, 24>;
|
||||
using InlineCountField = BitField<unsigned, 24, 4>;
|
||||
using InlineCapacityField = BitField<unsigned, 28, 4>;
|
||||
using IdField = base::BitField<NodeId, 0, 24>;
|
||||
using InlineCountField = base::BitField<unsigned, 24, 4>;
|
||||
using InlineCapacityField = base::BitField<unsigned, 28, 4>;
|
||||
static const int kOutlineMarker = InlineCountField::kMax;
|
||||
static const int kMaxInlineCapacity = InlineCapacityField::kMax - 1;
|
||||
|
||||
|
@ -3530,7 +3530,7 @@ Node* WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index,
|
||||
return index;
|
||||
}
|
||||
|
||||
if (!IsInBounds(offset, access_size, env_->max_memory_size)) {
|
||||
if (!base::IsInBounds(offset, access_size, env_->max_memory_size)) {
|
||||
// The access will be out of bounds, even for the largest memory.
|
||||
TrapIfEq32(wasm::kTrapMemOutOfBounds, Int32Constant(0), 0, position);
|
||||
return mcgraph()->IntPtrConstant(0);
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "src/strings/char-predicates.h"
|
||||
#include "src/utils/allocation.h"
|
||||
#include "src/utils/vector.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
@ -600,7 +600,7 @@ class GlobalHandles::Node final : public NodeBase<GlobalHandles::Node> {
|
||||
|
||||
// This stores three flags (independent, partially_dependent and
|
||||
// in_young_list) and a State.
|
||||
using NodeState = BitField8<State, 0, 3>;
|
||||
using NodeState = base::BitField8<State, 0, 3>;
|
||||
using IsInYoungList = NodeState::Next<bool, 1>;
|
||||
using NodeWeaknessType = IsInYoungList::Next<WeaknessType, 2>;
|
||||
|
||||
@ -674,7 +674,7 @@ class GlobalHandles::TracedNode final
|
||||
}
|
||||
|
||||
protected:
|
||||
using NodeState = BitField8<State, 0, 2>;
|
||||
using NodeState = base::BitField8<State, 0, 2>;
|
||||
using IsInYoungList = NodeState::Next<bool, 1>;
|
||||
using IsRoot = IsInYoungList::Next<bool, 1>;
|
||||
using HasDestructor = IsRoot::Next<bool, 1>;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <stack>
|
||||
|
||||
#include "src/base/atomic-utils.h"
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/base/bits.h"
|
||||
#include "src/heap/worklist.h"
|
||||
#include "src/objects/compressed-slots.h"
|
||||
@ -543,8 +544,8 @@ class V8_EXPORT_PRIVATE TypedSlots {
|
||||
void Merge(TypedSlots* other);
|
||||
|
||||
protected:
|
||||
using OffsetField = BitField<int, 0, 29>;
|
||||
using TypeField = BitField<SlotType, 29, 3>;
|
||||
using OffsetField = base::BitField<int, 0, 29>;
|
||||
using TypeField = base::BitField<SlotType, 29, 3>;
|
||||
struct TypedSlot {
|
||||
uint32_t type_and_offset;
|
||||
};
|
||||
|
@ -2460,8 +2460,9 @@ class V8_EXPORT_PRIVATE PagedSpace
|
||||
bool is_local_space() { return local_space_kind_ != LocalSpaceKind::kNone; }
|
||||
|
||||
bool is_compaction_space() {
|
||||
return IsInRange(local_space_kind_, LocalSpaceKind::kFirstCompactionSpace,
|
||||
LocalSpaceKind::kLastCompactionSpace);
|
||||
return base::IsInRange(local_space_kind_,
|
||||
LocalSpaceKind::kFirstCompactionSpace,
|
||||
LocalSpaceKind::kLastCompactionSpace);
|
||||
}
|
||||
|
||||
LocalSpaceKind local_space_kind() { return local_space_kind_; }
|
||||
|
@ -48,7 +48,7 @@ class LoadHandler final : public DataHandler {
|
||||
kNonExistent,
|
||||
kModuleExport
|
||||
};
|
||||
using KindBits = BitField<Kind, 0, 4>;
|
||||
using KindBits = base::BitField<Kind, 0, 4>;
|
||||
|
||||
// Defines whether access rights check should be done on receiver object.
|
||||
// Applicable to named property kinds only when loading value from prototype
|
||||
@ -206,7 +206,7 @@ class StoreHandler final : public DataHandler {
|
||||
kProxy,
|
||||
kKindsNumber // Keep last
|
||||
};
|
||||
using KindBits = BitField<Kind, 0, 4>;
|
||||
using KindBits = base::BitField<Kind, 0, 4>;
|
||||
|
||||
// Applicable to kGlobalProxy, kProxy kinds.
|
||||
|
||||
|
@ -5,7 +5,8 @@
|
||||
#ifndef V8_INTERPRETER_BYTECODE_FLAGS_H_
|
||||
#define V8_INTERPRETER_BYTECODE_FLAGS_H_
|
||||
|
||||
#include "src/utils/utils.h"
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/common/globals.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -18,7 +19,7 @@ namespace interpreter {
|
||||
|
||||
class CreateArrayLiteralFlags {
|
||||
public:
|
||||
using FlagsBits = BitField8<int, 0, 5>;
|
||||
using FlagsBits = base::BitField8<int, 0, 5>;
|
||||
using FastCloneSupportedBit = FlagsBits::Next<bool, 1>;
|
||||
|
||||
static uint8_t Encode(bool use_fast_shallow_clone, int runtime_flags);
|
||||
@ -29,7 +30,7 @@ class CreateArrayLiteralFlags {
|
||||
|
||||
class CreateObjectLiteralFlags {
|
||||
public:
|
||||
using FlagsBits = BitField8<int, 0, 5>;
|
||||
using FlagsBits = base::BitField8<int, 0, 5>;
|
||||
using FastCloneSupportedBit = FlagsBits::Next<bool, 1>;
|
||||
|
||||
static uint8_t Encode(int runtime_flags, bool fast_clone_supported);
|
||||
@ -40,7 +41,7 @@ class CreateObjectLiteralFlags {
|
||||
|
||||
class CreateClosureFlags {
|
||||
public:
|
||||
using PretenuredBit = BitField8<bool, 0, 1>;
|
||||
using PretenuredBit = base::BitField8<bool, 0, 1>;
|
||||
using FastNewClosureBit = PretenuredBit::Next<bool, 1>;
|
||||
|
||||
static uint8_t Encode(bool pretenure, bool is_function_scope,
|
||||
@ -80,7 +81,7 @@ class TestTypeOfFlags {
|
||||
|
||||
class StoreLookupSlotFlags {
|
||||
public:
|
||||
using LanguageModeBit = BitField8<LanguageMode, 0, 1>;
|
||||
using LanguageModeBit = base::BitField8<LanguageMode, 0, 1>;
|
||||
using LookupHoistingModeBit = LanguageModeBit::Next<bool, 1>;
|
||||
STATIC_ASSERT(LanguageModeSize <= LanguageModeBit::kNumValues);
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
#ifndef V8_INTERPRETER_BYTECODE_OPERANDS_H_
|
||||
#define V8_INTERPRETER_BYTECODE_OPERANDS_H_
|
||||
|
||||
#include "src/base/bounds.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -182,13 +182,14 @@ class BytecodeOperands : public AllStatic {
|
||||
|
||||
// Returns true if |operand_type| is a scalable signed byte.
|
||||
static constexpr bool IsScalableSignedByte(OperandType operand_type) {
|
||||
return IsInRange(operand_type, OperandType::kImm,
|
||||
OperandType::kRegOutTriple);
|
||||
return base::IsInRange(operand_type, OperandType::kImm,
|
||||
OperandType::kRegOutTriple);
|
||||
}
|
||||
|
||||
// Returns true if |operand_type| is a scalable unsigned byte.
|
||||
static constexpr bool IsScalableUnsignedByte(OperandType operand_type) {
|
||||
return IsInRange(operand_type, OperandType::kIdx, OperandType::kRegCount);
|
||||
return base::IsInRange(operand_type, OperandType::kIdx,
|
||||
OperandType::kRegCount);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -64,7 +64,7 @@ enum class EscapeKind : uint8_t {
|
||||
kUnicode
|
||||
};
|
||||
|
||||
using EscapeKindField = BitField8<EscapeKind, 0, 3>;
|
||||
using EscapeKindField = base::BitField8<EscapeKind, 0, 3>;
|
||||
using MayTerminateStringField = EscapeKindField::Next<bool, 1>;
|
||||
using NumberPartField = MayTerminateStringField::Next<bool, 1>;
|
||||
|
||||
@ -906,7 +906,8 @@ Handle<Object> JsonParser<Char>::ParseJsonNumber() {
|
||||
// Prefix zero is only allowed if it's the only digit before
|
||||
// a decimal point or exponent.
|
||||
c = NextCharacter();
|
||||
if (IsInRange(c, 0, static_cast<int32_t>(unibrow::Latin1::kMaxChar)) &&
|
||||
if (base::IsInRange(c, 0,
|
||||
static_cast<int32_t>(unibrow::Latin1::kMaxChar)) &&
|
||||
IsNumberPart(character_json_scan_flags[c])) {
|
||||
if (V8_UNLIKELY(IsDecimalDigit(c))) {
|
||||
AllowHeapAllocation allow_before_exception;
|
||||
@ -929,7 +930,8 @@ Handle<Object> JsonParser<Char>::ParseJsonNumber() {
|
||||
STATIC_ASSERT(Smi::IsValid(999999999));
|
||||
const int kMaxSmiLength = 9;
|
||||
if ((cursor_ - smi_start) <= kMaxSmiLength &&
|
||||
(!IsInRange(c, 0, static_cast<int32_t>(unibrow::Latin1::kMaxChar)) ||
|
||||
(!base::IsInRange(c, 0,
|
||||
static_cast<int32_t>(unibrow::Latin1::kMaxChar)) ||
|
||||
!IsNumberPart(character_json_scan_flags[c]))) {
|
||||
// Smi.
|
||||
int32_t i = 0;
|
||||
@ -1149,7 +1151,7 @@ JsonString JsonParser<Char>::ScanJsonString(bool needs_internalization) {
|
||||
if (*cursor_ == '\\') {
|
||||
has_escape = true;
|
||||
uc32 c = NextCharacter();
|
||||
if (V8_UNLIKELY(!IsInRange(
|
||||
if (V8_UNLIKELY(!base::IsInRange(
|
||||
c, 0, static_cast<int32_t>(unibrow::Latin1::kMaxChar)))) {
|
||||
AllowHeapAllocation allow_before_exception;
|
||||
ReportUnexpectedCharacter(c);
|
||||
|
@ -66,14 +66,14 @@ class AllocationSite : public Struct {
|
||||
bool IsNested();
|
||||
|
||||
// transition_info bitfields, for constructed array transition info.
|
||||
using ElementsKindBits = BitField<ElementsKind, 0, 5>;
|
||||
using DoNotInlineBit = BitField<bool, 5, 1>;
|
||||
using ElementsKindBits = base::BitField<ElementsKind, 0, 5>;
|
||||
using DoNotInlineBit = base::BitField<bool, 5, 1>;
|
||||
// Unused bits 6-30.
|
||||
|
||||
// Bitfields for pretenure_data
|
||||
using MementoFoundCountBits = BitField<int, 0, 26>;
|
||||
using PretenureDecisionBits = BitField<PretenureDecision, 26, 3>;
|
||||
using DeoptDependentCodeBit = BitField<bool, 29, 1>;
|
||||
using MementoFoundCountBits = base::BitField<int, 0, 26>;
|
||||
using PretenureDecisionBits = base::BitField<PretenureDecision, 26, 3>;
|
||||
using DeoptDependentCodeBit = base::BitField<bool, 29, 1>;
|
||||
STATIC_ASSERT(PretenureDecisionBits::kMax >= kLastPretenureDecisionValue);
|
||||
|
||||
// Increments the mementos found counter and returns true when the first
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef V8_OBJECTS_API_CALLBACKS_H_
|
||||
#define V8_OBJECTS_API_CALLBACKS_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/objects/struct.h"
|
||||
#include "torque-generated/class-definitions-tq.h"
|
||||
|
||||
|
@ -53,7 +53,7 @@ class BigIntBase : public PrimitiveHeapObject {
|
||||
// able to read the length concurrently, the getters and setters are atomic.
|
||||
static const int kLengthFieldBits = 30;
|
||||
STATIC_ASSERT(kMaxLength <= ((1 << kLengthFieldBits) - 1));
|
||||
using SignBits = BitField<bool, 0, 1>;
|
||||
using SignBits = base::BitField<bool, 0, 1>;
|
||||
using LengthBits = SignBits::Next<int, kLengthFieldBits>;
|
||||
STATIC_ASSERT(LengthBits::kLastUsedBit < 32);
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef V8_OBJECTS_CODE_H_
|
||||
#define V8_OBJECTS_CODE_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/codegen/handler-table.h"
|
||||
#include "src/objects/contexts.h"
|
||||
#include "src/objects/fixed-array.h"
|
||||
@ -434,7 +435,7 @@ class Code : public HeapObject {
|
||||
|
||||
class BodyDescriptor;
|
||||
|
||||
// Flags layout. BitField<type, shift, size>.
|
||||
// Flags layout. base::BitField<type, shift, size>.
|
||||
#define CODE_FLAGS_BIT_FIELDS(V, _) \
|
||||
V(HasUnwindingInfoField, bool, 1, _) \
|
||||
V(KindField, Kind, 5, _) \
|
||||
@ -712,8 +713,8 @@ class DependentCode : public WeakFixedArray {
|
||||
|
||||
inline int flags();
|
||||
inline void set_flags(int flags);
|
||||
using GroupField = BitField<int, 0, 3>;
|
||||
using CountField = BitField<int, 3, 27>;
|
||||
using GroupField = base::BitField<int, 0, 3>;
|
||||
using CountField = base::BitField<int, 3, 27>;
|
||||
STATIC_ASSERT(kGroupCount <= GroupField::kMax + 1);
|
||||
|
||||
OBJECT_CONSTRUCTORS(DependentCode, WeakFixedArray);
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/objects/fixed-array.h"
|
||||
#include "src/objects/objects.h"
|
||||
#include "src/objects/struct.h"
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "src/objects/fixed-array.h"
|
||||
// TODO(jkummerow): Consider forward-declaring instead.
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/objects/internal-index.h"
|
||||
#include "src/objects/objects.h"
|
||||
#include "src/objects/struct.h"
|
||||
|
@ -5,10 +5,10 @@
|
||||
#ifndef V8_OBJECTS_ELEMENTS_KIND_H_
|
||||
#define V8_OBJECTS_ELEMENTS_KIND_H_
|
||||
|
||||
#include "src/base/bounds.h"
|
||||
#include "src/base/macros.h"
|
||||
#include "src/common/checks.h"
|
||||
#include "src/flags/flags.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -119,18 +119,18 @@ inline bool IsDictionaryElementsKind(ElementsKind kind) {
|
||||
}
|
||||
|
||||
inline bool IsSloppyArgumentsElementsKind(ElementsKind kind) {
|
||||
return IsInRange(kind, FAST_SLOPPY_ARGUMENTS_ELEMENTS,
|
||||
SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
|
||||
return base::IsInRange(kind, FAST_SLOPPY_ARGUMENTS_ELEMENTS,
|
||||
SLOW_SLOPPY_ARGUMENTS_ELEMENTS);
|
||||
}
|
||||
|
||||
inline bool IsStringWrapperElementsKind(ElementsKind kind) {
|
||||
return IsInRange(kind, FAST_STRING_WRAPPER_ELEMENTS,
|
||||
SLOW_STRING_WRAPPER_ELEMENTS);
|
||||
return base::IsInRange(kind, FAST_STRING_WRAPPER_ELEMENTS,
|
||||
SLOW_STRING_WRAPPER_ELEMENTS);
|
||||
}
|
||||
|
||||
inline bool IsTypedArrayElementsKind(ElementsKind kind) {
|
||||
return IsInRange(kind, FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND,
|
||||
LAST_FIXED_TYPED_ARRAY_ELEMENTS_KIND);
|
||||
return base::IsInRange(kind, FIRST_FIXED_TYPED_ARRAY_ELEMENTS_KIND,
|
||||
LAST_FIXED_TYPED_ARRAY_ELEMENTS_KIND);
|
||||
}
|
||||
|
||||
inline bool IsTerminalElementsKind(ElementsKind kind) {
|
||||
@ -149,7 +149,7 @@ inline bool IsTransitionElementsKind(ElementsKind kind) {
|
||||
}
|
||||
|
||||
inline bool IsDoubleElementsKind(ElementsKind kind) {
|
||||
return IsInRange(kind, PACKED_DOUBLE_ELEMENTS, HOLEY_DOUBLE_ELEMENTS);
|
||||
return base::IsInRange(kind, PACKED_DOUBLE_ELEMENTS, HOLEY_DOUBLE_ELEMENTS);
|
||||
}
|
||||
|
||||
inline bool IsFixedFloatElementsKind(ElementsKind kind) {
|
||||
@ -162,8 +162,8 @@ inline bool IsDoubleOrFloatElementsKind(ElementsKind kind) {
|
||||
|
||||
// This predicate is used for disabling respective functionality in builtins.
|
||||
inline bool IsAnyNonextensibleElementsKindUnchecked(ElementsKind kind) {
|
||||
return IsInRange(kind, FIRST_ANY_NONEXTENSIBLE_ELEMENTS_KIND,
|
||||
LAST_ANY_NONEXTENSIBLE_ELEMENTS_KIND);
|
||||
return base::IsInRange(kind, FIRST_ANY_NONEXTENSIBLE_ELEMENTS_KIND,
|
||||
LAST_ANY_NONEXTENSIBLE_ELEMENTS_KIND);
|
||||
}
|
||||
|
||||
inline bool IsAnyNonextensibleElementsKind(ElementsKind kind) {
|
||||
@ -173,31 +173,33 @@ inline bool IsAnyNonextensibleElementsKind(ElementsKind kind) {
|
||||
}
|
||||
|
||||
inline bool IsNonextensibleElementsKind(ElementsKind kind) {
|
||||
DCHECK_IMPLIES(IsInRange(kind, PACKED_NONEXTENSIBLE_ELEMENTS,
|
||||
HOLEY_NONEXTENSIBLE_ELEMENTS),
|
||||
DCHECK_IMPLIES(base::IsInRange(kind, PACKED_NONEXTENSIBLE_ELEMENTS,
|
||||
HOLEY_NONEXTENSIBLE_ELEMENTS),
|
||||
FLAG_enable_sealed_frozen_elements_kind);
|
||||
return IsInRange(kind, PACKED_NONEXTENSIBLE_ELEMENTS,
|
||||
HOLEY_NONEXTENSIBLE_ELEMENTS);
|
||||
return base::IsInRange(kind, PACKED_NONEXTENSIBLE_ELEMENTS,
|
||||
HOLEY_NONEXTENSIBLE_ELEMENTS);
|
||||
}
|
||||
|
||||
inline bool IsSealedElementsKind(ElementsKind kind) {
|
||||
DCHECK_IMPLIES(IsInRange(kind, PACKED_SEALED_ELEMENTS, HOLEY_SEALED_ELEMENTS),
|
||||
FLAG_enable_sealed_frozen_elements_kind);
|
||||
return IsInRange(kind, PACKED_SEALED_ELEMENTS, HOLEY_SEALED_ELEMENTS);
|
||||
DCHECK_IMPLIES(
|
||||
base::IsInRange(kind, PACKED_SEALED_ELEMENTS, HOLEY_SEALED_ELEMENTS),
|
||||
FLAG_enable_sealed_frozen_elements_kind);
|
||||
return base::IsInRange(kind, PACKED_SEALED_ELEMENTS, HOLEY_SEALED_ELEMENTS);
|
||||
}
|
||||
|
||||
inline bool IsFrozenElementsKind(ElementsKind kind) {
|
||||
DCHECK_IMPLIES(IsInRange(kind, PACKED_FROZEN_ELEMENTS, HOLEY_FROZEN_ELEMENTS),
|
||||
FLAG_enable_sealed_frozen_elements_kind);
|
||||
return IsInRange(kind, PACKED_FROZEN_ELEMENTS, HOLEY_FROZEN_ELEMENTS);
|
||||
DCHECK_IMPLIES(
|
||||
base::IsInRange(kind, PACKED_FROZEN_ELEMENTS, HOLEY_FROZEN_ELEMENTS),
|
||||
FLAG_enable_sealed_frozen_elements_kind);
|
||||
return base::IsInRange(kind, PACKED_FROZEN_ELEMENTS, HOLEY_FROZEN_ELEMENTS);
|
||||
}
|
||||
|
||||
inline bool IsSmiOrObjectElementsKind(ElementsKind kind) {
|
||||
return IsInRange(kind, PACKED_SMI_ELEMENTS, HOLEY_ELEMENTS);
|
||||
return base::IsInRange(kind, PACKED_SMI_ELEMENTS, HOLEY_ELEMENTS);
|
||||
}
|
||||
|
||||
inline bool IsSmiElementsKind(ElementsKind kind) {
|
||||
return IsInRange(kind, PACKED_SMI_ELEMENTS, HOLEY_SMI_ELEMENTS);
|
||||
return base::IsInRange(kind, PACKED_SMI_ELEMENTS, HOLEY_SMI_ELEMENTS);
|
||||
}
|
||||
|
||||
inline bool IsFastNumberElementsKind(ElementsKind kind) {
|
||||
@ -205,7 +207,7 @@ inline bool IsFastNumberElementsKind(ElementsKind kind) {
|
||||
}
|
||||
|
||||
inline bool IsObjectElementsKind(ElementsKind kind) {
|
||||
return IsInRange(kind, PACKED_ELEMENTS, HOLEY_ELEMENTS);
|
||||
return base::IsInRange(kind, PACKED_ELEMENTS, HOLEY_ELEMENTS);
|
||||
}
|
||||
|
||||
inline bool IsAnyHoleyNonextensibleElementsKind(ElementsKind kind) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/base/logging.h"
|
||||
#include "src/base/macros.h"
|
||||
#include "src/common/globals.h"
|
||||
@ -554,8 +555,8 @@ class FeedbackMetadata : public HeapObject {
|
||||
void SetKind(FeedbackSlot slot, FeedbackSlotKind kind);
|
||||
|
||||
using VectorICComputer =
|
||||
BitSetComputer<FeedbackSlotKind, kFeedbackSlotKindBits,
|
||||
kInt32Size * kBitsPerByte, uint32_t>;
|
||||
base::BitSetComputer<FeedbackSlotKind, kFeedbackSlotKindBits,
|
||||
kInt32Size * kBitsPerByte, uint32_t>;
|
||||
|
||||
OBJECT_CONSTRUCTORS(FeedbackMetadata, HeapObject);
|
||||
};
|
||||
@ -699,8 +700,8 @@ class V8_EXPORT_PRIVATE FeedbackNexus final {
|
||||
// count (taken from the type feedback vector).
|
||||
float ComputeCallFrequency();
|
||||
|
||||
using SpeculationModeField = BitField<SpeculationMode, 0, 1>;
|
||||
using CallCountField = BitField<uint32_t, 1, 31>;
|
||||
using SpeculationModeField = base::BitField<SpeculationMode, 0, 1>;
|
||||
using CallCountField = base::BitField<uint32_t, 1, 31>;
|
||||
|
||||
// For InstanceOf ICs.
|
||||
MaybeHandle<JSObject> GetConstructorFeedback() const;
|
||||
|
@ -110,7 +110,7 @@ class FieldIndex final {
|
||||
(kDescriptorIndexBitCount + 1 + kTaggedSizeLog2);
|
||||
|
||||
// Index from beginning of object.
|
||||
using OffsetBits = BitField64<int, 0, kOffsetBitsSize>;
|
||||
using OffsetBits = base::BitField64<int, 0, kOffsetBitsSize>;
|
||||
using IsInObjectBits = OffsetBits::Next<bool, 1>;
|
||||
using EncodingBits = IsInObjectBits::Next<Encoding, 2>;
|
||||
// Number of inobject properties.
|
||||
|
@ -5,7 +5,7 @@
|
||||
#ifndef V8_OBJECTS_FUNCTION_KIND_H_
|
||||
#define V8_OBJECTS_FUNCTION_KIND_H_
|
||||
|
||||
#include "src/utils/utils.h"
|
||||
#include "src/base/bounds.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -57,12 +57,13 @@ enum FunctionKind : uint8_t {
|
||||
};
|
||||
|
||||
inline bool IsArrowFunction(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kArrowFunction,
|
||||
FunctionKind::kAsyncArrowFunction);
|
||||
return base::IsInRange(kind, FunctionKind::kArrowFunction,
|
||||
FunctionKind::kAsyncArrowFunction);
|
||||
}
|
||||
|
||||
inline bool IsModule(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kModule, FunctionKind::kAsyncModule);
|
||||
return base::IsInRange(kind, FunctionKind::kModule,
|
||||
FunctionKind::kAsyncModule);
|
||||
}
|
||||
|
||||
inline bool IsAsyncModule(FunctionKind kind) {
|
||||
@ -70,18 +71,18 @@ inline bool IsAsyncModule(FunctionKind kind) {
|
||||
}
|
||||
|
||||
inline bool IsAsyncGeneratorFunction(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kAsyncConciseGeneratorMethod,
|
||||
FunctionKind::kAsyncGeneratorFunction);
|
||||
return base::IsInRange(kind, FunctionKind::kAsyncConciseGeneratorMethod,
|
||||
FunctionKind::kAsyncGeneratorFunction);
|
||||
}
|
||||
|
||||
inline bool IsGeneratorFunction(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kAsyncConciseGeneratorMethod,
|
||||
FunctionKind::kConciseGeneratorMethod);
|
||||
return base::IsInRange(kind, FunctionKind::kAsyncConciseGeneratorMethod,
|
||||
FunctionKind::kConciseGeneratorMethod);
|
||||
}
|
||||
|
||||
inline bool IsAsyncFunction(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kAsyncArrowFunction,
|
||||
FunctionKind::kAsyncGeneratorFunction);
|
||||
return base::IsInRange(kind, FunctionKind::kAsyncArrowFunction,
|
||||
FunctionKind::kAsyncGeneratorFunction);
|
||||
}
|
||||
|
||||
inline bool IsResumableFunction(FunctionKind kind) {
|
||||
@ -89,19 +90,19 @@ inline bool IsResumableFunction(FunctionKind kind) {
|
||||
}
|
||||
|
||||
inline bool IsConciseMethod(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kAsyncConciseMethod,
|
||||
FunctionKind::kAsyncConciseGeneratorMethod) ||
|
||||
IsInRange(kind, FunctionKind::kConciseGeneratorMethod,
|
||||
FunctionKind::kClassMembersInitializerFunction);
|
||||
return base::IsInRange(kind, FunctionKind::kAsyncConciseMethod,
|
||||
FunctionKind::kAsyncConciseGeneratorMethod) ||
|
||||
base::IsInRange(kind, FunctionKind::kConciseGeneratorMethod,
|
||||
FunctionKind::kClassMembersInitializerFunction);
|
||||
}
|
||||
|
||||
inline bool IsStrictFunctionWithoutPrototype(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kGetterFunction,
|
||||
FunctionKind::kAsyncArrowFunction) ||
|
||||
IsInRange(kind, FunctionKind::kAsyncConciseMethod,
|
||||
FunctionKind::kAsyncConciseGeneratorMethod) ||
|
||||
IsInRange(kind, FunctionKind::kConciseGeneratorMethod,
|
||||
FunctionKind::kClassMembersInitializerFunction);
|
||||
return base::IsInRange(kind, FunctionKind::kGetterFunction,
|
||||
FunctionKind::kAsyncArrowFunction) ||
|
||||
base::IsInRange(kind, FunctionKind::kAsyncConciseMethod,
|
||||
FunctionKind::kAsyncConciseGeneratorMethod) ||
|
||||
base::IsInRange(kind, FunctionKind::kConciseGeneratorMethod,
|
||||
FunctionKind::kClassMembersInitializerFunction);
|
||||
}
|
||||
|
||||
inline bool IsGetterFunction(FunctionKind kind) {
|
||||
@ -113,28 +114,28 @@ inline bool IsSetterFunction(FunctionKind kind) {
|
||||
}
|
||||
|
||||
inline bool IsAccessorFunction(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kGetterFunction,
|
||||
FunctionKind::kSetterFunction);
|
||||
return base::IsInRange(kind, FunctionKind::kGetterFunction,
|
||||
FunctionKind::kSetterFunction);
|
||||
}
|
||||
|
||||
inline bool IsDefaultConstructor(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kDefaultBaseConstructor,
|
||||
FunctionKind::kDefaultDerivedConstructor);
|
||||
return base::IsInRange(kind, FunctionKind::kDefaultBaseConstructor,
|
||||
FunctionKind::kDefaultDerivedConstructor);
|
||||
}
|
||||
|
||||
inline bool IsBaseConstructor(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kBaseConstructor,
|
||||
FunctionKind::kDefaultBaseConstructor);
|
||||
return base::IsInRange(kind, FunctionKind::kBaseConstructor,
|
||||
FunctionKind::kDefaultBaseConstructor);
|
||||
}
|
||||
|
||||
inline bool IsDerivedConstructor(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kDefaultDerivedConstructor,
|
||||
FunctionKind::kDerivedConstructor);
|
||||
return base::IsInRange(kind, FunctionKind::kDefaultDerivedConstructor,
|
||||
FunctionKind::kDerivedConstructor);
|
||||
}
|
||||
|
||||
inline bool IsClassConstructor(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kBaseConstructor,
|
||||
FunctionKind::kDerivedConstructor);
|
||||
return base::IsInRange(kind, FunctionKind::kBaseConstructor,
|
||||
FunctionKind::kDerivedConstructor);
|
||||
}
|
||||
|
||||
inline bool IsClassMembersInitializerFunction(FunctionKind kind) {
|
||||
@ -142,8 +143,8 @@ inline bool IsClassMembersInitializerFunction(FunctionKind kind) {
|
||||
}
|
||||
|
||||
inline bool IsConstructable(FunctionKind kind) {
|
||||
return IsInRange(kind, FunctionKind::kNormalFunction,
|
||||
FunctionKind::kDerivedConstructor);
|
||||
return base::IsInRange(kind, FunctionKind::kNormalFunction,
|
||||
FunctionKind::kDerivedConstructor);
|
||||
}
|
||||
|
||||
inline const char* FunctionKind2String(FunctionKind kind) {
|
||||
|
@ -24,7 +24,7 @@ INSTANCE_TYPE_CHECKERS_SINGLE(INSTANCE_TYPE_CHECKER)
|
||||
template <InstanceType lower_limit, InstanceType upper_limit>
|
||||
struct InstanceRangeChecker {
|
||||
static constexpr bool Check(InstanceType value) {
|
||||
return IsInRange(value, lower_limit, upper_limit);
|
||||
return base::IsInRange(value, lower_limit, upper_limit);
|
||||
}
|
||||
};
|
||||
template <InstanceType upper_limit>
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef V8_OBJECTS_JS_ARRAY_BUFFER_H_
|
||||
#define V8_OBJECTS_JS_ARRAY_BUFFER_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/objects/backing-store.h"
|
||||
#include "src/objects/js-objects.h"
|
||||
|
||||
|
@ -250,13 +250,13 @@ std::string GetGMTTzID(Isolate* isolate, const std::string& input) {
|
||||
break;
|
||||
case 9:
|
||||
if ((input[7] == '+' || input[7] == '-') &&
|
||||
IsInRange(input[8], '0', '9')) {
|
||||
base::IsInRange(input[8], '0', '9')) {
|
||||
return ret + input[7] + input[8];
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
if ((input[7] == '+' || input[7] == '-') && (input[8] == '1') &&
|
||||
IsInRange(input[9], '0', '4')) {
|
||||
base::IsInRange(input[9], '0', '4')) {
|
||||
return ret + input[7] + input[8] + input[9];
|
||||
}
|
||||
break;
|
||||
@ -267,18 +267,18 @@ std::string GetGMTTzID(Isolate* isolate, const std::string& input) {
|
||||
// Locale independenty version of isalpha for ascii range. This will return
|
||||
// false if the ch is alpha but not in ascii range.
|
||||
bool IsAsciiAlpha(char ch) {
|
||||
return IsInRange(ch, 'A', 'Z') || IsInRange(ch, 'a', 'z');
|
||||
return base::IsInRange(ch, 'A', 'Z') || base::IsInRange(ch, 'a', 'z');
|
||||
}
|
||||
|
||||
// Locale independent toupper for ascii range. This will not return İ (dotted I)
|
||||
// for i under Turkish locale while std::toupper may.
|
||||
char LocaleIndependentAsciiToUpper(char ch) {
|
||||
return (IsInRange(ch, 'a', 'z')) ? (ch - 'a' + 'A') : ch;
|
||||
return (base::IsInRange(ch, 'a', 'z')) ? (ch - 'a' + 'A') : ch;
|
||||
}
|
||||
|
||||
// Locale independent tolower for ascii range.
|
||||
char LocaleIndependentAsciiToLower(char ch) {
|
||||
return (IsInRange(ch, 'A', 'Z')) ? (ch - 'A' + 'a') : ch;
|
||||
return (base::IsInRange(ch, 'A', 'Z')) ? (ch - 'A' + 'a') : ch;
|
||||
}
|
||||
|
||||
// Returns titlecased location, bueNos_airES -> Buenos_Aires
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/objects/intl-objects.h"
|
||||
#include "src/objects/managed.h"
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/objects/managed.h"
|
||||
|
@ -282,7 +282,9 @@ int CurrencyDigits(const icu::UnicodeString& currency) {
|
||||
return U_SUCCESS(status) ? fraction_digits : 2;
|
||||
}
|
||||
|
||||
bool IsAToZ(char ch) { return IsInRange(AsciiAlphaToLower(ch), 'a', 'z'); }
|
||||
bool IsAToZ(char ch) {
|
||||
return base::IsInRange(AsciiAlphaToLower(ch), 'a', 'z');
|
||||
}
|
||||
|
||||
// ecma402/#sec-iswellformedcurrencycode
|
||||
bool IsWellFormedCurrencyCode(const std::string& currency) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/objects/intl-objects.h"
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/objects/intl-objects.h"
|
||||
|
@ -70,7 +70,7 @@ class JSPromise : public TorqueGeneratedJSPromise<JSPromise, JSObject> {
|
||||
static const int kStatusBits = 2;
|
||||
static const int kHasHandlerBit = 2;
|
||||
static const int kHandledHintBit = 3;
|
||||
using AsyncTaskIdField = BitField<int, kHandledHintBit + 1, 22>;
|
||||
using AsyncTaskIdField = base::BitField<int, kHandledHintBit + 1, 22>;
|
||||
|
||||
static const int kStatusShift = 0;
|
||||
static const int kStatusMask = 0x3;
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/objects/managed.h"
|
||||
|
@ -9,6 +9,7 @@
|
||||
#ifndef V8_OBJECTS_JS_SEGMENT_ITERATOR_H_
|
||||
#define V8_OBJECTS_JS_SEGMENT_ITERATOR_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/objects/js-segmenter.h"
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/execution/isolate.h"
|
||||
#include "src/heap/factory.h"
|
||||
#include "src/objects/managed.h"
|
||||
|
@ -69,7 +69,7 @@ class JSFinalizationGroup : public JSObject {
|
||||
TORQUE_GENERATED_JS_FINALIZATION_GROUP_FIELDS)
|
||||
|
||||
// Bitfields in flags.
|
||||
using ScheduledForCleanupField = BitField<bool, 0, 1>;
|
||||
using ScheduledForCleanupField = base::BitField<bool, 0, 1>;
|
||||
|
||||
OBJECT_CONSTRUCTORS(JSFinalizationGroup, JSObject);
|
||||
};
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef V8_OBJECTS_LITERAL_OBJECTS_H_
|
||||
#define V8_OBJECTS_LITERAL_OBJECTS_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/objects/fixed-array.h"
|
||||
#include "src/objects/struct.h"
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef V8_OBJECTS_MAP_H_
|
||||
#define V8_OBJECTS_MAP_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/objects/code.h"
|
||||
#include "src/objects/heap-object.h"
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef V8_OBJECTS_NAME_H_
|
||||
#define V8_OBJECTS_NAME_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/objects/objects.h"
|
||||
#include "src/objects/primitive-heap-object.h"
|
||||
|
||||
@ -114,10 +115,10 @@ class Name : public TorqueGeneratedName<Name, PrimitiveHeapObject> {
|
||||
STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
|
||||
|
||||
using ArrayIndexValueBits =
|
||||
BitField<unsigned int, kNofHashBitFields, kArrayIndexValueBits>;
|
||||
base::BitField<unsigned int, kNofHashBitFields, kArrayIndexValueBits>;
|
||||
using ArrayIndexLengthBits =
|
||||
BitField<unsigned int, kNofHashBitFields + kArrayIndexValueBits,
|
||||
kArrayIndexLengthBits>;
|
||||
base::BitField<unsigned int, kNofHashBitFields + kArrayIndexValueBits,
|
||||
kArrayIndexLengthBits>;
|
||||
|
||||
// Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
|
||||
// could use a mask to test if the length of string is less than or equal to
|
||||
|
@ -2186,11 +2186,12 @@ int HeapObject::SizeFromMap(Map map) const {
|
||||
if (instance_size != kVariableSizeSentinel) return instance_size;
|
||||
// Only inline the most frequent cases.
|
||||
InstanceType instance_type = map.instance_type();
|
||||
if (IsInRange(instance_type, FIRST_FIXED_ARRAY_TYPE, LAST_FIXED_ARRAY_TYPE)) {
|
||||
if (base::IsInRange(instance_type, FIRST_FIXED_ARRAY_TYPE,
|
||||
LAST_FIXED_ARRAY_TYPE)) {
|
||||
return FixedArray::SizeFor(
|
||||
FixedArray::unchecked_cast(*this).synchronized_length());
|
||||
}
|
||||
if (IsInRange(instance_type, FIRST_CONTEXT_TYPE, LAST_CONTEXT_TYPE)) {
|
||||
if (base::IsInRange(instance_type, FIRST_CONTEXT_TYPE, LAST_CONTEXT_TYPE)) {
|
||||
if (instance_type == NATIVE_CONTEXT_TYPE) return NativeContext::kSize;
|
||||
return Context::SizeFor(Context::unchecked_cast(*this).length());
|
||||
}
|
||||
@ -2231,8 +2232,8 @@ int HeapObject::SizeFromMap(Map map) const {
|
||||
return DescriptorArray::SizeFor(
|
||||
DescriptorArray::unchecked_cast(*this).number_of_all_descriptors());
|
||||
}
|
||||
if (IsInRange(instance_type, FIRST_WEAK_FIXED_ARRAY_TYPE,
|
||||
LAST_WEAK_FIXED_ARRAY_TYPE)) {
|
||||
if (base::IsInRange(instance_type, FIRST_WEAK_FIXED_ARRAY_TYPE,
|
||||
LAST_WEAK_FIXED_ARRAY_TYPE)) {
|
||||
return WeakFixedArray::SizeFor(
|
||||
WeakFixedArray::unchecked_cast(*this).synchronized_length());
|
||||
}
|
||||
|
@ -61,10 +61,10 @@ class PropertyArray : public HeapObject {
|
||||
using BodyDescriptor = FlexibleBodyDescriptor<kHeaderSize>;
|
||||
|
||||
static const int kLengthFieldSize = 10;
|
||||
using LengthField = BitField<int, 0, kLengthFieldSize>;
|
||||
using LengthField = base::BitField<int, 0, kLengthFieldSize>;
|
||||
static const int kMaxLength = LengthField::kMax;
|
||||
using HashField =
|
||||
BitField<int, kLengthFieldSize, kSmiValueSize - kLengthFieldSize - 1>;
|
||||
using HashField = base::BitField<int, kLengthFieldSize,
|
||||
kSmiValueSize - kLengthFieldSize - 1>;
|
||||
|
||||
static const int kNoHashSentinel = 0;
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef V8_OBJECTS_PROPERTY_DESCRIPTOR_OBJECT_H_
|
||||
#define V8_OBJECTS_PROPERTY_DESCRIPTOR_OBJECT_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/objects/fixed-array.h"
|
||||
#include "src/objects/objects.h"
|
||||
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include "include/v8.h"
|
||||
#include "src/utils/allocation.h"
|
||||
// TODO(bmeurer): Remove once FLAG_modify_field_representation_inplace is gone.
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/flags/flags.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -322,7 +322,7 @@ class PropertyDetails {
|
||||
|
||||
// Bit fields in value_ (type, shift, size). Must be public so the
|
||||
// constants can be embedded in generated code.
|
||||
using KindField = BitField<PropertyKind, 0, 1>;
|
||||
using KindField = base::BitField<PropertyKind, 0, 1>;
|
||||
using LocationField = KindField::Next<PropertyLocation, 1>;
|
||||
using ConstnessField = LocationField::Next<PropertyConstness, 1>;
|
||||
using AttributesField = ConstnessField::Next<PropertyAttributes, 3>;
|
||||
|
@ -248,7 +248,7 @@ class ScopeInfo : public FixedArray {
|
||||
enum VariableAllocationInfo { NONE, STACK, CONTEXT, UNUSED };
|
||||
|
||||
// Properties of scopes.
|
||||
using ScopeTypeField = BitField<ScopeType, 0, 4>;
|
||||
using ScopeTypeField = base::BitField<ScopeType, 0, 4>;
|
||||
using SloppyEvalCanExtendVarsField = ScopeTypeField::Next<bool, 1>;
|
||||
STATIC_ASSERT(LanguageModeSize == 2);
|
||||
using LanguageModeField = SloppyEvalCanExtendVarsField::Next<LanguageMode, 1>;
|
||||
@ -347,7 +347,7 @@ class ScopeInfo : public FixedArray {
|
||||
static const int kPositionInfoEntries = 2;
|
||||
|
||||
// Properties of variables.
|
||||
using VariableModeField = BitField<VariableMode, 0, 4>;
|
||||
using VariableModeField = base::BitField<VariableMode, 0, 4>;
|
||||
using InitFlagField = VariableModeField::Next<InitializationFlag, 1>;
|
||||
using MaybeAssignedFlagField = InitFlagField::Next<MaybeAssignedFlag, 1>;
|
||||
using ParameterNumberField = MaybeAssignedFlagField::Next<uint32_t, 16>;
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/codegen/bailout-reason.h"
|
||||
#include "src/objects/compressed-slots.h"
|
||||
#include "src/objects/function-kind.h"
|
||||
|
@ -166,7 +166,7 @@ class ObjectTemplateInfo
|
||||
inline ObjectTemplateInfo GetParent(Isolate* isolate);
|
||||
|
||||
private:
|
||||
using IsImmutablePrototype = BitField<bool, 0, 1>;
|
||||
using IsImmutablePrototype = base::BitField<bool, 0, 1>;
|
||||
using EmbedderFieldCount = IsImmutablePrototype::Next<int, 29>;
|
||||
|
||||
TQ_OBJECT_CONSTRUCTORS(ObjectTemplateInfo)
|
||||
|
@ -196,7 +196,7 @@ class ExpressionScope {
|
||||
}
|
||||
|
||||
bool IsCertainlyDeclaration() const {
|
||||
return IsInRange(type_, kParameterDeclaration, kLexicalDeclaration);
|
||||
return base::IsInRange(type_, kParameterDeclaration, kLexicalDeclaration);
|
||||
}
|
||||
|
||||
int SetInitializers(int variable_index, int peek_position) {
|
||||
@ -263,14 +263,15 @@ class ExpressionScope {
|
||||
#endif
|
||||
|
||||
bool CanBeExpression() const {
|
||||
return IsInRange(type_, kExpression, kMaybeAsyncArrowParameterDeclaration);
|
||||
return base::IsInRange(type_, kExpression,
|
||||
kMaybeAsyncArrowParameterDeclaration);
|
||||
}
|
||||
bool CanBeDeclaration() const {
|
||||
return IsInRange(type_, kMaybeArrowParameterDeclaration,
|
||||
kLexicalDeclaration);
|
||||
return base::IsInRange(type_, kMaybeArrowParameterDeclaration,
|
||||
kLexicalDeclaration);
|
||||
}
|
||||
bool IsVariableDeclaration() const {
|
||||
return IsInRange(type_, kVarDeclaration, kLexicalDeclaration);
|
||||
return base::IsInRange(type_, kVarDeclaration, kLexicalDeclaration);
|
||||
}
|
||||
bool IsLexicalDeclaration() const { return type_ == kLexicalDeclaration; }
|
||||
bool IsAsyncArrowHeadParsingScope() const {
|
||||
@ -299,17 +300,17 @@ class ExpressionScope {
|
||||
}
|
||||
|
||||
bool IsArrowHeadParsingScope() const {
|
||||
return IsInRange(type_, kMaybeArrowParameterDeclaration,
|
||||
kMaybeAsyncArrowParameterDeclaration);
|
||||
return base::IsInRange(type_, kMaybeArrowParameterDeclaration,
|
||||
kMaybeAsyncArrowParameterDeclaration);
|
||||
}
|
||||
bool IsCertainlyPattern() const { return IsCertainlyDeclaration(); }
|
||||
bool CanBeParameterDeclaration() const {
|
||||
return IsInRange(type_, kMaybeArrowParameterDeclaration,
|
||||
kParameterDeclaration);
|
||||
return base::IsInRange(type_, kMaybeArrowParameterDeclaration,
|
||||
kParameterDeclaration);
|
||||
}
|
||||
bool CanBeArrowParameterDeclaration() const {
|
||||
return IsInRange(type_, kMaybeArrowParameterDeclaration,
|
||||
kMaybeAsyncArrowParameterDeclaration);
|
||||
return base::IsInRange(type_, kMaybeArrowParameterDeclaration,
|
||||
kMaybeAsyncArrowParameterDeclaration);
|
||||
}
|
||||
bool IsCertainlyParameterDeclaration() const {
|
||||
return type_ == kParameterDeclaration;
|
||||
|
@ -154,7 +154,7 @@ static const struct PerfectKeywordHashTableEntry kPerfectKeywordHashTable[64] =
|
||||
{"", Token::IDENTIFIER}};
|
||||
|
||||
inline Token::Value PerfectKeywordHash::GetToken(const char* str, int len) {
|
||||
if (IsInRange(len, MIN_WORD_LENGTH, MAX_WORD_LENGTH)) {
|
||||
if (base::IsInRange(len, MIN_WORD_LENGTH, MAX_WORD_LENGTH)) {
|
||||
unsigned int key = Hash(str, len) & 0x3f;
|
||||
|
||||
DCHECK_LT(key, arraysize(kPerfectKeywordLengthTable));
|
||||
|
@ -1051,8 +1051,8 @@ class ParserBase {
|
||||
ExpressionT ParseArrayLiteral();
|
||||
|
||||
inline static bool IsAccessor(ParsePropertyKind kind) {
|
||||
return IsInRange(kind, ParsePropertyKind::kAccessorGetter,
|
||||
ParsePropertyKind::kAccessorSetter);
|
||||
return base::IsInRange(kind, ParsePropertyKind::kAccessorGetter,
|
||||
ParsePropertyKind::kAccessorSetter);
|
||||
}
|
||||
|
||||
ExpressionT ParseProperty(ParsePropertyInfo* prop_info);
|
||||
@ -1503,7 +1503,7 @@ template <typename Impl>
|
||||
typename ParserBase<Impl>::IdentifierT
|
||||
ParserBase<Impl>::ParseAndClassifyIdentifier(Token::Value next) {
|
||||
DCHECK_EQ(scanner()->current_token(), next);
|
||||
if (V8_LIKELY(IsInRange(next, Token::IDENTIFIER, Token::ASYNC))) {
|
||||
if (V8_LIKELY(base::IsInRange(next, Token::IDENTIFIER, Token::ASYNC))) {
|
||||
IdentifierT name = impl()->GetIdentifier();
|
||||
if (V8_UNLIKELY(impl()->IsArguments(name) &&
|
||||
scope()->ShouldBanArguments())) {
|
||||
@ -2013,7 +2013,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseProperty(
|
||||
}
|
||||
|
||||
if (prop_info->kind == ParsePropertyKind::kNotSet &&
|
||||
IsInRange(peek(), Token::GET, Token::SET)) {
|
||||
base::IsInRange(peek(), Token::GET, Token::SET)) {
|
||||
Token::Value token = Next();
|
||||
if (prop_info->ParsePropertyKindFromToken(peek())) {
|
||||
prop_info->name = impl()->GetIdentifier();
|
||||
|
@ -21,7 +21,7 @@ namespace internal {
|
||||
|
||||
namespace {
|
||||
|
||||
using ScopeSloppyEvalCanExtendVarsField = BitField8<bool, 0, 1>;
|
||||
using ScopeSloppyEvalCanExtendVarsField = base::BitField8<bool, 0, 1>;
|
||||
using InnerScopeCallsEvalField =
|
||||
ScopeSloppyEvalCanExtendVarsField::Next<bool, 1>;
|
||||
using NeedsPrivateNameContextChainRecalcField =
|
||||
@ -29,14 +29,14 @@ using NeedsPrivateNameContextChainRecalcField =
|
||||
using ShouldSaveClassVariableIndexField =
|
||||
NeedsPrivateNameContextChainRecalcField::Next<bool, 1>;
|
||||
|
||||
using VariableMaybeAssignedField = BitField8<bool, 0, 1>;
|
||||
using VariableMaybeAssignedField = base::BitField8<bool, 0, 1>;
|
||||
using VariableContextAllocatedField = VariableMaybeAssignedField::Next<bool, 1>;
|
||||
|
||||
using HasDataField = BitField<bool, 0, 1>;
|
||||
using HasDataField = base::BitField<bool, 0, 1>;
|
||||
using LengthEqualsParametersField = HasDataField::Next<bool, 1>;
|
||||
using NumberOfParametersField = LengthEqualsParametersField::Next<uint16_t, 16>;
|
||||
|
||||
using LanguageField = BitField8<LanguageMode, 0, 1>;
|
||||
using LanguageField = base::BitField8<LanguageMode, 0, 1>;
|
||||
using UsesSuperField = LanguageField::Next<bool, 1>;
|
||||
STATIC_ASSERT(LanguageModeSize <= LanguageField::kNumValues);
|
||||
|
||||
|
@ -61,7 +61,7 @@ class PreParserIdentifier {
|
||||
bool IsArguments() const { return type_ == kArgumentsIdentifier; }
|
||||
bool IsEvalOrArguments() const {
|
||||
STATIC_ASSERT(kEvalIdentifier + 1 == kArgumentsIdentifier);
|
||||
return IsInRange(type_, kEvalIdentifier, kArgumentsIdentifier);
|
||||
return base::IsInRange(type_, kEvalIdentifier, kArgumentsIdentifier);
|
||||
}
|
||||
bool IsConstructor() const { return type_ == kConstructorIdentifier; }
|
||||
bool IsAwait() const { return type_ == kAwaitIdentifier; }
|
||||
@ -226,8 +226,8 @@ class PreParserExpression {
|
||||
|
||||
bool IsPattern() const {
|
||||
STATIC_ASSERT(kObjectLiteralExpression + 1 == kArrayLiteralExpression);
|
||||
return IsInRange(TypeField::decode(code_), kObjectLiteralExpression,
|
||||
kArrayLiteralExpression);
|
||||
return base::IsInRange(TypeField::decode(code_), kObjectLiteralExpression,
|
||||
kArrayLiteralExpression);
|
||||
}
|
||||
|
||||
bool IsStringLiteral() const {
|
||||
@ -345,7 +345,7 @@ class PreParserExpression {
|
||||
: code_(expression_code) {}
|
||||
|
||||
// The first three bits are for the Type.
|
||||
using TypeField = BitField<Type, 0, 3>;
|
||||
using TypeField = base::BitField<Type, 0, 3>;
|
||||
|
||||
// The high order bit applies only to nodes which would inherit from the
|
||||
// Expression ASTNode --- This is by necessity, due to the fact that
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "src/parsing/keywords-gen.h"
|
||||
#include "src/parsing/scanner.h"
|
||||
#include "src/strings/char-predicates-inl.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
@ -913,7 +913,7 @@ Token::Value Scanner::ScanIdentifierOrKeywordInnerSlow(bool escaped,
|
||||
Vector<const uint8_t> chars = next().literal_chars.one_byte_literal();
|
||||
Token::Value token =
|
||||
KeywordOrIdentifierToken(chars.begin(), chars.length());
|
||||
if (IsInRange(token, Token::IDENTIFIER, Token::YIELD)) return token;
|
||||
if (base::IsInRange(token, Token::IDENTIFIER, Token::YIELD)) return token;
|
||||
|
||||
if (token == Token::FUTURE_STRICT_RESERVED_WORD) {
|
||||
if (escaped) return Token::ESCAPED_STRICT_RESERVED_WORD;
|
||||
@ -923,7 +923,7 @@ Token::Value Scanner::ScanIdentifierOrKeywordInnerSlow(bool escaped,
|
||||
if (!escaped) return token;
|
||||
|
||||
STATIC_ASSERT(Token::LET + 1 == Token::STATIC);
|
||||
if (IsInRange(token, Token::LET, Token::STATIC)) {
|
||||
if (base::IsInRange(token, Token::LET, Token::STATIC)) {
|
||||
return Token::ESCAPED_STRICT_RESERVED_WORD;
|
||||
}
|
||||
return Token::ESCAPED_KEYWORD;
|
||||
|
@ -257,7 +257,7 @@ class V8_EXPORT_PRIVATE Scanner {
|
||||
Location() : beg_pos(0), end_pos(0) { }
|
||||
|
||||
int length() const { return end_pos - beg_pos; }
|
||||
bool IsValid() const { return IsInRange(beg_pos, 0, end_pos); }
|
||||
bool IsValid() const { return base::IsInRange(beg_pos, 0, end_pos); }
|
||||
|
||||
static Location invalid() { return Location(-1, 0); }
|
||||
|
||||
@ -447,13 +447,13 @@ class V8_EXPORT_PRIVATE Scanner {
|
||||
return token == Token::PRIVATE_NAME || token == Token::ILLEGAL ||
|
||||
token == Token::ESCAPED_KEYWORD || token == Token::UNINITIALIZED ||
|
||||
token == Token::REGEXP_LITERAL ||
|
||||
IsInRange(token, Token::NUMBER, Token::STRING) ||
|
||||
base::IsInRange(token, Token::NUMBER, Token::STRING) ||
|
||||
Token::IsAnyIdentifier(token) || Token::IsKeyword(token) ||
|
||||
IsInRange(token, Token::TEMPLATE_SPAN, Token::TEMPLATE_TAIL);
|
||||
base::IsInRange(token, Token::TEMPLATE_SPAN, Token::TEMPLATE_TAIL);
|
||||
}
|
||||
bool CanAccessRawLiteral() const {
|
||||
return token == Token::ILLEGAL || token == Token::UNINITIALIZED ||
|
||||
IsInRange(token, Token::TEMPLATE_SPAN, Token::TEMPLATE_TAIL);
|
||||
base::IsInRange(token, Token::TEMPLATE_SPAN, Token::TEMPLATE_TAIL);
|
||||
}
|
||||
#endif // DEBUG
|
||||
};
|
||||
@ -468,11 +468,11 @@ class V8_EXPORT_PRIVATE Scanner {
|
||||
};
|
||||
|
||||
inline bool IsValidBigIntKind(NumberKind kind) {
|
||||
return IsInRange(kind, BINARY, DECIMAL);
|
||||
return base::IsInRange(kind, BINARY, DECIMAL);
|
||||
}
|
||||
|
||||
inline bool IsDecimalNumberKind(NumberKind kind) {
|
||||
return IsInRange(kind, DECIMAL, DECIMAL_WITH_LEADING_ZERO);
|
||||
return base::IsInRange(kind, DECIMAL, DECIMAL_WITH_LEADING_ZERO);
|
||||
}
|
||||
|
||||
static const int kCharacterLookaheadBufferSize = 1;
|
||||
|
@ -5,9 +5,10 @@
|
||||
#ifndef V8_PARSING_TOKEN_H_
|
||||
#define V8_PARSING_TOKEN_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/base/bounds.h"
|
||||
#include "src/base/logging.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -217,7 +218,7 @@ class V8_EXPORT_PRIVATE Token {
|
||||
return name_[token];
|
||||
}
|
||||
|
||||
using IsKeywordBits = BitField8<bool, 0, 1>;
|
||||
using IsKeywordBits = base::BitField8<bool, 0, 1>;
|
||||
using IsPropertyNameBits = IsKeywordBits::Next<bool, 1>;
|
||||
|
||||
// Predicates
|
||||
@ -233,81 +234,85 @@ class V8_EXPORT_PRIVATE Token {
|
||||
LanguageMode language_mode,
|
||||
bool is_generator,
|
||||
bool disallow_await) {
|
||||
if (V8_LIKELY(IsInRange(token, IDENTIFIER, ASYNC))) return true;
|
||||
if (V8_LIKELY(base::IsInRange(token, IDENTIFIER, ASYNC))) return true;
|
||||
if (token == AWAIT) return !disallow_await;
|
||||
if (token == YIELD) return !is_generator && is_sloppy(language_mode);
|
||||
return IsStrictReservedWord(token) && is_sloppy(language_mode);
|
||||
}
|
||||
|
||||
static bool IsCallable(Value token) {
|
||||
return IsInRange(token, SUPER, ESCAPED_STRICT_RESERVED_WORD);
|
||||
return base::IsInRange(token, SUPER, ESCAPED_STRICT_RESERVED_WORD);
|
||||
}
|
||||
|
||||
static bool IsAutoSemicolon(Value token) {
|
||||
return IsInRange(token, SEMICOLON, EOS);
|
||||
return base::IsInRange(token, SEMICOLON, EOS);
|
||||
}
|
||||
|
||||
static bool IsAnyIdentifier(Value token) {
|
||||
return IsInRange(token, IDENTIFIER, ESCAPED_STRICT_RESERVED_WORD);
|
||||
return base::IsInRange(token, IDENTIFIER, ESCAPED_STRICT_RESERVED_WORD);
|
||||
}
|
||||
|
||||
static bool IsStrictReservedWord(Value token) {
|
||||
return IsInRange(token, YIELD, ESCAPED_STRICT_RESERVED_WORD);
|
||||
return base::IsInRange(token, YIELD, ESCAPED_STRICT_RESERVED_WORD);
|
||||
}
|
||||
|
||||
static bool IsLiteral(Value token) {
|
||||
return IsInRange(token, NULL_LITERAL, STRING);
|
||||
return base::IsInRange(token, NULL_LITERAL, STRING);
|
||||
}
|
||||
|
||||
static bool IsTemplate(Value token) {
|
||||
return IsInRange(token, TEMPLATE_SPAN, TEMPLATE_TAIL);
|
||||
return base::IsInRange(token, TEMPLATE_SPAN, TEMPLATE_TAIL);
|
||||
}
|
||||
|
||||
static bool IsMember(Value token) {
|
||||
return IsInRange(token, TEMPLATE_SPAN, LBRACK);
|
||||
return base::IsInRange(token, TEMPLATE_SPAN, LBRACK);
|
||||
}
|
||||
|
||||
static bool IsProperty(Value token) {
|
||||
return IsInRange(token, PERIOD, LBRACK);
|
||||
return base::IsInRange(token, PERIOD, LBRACK);
|
||||
}
|
||||
|
||||
static bool IsPropertyOrCall(Value token) {
|
||||
return IsInRange(token, TEMPLATE_SPAN, LPAREN);
|
||||
return base::IsInRange(token, TEMPLATE_SPAN, LPAREN);
|
||||
}
|
||||
|
||||
static bool IsArrowOrAssignmentOp(Value token) {
|
||||
return IsInRange(token, ARROW, ASSIGN_SUB);
|
||||
return base::IsInRange(token, ARROW, ASSIGN_SUB);
|
||||
}
|
||||
|
||||
static bool IsAssignmentOp(Value token) {
|
||||
return IsInRange(token, INIT, ASSIGN_SUB);
|
||||
return base::IsInRange(token, INIT, ASSIGN_SUB);
|
||||
}
|
||||
|
||||
static bool IsBinaryOp(Value op) { return IsInRange(op, COMMA, SUB); }
|
||||
static bool IsBinaryOp(Value op) { return base::IsInRange(op, COMMA, SUB); }
|
||||
|
||||
static bool IsCompareOp(Value op) { return IsInRange(op, EQ, IN); }
|
||||
static bool IsCompareOp(Value op) { return base::IsInRange(op, EQ, IN); }
|
||||
|
||||
static bool IsOrderedRelationalCompareOp(Value op) {
|
||||
return IsInRange(op, LT, GTE);
|
||||
return base::IsInRange(op, LT, GTE);
|
||||
}
|
||||
|
||||
static bool IsEqualityOp(Value op) { return IsInRange(op, EQ, EQ_STRICT); }
|
||||
static bool IsEqualityOp(Value op) {
|
||||
return base::IsInRange(op, EQ, EQ_STRICT);
|
||||
}
|
||||
|
||||
static Value BinaryOpForAssignment(Value op) {
|
||||
DCHECK(IsInRange(op, ASSIGN_BIT_OR, ASSIGN_SUB));
|
||||
DCHECK(base::IsInRange(op, ASSIGN_BIT_OR, ASSIGN_SUB));
|
||||
Value result = static_cast<Value>(op - ASSIGN_BIT_OR + BIT_OR);
|
||||
DCHECK(IsBinaryOp(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool IsBitOp(Value op) {
|
||||
return IsInRange(op, BIT_OR, SHR) || op == BIT_NOT;
|
||||
return base::IsInRange(op, BIT_OR, SHR) || op == BIT_NOT;
|
||||
}
|
||||
|
||||
static bool IsUnaryOp(Value op) { return IsInRange(op, ADD, VOID); }
|
||||
static bool IsCountOp(Value op) { return IsInRange(op, INC, DEC); }
|
||||
static bool IsUnaryOrCountOp(Value op) { return IsInRange(op, ADD, DEC); }
|
||||
static bool IsShiftOp(Value op) { return IsInRange(op, SHL, SHR); }
|
||||
static bool IsUnaryOp(Value op) { return base::IsInRange(op, ADD, VOID); }
|
||||
static bool IsCountOp(Value op) { return base::IsInRange(op, INC, DEC); }
|
||||
static bool IsUnaryOrCountOp(Value op) {
|
||||
return base::IsInRange(op, ADD, DEC);
|
||||
}
|
||||
static bool IsShiftOp(Value op) { return base::IsInRange(op, SHL, SHR); }
|
||||
|
||||
// Returns a string corresponding to the JS token string
|
||||
// (.e., "<" for the token LT) or nullptr if the token doesn't
|
||||
|
@ -83,8 +83,8 @@ class HeapGraphEdge {
|
||||
V8_INLINE HeapSnapshot* snapshot() const;
|
||||
int from_index() const { return FromIndexField::decode(bit_field_); }
|
||||
|
||||
using TypeField = BitField<Type, 0, 3>;
|
||||
using FromIndexField = BitField<int, 3, 29>;
|
||||
using TypeField = base::BitField<Type, 0, 3>;
|
||||
using FromIndexField = base::BitField<int, 3, 29>;
|
||||
uint32_t bit_field_;
|
||||
HeapEntry* to_entry_;
|
||||
union {
|
||||
|
@ -208,12 +208,12 @@ class CodeEntry {
|
||||
V8_EXPORT_PRIVATE static base::LazyDynamicInstance<
|
||||
CodeEntry, RootEntryCreateTrait>::type kRootEntry;
|
||||
|
||||
using TagField = BitField<CodeEventListener::LogEventsAndTags, 0, 8>;
|
||||
using BuiltinIdField = BitField<Builtins::Name, 8, 22>;
|
||||
using TagField = base::BitField<CodeEventListener::LogEventsAndTags, 0, 8>;
|
||||
using BuiltinIdField = base::BitField<Builtins::Name, 8, 22>;
|
||||
static_assert(Builtins::builtin_count <= BuiltinIdField::kNumValues,
|
||||
"builtin_count exceeds size of bitfield");
|
||||
using UsedField = BitField<bool, 30, 1>;
|
||||
using SharedCrossOriginField = BitField<bool, 31, 1>;
|
||||
using UsedField = base::BitField<bool, 30, 1>;
|
||||
using SharedCrossOriginField = base::BitField<bool, 31, 1>;
|
||||
|
||||
uint32_t bit_field_;
|
||||
const char* name_;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "include/v8.h"
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/base/platform/time.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/objects/elements-kind.h"
|
||||
@ -786,11 +787,11 @@ V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream&, Runtime::FunctionId);
|
||||
//---------------------------------------------------------------------------
|
||||
// Constants used by interface to runtime functions.
|
||||
|
||||
using AllocateDoubleAlignFlag = BitField<bool, 0, 1>;
|
||||
using AllocateDoubleAlignFlag = base::BitField<bool, 0, 1>;
|
||||
|
||||
using AllowLargeObjectAllocationFlag = BitField<bool, 1, 1>;
|
||||
using AllowLargeObjectAllocationFlag = base::BitField<bool, 1, 1>;
|
||||
|
||||
using DeclareGlobalsEvalFlag = BitField<bool, 0, 1>;
|
||||
using DeclareGlobalsEvalFlag = base::BitField<bool, 0, 1>;
|
||||
|
||||
// A set of bits returned by Runtime_GetOptimizationStatus.
|
||||
// These bits must be in sync with bits defined in test/mjsunit/mjsunit.js
|
||||
|
@ -64,7 +64,7 @@ class EmbeddedData final {
|
||||
|
||||
uint32_t AddressForHashing(Address addr) {
|
||||
Address start = reinterpret_cast<Address>(data_);
|
||||
DCHECK(IsInRange(addr, start, start + size_));
|
||||
DCHECK(base::IsInRange(addr, start, start + size_));
|
||||
return static_cast<uint32_t>(addr - start);
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,9 @@
|
||||
#ifndef V8_SNAPSHOT_REFERENCES_H_
|
||||
#define V8_SNAPSHOT_REFERENCES_H_
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/base/hashmap.h"
|
||||
#include "src/common/assert-scope.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -154,7 +154,7 @@ class SerializerReference {
|
||||
}
|
||||
|
||||
private:
|
||||
using SpaceBits = BitField<SnapshotSpace, 0, kSpaceTagSize>;
|
||||
using SpaceBits = base::BitField<SnapshotSpace, 0, kSpaceTagSize>;
|
||||
using ChunkIndexBits = SpaceBits::Next<uint32_t, 32 - kSpaceTagSize>;
|
||||
using SpecialValueTypeBits =
|
||||
SpaceBits::Next<SpecialValueType, 32 - kSpaceTagSize>;
|
||||
|
@ -34,8 +34,8 @@ class ExternalReferenceEncoder {
|
||||
uint32_t index() const { return Index::decode(value_); }
|
||||
|
||||
private:
|
||||
using Index = BitField<uint32_t, 0, 31>;
|
||||
using IsFromAPI = BitField<bool, 31, 1>;
|
||||
using Index = base::BitField<uint32_t, 0, 31>;
|
||||
using IsFromAPI = base::BitField<bool, 31, 1>;
|
||||
uint32_t value_;
|
||||
};
|
||||
|
||||
@ -266,15 +266,15 @@ class SerializerDeserializer : public RootVisitor {
|
||||
|
||||
// Encodes repeat count into a fixed repeat bytecode.
|
||||
static int EncodeFixedRepeat(int repeat_count) {
|
||||
DCHECK(IsInRange(repeat_count, kFirstEncodableRepeatCount,
|
||||
kLastEncodableFixedRepeatCount));
|
||||
DCHECK(base::IsInRange(repeat_count, kFirstEncodableRepeatCount,
|
||||
kLastEncodableFixedRepeatCount));
|
||||
return kFixedRepeat + repeat_count - kFirstEncodableRepeatCount;
|
||||
}
|
||||
|
||||
// Decodes repeat count from a fixed repeat bytecode.
|
||||
static int DecodeFixedRepeatCount(int bytecode) {
|
||||
DCHECK(IsInRange(bytecode, kFixedRepeat + 0,
|
||||
kFixedRepeat + kNumberOfFixedRepeat));
|
||||
DCHECK(base::IsInRange(bytecode, kFixedRepeat + 0,
|
||||
kFixedRepeat + kNumberOfFixedRepeat));
|
||||
return bytecode - kFixedRepeat + kFirstEncodableRepeatCount;
|
||||
}
|
||||
|
||||
@ -328,8 +328,8 @@ class SerializedData {
|
||||
|
||||
uint32_t GetMagicNumber() const { return GetHeaderValue(kMagicNumberOffset); }
|
||||
|
||||
using ChunkSizeBits = BitField<uint32_t, 0, 31>;
|
||||
using IsLastChunkBits = BitField<bool, 31, 1>;
|
||||
using ChunkSizeBits = base::BitField<uint32_t, 0, 31>;
|
||||
using IsLastChunkBits = base::BitField<bool, 31, 1>;
|
||||
|
||||
static constexpr uint32_t kMagicNumberOffset = 0;
|
||||
static constexpr uint32_t kMagicNumber =
|
||||
|
@ -5,7 +5,9 @@
|
||||
#ifndef V8_STRINGS_CHAR_PREDICATES_INL_H_
|
||||
#define V8_STRINGS_CHAR_PREDICATES_INL_H_
|
||||
|
||||
#include "src/base/bounds.h"
|
||||
#include "src/strings/char-predicates.h"
|
||||
#include "src/utils/utils.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -24,26 +26,26 @@ inline constexpr bool IsAsciiIdentifier(uc32 c) {
|
||||
}
|
||||
|
||||
inline constexpr bool IsAlphaNumeric(uc32 c) {
|
||||
return IsInRange(AsciiAlphaToLower(c), 'a', 'z') || IsDecimalDigit(c);
|
||||
return base::IsInRange(AsciiAlphaToLower(c), 'a', 'z') || IsDecimalDigit(c);
|
||||
}
|
||||
|
||||
inline constexpr bool IsDecimalDigit(uc32 c) {
|
||||
// ECMA-262, 3rd, 7.8.3 (p 16)
|
||||
return IsInRange(c, '0', '9');
|
||||
return base::IsInRange(c, '0', '9');
|
||||
}
|
||||
|
||||
inline constexpr bool IsHexDigit(uc32 c) {
|
||||
// ECMA-262, 3rd, 7.6 (p 15)
|
||||
return IsDecimalDigit(c) || IsInRange(AsciiAlphaToLower(c), 'a', 'f');
|
||||
return IsDecimalDigit(c) || base::IsInRange(AsciiAlphaToLower(c), 'a', 'f');
|
||||
}
|
||||
|
||||
inline constexpr bool IsOctalDigit(uc32 c) {
|
||||
// ECMA-262, 6th, 7.8.3
|
||||
return IsInRange(c, '0', '7');
|
||||
return base::IsInRange(c, '0', '7');
|
||||
}
|
||||
|
||||
inline constexpr bool IsNonOctalDecimalDigit(uc32 c) {
|
||||
return IsInRange(c, '8', '9');
|
||||
return base::IsInRange(c, '8', '9');
|
||||
}
|
||||
|
||||
inline constexpr bool IsBinaryDigit(uc32 c) {
|
||||
@ -51,9 +53,13 @@ inline constexpr bool IsBinaryDigit(uc32 c) {
|
||||
return c == '0' || c == '1';
|
||||
}
|
||||
|
||||
inline constexpr bool IsAsciiLower(uc32 c) { return IsInRange(c, 'a', 'z'); }
|
||||
inline constexpr bool IsAsciiLower(uc32 c) {
|
||||
return base::IsInRange(c, 'a', 'z');
|
||||
}
|
||||
|
||||
inline constexpr bool IsAsciiUpper(uc32 c) { return IsInRange(c, 'A', 'Z'); }
|
||||
inline constexpr bool IsAsciiUpper(uc32 c) {
|
||||
return base::IsInRange(c, 'A', 'Z');
|
||||
}
|
||||
|
||||
inline constexpr uc32 ToAsciiUpper(uc32 c) {
|
||||
return c & ~(IsAsciiLower(c) << 5);
|
||||
@ -64,7 +70,7 @@ inline constexpr uc32 ToAsciiLower(uc32 c) {
|
||||
}
|
||||
|
||||
inline constexpr bool IsRegExpWord(uc16 c) {
|
||||
return IsInRange(AsciiAlphaToLower(c), 'a', 'z') || IsDecimalDigit(c) ||
|
||||
return base::IsInRange(AsciiAlphaToLower(c), 'a', 'z') || IsDecimalDigit(c) ||
|
||||
(c == '_');
|
||||
}
|
||||
|
||||
@ -97,28 +103,28 @@ const constexpr uint8_t kAsciiCharFlags[128] = {
|
||||
};
|
||||
|
||||
bool IsIdentifierStart(uc32 c) {
|
||||
if (!IsInRange(c, 0, 127)) return IsIdentifierStartSlow(c);
|
||||
if (!base::IsInRange(c, 0, 127)) return IsIdentifierStartSlow(c);
|
||||
DCHECK_EQ(IsIdentifierStartSlow(c),
|
||||
static_cast<bool>(kAsciiCharFlags[c] & kIsIdentifierStart));
|
||||
return kAsciiCharFlags[c] & kIsIdentifierStart;
|
||||
}
|
||||
|
||||
bool IsIdentifierPart(uc32 c) {
|
||||
if (!IsInRange(c, 0, 127)) return IsIdentifierPartSlow(c);
|
||||
if (!base::IsInRange(c, 0, 127)) return IsIdentifierPartSlow(c);
|
||||
DCHECK_EQ(IsIdentifierPartSlow(c),
|
||||
static_cast<bool>(kAsciiCharFlags[c] & kIsIdentifierPart));
|
||||
return kAsciiCharFlags[c] & kIsIdentifierPart;
|
||||
}
|
||||
|
||||
bool IsWhiteSpace(uc32 c) {
|
||||
if (!IsInRange(c, 0, 127)) return IsWhiteSpaceSlow(c);
|
||||
if (!base::IsInRange(c, 0, 127)) return IsWhiteSpaceSlow(c);
|
||||
DCHECK_EQ(IsWhiteSpaceSlow(c),
|
||||
static_cast<bool>(kAsciiCharFlags[c] & kIsWhiteSpace));
|
||||
return kAsciiCharFlags[c] & kIsWhiteSpace;
|
||||
}
|
||||
|
||||
bool IsWhiteSpaceOrLineTerminator(uc32 c) {
|
||||
if (!IsInRange(c, 0, 127)) return IsWhiteSpaceOrLineTerminatorSlow(c);
|
||||
if (!base::IsInRange(c, 0, 127)) return IsWhiteSpaceOrLineTerminatorSlow(c);
|
||||
DCHECK_EQ(
|
||||
IsWhiteSpaceOrLineTerminatorSlow(c),
|
||||
static_cast<bool>(kAsciiCharFlags[c] & kIsWhiteSpaceOrLineTerminator));
|
||||
|
@ -21,10 +21,10 @@ const int kStringBuilderConcatHelperLengthBits = 11;
|
||||
const int kStringBuilderConcatHelperPositionBits = 19;
|
||||
|
||||
using StringBuilderSubstringLength =
|
||||
BitField<int, 0, kStringBuilderConcatHelperLengthBits>;
|
||||
base::BitField<int, 0, kStringBuilderConcatHelperLengthBits>;
|
||||
using StringBuilderSubstringPosition =
|
||||
BitField<int, kStringBuilderConcatHelperLengthBits,
|
||||
kStringBuilderConcatHelperPositionBits>;
|
||||
base::BitField<int, kStringBuilderConcatHelperLengthBits,
|
||||
kStringBuilderConcatHelperPositionBits>;
|
||||
|
||||
template <typename sinkchar>
|
||||
void StringBuilderConcatHelper(String special, sinkchar* sink,
|
||||
|
@ -6,9 +6,9 @@
|
||||
#define V8_STRINGS_UNICODE_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/common/globals.h"
|
||||
#include "src/third_party/utf8-decoder/utf8-decoder.h"
|
||||
#include "src/utils/utils.h"
|
||||
/**
|
||||
* \file
|
||||
* Definitions and convenience functions for working with unicode.
|
||||
@ -51,8 +51,8 @@ class Predicate {
|
||||
bool value() const { return ValueField::decode(bit_field_); }
|
||||
|
||||
private:
|
||||
using CodePointField = v8::internal::BitField<uchar, 0, 21>;
|
||||
using ValueField = v8::internal::BitField<bool, 21, 1>;
|
||||
using CodePointField = v8::base::BitField<uchar, 0, 21>;
|
||||
using ValueField = v8::base::BitField<bool, 21, 1>;
|
||||
|
||||
uint32_t bit_field_;
|
||||
};
|
||||
|
@ -52,43 +52,6 @@ inline char HexCharOfValue(int value) {
|
||||
return value - 10 + 'A';
|
||||
}
|
||||
|
||||
// Checks if value is in range [lower_limit, higher_limit] using a single
|
||||
// branch.
|
||||
template <typename T, typename U>
|
||||
inline constexpr bool IsInRange(T value, U lower_limit, U higher_limit) {
|
||||
#if V8_HAS_CXX14_CONSTEXPR
|
||||
DCHECK_LE(lower_limit, higher_limit);
|
||||
#endif
|
||||
STATIC_ASSERT(sizeof(U) <= sizeof(T));
|
||||
using unsigned_T = typename std::make_unsigned<T>::type;
|
||||
// Use static_cast to support enum classes.
|
||||
return static_cast<unsigned_T>(static_cast<unsigned_T>(value) -
|
||||
static_cast<unsigned_T>(lower_limit)) <=
|
||||
static_cast<unsigned_T>(static_cast<unsigned_T>(higher_limit) -
|
||||
static_cast<unsigned_T>(lower_limit));
|
||||
}
|
||||
|
||||
// Checks if [index, index+length) is in range [0, max). Note that this check
|
||||
// works even if {index+length} would wrap around.
|
||||
inline constexpr bool IsInBounds(size_t index, size_t length, size_t max) {
|
||||
return length <= max && index <= (max - length);
|
||||
}
|
||||
|
||||
// Checks if [index, index+length) is in range [0, max). If not, {length} is
|
||||
// clamped to its valid range. Note that this check works even if
|
||||
// {index+length} would wrap around.
|
||||
template <typename T>
|
||||
inline bool ClampToBounds(T index, T* length, T max) {
|
||||
if (index > max) {
|
||||
*length = 0;
|
||||
return false;
|
||||
}
|
||||
T avail = max - index;
|
||||
bool oob = *length > avail;
|
||||
if (oob) *length = avail;
|
||||
return !oob;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T ArithmeticShiftRight(T x, int shift) {
|
||||
DCHECK_LE(0, shift);
|
||||
@ -213,147 +176,6 @@ T SaturateSub(T a, T b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// BitField is a help template for encoding and decode bitfield with
|
||||
// unsigned content.
|
||||
// Instantiate them via 'using', which is cheaper than deriving a new class:
|
||||
// using MyBitField = BitField<int, 4, 2, MyEnum>;
|
||||
// The BitField class is final to enforce this style over derivation.
|
||||
|
||||
template <class T, int shift, int size, class U = uint32_t>
|
||||
class BitField final {
|
||||
public:
|
||||
STATIC_ASSERT(std::is_unsigned<U>::value);
|
||||
STATIC_ASSERT(shift < 8 * sizeof(U)); // Otherwise shifts by {shift} are UB.
|
||||
STATIC_ASSERT(size < 8 * sizeof(U)); // Otherwise shifts by {size} are UB.
|
||||
STATIC_ASSERT(shift + size <= 8 * sizeof(U));
|
||||
STATIC_ASSERT(size > 0);
|
||||
|
||||
using FieldType = T;
|
||||
|
||||
// A type U mask of bit field. To use all bits of a type U of x bits
|
||||
// in a bitfield without compiler warnings we have to compute 2^x
|
||||
// without using a shift count of x in the computation.
|
||||
static constexpr int kShift = shift;
|
||||
static constexpr int kSize = size;
|
||||
static constexpr U kMask = ((U{1} << kShift) << kSize) - (U{1} << kShift);
|
||||
static constexpr int kLastUsedBit = kShift + kSize - 1;
|
||||
static constexpr U kNumValues = U{1} << kSize;
|
||||
|
||||
// Value for the field with all bits set.
|
||||
static constexpr T kMax = static_cast<T>(kNumValues - 1);
|
||||
|
||||
template <class T2, int size2>
|
||||
using Next = BitField<T2, kShift + kSize, size2, U>;
|
||||
|
||||
// Tells whether the provided value fits into the bit field.
|
||||
static constexpr bool is_valid(T value) {
|
||||
return (static_cast<U>(value) & ~static_cast<U>(kMax)) == 0;
|
||||
}
|
||||
|
||||
// Returns a type U with the bit field value encoded.
|
||||
static constexpr U encode(T value) {
|
||||
#if V8_HAS_CXX14_CONSTEXPR
|
||||
DCHECK(is_valid(value));
|
||||
#endif
|
||||
return static_cast<U>(value) << kShift;
|
||||
}
|
||||
|
||||
// Returns a type U with the bit field value updated.
|
||||
static constexpr U update(U previous, T value) {
|
||||
return (previous & ~kMask) | encode(value);
|
||||
}
|
||||
|
||||
// Extracts the bit field from the value.
|
||||
static constexpr T decode(U value) {
|
||||
return static_cast<T>((value & kMask) >> kShift);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, int shift, int size>
|
||||
using BitField8 = BitField<T, shift, size, uint8_t>;
|
||||
|
||||
template <class T, int shift, int size>
|
||||
using BitField16 = BitField<T, shift, size, uint16_t>;
|
||||
|
||||
template <class T, int shift, int size>
|
||||
using BitField64 = BitField<T, shift, size, uint64_t>;
|
||||
|
||||
// Helper macros for defining a contiguous sequence of bit fields. Example:
|
||||
// (backslashes at the ends of respective lines of this multi-line macro
|
||||
// definition are omitted here to please the compiler)
|
||||
//
|
||||
// #define MAP_BIT_FIELD1(V, _)
|
||||
// V(IsAbcBit, bool, 1, _)
|
||||
// V(IsBcdBit, bool, 1, _)
|
||||
// V(CdeBits, int, 5, _)
|
||||
// V(DefBits, MutableMode, 1, _)
|
||||
//
|
||||
// DEFINE_BIT_FIELDS(MAP_BIT_FIELD1)
|
||||
// or
|
||||
// DEFINE_BIT_FIELDS_64(MAP_BIT_FIELD1)
|
||||
//
|
||||
#define DEFINE_BIT_FIELD_RANGE_TYPE(Name, Type, Size, _) \
|
||||
k##Name##Start, k##Name##End = k##Name##Start + Size - 1,
|
||||
|
||||
#define DEFINE_BIT_RANGES(LIST_MACRO) \
|
||||
struct LIST_MACRO##_Ranges { \
|
||||
enum { LIST_MACRO(DEFINE_BIT_FIELD_RANGE_TYPE, _) kBitsCount }; \
|
||||
};
|
||||
|
||||
#define DEFINE_BIT_FIELD_TYPE(Name, Type, Size, RangesName) \
|
||||
using Name = BitField<Type, RangesName::k##Name##Start, Size>;
|
||||
|
||||
#define DEFINE_BIT_FIELD_64_TYPE(Name, Type, Size, RangesName) \
|
||||
using Name = BitField64<Type, RangesName::k##Name##Start, Size>;
|
||||
|
||||
#define DEFINE_BIT_FIELDS(LIST_MACRO) \
|
||||
DEFINE_BIT_RANGES(LIST_MACRO) \
|
||||
LIST_MACRO(DEFINE_BIT_FIELD_TYPE, LIST_MACRO##_Ranges)
|
||||
|
||||
#define DEFINE_BIT_FIELDS_64(LIST_MACRO) \
|
||||
DEFINE_BIT_RANGES(LIST_MACRO) \
|
||||
LIST_MACRO(DEFINE_BIT_FIELD_64_TYPE, LIST_MACRO##_Ranges)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// BitSetComputer is a help template for encoding and decoding information for
|
||||
// a variable number of items in an array.
|
||||
//
|
||||
// To encode boolean data in a smi array you would use:
|
||||
// using BoolComputer = BitSetComputer<bool, 1, kSmiValueSize, uint32_t>;
|
||||
//
|
||||
template <class T, int kBitsPerItem, int kBitsPerWord, class U>
|
||||
class BitSetComputer {
|
||||
public:
|
||||
static const int kItemsPerWord = kBitsPerWord / kBitsPerItem;
|
||||
static const int kMask = (1 << kBitsPerItem) - 1;
|
||||
|
||||
// The number of array elements required to embed T information for each item.
|
||||
static int word_count(int items) {
|
||||
if (items == 0) return 0;
|
||||
return (items - 1) / kItemsPerWord + 1;
|
||||
}
|
||||
|
||||
// The array index to look at for item.
|
||||
static int index(int base_index, int item) {
|
||||
return base_index + item / kItemsPerWord;
|
||||
}
|
||||
|
||||
// Extract T data for a given item from data.
|
||||
static T decode(U data, int item) {
|
||||
return static_cast<T>((data >> shift(item)) & kMask);
|
||||
}
|
||||
|
||||
// Return the encoding for a store of value for item in previous.
|
||||
static U encode(U previous, int item, T value) {
|
||||
int shift_value = shift(item);
|
||||
int set_bits = (static_cast<int>(value) << shift_value);
|
||||
return (previous & ~(kMask << shift_value)) | set_bits;
|
||||
}
|
||||
|
||||
static int shift(int item) { return (item % kItemsPerWord) * kBitsPerItem; }
|
||||
};
|
||||
|
||||
// Helper macros for defining a contiguous sequence of field offset constants.
|
||||
// Example: (backslashes at the ends of respective lines of this multi-line
|
||||
// macro definition are omitted here to please the compiler)
|
||||
|
@ -1580,7 +1580,7 @@ class LiftoffCompiler {
|
||||
bool BoundsCheckMem(FullDecoder* decoder, uint32_t access_size,
|
||||
uint32_t offset, Register index, LiftoffRegList pinned) {
|
||||
const bool statically_oob =
|
||||
!IsInBounds(offset, access_size, env_->max_memory_size);
|
||||
!base::IsInBounds(offset, access_size, env_->max_memory_size);
|
||||
|
||||
if (!statically_oob &&
|
||||
(FLAG_wasm_no_bounds_checks || env_->use_trap_handler)) {
|
||||
|
@ -540,9 +540,9 @@ class CompilationStateImpl {
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Encoding of fields in the {compilation_progress_} vector.
|
||||
using RequiredBaselineTierField = BitField8<ExecutionTier, 0, 2>;
|
||||
using RequiredTopTierField = BitField8<ExecutionTier, 2, 2>;
|
||||
using ReachedTierField = BitField8<ExecutionTier, 4, 2>;
|
||||
using RequiredBaselineTierField = base::BitField8<ExecutionTier, 0, 2>;
|
||||
using RequiredTopTierField = base::BitField8<ExecutionTier, 2, 2>;
|
||||
using ReachedTierField = base::BitField8<ExecutionTier, 4, 2>;
|
||||
};
|
||||
|
||||
CompilationStateImpl* Impl(CompilationState* compilation_state) {
|
||||
|
@ -491,7 +491,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
|
||||
elem_segment.table_index)),
|
||||
isolate_);
|
||||
size_t table_size = table_object->entries().length();
|
||||
if (!IsInBounds(base, elem_segment.entries.size(), table_size)) {
|
||||
if (!base::IsInBounds(base, elem_segment.entries.size(), table_size)) {
|
||||
thrower_->LinkError("table initializer is out of bounds");
|
||||
return {};
|
||||
}
|
||||
@ -503,7 +503,8 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
|
||||
for (const WasmDataSegment& seg : module_->data_segments) {
|
||||
if (!seg.active) continue;
|
||||
uint32_t base = EvalUint32InitExpr(instance, seg.dest_addr);
|
||||
if (!IsInBounds(base, seg.source.length(), instance->memory_size())) {
|
||||
if (!base::IsInBounds(base, seg.source.length(),
|
||||
instance->memory_size())) {
|
||||
thrower_->LinkError("data segment is out of bounds");
|
||||
return {};
|
||||
}
|
||||
@ -662,8 +663,8 @@ void InstanceBuilder::LoadDataSegments(Handle<WasmInstanceObject> instance) {
|
||||
if (!segment.active) continue;
|
||||
|
||||
uint32_t dest_offset = EvalUint32InitExpr(instance, segment.dest_addr);
|
||||
bool ok = ClampToBounds(dest_offset, &size,
|
||||
static_cast<uint32_t>(instance->memory_size()));
|
||||
bool ok = base::ClampToBounds(
|
||||
dest_offset, &size, static_cast<uint32_t>(instance->memory_size()));
|
||||
Address dest_addr =
|
||||
reinterpret_cast<Address>(instance->memory_start()) + dest_offset;
|
||||
Address src_addr = reinterpret_cast<Address>(wire_bytes.begin()) +
|
||||
@ -679,7 +680,7 @@ void InstanceBuilder::LoadDataSegments(Handle<WasmInstanceObject> instance) {
|
||||
if (size == 0) continue;
|
||||
|
||||
uint32_t dest_offset = EvalUint32InitExpr(instance, segment.dest_addr);
|
||||
DCHECK(IsInBounds(dest_offset, size, instance->memory_size()));
|
||||
DCHECK(base::IsInBounds(dest_offset, size, instance->memory_size()));
|
||||
byte* dest = instance->memory_start() + dest_offset;
|
||||
const byte* src = wire_bytes.begin() + segment.source.offset();
|
||||
memcpy(dest, src, size);
|
||||
@ -1633,10 +1634,10 @@ bool LoadElemSegmentImpl(Isolate* isolate, Handle<WasmInstanceObject> instance,
|
||||
// TODO(wasm): Move this functionality into wasm-objects, since it is used
|
||||
// for both instantiation and in the implementation of the table.init
|
||||
// instruction.
|
||||
bool ok =
|
||||
ClampToBounds<size_t>(dst, &count, table_object->entries().length());
|
||||
bool ok = base::ClampToBounds<size_t>(dst, &count,
|
||||
table_object->entries().length());
|
||||
// Use & instead of && so the clamp is not short-circuited.
|
||||
ok &= ClampToBounds<size_t>(src, &count, elem_segment.entries.size());
|
||||
ok &= base::ClampToBounds<size_t>(src, &count, elem_segment.entries.size());
|
||||
|
||||
const WasmModule* module = instance->module();
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
|
@ -1645,8 +1645,8 @@ class ThreadImpl {
|
||||
if (effective_index < index) {
|
||||
return kNullAddress; // wraparound => oob
|
||||
}
|
||||
if (!IsInBounds(effective_index, sizeof(mtype),
|
||||
instance_object_->memory_size())) {
|
||||
if (!base::IsInBounds(effective_index, sizeof(mtype),
|
||||
instance_object_->memory_size())) {
|
||||
return kNullAddress; // oob
|
||||
}
|
||||
return EffectiveAddress(effective_index);
|
||||
@ -1654,7 +1654,7 @@ class ThreadImpl {
|
||||
|
||||
inline bool BoundsCheckMemRange(uint32_t index, uint32_t* size,
|
||||
Address* out_address) {
|
||||
bool ok = ClampToBounds(
|
||||
bool ok = base::ClampToBounds(
|
||||
index, size, static_cast<uint32_t>(instance_object_->memory_size()));
|
||||
*out_address = EffectiveAddress(index);
|
||||
return ok;
|
||||
@ -1807,7 +1807,7 @@ class ThreadImpl {
|
||||
auto src_max =
|
||||
instance_object_->data_segment_sizes()[imm.data_segment_index];
|
||||
// Use & instead of && so the clamp is not short-circuited.
|
||||
ok &= ClampToBounds(src, &size, src_max);
|
||||
ok &= base::ClampToBounds(src, &size, src_max);
|
||||
Address src_addr =
|
||||
instance_object_->data_segment_starts()[imm.data_segment_index] +
|
||||
src;
|
||||
|
@ -1444,9 +1444,9 @@ bool WasmInstanceObject::CopyTableEntries(Isolate* isolate,
|
||||
uint32_t max_dst = static_cast<uint32_t>(table_dst->entries().length());
|
||||
uint32_t max_src = static_cast<uint32_t>(table_src->entries().length());
|
||||
bool copy_backward = src < dst;
|
||||
bool ok = ClampToBounds(dst, &count, max_dst);
|
||||
bool ok = base::ClampToBounds(dst, &count, max_dst);
|
||||
// Use & instead of && so the clamp is not short-circuited.
|
||||
ok &= ClampToBounds(src, &count, max_src);
|
||||
ok &= base::ClampToBounds(src, &count, max_src);
|
||||
|
||||
// If performing a partial copy when copying backward, then the first access
|
||||
// will be out-of-bounds, so no entries should be copied.
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/base/bits.h"
|
||||
#include "src/codegen/signature.h"
|
||||
#include "src/debug/debug.h"
|
||||
|
@ -467,7 +467,7 @@ TEST(DecodeWordFromWord32) {
|
||||
CodeAssemblerTester asm_tester(isolate);
|
||||
CodeStubAssembler m(asm_tester.state());
|
||||
|
||||
using TestBitField = BitField<unsigned, 3, 3>;
|
||||
using TestBitField = base::BitField<unsigned, 3, 3>;
|
||||
m.Return(m.SmiTag(
|
||||
m.Signed(m.DecodeWordFromWord32<TestBitField>(m.Int32Constant(0x2F)))));
|
||||
FunctionTester ft(asm_tester.GenerateCode());
|
||||
|
@ -312,10 +312,10 @@ TEST(ExponentNumberStr) {
|
||||
CHECK_EQ(1e-106, StringToDouble(".000001e-100", NO_FLAGS));
|
||||
}
|
||||
|
||||
using OneBit1 = BitField<uint32_t, 0, 1>;
|
||||
using OneBit2 = BitField<uint32_t, 7, 1>;
|
||||
using EightBit1 = BitField<uint32_t, 0, 8>;
|
||||
using EightBit2 = BitField<uint32_t, 13, 8>;
|
||||
using OneBit1 = base::BitField<uint32_t, 0, 1>;
|
||||
using OneBit2 = base::BitField<uint32_t, 7, 1>;
|
||||
using EightBit1 = base::BitField<uint32_t, 0, 8>;
|
||||
using EightBit2 = base::BitField<uint32_t, 13, 8>;
|
||||
|
||||
TEST(BitField) {
|
||||
uint32_t x;
|
||||
@ -350,8 +350,8 @@ TEST(BitField) {
|
||||
CHECK(!EightBit2::is_valid(256));
|
||||
}
|
||||
|
||||
using UpperBits = BitField64<int, 61, 3>;
|
||||
using MiddleBits = BitField64<int, 31, 2>;
|
||||
using UpperBits = base::BitField64<int, 61, 3>;
|
||||
using MiddleBits = base::BitField64<int, 31, 2>;
|
||||
|
||||
TEST(BitField64) {
|
||||
uint64_t x;
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "src/init/v8.h"
|
||||
|
||||
#include "src/api/api-inl.h"
|
||||
#include "src/base/bit-field.h"
|
||||
#include "src/base/platform/platform.h"
|
||||
#include "src/numbers/conversions.h"
|
||||
#include "test/cctest/cctest.h"
|
||||
@ -79,7 +80,7 @@ TEST(Utils1) {
|
||||
|
||||
|
||||
TEST(BitSetComputer) {
|
||||
using BoolComputer = BitSetComputer<bool, 1, kSmiValueSize, uint32_t>;
|
||||
using BoolComputer = base::BitSetComputer<bool, 1, kSmiValueSize, uint32_t>;
|
||||
CHECK_EQ(0, BoolComputer::word_count(0));
|
||||
CHECK_EQ(1, BoolComputer::word_count(8));
|
||||
CHECK_EQ(2, BoolComputer::word_count(50));
|
||||
@ -97,7 +98,7 @@ TEST(BitSetComputer) {
|
||||
|
||||
// Lets store 2 bits per item with 3000 items and verify the values are
|
||||
// correct.
|
||||
using TwoBits = BitSetComputer<unsigned char, 2, 8, unsigned char>;
|
||||
using TwoBits = base::BitSetComputer<unsigned char, 2, 8, unsigned char>;
|
||||
const int words = 750;
|
||||
CHECK_EQ(words, TwoBits::word_count(3000));
|
||||
const int offset = 10;
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "src/base/bounds.h"
|
||||
#include "src/utils/utils.h"
|
||||
#include "testing/gtest-support.h"
|
||||
|
||||
@ -134,8 +135,8 @@ TYPED_TEST(UtilsTest, PassesFilterTest) {
|
||||
|
||||
TEST(UtilsTest, IsInBounds) {
|
||||
// for column consistency and terseness
|
||||
#define INB(x, y, z) EXPECT_TRUE(IsInBounds(x, y, z))
|
||||
#define OOB(x, y, z) EXPECT_FALSE(IsInBounds(x, y, z))
|
||||
#define INB(x, y, z) EXPECT_TRUE(base::IsInBounds(x, y, z))
|
||||
#define OOB(x, y, z) EXPECT_FALSE(base::IsInBounds(x, y, z))
|
||||
INB(0, 0, 1);
|
||||
INB(0, 1, 1);
|
||||
INB(1, 0, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user