5 #ifndef V8_X64_ASSEMBLER_X64_INL_H_ 6 #define V8_X64_ASSEMBLER_X64_INL_H_ 8 #include "src/x64/assembler-x64.h" 10 #include "src/base/cpu.h" 11 #include "src/debug/debug.h" 12 #include "src/objects-inl.h" 13 #include "src/v8memory.h" 18 bool CpuFeatures::SupportsOptimizer() {
return true; }
20 bool CpuFeatures::SupportsWasmSimd128() {
return IsSupported(SSE4_1); }
27 Memory<uint32_t>(pc_) = x;
31 void Assembler::emitp(Address x, RelocInfo::Mode rmode) {
32 Memory<uintptr_t>(pc_) = x;
33 if (!RelocInfo::IsNone(rmode)) {
34 RecordRelocInfo(rmode, x);
40 void Assembler::emitq(uint64_t x) {
41 Memory<uint64_t>(pc_) = x;
42 pc_ +=
sizeof(uint64_t);
46 void Assembler::emitw(uint16_t x) {
47 Memory<uint16_t>(pc_) = x;
48 pc_ +=
sizeof(uint16_t);
51 void Assembler::emit_runtime_entry(Address entry, RelocInfo::Mode rmode) {
52 DCHECK(RelocInfo::IsRuntimeEntry(rmode));
53 RecordRelocInfo(rmode);
54 emitl(static_cast<uint32_t>(entry - options().code_range_start));
57 void Assembler::emit(Immediate x) {
58 if (!RelocInfo::IsNone(x.rmode_)) {
59 RecordRelocInfo(x.rmode_);
64 void Assembler::emit_rex_64(Register reg, Register rm_reg) {
65 emit(0x48 | reg.high_bit() << 2 | rm_reg.high_bit());
69 void Assembler::emit_rex_64(XMMRegister reg, Register rm_reg) {
70 emit(0x48 | (reg.code() & 0x8) >> 1 | rm_reg.code() >> 3);
74 void Assembler::emit_rex_64(Register reg, XMMRegister rm_reg) {
75 emit(0x48 | (reg.code() & 0x8) >> 1 | rm_reg.code() >> 3);
78 void Assembler::emit_rex_64(XMMRegister reg, XMMRegister rm_reg) {
79 emit(0x48 | (reg.code() & 0x8) >> 1 | rm_reg.code() >> 3);
82 void Assembler::emit_rex_64(Register reg, Operand op) {
83 emit(0x48 | reg.high_bit() << 2 | op.data().rex);
86 void Assembler::emit_rex_64(XMMRegister reg, Operand op) {
87 emit(0x48 | (reg.code() & 0x8) >> 1 | op.data().rex);
91 void Assembler::emit_rex_64(Register rm_reg) {
92 DCHECK_EQ(rm_reg.code() & 0xf, rm_reg.code());
93 emit(0x48 | rm_reg.high_bit());
96 void Assembler::emit_rex_64(Operand op) { emit(0x48 | op.data().rex); }
98 void Assembler::emit_rex_32(Register reg, Register rm_reg) {
99 emit(0x40 | reg.high_bit() << 2 | rm_reg.high_bit());
102 void Assembler::emit_rex_32(Register reg, Operand op) {
103 emit(0x40 | reg.high_bit() << 2 | op.data().rex);
107 void Assembler::emit_rex_32(Register rm_reg) {
108 emit(0x40 | rm_reg.high_bit());
111 void Assembler::emit_rex_32(Operand op) { emit(0x40 | op.data().rex); }
113 void Assembler::emit_optional_rex_32(Register reg, Register rm_reg) {
114 byte rex_bits = reg.high_bit() << 2 | rm_reg.high_bit();
115 if (rex_bits != 0) emit(0x40 | rex_bits);
118 void Assembler::emit_optional_rex_32(Register reg, Operand op) {
119 byte rex_bits = reg.high_bit() << 2 | op.data().rex;
120 if (rex_bits != 0) emit(0x40 | rex_bits);
123 void Assembler::emit_optional_rex_32(XMMRegister reg, Operand op) {
124 byte rex_bits = (reg.code() & 0x8) >> 1 | op.data().rex;
125 if (rex_bits != 0) emit(0x40 | rex_bits);
129 void Assembler::emit_optional_rex_32(XMMRegister reg, XMMRegister base) {
130 byte rex_bits = (reg.code() & 0x8) >> 1 | (base.code() & 0x8) >> 3;
131 if (rex_bits != 0) emit(0x40 | rex_bits);
135 void Assembler::emit_optional_rex_32(XMMRegister reg, Register base) {
136 byte rex_bits = (reg.code() & 0x8) >> 1 | (base.code() & 0x8) >> 3;
137 if (rex_bits != 0) emit(0x40 | rex_bits);
141 void Assembler::emit_optional_rex_32(Register reg, XMMRegister base) {
142 byte rex_bits = (reg.code() & 0x8) >> 1 | (base.code() & 0x8) >> 3;
143 if (rex_bits != 0) emit(0x40 | rex_bits);
147 void Assembler::emit_optional_rex_32(Register rm_reg) {
148 if (rm_reg.high_bit()) emit(0x41);
151 void Assembler::emit_optional_rex_32(XMMRegister rm_reg) {
152 if (rm_reg.high_bit()) emit(0x41);
155 void Assembler::emit_optional_rex_32(Operand op) {
156 if (op.data().rex != 0) emit(0x40 | op.data().rex);
161 void Assembler::emit_vex3_byte1(XMMRegister reg, XMMRegister rm,
163 byte rxb = ~((reg.high_bit() << 2) | rm.high_bit()) << 5;
169 void Assembler::emit_vex3_byte1(XMMRegister reg, Operand rm, LeadingOpcode m) {
170 byte rxb = ~((reg.high_bit() << 2) | rm.data().rex) << 5;
176 void Assembler::emit_vex2_byte1(XMMRegister reg, XMMRegister v, VectorLength l,
178 byte rv = ~((reg.high_bit() << 4) | v.code()) << 3;
184 void Assembler::emit_vex3_byte2(VexW w, XMMRegister v, VectorLength l,
186 emit(w | ((~v.code() & 0xf) << 3) | l | pp);
190 void Assembler::emit_vex_prefix(XMMRegister reg, XMMRegister vreg,
191 XMMRegister rm, VectorLength l, SIMDPrefix pp,
192 LeadingOpcode mm, VexW w) {
193 if (rm.high_bit() || mm != k0F || w != kW0) {
195 emit_vex3_byte1(reg, rm, mm);
196 emit_vex3_byte2(w, vreg, l, pp);
199 emit_vex2_byte1(reg, vreg, l, pp);
204 void Assembler::emit_vex_prefix(Register reg, Register vreg, Register rm,
205 VectorLength l, SIMDPrefix pp, LeadingOpcode mm,
207 XMMRegister ireg = XMMRegister::from_code(reg.code());
208 XMMRegister ivreg = XMMRegister::from_code(vreg.code());
209 XMMRegister irm = XMMRegister::from_code(rm.code());
210 emit_vex_prefix(ireg, ivreg, irm, l, pp, mm, w);
213 void Assembler::emit_vex_prefix(XMMRegister reg, XMMRegister vreg, Operand rm,
214 VectorLength l, SIMDPrefix pp, LeadingOpcode mm,
216 if (rm.data().rex || mm != k0F || w != kW0) {
218 emit_vex3_byte1(reg, rm, mm);
219 emit_vex3_byte2(w, vreg, l, pp);
222 emit_vex2_byte1(reg, vreg, l, pp);
226 void Assembler::emit_vex_prefix(Register reg, Register vreg, Operand rm,
227 VectorLength l, SIMDPrefix pp, LeadingOpcode mm,
229 XMMRegister ireg = XMMRegister::from_code(reg.code());
230 XMMRegister ivreg = XMMRegister::from_code(vreg.code());
231 emit_vex_prefix(ireg, ivreg, rm, l, pp, mm, w);
235 Address Assembler::target_address_at(Address pc, Address constant_pool) {
236 return Memory<int32_t>(pc) + pc + 4;
239 void Assembler::set_target_address_at(Address pc, Address constant_pool,
241 ICacheFlushMode icache_flush_mode) {
242 Memory<int32_t>(pc) = static_cast<int32_t>(target - pc - 4);
243 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
244 Assembler::FlushICache(pc,
sizeof(int32_t));
248 void Assembler::deserialization_set_target_internal_reference_at(
249 Address pc, Address target, RelocInfo::Mode mode) {
250 Memory<Address>(pc) = target;
254 Address Assembler::target_address_from_return_address(Address pc) {
255 return pc - kCallTargetAddressOffset;
258 void Assembler::deserialization_set_special_target_at(
259 Address instruction_payload, Code code, Address target) {
260 set_target_address_at(instruction_payload,
261 !code.is_null() ? code->constant_pool() : kNullAddress,
265 int Assembler::deserialization_special_target_size(
266 Address instruction_payload) {
267 return kSpecialTargetSize;
270 Handle<Code> Assembler::code_target_object_handle_at(Address pc) {
271 return GetCodeTarget(Memory<int32_t>(pc));
274 Address Assembler::runtime_entry_at(Address pc) {
275 return Memory<int32_t>(pc) + options().code_range_start;
282 void RelocInfo::apply(intptr_t delta) {
283 if (IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)) {
284 Memory<int32_t>(pc_) -= static_cast<int32_t>(delta);
285 }
else if (IsInternalReference(rmode_)) {
287 Memory<Address>(pc_) += delta;
292 Address RelocInfo::target_address() {
293 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) || IsWasmCall(rmode_));
294 return Assembler::target_address_at(pc_, constant_pool_);
297 Address RelocInfo::target_address_address() {
298 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) || IsWasmCall(rmode_) ||
299 IsWasmStubCall(rmode_) || IsEmbeddedObject(rmode_) ||
300 IsExternalReference(rmode_) || IsOffHeapTarget(rmode_));
305 Address RelocInfo::constant_pool_entry_address() {
310 int RelocInfo::target_address_size() {
311 if (IsCodedSpecially()) {
312 return Assembler::kSpecialTargetSize;
318 HeapObject* RelocInfo::target_object() {
319 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
320 return HeapObject::cast(Memory<Object*>(pc_));
323 Handle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
324 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
325 if (rmode_ == EMBEDDED_OBJECT) {
326 return Handle<HeapObject>::cast(Memory<Handle<Object>>(pc_));
328 return origin->code_target_object_handle_at(pc_);
332 Address RelocInfo::target_external_reference() {
333 DCHECK(rmode_ == RelocInfo::EXTERNAL_REFERENCE);
334 return Memory<Address>(pc_);
337 void RelocInfo::set_target_external_reference(
338 Address target, ICacheFlushMode icache_flush_mode) {
339 DCHECK(rmode_ == RelocInfo::EXTERNAL_REFERENCE);
340 Memory<Address>(pc_) = target;
341 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
342 Assembler::FlushICache(pc_,
sizeof(Address));
346 Address RelocInfo::target_internal_reference() {
347 DCHECK(rmode_ == INTERNAL_REFERENCE);
348 return Memory<Address>(pc_);
352 Address RelocInfo::target_internal_reference_address() {
353 DCHECK(rmode_ == INTERNAL_REFERENCE);
357 void RelocInfo::set_target_object(Heap* heap, HeapObject* target,
358 WriteBarrierMode write_barrier_mode,
359 ICacheFlushMode icache_flush_mode) {
360 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
361 Memory<Object*>(pc_) = target;
362 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
363 Assembler::FlushICache(pc_,
sizeof(Address));
365 if (write_barrier_mode == UPDATE_WRITE_BARRIER && !host().is_null()) {
366 WriteBarrierForCode(host(),
this, target);
371 Address RelocInfo::target_runtime_entry(Assembler* origin) {
372 DCHECK(IsRuntimeEntry(rmode_));
373 return origin->runtime_entry_at(pc_);
376 void RelocInfo::set_target_runtime_entry(Address target,
377 WriteBarrierMode write_barrier_mode,
378 ICacheFlushMode icache_flush_mode) {
379 DCHECK(IsRuntimeEntry(rmode_));
380 if (target_address() != target) {
381 set_target_address(target, write_barrier_mode, icache_flush_mode);
385 Address RelocInfo::target_off_heap_target() {
386 DCHECK(IsOffHeapTarget(rmode_));
387 return Memory<Address>(pc_);
390 void RelocInfo::WipeOut() {
391 if (IsEmbeddedObject(rmode_) || IsExternalReference(rmode_) ||
392 IsInternalReference(rmode_) || IsOffHeapTarget(rmode_)) {
393 Memory<Address>(pc_) = kNullAddress;
394 }
else if (IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)) {
396 Assembler::set_target_address_at(pc_, constant_pool_,
397 pc_ +
sizeof(int32_t));
403 template <
typename ObjectVisitor>
404 void RelocInfo::Visit(ObjectVisitor* visitor) {
405 RelocInfo::Mode mode = rmode();
406 if (mode == RelocInfo::EMBEDDED_OBJECT) {
407 visitor->VisitEmbeddedPointer(host(),
this);
408 Assembler::FlushICache(pc_,
sizeof(Address));
409 }
else if (RelocInfo::IsCodeTargetMode(mode)) {
410 visitor->VisitCodeTarget(host(),
this);
411 }
else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
412 visitor->VisitExternalReference(host(),
this);
413 }
else if (mode == RelocInfo::INTERNAL_REFERENCE) {
414 visitor->VisitInternalReference(host(),
this);
415 }
else if (RelocInfo::IsRuntimeEntry(mode)) {
416 visitor->VisitRuntimeEntry(host(),
this);
417 }
else if (RelocInfo::IsOffHeapTarget(mode)) {
418 visitor->VisitOffHeapTarget(host(),
this);
425 #endif // V8_X64_ASSEMBLER_X64_INL_H_