v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
assembler-ia32-inl.h
Go to the documentation of this file.
1// Copyright (c) 1994-2006 Sun Microsystems Inc.
2// All Rights Reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// - Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10//
11// - Redistribution in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// - Neither the name of Sun Microsystems or the names of contributors may
16// be used to endorse or promote products derived from this software without
17// specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// The original source code covered by the above license above has been
32// modified significantly by Google Inc.
33// Copyright 2012 the V8 project authors. All rights reserved.
34
35// A light-weight IA32 Assembler.
36
37#ifndef V8_CODEGEN_IA32_ASSEMBLER_IA32_INL_H_
38#define V8_CODEGEN_IA32_ASSEMBLER_IA32_INL_H_
39
41// Include the non-inl header before the rest of the headers.
42
43#include "src/base/memory.h"
46#include "src/debug/debug.h"
48
49namespace v8 {
50namespace internal {
51
52bool CpuFeatures::SupportsOptimizer() { return true; }
53
54// The modes possibly affected by apply must be in kApplyMask.
55void WritableRelocInfo::apply(intptr_t delta) {
64 } else if (IsInternalReference(rmode_)) {
65 // Absolute code pointer inside code object moves with the code object.
68 }
69}
70
74}
75
78 return pc_;
79}
80
82
84
85Tagged<HeapObject> RelocInfo::target_object(PtrComprCageBase cage_base) {
87 return Cast<HeapObject>(Tagged<Object>(ReadUnalignedValue<Address>(pc_)));
88}
89
90DirectHandle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
92 return Cast<HeapObject>(ReadUnalignedValue<IndirectHandle<Object>>(pc_));
93}
94
97 return JSDispatchHandle(ReadUnalignedValue<JSDispatchHandle>(pc_));
98}
99
101 ICacheFlushMode icache_flush_mode) {
103 WriteUnalignedValue(pc_, target.ptr());
104 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
106 }
107}
108
111 return ReadUnalignedValue<Address>(pc_);
112}
113
115 Address target, ICacheFlushMode icache_flush_mode) {
117 WriteUnalignedValue(pc_, target);
118 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
120 }
121}
122
123WasmCodePointer RelocInfo::wasm_code_pointer_table_entry() const {
125 return WasmCodePointer{ReadUnalignedValue<uint32_t>(pc_)};
126}
127
129 WasmCodePointer target, ICacheFlushMode icache_flush_mode) {
131 WriteUnalignedValue(pc_, target.value());
132 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
134 }
135}
136
139 return ReadUnalignedValue<Address>(pc_);
140}
141
144 return pc_;
145}
146
147Builtin RelocInfo::target_builtin_at(Assembler* origin) { UNREACHABLE(); }
148
152}
153
155 return ReadUnalignedValue<uint32_t>(pc);
156}
157
159 uint32_t new_constant,
160 WritableJitAllocation* jit_allocation,
161 ICacheFlushMode icache_flush_mode) {
162 if (jit_allocation) {
163 jit_allocation->WriteUnalignedValue<uint32_t>(pc, new_constant);
164 } else {
165 WriteUnalignedValue<uint32_t>(pc, new_constant);
166 }
167 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
168 FlushInstructionCache(pc, sizeof(uint32_t));
169 }
170}
171
172void Assembler::emit(uint32_t x) {
173 WriteUnalignedValue(reinterpret_cast<Address>(pc_), x);
174 pc_ += sizeof(uint32_t);
175}
176
177void Assembler::emit_q(uint64_t x) {
178 WriteUnalignedValue(reinterpret_cast<Address>(pc_), x);
179 pc_ += sizeof(uint64_t);
180}
181
185
186void Assembler::emit(uint32_t x, RelocInfo::Mode rmode) {
187 if (!RelocInfo::IsNoInfo(rmode)) {
188 RecordRelocInfo(rmode);
189 }
190 emit(x);
191}
192
194 emit(code.address(), rmode);
195}
196
198 if (x.rmode_ == RelocInfo::INTERNAL_REFERENCE) {
199 Label* label = reinterpret_cast<Label*>(x.immediate());
201 return;
202 }
203 if (!RelocInfo::IsNoInfo(x.rmode_)) RecordRelocInfo(x.rmode_);
204 if (x.is_heap_number_request()) {
205 RequestHeapNumber(x.heap_number_request());
206 emit(0);
207 return;
208 }
209 emit(x.immediate());
210}
211
213 if (label->is_bound()) {
214 int32_t pos;
216 emit(pos);
217 } else {
219 }
220}
221
223 DCHECK(x.is_int8() || x.is_uint8());
224 uint8_t value = static_cast<uint8_t>(x.immediate());
225 *pc_++ = value;
226}
227
230 uint16_t value = static_cast<uint16_t>(x.immediate());
231 WriteUnalignedValue(reinterpret_cast<Address>(pc_), value);
232 pc_ += sizeof(uint16_t);
233}
234
236 return pc + sizeof(int32_t) + ReadUnalignedValue<int32_t>(pc);
237}
238
240 Address target,
241 WritableJitAllocation* jit_allocation,
242 ICacheFlushMode icache_flush_mode) {
243 if (jit_allocation) {
244 jit_allocation->WriteUnalignedValue(pc, target - (pc + sizeof(int32_t)));
245 } else {
246 WriteUnalignedValue(pc, target - (pc + sizeof(int32_t)));
247 }
248 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
249 FlushInstructionCache(pc, sizeof(int32_t));
250 }
251}
252
254 Address instruction_payload) {
255 return kSpecialTargetSize;
256}
257
261
263 long_at_put(L->pos(), disp.data());
264}
265
267 Displacement disp(L, type);
268 L->link_to(pc_offset());
269 emit(static_cast<int>(disp.data()));
270}
271
273 uint8_t disp = 0x00;
274 if (L->is_near_linked()) {
275 int offset = L->near_link_pos() - pc_offset();
276 DCHECK(is_int8(offset));
277 disp = static_cast<uint8_t>(offset & 0xFF);
278 }
279 L->link_to(pc_offset(), Label::kNear);
280 *pc_++ = disp;
281}
282
284 Address pc, Address target, WritableJitAllocation& jit_allocation,
285 RelocInfo::Mode mode) {
286 jit_allocation.WriteUnalignedValue(pc, target);
287}
288
290 DCHECK_EQ(len_, 1);
291 DCHECK_EQ(scale & -4, 0);
292 // Use SIB with no index register only for base esp.
293 DCHECK(index != esp || base == esp);
294 buf_[1] = scale << 6 | index.code() << 3 | base.code();
295 len_ = 2;
296}
297
298void Operand::set_disp8(int8_t disp) {
299 DCHECK(len_ == 1 || len_ == 2);
300 *reinterpret_cast<int8_t*>(&buf_[len_++]) = disp;
301}
302
303} // namespace internal
304} // namespace v8
305
306#endif // V8_CODEGEN_IA32_ASSEMBLER_IA32_INL_H_
interpreter::OperandScale scale
Definition builtins.cc:44
SourcePosition pos
void RequestHeapNumber(HeapNumberRequest request)
Definition assembler.cc:262
static constexpr int kSpecialTargetSize
static void deserialization_set_target_internal_reference_at(Address pc, Address target, WritableJitAllocation &jit_allocation, RelocInfo::Mode mode=RelocInfo::INTERNAL_REFERENCE)
void emit_w(const Immediate &x)
void disp_at_put(Label *L, Displacement disp)
void emit_code_relative_offset(Label *label)
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)
void emit_disp(Label *L, Displacement::Type type)
void long_at_put(int pos, uint32_t x)
Displacement disp_at(Label *L)
void RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data=0)
uint32_t long_at(int pos)
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)
static int deserialization_special_target_size(Address location)
static V8_INLINE Address target_address_at(Address pc, Address constant_pool)
Instruction * pc() const
static uint32_t uint32_constant_at(Address pc, Address constant_pool)
static constexpr int kHeaderSize
void set_disp8(int8_t disp)
void set_sib(ScaleFactor scale, Register index, Register base)
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 const int kApplyMask
Definition reloc-info.h:369
static constexpr int ModeMask(Mode mode)
Definition reloc-info.h:272
V8_INLINE Address target_address()
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
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 constexpr bool IsNoInfo(Mode mode)
Definition reloc-info.h:257
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)
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)
Label label
int32_t offset
int x
static V ReadUnalignedValue(Address p)
Definition memory.h:28
static void WriteUnalignedValue(Address p, V value)
Definition memory.h:41
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
void FlushInstructionCache(void *start, size_t size)
kInterpreterTrampolineOffset Tagged< HeapObject >
base::StrongAlias< JSDispatchHandleAliasTag, uint32_t > JSDispatchHandle
Definition globals.h:557
constexpr int L
Handle< T > IndirectHandle
Definition globals.h:1086
const int kHeapObjectTag
Definition v8-internal.h:72
return value
Definition map-inl.h:893
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485