5#ifndef V8_WASM_SIGNATURE_HASHING_H_
6#define V8_WASM_SIGNATURE_HASHING_H_
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
21 return type.machine_representation();
25 return type.representation();
41template <
class ResultCollector,
class SigType>
43 ResultCollector& locations,
44 int* untagged_parameter_slots,
45 int* total_parameter_slots,
46 int* untagged_return_slots,
int* total_return_slots) {
47 constexpr int kParamsSlotOffset = 0;
52 const size_t param_offset = 1;
59 bool has_tagged_param =
false;
64 has_tagged_param =
true;
67 locations.AddParamAt(
i + param_offset, params.Next(param));
70 *untagged_parameter_slots = params.NumStackSlots();
71 if (has_tagged_param) {
75 locations.AddParamAt(
i + param_offset, params.Next(param));
80 if (extra_callable_param) {
87 *total_parameter_slots = params_stack_height;
97 const size_t return_count =
sig->return_count();
98 bool has_tagged_result =
false;
99 for (
size_t i = 0;
i < return_count;
i++) {
102 has_tagged_result =
true;
105 locations.AddReturnAt(
i, rets.
Next(ret));
109 if (has_tagged_result) {
110 for (
size_t i = 0;
i < return_count;
i++) {
113 locations.AddReturnAt(
i, rets.
Next(ret));
135class SignatureHasher {
137 template <
typename SigType>
138 static uint64_t
Hash(
const SigType*
sig) {
139 SignatureHasher hasher;
140 int total_param_stack_slots;
141 int total_return_stack_slots;
144 &hasher.params_.untagged_on_stack_, &total_param_stack_slots,
145 &hasher.rets_.untagged_on_stack_, &total_return_stack_slots);
147 hasher.params_.tagged_on_stack_ =
148 total_param_stack_slots - hasher.params_.untagged_on_stack_;
149 hasher.rets_.tagged_on_stack_ =
150 total_return_stack_slots - hasher.rets_.untagged_on_stack_;
152 return hasher.GetHash();
155 void AddParamAt(
size_t index, LinkageLocation location) {
156 if (index == 0)
return;
157 CountIfRegister(location, params_);
159 void AddReturnAt(
size_t index, LinkageLocation location) {
160 CountIfRegister(location, rets_);
164 static constexpr int kUntaggedInRegBits = 3;
165 static constexpr int kTaggedInRegBits = 3;
166 static constexpr int kUntaggedOnStackBits = 11;
167 static constexpr int kTaggedOnStackBits = 10;
169 using UntaggedInReg =
170 base::BitField<uint32_t, 0, kUntaggedInRegBits, uint64_t>;
171 using TaggedInReg = UntaggedInReg::Next<uint32_t, kTaggedInRegBits>;
172 using UntaggedOnStack = TaggedInReg::Next<uint32_t, kUntaggedOnStackBits>;
173 using TaggedOnStack = UntaggedOnStack::Next<uint32_t, kTaggedOnStackBits>;
175 static constexpr int kTotalWidth = TaggedOnStack::kLastUsedBit + 1;
177 static_assert(kTotalWidth * 2 <= 64);
180 static_assert(kTotalWidth * 2 < 64);
184 UntaggedInReg::kNumValues);
187 UntaggedInReg::kNumValues);
189 static constexpr int kMaxValueSizeInPointers =
192 UntaggedOnStack::kNumValues);
195 UntaggedOnStack::kNumValues);
199 int tagged_in_reg_{0};
200 int untagged_in_reg_{0};
201 int tagged_on_stack_{0};
202 int untagged_on_stack_{0};
204 uint64_t GetHash()
const {
205 return UntaggedInReg::encode(untagged_in_reg_) |
206 TaggedInReg::encode(tagged_in_reg_) |
207 UntaggedOnStack::encode(untagged_on_stack_) |
208 TaggedOnStack::encode(tagged_on_stack_);
212 uint64_t GetHash()
const {
213 return (rets_.GetHash() << kTotalWidth) | params_.GetHash();
216 void CountIfRegister(LinkageLocation loc, Counts& counts) {
217 if (!loc.IsRegister()) {
218 DCHECK(loc.IsCallerFrameSlot());
221 MachineType type = loc.GetType();
222 if (type.IsTagged()) {
223 counts.tagged_in_reg_++;
224 }
else if (
IsIntegral(type.representation())) {
225 counts.untagged_in_reg_++;
240 template <
typename SigType>
static LinkageLocation ForRegister(int32_t reg, MachineType type=MachineType::None())
static constexpr MachineType TaggedPointer()
constexpr int8_t code() const
int NumStackSlots() const
LinkageLocation Next(MachineRepresentation rep)
static uint64_t Hash(const SigType *sig)
constexpr DoubleRegister kFpReturnRegisters[]
constexpr Register kGpParamRegisters[]
constexpr DoubleRegister kFpParamRegisters[]
constexpr Register kGpReturnRegisters[]
constexpr size_t kV8MaxWasmFunctionReturns
void IterateSignatureImpl(const SigType *sig, bool extra_callable_param, ResultCollector &locations, int *untagged_parameter_slots, int *total_parameter_slots, int *untagged_return_slots, int *total_return_slots)
MachineRepresentation GetMachineRepresentation(ValueTypeBase type)
constexpr int kMaxValueTypeSize
constexpr size_t kV8MaxWasmFunctionParams
constexpr int AddArgumentPaddingSlots(int argument_count)
kWasmInternalFunctionIndirectPointerTag kProtectedInstanceDataOffset sig
constexpr bool IsAnyTagged(MachineRepresentation rep)
constexpr int kSystemPointerSize
constexpr bool IsFloatingPoint(MachineRepresentation rep)
constexpr bool IsIntegral(MachineRepresentation rep)
constexpr Register kJSFunctionRegister
#define DCHECK(condition)