v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
assembler-loong64-inl.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_CODEGEN_LOONG64_ASSEMBLER_LOONG64_INL_H_
6#define V8_CODEGEN_LOONG64_ASSEMBLER_LOONG64_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
13#include "src/debug/debug.h"
17
18namespace v8 {
19namespace internal {
20
21bool CpuFeatures::SupportsOptimizer() { return IsSupported(FPU); }
22
23// -----------------------------------------------------------------------------
24// Operand and MemOperand.
25
26bool Operand::is_reg() const { return rm_.is_valid(); }
27
28int64_t Operand::immediate() const {
29 DCHECK(!is_reg());
31 return value_.immediate;
32}
33
34// -----------------------------------------------------------------------------
35// RelocInfo.
36
37void WritableRelocInfo::apply(intptr_t delta) {
39 // Absolute code pointer inside code object moves with the code object.
40 intptr_t internal_ref = ReadUnalignedValue<intptr_t>(pc_);
41 internal_ref += delta; // Relocate entry.
42 jit_allocation_.WriteUnalignedValue<intptr_t>(pc_, internal_ref);
43 } else {
46 }
47}
48
53}
54
57 // Read the address of the word containing the target_address in an
58 // instruction stream.
59 // The only architecture-independent user of this function is the serializer.
60 // The serializer uses it to find out how many raw bytes of instruction to
61 // output before the next target.
62 // For an instruction like LUI/ORI where the target bits are mixed into the
63 // instruction bits, the size of the target will be zero, indicating that the
64 // serializer should not step forward in memory after a target is resolved
65 // and written. In this case the target_address_address function should
66 // return the end of the instructions to be patched, allowing the
67 // deserializer to deserialize the instructions as raw bytes and put them in
68 // place, ready to be patched with the target. After jump optimization,
69 // that is the address of the instruction that follows J/JAL/JR/JALR
70 // instruction.
72}
73
75
77
79 Address instruction_payload) {
80 return kSpecialTargetSize;
81}
82
84 Address pc, Address target, WritableJitAllocation& jit_allocation,
85 RelocInfo::Mode mode) {
86 jit_allocation.WriteUnalignedValue<Address>(pc, target);
87}
88
93
98
101 int index =
102 static_cast<int>(target_address_at(pc, constant_pool)) & 0xFFFFFFFF;
103 return GetCodeTarget(index);
104}
105
107 int builtin_id = static_cast<int>(target_address_at(pc) - pc) >> 2;
108 DCHECK(Builtins::IsBuiltinId(builtin_id));
109 return static_cast<Builtin>(builtin_id);
110}
111
112Tagged<HeapObject> RelocInfo::target_object(PtrComprCageBase cage_base) {
115 Tagged_t compressed =
117 DCHECK(!HAS_SMI_TAG(compressed));
118 Tagged<Object> obj(
119 V8HeapCompressionScheme::DecompressTagged(cage_base, compressed));
120 return Cast<HeapObject>(obj);
121 } else {
122 return Cast<HeapObject>(
124 }
125}
126
127DirectHandle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
128 if (IsCodeTarget(rmode_)) {
129 return origin->code_target_object_handle_at(pc_, constant_pool_);
130 } else if (IsFullEmbeddedObject(rmode_)) {
131 return origin->embedded_object_handle_at(pc_, constant_pool_);
133 return origin->compressed_embedded_object_handle_at(pc_, constant_pool_);
134 } else {
136 return origin->relative_code_target_object_handle_at(pc_);
137 }
138}
139
141 ICacheFlushMode icache_flush_mode) {
145 // We must not compress pointers to objects outside of the main pointer
146 // compression cage as we wouldn't be able to decompress them with the
147 // correct cage base.
150 !HeapLayout::InCodeSpace(target));
154 icache_flush_mode);
155 } else {
157 &jit_allocation_, icache_flush_mode);
158 }
159}
160
164}
165
167 Address target, ICacheFlushMode icache_flush_mode) {
170 &jit_allocation_, icache_flush_mode);
171}
172
173WasmCodePointer RelocInfo::wasm_code_pointer_table_entry() const {
175 return WasmCodePointer{Assembler::uint32_constant_at(pc_, constant_pool_)};
176}
177
179 WasmCodePointer target, ICacheFlushMode icache_flush_mode) {
182 &jit_allocation_, icache_flush_mode);
183}
184
186 if (rmode_ == INTERNAL_REFERENCE) {
187 return Memory<Address>(pc_);
188 } else {
189 UNREACHABLE();
190 }
191}
192
195 return pc_;
196}
197
201}
202
204 Address pc) const {
206 int32_t code_target_index = instr & kImm26Mask;
207 code_target_index = ((code_target_index & 0x3ff) << 22 >> 6) |
208 ((code_target_index >> 10) & kImm16Mask);
209 return GetCodeTarget(code_target_index);
210}
211
212Builtin RelocInfo::target_builtin_at(Assembler* origin) {
215}
216
220}
221
223 // target_compressed_address_at function could interpret lu12i.w and ori
224 // instructions generated by MacroAssembler::li for a 32-bit value.
226}
227
229 uint32_t new_constant,
230 WritableJitAllocation* jit_allocation,
231 ICacheFlushMode icache_flush_mode) {
232 // set_target_compressed_value_at function could update 32-bit value loaded
233 // by lu12i.w and ori instructions.
234 Assembler::set_target_compressed_value_at(pc, new_constant, jit_allocation,
235 icache_flush_mode);
236}
237
238// -----------------------------------------------------------------------------
239// Assembler.
240
242 if (buffer_space() <= kGap) {
243 GrowBuffer();
244 }
245}
246
248 *reinterpret_cast<Instr*>(pc_) = x;
249 pc_ += kInstrSize;
251}
252
253template <>
254inline void Assembler::EmitHelper(uint8_t x);
255
256template <typename T>
258 *reinterpret_cast<T*>(pc_) = x;
259 pc_ += sizeof(x);
261}
262
263template <>
265 *reinterpret_cast<uint8_t*>(pc_) = x;
266 pc_ += sizeof(x);
267 if (reinterpret_cast<intptr_t>(pc_) % kInstrSize == 0) {
269 }
270}
271
272void Assembler::emit(Instr x) {
274 CheckBuffer();
275 }
276 EmitHelper(x);
277}
278
279void Assembler::emit(uint64_t data) {
280 // CheckForEmitInForbiddenSlot();
282 CheckBuffer();
283 }
284 EmitHelper(data);
285}
286
287EnsureSpace::EnsureSpace(Assembler* assembler) { assembler->CheckBuffer(); }
288
289} // namespace internal
290} // namespace v8
291
292#endif // V8_CODEGEN_LOONG64_ASSEMBLER_LOONG64_INL_H_
IndirectHandle< Code > GetCodeTarget(intptr_t code_target_index) const
Definition assembler.cc:279
IndirectHandle< HeapObject > GetEmbeddedObject(EmbeddedObjectIndex index) const
Definition assembler.cc:300
static constexpr int kSpecialTargetSize
bool is_buffer_growth_blocked() const
static void deserialization_set_target_internal_reference_at(Address pc, Address target, WritableJitAllocation &jit_allocation, RelocInfo::Mode mode=RelocInfo::INTERNAL_REFERENCE)
V8_INLINE Handle< Code > relative_code_target_object_handle_at(Address pc_) const
static Tagged_t target_compressed_address_at(Address pc, Address constant_pool)
static void RelocateRelativeReference(RelocInfo::Mode rmode, Address pc, intptr_t pc_delta, WritableJitAllocation *jit_allocation=nullptr)
static void set_target_compressed_address_at(Address pc, Address constant_pool, Tagged_t target, WritableJitAllocation *jit_allocation, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
static void set_uint32_constant_at(Address pc, Address constant_pool, uint32_t new_constant, WritableJitAllocation *jit_allocation, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
static void set_target_compressed_value_at(Address pc, uint32_t target, WritableJitAllocation *jit_allocation=nullptr, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
static constexpr int kGap
static V8_INLINE void set_target_address_at(Address pc, Address constant_pool, Address target, WritableJitAllocation *jit_allocation, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
Handle< HeapObject > compressed_embedded_object_handle_at(Address pc, Address constant_pool)
static Builtin target_builtin_at(Address pc)
static constexpr int kInstructionsFor64BitConstant
static int deserialization_special_target_size(Address location)
Handle< HeapObject > embedded_object_handle_at(Address pc, Address constant_pool)
static V8_INLINE Address target_address_at(Address pc, Address constant_pool)
void CheckTrampolinePoolQuick(int extra_instructions=0)
Instruction * pc() const
Handle< Code > code_target_object_handle_at(Address pc)
static uint32_t uint32_constant_at(Address pc, Address constant_pool)
static constexpr bool IsBuiltinId(Builtin builtin)
Definition builtins.h:128
static bool IsSupported(CpuFeature f)
V8_INLINE EnsureSpace(Assembler *assembler)
static V8_INLINE bool InTrustedSpace(Tagged< HeapObject > object)
static V8_INLINE bool InCodeSpace(Tagged< HeapObject > object)
union v8::internal::Operand::Value value_
bool IsHeapNumberRequest() const
V8_INLINE bool is_reg() const
int32_t immediate() const
constexpr bool is_valid() const
V8_INLINE Address target_internal_reference()
static constexpr bool IsInternalReference(Mode mode)
Definition reloc-info.h:238
static constexpr bool IsOffHeapTarget(Mode mode)
Definition reloc-info.h:244
static constexpr bool IsRelativeCodeTarget(Mode mode)
Definition reloc-info.h:200
static constexpr bool IsCodeTargetMode(Mode mode)
Definition reloc-info.h:197
static constexpr bool IsCompressedEmbeddedObject(Mode mode)
Definition reloc-info.h:206
V8_INLINE Address target_address()
static constexpr bool IsNearBuiltinEntry(Mode mode)
Definition reloc-info.h:247
V8_INLINE Address target_internal_reference_address()
static constexpr bool IsCodeTarget(Mode mode)
Definition reloc-info.h:196
static constexpr bool IsWasmCall(Mode mode)
Definition reloc-info.h:213
V8_INLINE int target_address_size()
V8_INLINE Builtin target_builtin_at(Assembler *origin)
V8_INLINE WasmCodePointer wasm_code_pointer_table_entry() const
V8_INLINE Address target_off_heap_target()
static constexpr bool IsWasmStubCall(Mode mode)
Definition reloc-info.h:214
static constexpr bool IsEmbeddedObjectMode(Mode mode)
Definition reloc-info.h:209
V8_INLINE Address target_external_reference()
V8_INLINE Tagged< HeapObject > target_object(PtrComprCageBase cage_base)
V8_INLINE Address constant_pool_entry_address()
V8_INLINE JSDispatchHandle js_dispatch_handle()
V8_INLINE DirectHandle< HeapObject > target_object_handle(Assembler *origin)
static constexpr bool IsFullEmbeddedObject(Mode mode)
Definition reloc-info.h:203
bool HasTargetAddressAddress() const
V8_INLINE Address target_address_address()
static V8_INLINE Tagged_t CompressObject(Address tagged)
static V8_INLINE Address DecompressTagged(TOnHeapAddress on_heap_addr, Tagged_t raw_value)
V8_INLINE void WriteUnalignedValue(Address address, T value)
V8_INLINE void set_target_object(Tagged< InstructionStream > host, Tagged< HeapObject > target, WriteBarrierMode write_barrier_mode=UPDATE_WRITE_BARRIER, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
WritableJitAllocation & jit_allocation_
Definition reloc-info.h:462
V8_INLINE void set_wasm_code_pointer_table_entry(WasmCodePointer, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
V8_INLINE void apply(intptr_t delta)
V8_INLINE void set_target_external_reference(Address, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
#define V8_EXTERNAL_CODE_SPACE_BOOL
Definition globals.h:255
#define COMPRESS_POINTERS_BOOL
Definition globals.h:99
#define HAS_SMI_TAG(value)
Definition globals.h:1771
#define V8_ENABLE_SANDBOX_BOOL
Definition globals.h:160
TNode< Object > target
Instruction * instr
int x
int int32_t
Definition unicode.cc:40
kInterpreterTrampolineOffset Tagged< HeapObject >
Address Tagged_t
Definition globals.h:547
base::StrongAlias< JSDispatchHandleAliasTag, uint32_t > JSDispatchHandle
Definition globals.h:557
constexpr int kImm16Mask
constexpr uint8_t kInstrSize
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
Local< T > Handle
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK(condition)
Definition logging.h:482