11cb0ef41Sopenharmony_ci// Copyright (c) 1994-2006 Sun Microsystems Inc. 21cb0ef41Sopenharmony_ci// All Rights Reserved. 31cb0ef41Sopenharmony_ci// 41cb0ef41Sopenharmony_ci// Redistribution and use in source and binary forms, with or without 51cb0ef41Sopenharmony_ci// modification, are permitted provided that the following conditions 61cb0ef41Sopenharmony_ci// are met: 71cb0ef41Sopenharmony_ci// 81cb0ef41Sopenharmony_ci// - Redistributions of source code must retain the above copyright notice, 91cb0ef41Sopenharmony_ci// this list of conditions and the following disclaimer. 101cb0ef41Sopenharmony_ci// 111cb0ef41Sopenharmony_ci// - Redistribution in binary form must reproduce the above copyright 121cb0ef41Sopenharmony_ci// notice, this list of conditions and the following disclaimer in the 131cb0ef41Sopenharmony_ci// documentation and/or other materials provided with the 141cb0ef41Sopenharmony_ci// distribution. 151cb0ef41Sopenharmony_ci// 161cb0ef41Sopenharmony_ci// - Neither the name of Sun Microsystems or the names of contributors may 171cb0ef41Sopenharmony_ci// be used to endorse or promote products derived from this software without 181cb0ef41Sopenharmony_ci// specific prior written permission. 191cb0ef41Sopenharmony_ci// 201cb0ef41Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 211cb0ef41Sopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 221cb0ef41Sopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 231cb0ef41Sopenharmony_ci// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 241cb0ef41Sopenharmony_ci// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 251cb0ef41Sopenharmony_ci// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 261cb0ef41Sopenharmony_ci// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 271cb0ef41Sopenharmony_ci// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281cb0ef41Sopenharmony_ci// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 291cb0ef41Sopenharmony_ci// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 301cb0ef41Sopenharmony_ci// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 311cb0ef41Sopenharmony_ci// OF THE POSSIBILITY OF SUCH DAMAGE. 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci// The original source code covered by the above license above has been modified 341cb0ef41Sopenharmony_ci// significantly by Google Inc. 351cb0ef41Sopenharmony_ci// Copyright 2012 the V8 project authors. All rights reserved. 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci#include "src/codegen/ia32/assembler-ia32.h" 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci#include <cstring> 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_IA32 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci#if V8_LIBC_MSVCRT 441cb0ef41Sopenharmony_ci#include <intrin.h> // _xgetbv() 451cb0ef41Sopenharmony_ci#endif 461cb0ef41Sopenharmony_ci#if V8_OS_DARWIN 471cb0ef41Sopenharmony_ci#include <sys/sysctl.h> 481cb0ef41Sopenharmony_ci#endif 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci#include "src/base/bits.h" 511cb0ef41Sopenharmony_ci#include "src/base/cpu.h" 521cb0ef41Sopenharmony_ci#include "src/codegen/assembler-inl.h" 531cb0ef41Sopenharmony_ci#include "src/codegen/macro-assembler.h" 541cb0ef41Sopenharmony_ci#include "src/codegen/string-constants.h" 551cb0ef41Sopenharmony_ci#include "src/deoptimizer/deoptimizer.h" 561cb0ef41Sopenharmony_ci#include "src/diagnostics/disassembler.h" 571cb0ef41Sopenharmony_ci#include "src/init/v8.h" 581cb0ef41Sopenharmony_ci#include "src/numbers/conversions-inl.h" 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_cinamespace v8 { 611cb0ef41Sopenharmony_cinamespace internal { 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ciImmediate Immediate::EmbeddedNumber(double value) { 641cb0ef41Sopenharmony_ci int32_t smi; 651cb0ef41Sopenharmony_ci if (DoubleToSmiInteger(value, &smi)) return Immediate(Smi::FromInt(smi)); 661cb0ef41Sopenharmony_ci Immediate result(0, RelocInfo::FULL_EMBEDDED_OBJECT); 671cb0ef41Sopenharmony_ci result.is_heap_object_request_ = true; 681cb0ef41Sopenharmony_ci result.value_.heap_object_request = HeapObjectRequest(value); 691cb0ef41Sopenharmony_ci return result; 701cb0ef41Sopenharmony_ci} 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ciImmediate Immediate::EmbeddedStringConstant(const StringConstantBase* str) { 731cb0ef41Sopenharmony_ci Immediate result(0, RelocInfo::FULL_EMBEDDED_OBJECT); 741cb0ef41Sopenharmony_ci result.is_heap_object_request_ = true; 751cb0ef41Sopenharmony_ci result.value_.heap_object_request = HeapObjectRequest(str); 761cb0ef41Sopenharmony_ci return result; 771cb0ef41Sopenharmony_ci} 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 801cb0ef41Sopenharmony_ci// Implementation of CpuFeatures 811cb0ef41Sopenharmony_ci 821cb0ef41Sopenharmony_cinamespace { 831cb0ef41Sopenharmony_ci 841cb0ef41Sopenharmony_ciV8_INLINE uint64_t xgetbv(unsigned int xcr) { 851cb0ef41Sopenharmony_ci#if V8_LIBC_MSVCRT 861cb0ef41Sopenharmony_ci return _xgetbv(xcr); 871cb0ef41Sopenharmony_ci#else 881cb0ef41Sopenharmony_ci unsigned eax, edx; 891cb0ef41Sopenharmony_ci // Check xgetbv; this uses a .byte sequence instead of the instruction 901cb0ef41Sopenharmony_ci // directly because older assemblers do not include support for xgetbv and 911cb0ef41Sopenharmony_ci // there is no easy way to conditionally compile based on the assembler 921cb0ef41Sopenharmony_ci // used. 931cb0ef41Sopenharmony_ci __asm__ volatile(".byte 0x0F, 0x01, 0xD0" : "=a"(eax), "=d"(edx) : "c"(xcr)); 941cb0ef41Sopenharmony_ci return static_cast<uint64_t>(eax) | (static_cast<uint64_t>(edx) << 32); 951cb0ef41Sopenharmony_ci#endif 961cb0ef41Sopenharmony_ci} 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_cibool OSHasAVXSupport() { 991cb0ef41Sopenharmony_ci#if V8_OS_DARWIN 1001cb0ef41Sopenharmony_ci // Mac OS X up to 10.9 has a bug where AVX transitions were indeed being 1011cb0ef41Sopenharmony_ci // caused by ISRs, so we detect that here and disable AVX in that case. 1021cb0ef41Sopenharmony_ci char buffer[128]; 1031cb0ef41Sopenharmony_ci size_t buffer_size = arraysize(buffer); 1041cb0ef41Sopenharmony_ci int ctl_name[] = {CTL_KERN, KERN_OSRELEASE}; 1051cb0ef41Sopenharmony_ci if (sysctl(ctl_name, 2, buffer, &buffer_size, nullptr, 0) != 0) { 1061cb0ef41Sopenharmony_ci FATAL("V8 failed to get kernel version"); 1071cb0ef41Sopenharmony_ci } 1081cb0ef41Sopenharmony_ci // The buffer now contains a string of the form XX.YY.ZZ, where 1091cb0ef41Sopenharmony_ci // XX is the major kernel version component. 1101cb0ef41Sopenharmony_ci char* period_pos = strchr(buffer, '.'); 1111cb0ef41Sopenharmony_ci DCHECK_NOT_NULL(period_pos); 1121cb0ef41Sopenharmony_ci *period_pos = '\0'; 1131cb0ef41Sopenharmony_ci long kernel_version_major = strtol(buffer, nullptr, 10); // NOLINT 1141cb0ef41Sopenharmony_ci if (kernel_version_major <= 13) return false; 1151cb0ef41Sopenharmony_ci#endif // V8_OS_DARWIN 1161cb0ef41Sopenharmony_ci // Check whether OS claims to support AVX. 1171cb0ef41Sopenharmony_ci uint64_t feature_mask = xgetbv(0); // XCR_XFEATURE_ENABLED_MASK 1181cb0ef41Sopenharmony_ci return (feature_mask & 0x6) == 0x6; 1191cb0ef41Sopenharmony_ci} 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci#undef _XCR_XFEATURE_ENABLED_MASK 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci} // namespace 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_cibool CpuFeatures::SupportsWasmSimd128() { 1261cb0ef41Sopenharmony_ci#if V8_ENABLE_WEBASSEMBLY 1271cb0ef41Sopenharmony_ci if (IsSupported(SSE4_1)) return true; 1281cb0ef41Sopenharmony_ci if (FLAG_wasm_simd_ssse3_codegen && IsSupported(SSSE3)) return true; 1291cb0ef41Sopenharmony_ci#endif // V8_ENABLE_WEBASSEMBLY 1301cb0ef41Sopenharmony_ci return false; 1311cb0ef41Sopenharmony_ci} 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_civoid CpuFeatures::ProbeImpl(bool cross_compile) { 1341cb0ef41Sopenharmony_ci base::CPU cpu; 1351cb0ef41Sopenharmony_ci CHECK(cpu.has_sse2()); // SSE2 support is mandatory. 1361cb0ef41Sopenharmony_ci CHECK(cpu.has_cmov()); // CMOV support is mandatory. 1371cb0ef41Sopenharmony_ci 1381cb0ef41Sopenharmony_ci // Only use statically determined features for cross compile (snapshot). 1391cb0ef41Sopenharmony_ci if (cross_compile) return; 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ci if (cpu.has_sse42()) SetSupported(SSE4_2); 1421cb0ef41Sopenharmony_ci if (cpu.has_sse41()) SetSupported(SSE4_1); 1431cb0ef41Sopenharmony_ci if (cpu.has_ssse3()) SetSupported(SSSE3); 1441cb0ef41Sopenharmony_ci if (cpu.has_sse3()) SetSupported(SSE3); 1451cb0ef41Sopenharmony_ci if (cpu.has_avx() && cpu.has_osxsave() && OSHasAVXSupport()) { 1461cb0ef41Sopenharmony_ci SetSupported(AVX); 1471cb0ef41Sopenharmony_ci if (cpu.has_avx2()) SetSupported(AVX2); 1481cb0ef41Sopenharmony_ci if (cpu.has_fma3()) SetSupported(FMA3); 1491cb0ef41Sopenharmony_ci } 1501cb0ef41Sopenharmony_ci 1511cb0ef41Sopenharmony_ci if (cpu.has_bmi1() && FLAG_enable_bmi1) SetSupported(BMI1); 1521cb0ef41Sopenharmony_ci if (cpu.has_bmi2() && FLAG_enable_bmi2) SetSupported(BMI2); 1531cb0ef41Sopenharmony_ci if (cpu.has_lzcnt() && FLAG_enable_lzcnt) SetSupported(LZCNT); 1541cb0ef41Sopenharmony_ci if (cpu.has_popcnt() && FLAG_enable_popcnt) SetSupported(POPCNT); 1551cb0ef41Sopenharmony_ci if (strcmp(FLAG_mcpu, "auto") == 0) { 1561cb0ef41Sopenharmony_ci if (cpu.is_atom()) SetSupported(INTEL_ATOM); 1571cb0ef41Sopenharmony_ci } else if (strcmp(FLAG_mcpu, "atom") == 0) { 1581cb0ef41Sopenharmony_ci SetSupported(INTEL_ATOM); 1591cb0ef41Sopenharmony_ci } 1601cb0ef41Sopenharmony_ci 1611cb0ef41Sopenharmony_ci // Ensure that supported cpu features make sense. E.g. it is wrong to support 1621cb0ef41Sopenharmony_ci // AVX but not SSE4_2, if we have --enable-avx and --no-enable-sse4-2, the 1631cb0ef41Sopenharmony_ci // code above would set AVX to supported, and SSE4_2 to unsupported, then the 1641cb0ef41Sopenharmony_ci // checks below will set AVX to unsupported. 1651cb0ef41Sopenharmony_ci if (!FLAG_enable_sse3) SetUnsupported(SSE3); 1661cb0ef41Sopenharmony_ci if (!FLAG_enable_ssse3 || !IsSupported(SSE3)) SetUnsupported(SSSE3); 1671cb0ef41Sopenharmony_ci if (!FLAG_enable_sse4_1 || !IsSupported(SSSE3)) SetUnsupported(SSE4_1); 1681cb0ef41Sopenharmony_ci if (!FLAG_enable_sse4_2 || !IsSupported(SSE4_1)) SetUnsupported(SSE4_2); 1691cb0ef41Sopenharmony_ci if (!FLAG_enable_avx || !IsSupported(SSE4_2)) SetUnsupported(AVX); 1701cb0ef41Sopenharmony_ci if (!FLAG_enable_avx2 || !IsSupported(AVX)) SetUnsupported(AVX2); 1711cb0ef41Sopenharmony_ci if (!FLAG_enable_fma3 || !IsSupported(AVX)) SetUnsupported(FMA3); 1721cb0ef41Sopenharmony_ci 1731cb0ef41Sopenharmony_ci // Set a static value on whether Simd is supported. 1741cb0ef41Sopenharmony_ci // This variable is only used for certain archs to query SupportWasmSimd128() 1751cb0ef41Sopenharmony_ci // at runtime in builtins using an extern ref. Other callers should use 1761cb0ef41Sopenharmony_ci // CpuFeatures::SupportWasmSimd128(). 1771cb0ef41Sopenharmony_ci CpuFeatures::supports_wasm_simd_128_ = CpuFeatures::SupportsWasmSimd128(); 1781cb0ef41Sopenharmony_ci} 1791cb0ef41Sopenharmony_ci 1801cb0ef41Sopenharmony_civoid CpuFeatures::PrintTarget() {} 1811cb0ef41Sopenharmony_civoid CpuFeatures::PrintFeatures() { 1821cb0ef41Sopenharmony_ci printf( 1831cb0ef41Sopenharmony_ci "SSE3=%d SSSE3=%d SSE4_1=%d AVX=%d AVX2=%d FMA3=%d BMI1=%d BMI2=%d " 1841cb0ef41Sopenharmony_ci "LZCNT=%d " 1851cb0ef41Sopenharmony_ci "POPCNT=%d ATOM=%d\n", 1861cb0ef41Sopenharmony_ci CpuFeatures::IsSupported(SSE3), CpuFeatures::IsSupported(SSSE3), 1871cb0ef41Sopenharmony_ci CpuFeatures::IsSupported(SSE4_1), CpuFeatures::IsSupported(AVX), 1881cb0ef41Sopenharmony_ci CpuFeatures::IsSupported(AVX2), CpuFeatures::IsSupported(FMA3), 1891cb0ef41Sopenharmony_ci CpuFeatures::IsSupported(BMI1), CpuFeatures::IsSupported(BMI2), 1901cb0ef41Sopenharmony_ci CpuFeatures::IsSupported(LZCNT), CpuFeatures::IsSupported(POPCNT), 1911cb0ef41Sopenharmony_ci CpuFeatures::IsSupported(INTEL_ATOM)); 1921cb0ef41Sopenharmony_ci} 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 1951cb0ef41Sopenharmony_ci// Implementation of Displacement 1961cb0ef41Sopenharmony_ci 1971cb0ef41Sopenharmony_civoid Displacement::init(Label* L, Type type) { 1981cb0ef41Sopenharmony_ci DCHECK(!L->is_bound()); 1991cb0ef41Sopenharmony_ci int next = 0; 2001cb0ef41Sopenharmony_ci if (L->is_linked()) { 2011cb0ef41Sopenharmony_ci next = L->pos(); 2021cb0ef41Sopenharmony_ci DCHECK_GT(next, 0); // Displacements must be at positions > 0 2031cb0ef41Sopenharmony_ci } 2041cb0ef41Sopenharmony_ci // Ensure that we _never_ overflow the next field. 2051cb0ef41Sopenharmony_ci DCHECK(NextField::is_valid(Assembler::kMaximalBufferSize)); 2061cb0ef41Sopenharmony_ci data_ = NextField::encode(next) | TypeField::encode(type); 2071cb0ef41Sopenharmony_ci} 2081cb0ef41Sopenharmony_ci 2091cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 2101cb0ef41Sopenharmony_ci// Implementation of RelocInfo 2111cb0ef41Sopenharmony_ci 2121cb0ef41Sopenharmony_ciconst int RelocInfo::kApplyMask = 2131cb0ef41Sopenharmony_ci RelocInfo::ModeMask(RelocInfo::CODE_TARGET) | 2141cb0ef41Sopenharmony_ci RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) | 2151cb0ef41Sopenharmony_ci RelocInfo::ModeMask(RelocInfo::OFF_HEAP_TARGET) | 2161cb0ef41Sopenharmony_ci RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY); 2171cb0ef41Sopenharmony_ci 2181cb0ef41Sopenharmony_cibool RelocInfo::IsCodedSpecially() { 2191cb0ef41Sopenharmony_ci // The deserializer needs to know whether a pointer is specially coded. Being 2201cb0ef41Sopenharmony_ci // specially coded on IA32 means that it is a relative address, as used by 2211cb0ef41Sopenharmony_ci // branch instructions. These are also the ones that need changing when a 2221cb0ef41Sopenharmony_ci // code object moves. 2231cb0ef41Sopenharmony_ci return RelocInfo::ModeMask(rmode_) & kApplyMask; 2241cb0ef41Sopenharmony_ci} 2251cb0ef41Sopenharmony_ci 2261cb0ef41Sopenharmony_cibool RelocInfo::IsInConstantPool() { return false; } 2271cb0ef41Sopenharmony_ci 2281cb0ef41Sopenharmony_ciuint32_t RelocInfo::wasm_call_tag() const { 2291cb0ef41Sopenharmony_ci DCHECK(rmode_ == WASM_CALL || rmode_ == WASM_STUB_CALL); 2301cb0ef41Sopenharmony_ci return ReadUnalignedValue<uint32_t>(pc_); 2311cb0ef41Sopenharmony_ci} 2321cb0ef41Sopenharmony_ci 2331cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 2341cb0ef41Sopenharmony_ci// Implementation of Operand 2351cb0ef41Sopenharmony_ci 2361cb0ef41Sopenharmony_ciOperand::Operand(Register base, int32_t disp, RelocInfo::Mode rmode) { 2371cb0ef41Sopenharmony_ci // [base + disp/r] 2381cb0ef41Sopenharmony_ci if (disp == 0 && RelocInfo::IsNoInfo(rmode) && base != ebp) { 2391cb0ef41Sopenharmony_ci // [base] 2401cb0ef41Sopenharmony_ci set_modrm(0, base); 2411cb0ef41Sopenharmony_ci if (base == esp) set_sib(times_1, esp, base); 2421cb0ef41Sopenharmony_ci } else if (is_int8(disp) && RelocInfo::IsNoInfo(rmode)) { 2431cb0ef41Sopenharmony_ci // [base + disp8] 2441cb0ef41Sopenharmony_ci set_modrm(1, base); 2451cb0ef41Sopenharmony_ci if (base == esp) set_sib(times_1, esp, base); 2461cb0ef41Sopenharmony_ci set_disp8(disp); 2471cb0ef41Sopenharmony_ci } else { 2481cb0ef41Sopenharmony_ci // [base + disp/r] 2491cb0ef41Sopenharmony_ci set_modrm(2, base); 2501cb0ef41Sopenharmony_ci if (base == esp) set_sib(times_1, esp, base); 2511cb0ef41Sopenharmony_ci set_dispr(disp, rmode); 2521cb0ef41Sopenharmony_ci } 2531cb0ef41Sopenharmony_ci} 2541cb0ef41Sopenharmony_ci 2551cb0ef41Sopenharmony_ciOperand::Operand(Register base, Register index, ScaleFactor scale, int32_t disp, 2561cb0ef41Sopenharmony_ci RelocInfo::Mode rmode) { 2571cb0ef41Sopenharmony_ci DCHECK(index != esp); // illegal addressing mode 2581cb0ef41Sopenharmony_ci // [base + index*scale + disp/r] 2591cb0ef41Sopenharmony_ci if (disp == 0 && RelocInfo::IsNoInfo(rmode) && base != ebp) { 2601cb0ef41Sopenharmony_ci // [base + index*scale] 2611cb0ef41Sopenharmony_ci set_modrm(0, esp); 2621cb0ef41Sopenharmony_ci set_sib(scale, index, base); 2631cb0ef41Sopenharmony_ci } else if (is_int8(disp) && RelocInfo::IsNoInfo(rmode)) { 2641cb0ef41Sopenharmony_ci // [base + index*scale + disp8] 2651cb0ef41Sopenharmony_ci set_modrm(1, esp); 2661cb0ef41Sopenharmony_ci set_sib(scale, index, base); 2671cb0ef41Sopenharmony_ci set_disp8(disp); 2681cb0ef41Sopenharmony_ci } else { 2691cb0ef41Sopenharmony_ci // [base + index*scale + disp/r] 2701cb0ef41Sopenharmony_ci set_modrm(2, esp); 2711cb0ef41Sopenharmony_ci set_sib(scale, index, base); 2721cb0ef41Sopenharmony_ci set_dispr(disp, rmode); 2731cb0ef41Sopenharmony_ci } 2741cb0ef41Sopenharmony_ci} 2751cb0ef41Sopenharmony_ci 2761cb0ef41Sopenharmony_ciOperand::Operand(Register index, ScaleFactor scale, int32_t disp, 2771cb0ef41Sopenharmony_ci RelocInfo::Mode rmode) { 2781cb0ef41Sopenharmony_ci DCHECK(index != esp); // illegal addressing mode 2791cb0ef41Sopenharmony_ci // [index*scale + disp/r] 2801cb0ef41Sopenharmony_ci set_modrm(0, esp); 2811cb0ef41Sopenharmony_ci set_sib(scale, index, ebp); 2821cb0ef41Sopenharmony_ci set_dispr(disp, rmode); 2831cb0ef41Sopenharmony_ci} 2841cb0ef41Sopenharmony_ci 2851cb0ef41Sopenharmony_cibool Operand::is_reg_only() const { 2861cb0ef41Sopenharmony_ci return (buf_[0] & 0xF8) == 0xC0; // Addressing mode is register only. 2871cb0ef41Sopenharmony_ci} 2881cb0ef41Sopenharmony_ci 2891cb0ef41Sopenharmony_ciRegister Operand::reg() const { 2901cb0ef41Sopenharmony_ci DCHECK(is_reg_only()); 2911cb0ef41Sopenharmony_ci return Register::from_code(buf_[0] & 0x07); 2921cb0ef41Sopenharmony_ci} 2931cb0ef41Sopenharmony_ci 2941cb0ef41Sopenharmony_cibool operator!=(Operand op, XMMRegister r) { return !op.is_reg(r); } 2951cb0ef41Sopenharmony_ci 2961cb0ef41Sopenharmony_civoid Assembler::AllocateAndInstallRequestedHeapObjects(Isolate* isolate) { 2971cb0ef41Sopenharmony_ci DCHECK_IMPLIES(isolate == nullptr, heap_object_requests_.empty()); 2981cb0ef41Sopenharmony_ci for (auto& request : heap_object_requests_) { 2991cb0ef41Sopenharmony_ci Handle<HeapObject> object; 3001cb0ef41Sopenharmony_ci switch (request.kind()) { 3011cb0ef41Sopenharmony_ci case HeapObjectRequest::kHeapNumber: 3021cb0ef41Sopenharmony_ci object = isolate->factory()->NewHeapNumber<AllocationType::kOld>( 3031cb0ef41Sopenharmony_ci request.heap_number()); 3041cb0ef41Sopenharmony_ci break; 3051cb0ef41Sopenharmony_ci case HeapObjectRequest::kStringConstant: { 3061cb0ef41Sopenharmony_ci const StringConstantBase* str = request.string(); 3071cb0ef41Sopenharmony_ci CHECK_NOT_NULL(str); 3081cb0ef41Sopenharmony_ci object = str->AllocateStringConstant(isolate); 3091cb0ef41Sopenharmony_ci break; 3101cb0ef41Sopenharmony_ci } 3111cb0ef41Sopenharmony_ci } 3121cb0ef41Sopenharmony_ci Address pc = reinterpret_cast<Address>(buffer_start_) + request.offset(); 3131cb0ef41Sopenharmony_ci WriteUnalignedValue(pc, object); 3141cb0ef41Sopenharmony_ci } 3151cb0ef41Sopenharmony_ci} 3161cb0ef41Sopenharmony_ci 3171cb0ef41Sopenharmony_ci// ----------------------------------------------------------------------------- 3181cb0ef41Sopenharmony_ci// Implementation of Assembler. 3191cb0ef41Sopenharmony_ci 3201cb0ef41Sopenharmony_ci// Emit a single byte. Must always be inlined. 3211cb0ef41Sopenharmony_ci#define EMIT(x) *pc_++ = (x) 3221cb0ef41Sopenharmony_ci 3231cb0ef41Sopenharmony_ciAssembler::Assembler(const AssemblerOptions& options, 3241cb0ef41Sopenharmony_ci std::unique_ptr<AssemblerBuffer> buffer) 3251cb0ef41Sopenharmony_ci : AssemblerBase(options, std::move(buffer)) { 3261cb0ef41Sopenharmony_ci reloc_info_writer.Reposition(buffer_start_ + buffer_->size(), pc_); 3271cb0ef41Sopenharmony_ci if (CpuFeatures::IsSupported(SSE4_2)) { 3281cb0ef41Sopenharmony_ci EnableCpuFeature(SSE4_1); 3291cb0ef41Sopenharmony_ci } 3301cb0ef41Sopenharmony_ci if (CpuFeatures::IsSupported(SSE4_1)) { 3311cb0ef41Sopenharmony_ci EnableCpuFeature(SSSE3); 3321cb0ef41Sopenharmony_ci } 3331cb0ef41Sopenharmony_ci if (CpuFeatures::IsSupported(SSSE3)) { 3341cb0ef41Sopenharmony_ci EnableCpuFeature(SSE3); 3351cb0ef41Sopenharmony_ci } 3361cb0ef41Sopenharmony_ci} 3371cb0ef41Sopenharmony_ci 3381cb0ef41Sopenharmony_civoid Assembler::GetCode(Isolate* isolate, CodeDesc* desc, 3391cb0ef41Sopenharmony_ci SafepointTableBuilder* safepoint_table_builder, 3401cb0ef41Sopenharmony_ci int handler_table_offset) { 3411cb0ef41Sopenharmony_ci // As a crutch to avoid having to add manual Align calls wherever we use a 3421cb0ef41Sopenharmony_ci // raw workflow to create Code objects (mostly in tests), add another Align 3431cb0ef41Sopenharmony_ci // call here. It does no harm - the end of the Code object is aligned to the 3441cb0ef41Sopenharmony_ci // (larger) kCodeAlignment anyways. 3451cb0ef41Sopenharmony_ci // TODO(jgruber): Consider moving responsibility for proper alignment to 3461cb0ef41Sopenharmony_ci // metadata table builders (safepoint, handler, constant pool, code 3471cb0ef41Sopenharmony_ci // comments). 3481cb0ef41Sopenharmony_ci DataAlign(Code::kMetadataAlignment); 3491cb0ef41Sopenharmony_ci 3501cb0ef41Sopenharmony_ci const int code_comments_size = WriteCodeComments(); 3511cb0ef41Sopenharmony_ci 3521cb0ef41Sopenharmony_ci // Finalize code (at this point overflow() may be true, but the gap ensures 3531cb0ef41Sopenharmony_ci // that we are still not overlapping instructions and relocation info). 3541cb0ef41Sopenharmony_ci DCHECK(pc_ <= reloc_info_writer.pos()); // No overlap. 3551cb0ef41Sopenharmony_ci 3561cb0ef41Sopenharmony_ci AllocateAndInstallRequestedHeapObjects(isolate); 3571cb0ef41Sopenharmony_ci 3581cb0ef41Sopenharmony_ci // Set up code descriptor. 3591cb0ef41Sopenharmony_ci // TODO(jgruber): Reconsider how these offsets and sizes are maintained up to 3601cb0ef41Sopenharmony_ci // this point to make CodeDesc initialization less fiddly. 3611cb0ef41Sopenharmony_ci 3621cb0ef41Sopenharmony_ci static constexpr int kConstantPoolSize = 0; 3631cb0ef41Sopenharmony_ci const int instruction_size = pc_offset(); 3641cb0ef41Sopenharmony_ci const int code_comments_offset = instruction_size - code_comments_size; 3651cb0ef41Sopenharmony_ci const int constant_pool_offset = code_comments_offset - kConstantPoolSize; 3661cb0ef41Sopenharmony_ci const int handler_table_offset2 = (handler_table_offset == kNoHandlerTable) 3671cb0ef41Sopenharmony_ci ? constant_pool_offset 3681cb0ef41Sopenharmony_ci : handler_table_offset; 3691cb0ef41Sopenharmony_ci const int safepoint_table_offset = 3701cb0ef41Sopenharmony_ci (safepoint_table_builder == kNoSafepointTable) 3711cb0ef41Sopenharmony_ci ? handler_table_offset2 3721cb0ef41Sopenharmony_ci : safepoint_table_builder->safepoint_table_offset(); 3731cb0ef41Sopenharmony_ci const int reloc_info_offset = 3741cb0ef41Sopenharmony_ci static_cast<int>(reloc_info_writer.pos() - buffer_->start()); 3751cb0ef41Sopenharmony_ci CodeDesc::Initialize(desc, this, safepoint_table_offset, 3761cb0ef41Sopenharmony_ci handler_table_offset2, constant_pool_offset, 3771cb0ef41Sopenharmony_ci code_comments_offset, reloc_info_offset); 3781cb0ef41Sopenharmony_ci} 3791cb0ef41Sopenharmony_ci 3801cb0ef41Sopenharmony_civoid Assembler::FinalizeJumpOptimizationInfo() { 3811cb0ef41Sopenharmony_ci // Collection stage 3821cb0ef41Sopenharmony_ci auto jump_opt = jump_optimization_info(); 3831cb0ef41Sopenharmony_ci if (jump_opt && jump_opt->is_collecting()) { 3841cb0ef41Sopenharmony_ci auto& bitmap = jump_opt->farjmp_bitmap(); 3851cb0ef41Sopenharmony_ci int num = static_cast<int>(farjmp_positions_.size()); 3861cb0ef41Sopenharmony_ci if (num && bitmap.empty()) { 3871cb0ef41Sopenharmony_ci bool can_opt = false; 3881cb0ef41Sopenharmony_ci 3891cb0ef41Sopenharmony_ci bitmap.resize((num + 31) / 32, 0); 3901cb0ef41Sopenharmony_ci for (int i = 0; i < num; i++) { 3911cb0ef41Sopenharmony_ci int disp_pos = farjmp_positions_[i]; 3921cb0ef41Sopenharmony_ci int disp = long_at(disp_pos); 3931cb0ef41Sopenharmony_ci if (is_int8(disp)) { 3941cb0ef41Sopenharmony_ci bitmap[i / 32] |= 1 << (i & 31); 3951cb0ef41Sopenharmony_ci can_opt = true; 3961cb0ef41Sopenharmony_ci } 3971cb0ef41Sopenharmony_ci } 3981cb0ef41Sopenharmony_ci if (can_opt) { 3991cb0ef41Sopenharmony_ci jump_opt->set_optimizable(); 4001cb0ef41Sopenharmony_ci } 4011cb0ef41Sopenharmony_ci } 4021cb0ef41Sopenharmony_ci } 4031cb0ef41Sopenharmony_ci} 4041cb0ef41Sopenharmony_ci 4051cb0ef41Sopenharmony_civoid Assembler::Align(int m) { 4061cb0ef41Sopenharmony_ci DCHECK(base::bits::IsPowerOfTwo(m)); 4071cb0ef41Sopenharmony_ci int mask = m - 1; 4081cb0ef41Sopenharmony_ci int addr = pc_offset(); 4091cb0ef41Sopenharmony_ci Nop((m - (addr & mask)) & mask); 4101cb0ef41Sopenharmony_ci} 4111cb0ef41Sopenharmony_ci 4121cb0ef41Sopenharmony_cibool Assembler::IsNop(Address addr) { 4131cb0ef41Sopenharmony_ci byte* a = reinterpret_cast<byte*>(addr); 4141cb0ef41Sopenharmony_ci while (*a == 0x66) a++; 4151cb0ef41Sopenharmony_ci if (*a == 0x90) return true; 4161cb0ef41Sopenharmony_ci if (a[0] == 0xF && a[1] == 0x1F) return true; 4171cb0ef41Sopenharmony_ci return false; 4181cb0ef41Sopenharmony_ci} 4191cb0ef41Sopenharmony_ci 4201cb0ef41Sopenharmony_civoid Assembler::Nop(int bytes) { 4211cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 4221cb0ef41Sopenharmony_ci // Multi byte nops from http://support.amd.com/us/Processor_TechDocs/40546.pdf 4231cb0ef41Sopenharmony_ci while (bytes > 0) { 4241cb0ef41Sopenharmony_ci switch (bytes) { 4251cb0ef41Sopenharmony_ci case 2: 4261cb0ef41Sopenharmony_ci EMIT(0x66); 4271cb0ef41Sopenharmony_ci V8_FALLTHROUGH; 4281cb0ef41Sopenharmony_ci case 1: 4291cb0ef41Sopenharmony_ci EMIT(0x90); 4301cb0ef41Sopenharmony_ci return; 4311cb0ef41Sopenharmony_ci case 3: 4321cb0ef41Sopenharmony_ci EMIT(0xF); 4331cb0ef41Sopenharmony_ci EMIT(0x1F); 4341cb0ef41Sopenharmony_ci EMIT(0); 4351cb0ef41Sopenharmony_ci return; 4361cb0ef41Sopenharmony_ci case 4: 4371cb0ef41Sopenharmony_ci EMIT(0xF); 4381cb0ef41Sopenharmony_ci EMIT(0x1F); 4391cb0ef41Sopenharmony_ci EMIT(0x40); 4401cb0ef41Sopenharmony_ci EMIT(0); 4411cb0ef41Sopenharmony_ci return; 4421cb0ef41Sopenharmony_ci case 6: 4431cb0ef41Sopenharmony_ci EMIT(0x66); 4441cb0ef41Sopenharmony_ci V8_FALLTHROUGH; 4451cb0ef41Sopenharmony_ci case 5: 4461cb0ef41Sopenharmony_ci EMIT(0xF); 4471cb0ef41Sopenharmony_ci EMIT(0x1F); 4481cb0ef41Sopenharmony_ci EMIT(0x44); 4491cb0ef41Sopenharmony_ci EMIT(0); 4501cb0ef41Sopenharmony_ci EMIT(0); 4511cb0ef41Sopenharmony_ci return; 4521cb0ef41Sopenharmony_ci case 7: 4531cb0ef41Sopenharmony_ci EMIT(0xF); 4541cb0ef41Sopenharmony_ci EMIT(0x1F); 4551cb0ef41Sopenharmony_ci EMIT(0x80); 4561cb0ef41Sopenharmony_ci EMIT(0); 4571cb0ef41Sopenharmony_ci EMIT(0); 4581cb0ef41Sopenharmony_ci EMIT(0); 4591cb0ef41Sopenharmony_ci EMIT(0); 4601cb0ef41Sopenharmony_ci return; 4611cb0ef41Sopenharmony_ci default: 4621cb0ef41Sopenharmony_ci case 11: 4631cb0ef41Sopenharmony_ci EMIT(0x66); 4641cb0ef41Sopenharmony_ci bytes--; 4651cb0ef41Sopenharmony_ci V8_FALLTHROUGH; 4661cb0ef41Sopenharmony_ci case 10: 4671cb0ef41Sopenharmony_ci EMIT(0x66); 4681cb0ef41Sopenharmony_ci bytes--; 4691cb0ef41Sopenharmony_ci V8_FALLTHROUGH; 4701cb0ef41Sopenharmony_ci case 9: 4711cb0ef41Sopenharmony_ci EMIT(0x66); 4721cb0ef41Sopenharmony_ci bytes--; 4731cb0ef41Sopenharmony_ci V8_FALLTHROUGH; 4741cb0ef41Sopenharmony_ci case 8: 4751cb0ef41Sopenharmony_ci EMIT(0xF); 4761cb0ef41Sopenharmony_ci EMIT(0x1F); 4771cb0ef41Sopenharmony_ci EMIT(0x84); 4781cb0ef41Sopenharmony_ci EMIT(0); 4791cb0ef41Sopenharmony_ci EMIT(0); 4801cb0ef41Sopenharmony_ci EMIT(0); 4811cb0ef41Sopenharmony_ci EMIT(0); 4821cb0ef41Sopenharmony_ci EMIT(0); 4831cb0ef41Sopenharmony_ci bytes -= 8; 4841cb0ef41Sopenharmony_ci } 4851cb0ef41Sopenharmony_ci } 4861cb0ef41Sopenharmony_ci} 4871cb0ef41Sopenharmony_ci 4881cb0ef41Sopenharmony_civoid Assembler::CodeTargetAlign() { 4891cb0ef41Sopenharmony_ci Align(16); // Preferred alignment of jump targets on ia32. 4901cb0ef41Sopenharmony_ci} 4911cb0ef41Sopenharmony_ci 4921cb0ef41Sopenharmony_civoid Assembler::cpuid() { 4931cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 4941cb0ef41Sopenharmony_ci EMIT(0x0F); 4951cb0ef41Sopenharmony_ci EMIT(0xA2); 4961cb0ef41Sopenharmony_ci} 4971cb0ef41Sopenharmony_ci 4981cb0ef41Sopenharmony_civoid Assembler::pushad() { 4991cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5001cb0ef41Sopenharmony_ci EMIT(0x60); 5011cb0ef41Sopenharmony_ci} 5021cb0ef41Sopenharmony_ci 5031cb0ef41Sopenharmony_civoid Assembler::popad() { 5041cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5051cb0ef41Sopenharmony_ci EMIT(0x61); 5061cb0ef41Sopenharmony_ci} 5071cb0ef41Sopenharmony_ci 5081cb0ef41Sopenharmony_civoid Assembler::pushfd() { 5091cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5101cb0ef41Sopenharmony_ci EMIT(0x9C); 5111cb0ef41Sopenharmony_ci} 5121cb0ef41Sopenharmony_ci 5131cb0ef41Sopenharmony_civoid Assembler::popfd() { 5141cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5151cb0ef41Sopenharmony_ci EMIT(0x9D); 5161cb0ef41Sopenharmony_ci} 5171cb0ef41Sopenharmony_ci 5181cb0ef41Sopenharmony_civoid Assembler::push(const Immediate& x) { 5191cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5201cb0ef41Sopenharmony_ci if (x.is_int8()) { 5211cb0ef41Sopenharmony_ci EMIT(0x6A); 5221cb0ef41Sopenharmony_ci EMIT(x.immediate()); 5231cb0ef41Sopenharmony_ci } else { 5241cb0ef41Sopenharmony_ci EMIT(0x68); 5251cb0ef41Sopenharmony_ci emit(x); 5261cb0ef41Sopenharmony_ci } 5271cb0ef41Sopenharmony_ci} 5281cb0ef41Sopenharmony_ci 5291cb0ef41Sopenharmony_civoid Assembler::push_imm32(int32_t imm32) { 5301cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5311cb0ef41Sopenharmony_ci EMIT(0x68); 5321cb0ef41Sopenharmony_ci emit(imm32); 5331cb0ef41Sopenharmony_ci} 5341cb0ef41Sopenharmony_ci 5351cb0ef41Sopenharmony_civoid Assembler::push(Register src) { 5361cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5371cb0ef41Sopenharmony_ci EMIT(0x50 | src.code()); 5381cb0ef41Sopenharmony_ci} 5391cb0ef41Sopenharmony_ci 5401cb0ef41Sopenharmony_civoid Assembler::push(Operand src) { 5411cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5421cb0ef41Sopenharmony_ci EMIT(0xFF); 5431cb0ef41Sopenharmony_ci emit_operand(esi, src); 5441cb0ef41Sopenharmony_ci} 5451cb0ef41Sopenharmony_ci 5461cb0ef41Sopenharmony_civoid Assembler::pop(Register dst) { 5471cb0ef41Sopenharmony_ci DCHECK_NOT_NULL(reloc_info_writer.last_pc()); 5481cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5491cb0ef41Sopenharmony_ci EMIT(0x58 | dst.code()); 5501cb0ef41Sopenharmony_ci} 5511cb0ef41Sopenharmony_ci 5521cb0ef41Sopenharmony_civoid Assembler::pop(Operand dst) { 5531cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5541cb0ef41Sopenharmony_ci EMIT(0x8F); 5551cb0ef41Sopenharmony_ci emit_operand(eax, dst); 5561cb0ef41Sopenharmony_ci} 5571cb0ef41Sopenharmony_ci 5581cb0ef41Sopenharmony_civoid Assembler::leave() { 5591cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5601cb0ef41Sopenharmony_ci EMIT(0xC9); 5611cb0ef41Sopenharmony_ci} 5621cb0ef41Sopenharmony_ci 5631cb0ef41Sopenharmony_civoid Assembler::mov_b(Register dst, Operand src) { 5641cb0ef41Sopenharmony_ci CHECK(dst.is_byte_register()); 5651cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5661cb0ef41Sopenharmony_ci EMIT(0x8A); 5671cb0ef41Sopenharmony_ci emit_operand(dst, src); 5681cb0ef41Sopenharmony_ci} 5691cb0ef41Sopenharmony_ci 5701cb0ef41Sopenharmony_civoid Assembler::mov_b(Operand dst, const Immediate& src) { 5711cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5721cb0ef41Sopenharmony_ci EMIT(0xC6); 5731cb0ef41Sopenharmony_ci emit_operand(eax, dst); 5741cb0ef41Sopenharmony_ci EMIT(static_cast<int8_t>(src.immediate())); 5751cb0ef41Sopenharmony_ci} 5761cb0ef41Sopenharmony_ci 5771cb0ef41Sopenharmony_civoid Assembler::mov_b(Operand dst, Register src) { 5781cb0ef41Sopenharmony_ci CHECK(src.is_byte_register()); 5791cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5801cb0ef41Sopenharmony_ci EMIT(0x88); 5811cb0ef41Sopenharmony_ci emit_operand(src, dst); 5821cb0ef41Sopenharmony_ci} 5831cb0ef41Sopenharmony_ci 5841cb0ef41Sopenharmony_civoid Assembler::mov_w(Register dst, Operand src) { 5851cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5861cb0ef41Sopenharmony_ci EMIT(0x66); 5871cb0ef41Sopenharmony_ci EMIT(0x8B); 5881cb0ef41Sopenharmony_ci emit_operand(dst, src); 5891cb0ef41Sopenharmony_ci} 5901cb0ef41Sopenharmony_ci 5911cb0ef41Sopenharmony_civoid Assembler::mov_w(Operand dst, Register src) { 5921cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 5931cb0ef41Sopenharmony_ci EMIT(0x66); 5941cb0ef41Sopenharmony_ci EMIT(0x89); 5951cb0ef41Sopenharmony_ci emit_operand(src, dst); 5961cb0ef41Sopenharmony_ci} 5971cb0ef41Sopenharmony_ci 5981cb0ef41Sopenharmony_civoid Assembler::mov_w(Operand dst, const Immediate& src) { 5991cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6001cb0ef41Sopenharmony_ci EMIT(0x66); 6011cb0ef41Sopenharmony_ci EMIT(0xC7); 6021cb0ef41Sopenharmony_ci emit_operand(eax, dst); 6031cb0ef41Sopenharmony_ci EMIT(static_cast<int8_t>(src.immediate() & 0xFF)); 6041cb0ef41Sopenharmony_ci EMIT(static_cast<int8_t>(src.immediate() >> 8)); 6051cb0ef41Sopenharmony_ci} 6061cb0ef41Sopenharmony_ci 6071cb0ef41Sopenharmony_civoid Assembler::mov(Register dst, int32_t imm32) { 6081cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6091cb0ef41Sopenharmony_ci EMIT(0xB8 | dst.code()); 6101cb0ef41Sopenharmony_ci emit(imm32); 6111cb0ef41Sopenharmony_ci} 6121cb0ef41Sopenharmony_ci 6131cb0ef41Sopenharmony_civoid Assembler::mov(Register dst, const Immediate& x) { 6141cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6151cb0ef41Sopenharmony_ci EMIT(0xB8 | dst.code()); 6161cb0ef41Sopenharmony_ci emit(x); 6171cb0ef41Sopenharmony_ci} 6181cb0ef41Sopenharmony_ci 6191cb0ef41Sopenharmony_civoid Assembler::mov(Register dst, Handle<HeapObject> handle) { 6201cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6211cb0ef41Sopenharmony_ci EMIT(0xB8 | dst.code()); 6221cb0ef41Sopenharmony_ci emit(handle); 6231cb0ef41Sopenharmony_ci} 6241cb0ef41Sopenharmony_ci 6251cb0ef41Sopenharmony_civoid Assembler::mov(Register dst, Operand src) { 6261cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6271cb0ef41Sopenharmony_ci EMIT(0x8B); 6281cb0ef41Sopenharmony_ci emit_operand(dst, src); 6291cb0ef41Sopenharmony_ci} 6301cb0ef41Sopenharmony_ci 6311cb0ef41Sopenharmony_civoid Assembler::mov(Register dst, Register src) { 6321cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6331cb0ef41Sopenharmony_ci EMIT(0x89); 6341cb0ef41Sopenharmony_ci EMIT(0xC0 | src.code() << 3 | dst.code()); 6351cb0ef41Sopenharmony_ci} 6361cb0ef41Sopenharmony_ci 6371cb0ef41Sopenharmony_civoid Assembler::mov(Operand dst, const Immediate& x) { 6381cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6391cb0ef41Sopenharmony_ci EMIT(0xC7); 6401cb0ef41Sopenharmony_ci emit_operand(eax, dst); 6411cb0ef41Sopenharmony_ci emit(x); 6421cb0ef41Sopenharmony_ci} 6431cb0ef41Sopenharmony_ci 6441cb0ef41Sopenharmony_civoid Assembler::mov(Operand dst, Address src, RelocInfo::Mode rmode) { 6451cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6461cb0ef41Sopenharmony_ci EMIT(0xC7); 6471cb0ef41Sopenharmony_ci emit_operand(eax, dst); 6481cb0ef41Sopenharmony_ci emit(src, rmode); 6491cb0ef41Sopenharmony_ci} 6501cb0ef41Sopenharmony_ci 6511cb0ef41Sopenharmony_civoid Assembler::mov(Operand dst, Handle<HeapObject> handle) { 6521cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6531cb0ef41Sopenharmony_ci EMIT(0xC7); 6541cb0ef41Sopenharmony_ci emit_operand(eax, dst); 6551cb0ef41Sopenharmony_ci emit(handle); 6561cb0ef41Sopenharmony_ci} 6571cb0ef41Sopenharmony_ci 6581cb0ef41Sopenharmony_civoid Assembler::mov(Operand dst, Register src) { 6591cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6601cb0ef41Sopenharmony_ci EMIT(0x89); 6611cb0ef41Sopenharmony_ci emit_operand(src, dst); 6621cb0ef41Sopenharmony_ci} 6631cb0ef41Sopenharmony_ci 6641cb0ef41Sopenharmony_civoid Assembler::movsx_b(Register dst, Operand src) { 6651cb0ef41Sopenharmony_ci DCHECK_IMPLIES(src.is_reg_only(), src.reg().is_byte_register()); 6661cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6671cb0ef41Sopenharmony_ci EMIT(0x0F); 6681cb0ef41Sopenharmony_ci EMIT(0xBE); 6691cb0ef41Sopenharmony_ci emit_operand(dst, src); 6701cb0ef41Sopenharmony_ci} 6711cb0ef41Sopenharmony_ci 6721cb0ef41Sopenharmony_civoid Assembler::movsx_w(Register dst, Operand src) { 6731cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6741cb0ef41Sopenharmony_ci EMIT(0x0F); 6751cb0ef41Sopenharmony_ci EMIT(0xBF); 6761cb0ef41Sopenharmony_ci emit_operand(dst, src); 6771cb0ef41Sopenharmony_ci} 6781cb0ef41Sopenharmony_ci 6791cb0ef41Sopenharmony_civoid Assembler::movzx_b(Register dst, Operand src) { 6801cb0ef41Sopenharmony_ci DCHECK_IMPLIES(src.is_reg_only(), src.reg().is_byte_register()); 6811cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6821cb0ef41Sopenharmony_ci EMIT(0x0F); 6831cb0ef41Sopenharmony_ci EMIT(0xB6); 6841cb0ef41Sopenharmony_ci emit_operand(dst, src); 6851cb0ef41Sopenharmony_ci} 6861cb0ef41Sopenharmony_ci 6871cb0ef41Sopenharmony_civoid Assembler::movzx_w(Register dst, Operand src) { 6881cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6891cb0ef41Sopenharmony_ci EMIT(0x0F); 6901cb0ef41Sopenharmony_ci EMIT(0xB7); 6911cb0ef41Sopenharmony_ci emit_operand(dst, src); 6921cb0ef41Sopenharmony_ci} 6931cb0ef41Sopenharmony_ci 6941cb0ef41Sopenharmony_civoid Assembler::movq(XMMRegister dst, Operand src) { 6951cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 6961cb0ef41Sopenharmony_ci EMIT(0xF3); 6971cb0ef41Sopenharmony_ci EMIT(0x0F); 6981cb0ef41Sopenharmony_ci EMIT(0x7E); 6991cb0ef41Sopenharmony_ci emit_operand(dst, src); 7001cb0ef41Sopenharmony_ci} 7011cb0ef41Sopenharmony_ci 7021cb0ef41Sopenharmony_civoid Assembler::movq(Operand dst, XMMRegister src) { 7031cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7041cb0ef41Sopenharmony_ci EMIT(0x66); 7051cb0ef41Sopenharmony_ci EMIT(0x0F); 7061cb0ef41Sopenharmony_ci EMIT(0xD6); 7071cb0ef41Sopenharmony_ci emit_operand(src, dst); 7081cb0ef41Sopenharmony_ci} 7091cb0ef41Sopenharmony_ci 7101cb0ef41Sopenharmony_civoid Assembler::cmov(Condition cc, Register dst, Operand src) { 7111cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7121cb0ef41Sopenharmony_ci // Opcode: 0f 40 + cc /r. 7131cb0ef41Sopenharmony_ci EMIT(0x0F); 7141cb0ef41Sopenharmony_ci EMIT(0x40 + cc); 7151cb0ef41Sopenharmony_ci emit_operand(dst, src); 7161cb0ef41Sopenharmony_ci} 7171cb0ef41Sopenharmony_ci 7181cb0ef41Sopenharmony_civoid Assembler::cld() { 7191cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7201cb0ef41Sopenharmony_ci EMIT(0xFC); 7211cb0ef41Sopenharmony_ci} 7221cb0ef41Sopenharmony_ci 7231cb0ef41Sopenharmony_civoid Assembler::rep_movs() { 7241cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7251cb0ef41Sopenharmony_ci EMIT(0xF3); 7261cb0ef41Sopenharmony_ci EMIT(0xA5); 7271cb0ef41Sopenharmony_ci} 7281cb0ef41Sopenharmony_ci 7291cb0ef41Sopenharmony_civoid Assembler::rep_stos() { 7301cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7311cb0ef41Sopenharmony_ci EMIT(0xF3); 7321cb0ef41Sopenharmony_ci EMIT(0xAB); 7331cb0ef41Sopenharmony_ci} 7341cb0ef41Sopenharmony_ci 7351cb0ef41Sopenharmony_civoid Assembler::stos() { 7361cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7371cb0ef41Sopenharmony_ci EMIT(0xAB); 7381cb0ef41Sopenharmony_ci} 7391cb0ef41Sopenharmony_ci 7401cb0ef41Sopenharmony_civoid Assembler::xadd(Operand dst, Register src) { 7411cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7421cb0ef41Sopenharmony_ci EMIT(0x0F); 7431cb0ef41Sopenharmony_ci EMIT(0xC1); 7441cb0ef41Sopenharmony_ci emit_operand(src, dst); 7451cb0ef41Sopenharmony_ci} 7461cb0ef41Sopenharmony_ci 7471cb0ef41Sopenharmony_civoid Assembler::xadd_b(Operand dst, Register src) { 7481cb0ef41Sopenharmony_ci DCHECK(src.is_byte_register()); 7491cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7501cb0ef41Sopenharmony_ci EMIT(0x0F); 7511cb0ef41Sopenharmony_ci EMIT(0xC0); 7521cb0ef41Sopenharmony_ci emit_operand(src, dst); 7531cb0ef41Sopenharmony_ci} 7541cb0ef41Sopenharmony_ci 7551cb0ef41Sopenharmony_civoid Assembler::xadd_w(Operand dst, Register src) { 7561cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7571cb0ef41Sopenharmony_ci EMIT(0x66); 7581cb0ef41Sopenharmony_ci EMIT(0x0F); 7591cb0ef41Sopenharmony_ci EMIT(0xC1); 7601cb0ef41Sopenharmony_ci emit_operand(src, dst); 7611cb0ef41Sopenharmony_ci} 7621cb0ef41Sopenharmony_ci 7631cb0ef41Sopenharmony_civoid Assembler::xchg(Register dst, Register src) { 7641cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7651cb0ef41Sopenharmony_ci if (src == eax || dst == eax) { // Single-byte encoding. 7661cb0ef41Sopenharmony_ci EMIT(0x90 | (src == eax ? dst.code() : src.code())); 7671cb0ef41Sopenharmony_ci } else { 7681cb0ef41Sopenharmony_ci EMIT(0x87); 7691cb0ef41Sopenharmony_ci EMIT(0xC0 | src.code() << 3 | dst.code()); 7701cb0ef41Sopenharmony_ci } 7711cb0ef41Sopenharmony_ci} 7721cb0ef41Sopenharmony_ci 7731cb0ef41Sopenharmony_civoid Assembler::xchg(Register dst, Operand src) { 7741cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7751cb0ef41Sopenharmony_ci EMIT(0x87); 7761cb0ef41Sopenharmony_ci emit_operand(dst, src); 7771cb0ef41Sopenharmony_ci} 7781cb0ef41Sopenharmony_ci 7791cb0ef41Sopenharmony_civoid Assembler::xchg_b(Register reg, Operand op) { 7801cb0ef41Sopenharmony_ci DCHECK(reg.is_byte_register()); 7811cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7821cb0ef41Sopenharmony_ci EMIT(0x86); 7831cb0ef41Sopenharmony_ci emit_operand(reg, op); 7841cb0ef41Sopenharmony_ci} 7851cb0ef41Sopenharmony_ci 7861cb0ef41Sopenharmony_civoid Assembler::xchg_w(Register reg, Operand op) { 7871cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7881cb0ef41Sopenharmony_ci EMIT(0x66); 7891cb0ef41Sopenharmony_ci EMIT(0x87); 7901cb0ef41Sopenharmony_ci emit_operand(reg, op); 7911cb0ef41Sopenharmony_ci} 7921cb0ef41Sopenharmony_ci 7931cb0ef41Sopenharmony_civoid Assembler::lock() { 7941cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 7951cb0ef41Sopenharmony_ci EMIT(0xF0); 7961cb0ef41Sopenharmony_ci} 7971cb0ef41Sopenharmony_ci 7981cb0ef41Sopenharmony_civoid Assembler::cmpxchg(Operand dst, Register src) { 7991cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8001cb0ef41Sopenharmony_ci EMIT(0x0F); 8011cb0ef41Sopenharmony_ci EMIT(0xB1); 8021cb0ef41Sopenharmony_ci emit_operand(src, dst); 8031cb0ef41Sopenharmony_ci} 8041cb0ef41Sopenharmony_ci 8051cb0ef41Sopenharmony_civoid Assembler::cmpxchg_b(Operand dst, Register src) { 8061cb0ef41Sopenharmony_ci DCHECK(src.is_byte_register()); 8071cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8081cb0ef41Sopenharmony_ci EMIT(0x0F); 8091cb0ef41Sopenharmony_ci EMIT(0xB0); 8101cb0ef41Sopenharmony_ci emit_operand(src, dst); 8111cb0ef41Sopenharmony_ci} 8121cb0ef41Sopenharmony_ci 8131cb0ef41Sopenharmony_civoid Assembler::cmpxchg_w(Operand dst, Register src) { 8141cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8151cb0ef41Sopenharmony_ci EMIT(0x66); 8161cb0ef41Sopenharmony_ci EMIT(0x0F); 8171cb0ef41Sopenharmony_ci EMIT(0xB1); 8181cb0ef41Sopenharmony_ci emit_operand(src, dst); 8191cb0ef41Sopenharmony_ci} 8201cb0ef41Sopenharmony_ci 8211cb0ef41Sopenharmony_civoid Assembler::cmpxchg8b(Operand dst) { 8221cb0ef41Sopenharmony_ci EnsureSpace enure_space(this); 8231cb0ef41Sopenharmony_ci EMIT(0x0F); 8241cb0ef41Sopenharmony_ci EMIT(0xC7); 8251cb0ef41Sopenharmony_ci emit_operand(ecx, dst); 8261cb0ef41Sopenharmony_ci} 8271cb0ef41Sopenharmony_ci 8281cb0ef41Sopenharmony_civoid Assembler::mfence() { 8291cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8301cb0ef41Sopenharmony_ci EMIT(0x0F); 8311cb0ef41Sopenharmony_ci EMIT(0xAE); 8321cb0ef41Sopenharmony_ci EMIT(0xF0); 8331cb0ef41Sopenharmony_ci} 8341cb0ef41Sopenharmony_ci 8351cb0ef41Sopenharmony_civoid Assembler::lfence() { 8361cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8371cb0ef41Sopenharmony_ci EMIT(0x0F); 8381cb0ef41Sopenharmony_ci EMIT(0xAE); 8391cb0ef41Sopenharmony_ci EMIT(0xE8); 8401cb0ef41Sopenharmony_ci} 8411cb0ef41Sopenharmony_ci 8421cb0ef41Sopenharmony_civoid Assembler::pause() { 8431cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8441cb0ef41Sopenharmony_ci EMIT(0xF3); 8451cb0ef41Sopenharmony_ci EMIT(0x90); 8461cb0ef41Sopenharmony_ci} 8471cb0ef41Sopenharmony_ci 8481cb0ef41Sopenharmony_civoid Assembler::adc(Register dst, int32_t imm32) { 8491cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8501cb0ef41Sopenharmony_ci emit_arith(2, Operand(dst), Immediate(imm32)); 8511cb0ef41Sopenharmony_ci} 8521cb0ef41Sopenharmony_ci 8531cb0ef41Sopenharmony_civoid Assembler::adc(Register dst, Operand src) { 8541cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8551cb0ef41Sopenharmony_ci EMIT(0x13); 8561cb0ef41Sopenharmony_ci emit_operand(dst, src); 8571cb0ef41Sopenharmony_ci} 8581cb0ef41Sopenharmony_ci 8591cb0ef41Sopenharmony_civoid Assembler::add(Register dst, Operand src) { 8601cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8611cb0ef41Sopenharmony_ci EMIT(0x03); 8621cb0ef41Sopenharmony_ci emit_operand(dst, src); 8631cb0ef41Sopenharmony_ci} 8641cb0ef41Sopenharmony_ci 8651cb0ef41Sopenharmony_civoid Assembler::add(Operand dst, Register src) { 8661cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8671cb0ef41Sopenharmony_ci EMIT(0x01); 8681cb0ef41Sopenharmony_ci emit_operand(src, dst); 8691cb0ef41Sopenharmony_ci} 8701cb0ef41Sopenharmony_ci 8711cb0ef41Sopenharmony_civoid Assembler::add(Operand dst, const Immediate& x) { 8721cb0ef41Sopenharmony_ci DCHECK_NOT_NULL(reloc_info_writer.last_pc()); 8731cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8741cb0ef41Sopenharmony_ci emit_arith(0, dst, x); 8751cb0ef41Sopenharmony_ci} 8761cb0ef41Sopenharmony_ci 8771cb0ef41Sopenharmony_civoid Assembler::and_(Register dst, int32_t imm32) { 8781cb0ef41Sopenharmony_ci and_(dst, Immediate(imm32)); 8791cb0ef41Sopenharmony_ci} 8801cb0ef41Sopenharmony_ci 8811cb0ef41Sopenharmony_civoid Assembler::and_(Register dst, const Immediate& x) { 8821cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8831cb0ef41Sopenharmony_ci emit_arith(4, Operand(dst), x); 8841cb0ef41Sopenharmony_ci} 8851cb0ef41Sopenharmony_ci 8861cb0ef41Sopenharmony_civoid Assembler::and_(Register dst, Operand src) { 8871cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8881cb0ef41Sopenharmony_ci EMIT(0x23); 8891cb0ef41Sopenharmony_ci emit_operand(dst, src); 8901cb0ef41Sopenharmony_ci} 8911cb0ef41Sopenharmony_ci 8921cb0ef41Sopenharmony_civoid Assembler::and_(Operand dst, const Immediate& x) { 8931cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8941cb0ef41Sopenharmony_ci emit_arith(4, dst, x); 8951cb0ef41Sopenharmony_ci} 8961cb0ef41Sopenharmony_ci 8971cb0ef41Sopenharmony_civoid Assembler::and_(Operand dst, Register src) { 8981cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 8991cb0ef41Sopenharmony_ci EMIT(0x21); 9001cb0ef41Sopenharmony_ci emit_operand(src, dst); 9011cb0ef41Sopenharmony_ci} 9021cb0ef41Sopenharmony_ci 9031cb0ef41Sopenharmony_civoid Assembler::cmpb(Operand op, Immediate imm8) { 9041cb0ef41Sopenharmony_ci DCHECK(imm8.is_int8() || imm8.is_uint8()); 9051cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9061cb0ef41Sopenharmony_ci if (op.is_reg(eax)) { 9071cb0ef41Sopenharmony_ci EMIT(0x3C); 9081cb0ef41Sopenharmony_ci } else { 9091cb0ef41Sopenharmony_ci EMIT(0x80); 9101cb0ef41Sopenharmony_ci emit_operand(edi, op); // edi == 7 9111cb0ef41Sopenharmony_ci } 9121cb0ef41Sopenharmony_ci emit_b(imm8); 9131cb0ef41Sopenharmony_ci} 9141cb0ef41Sopenharmony_ci 9151cb0ef41Sopenharmony_civoid Assembler::cmpb(Operand op, Register reg) { 9161cb0ef41Sopenharmony_ci CHECK(reg.is_byte_register()); 9171cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9181cb0ef41Sopenharmony_ci EMIT(0x38); 9191cb0ef41Sopenharmony_ci emit_operand(reg, op); 9201cb0ef41Sopenharmony_ci} 9211cb0ef41Sopenharmony_ci 9221cb0ef41Sopenharmony_civoid Assembler::cmpb(Register reg, Operand op) { 9231cb0ef41Sopenharmony_ci CHECK(reg.is_byte_register()); 9241cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9251cb0ef41Sopenharmony_ci EMIT(0x3A); 9261cb0ef41Sopenharmony_ci emit_operand(reg, op); 9271cb0ef41Sopenharmony_ci} 9281cb0ef41Sopenharmony_ci 9291cb0ef41Sopenharmony_civoid Assembler::cmpw(Operand op, Immediate imm16) { 9301cb0ef41Sopenharmony_ci DCHECK(imm16.is_int16() || imm16.is_uint16()); 9311cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9321cb0ef41Sopenharmony_ci EMIT(0x66); 9331cb0ef41Sopenharmony_ci EMIT(0x81); 9341cb0ef41Sopenharmony_ci emit_operand(edi, op); 9351cb0ef41Sopenharmony_ci emit_w(imm16); 9361cb0ef41Sopenharmony_ci} 9371cb0ef41Sopenharmony_ci 9381cb0ef41Sopenharmony_civoid Assembler::cmpw(Register reg, Operand op) { 9391cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9401cb0ef41Sopenharmony_ci EMIT(0x66); 9411cb0ef41Sopenharmony_ci EMIT(0x3B); 9421cb0ef41Sopenharmony_ci emit_operand(reg, op); 9431cb0ef41Sopenharmony_ci} 9441cb0ef41Sopenharmony_ci 9451cb0ef41Sopenharmony_civoid Assembler::cmpw(Operand op, Register reg) { 9461cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9471cb0ef41Sopenharmony_ci EMIT(0x66); 9481cb0ef41Sopenharmony_ci EMIT(0x39); 9491cb0ef41Sopenharmony_ci emit_operand(reg, op); 9501cb0ef41Sopenharmony_ci} 9511cb0ef41Sopenharmony_ci 9521cb0ef41Sopenharmony_civoid Assembler::cmp(Register reg, int32_t imm32) { 9531cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9541cb0ef41Sopenharmony_ci emit_arith(7, Operand(reg), Immediate(imm32)); 9551cb0ef41Sopenharmony_ci} 9561cb0ef41Sopenharmony_ci 9571cb0ef41Sopenharmony_civoid Assembler::cmp(Register reg, Handle<HeapObject> handle) { 9581cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9591cb0ef41Sopenharmony_ci emit_arith(7, Operand(reg), Immediate(handle)); 9601cb0ef41Sopenharmony_ci} 9611cb0ef41Sopenharmony_ci 9621cb0ef41Sopenharmony_civoid Assembler::cmp(Register reg, Operand op) { 9631cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9641cb0ef41Sopenharmony_ci EMIT(0x3B); 9651cb0ef41Sopenharmony_ci emit_operand(reg, op); 9661cb0ef41Sopenharmony_ci} 9671cb0ef41Sopenharmony_ci 9681cb0ef41Sopenharmony_civoid Assembler::cmp(Operand op, Register reg) { 9691cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9701cb0ef41Sopenharmony_ci EMIT(0x39); 9711cb0ef41Sopenharmony_ci emit_operand(reg, op); 9721cb0ef41Sopenharmony_ci} 9731cb0ef41Sopenharmony_ci 9741cb0ef41Sopenharmony_civoid Assembler::cmp(Operand op, const Immediate& imm) { 9751cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9761cb0ef41Sopenharmony_ci emit_arith(7, op, imm); 9771cb0ef41Sopenharmony_ci} 9781cb0ef41Sopenharmony_ci 9791cb0ef41Sopenharmony_civoid Assembler::cmp(Operand op, Handle<HeapObject> handle) { 9801cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9811cb0ef41Sopenharmony_ci emit_arith(7, op, Immediate(handle)); 9821cb0ef41Sopenharmony_ci} 9831cb0ef41Sopenharmony_ci 9841cb0ef41Sopenharmony_civoid Assembler::cmpb_al(Operand op) { 9851cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9861cb0ef41Sopenharmony_ci EMIT(0x38); // CMP r/m8, r8 9871cb0ef41Sopenharmony_ci emit_operand(eax, op); // eax has same code as register al. 9881cb0ef41Sopenharmony_ci} 9891cb0ef41Sopenharmony_ci 9901cb0ef41Sopenharmony_civoid Assembler::cmpw_ax(Operand op) { 9911cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 9921cb0ef41Sopenharmony_ci EMIT(0x66); 9931cb0ef41Sopenharmony_ci EMIT(0x39); // CMP r/m16, r16 9941cb0ef41Sopenharmony_ci emit_operand(eax, op); // eax has same code as register ax. 9951cb0ef41Sopenharmony_ci} 9961cb0ef41Sopenharmony_ci 9971cb0ef41Sopenharmony_civoid Assembler::dec_b(Register dst) { 9981cb0ef41Sopenharmony_ci CHECK(dst.is_byte_register()); 9991cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10001cb0ef41Sopenharmony_ci EMIT(0xFE); 10011cb0ef41Sopenharmony_ci EMIT(0xC8 | dst.code()); 10021cb0ef41Sopenharmony_ci} 10031cb0ef41Sopenharmony_ci 10041cb0ef41Sopenharmony_civoid Assembler::dec_b(Operand dst) { 10051cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10061cb0ef41Sopenharmony_ci EMIT(0xFE); 10071cb0ef41Sopenharmony_ci emit_operand(ecx, dst); 10081cb0ef41Sopenharmony_ci} 10091cb0ef41Sopenharmony_ci 10101cb0ef41Sopenharmony_civoid Assembler::dec(Register dst) { 10111cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10121cb0ef41Sopenharmony_ci EMIT(0x48 | dst.code()); 10131cb0ef41Sopenharmony_ci} 10141cb0ef41Sopenharmony_ci 10151cb0ef41Sopenharmony_civoid Assembler::dec(Operand dst) { 10161cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10171cb0ef41Sopenharmony_ci EMIT(0xFF); 10181cb0ef41Sopenharmony_ci emit_operand(ecx, dst); 10191cb0ef41Sopenharmony_ci} 10201cb0ef41Sopenharmony_ci 10211cb0ef41Sopenharmony_civoid Assembler::cdq() { 10221cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10231cb0ef41Sopenharmony_ci EMIT(0x99); 10241cb0ef41Sopenharmony_ci} 10251cb0ef41Sopenharmony_ci 10261cb0ef41Sopenharmony_civoid Assembler::idiv(Operand src) { 10271cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10281cb0ef41Sopenharmony_ci EMIT(0xF7); 10291cb0ef41Sopenharmony_ci emit_operand(edi, src); 10301cb0ef41Sopenharmony_ci} 10311cb0ef41Sopenharmony_ci 10321cb0ef41Sopenharmony_civoid Assembler::div(Operand src) { 10331cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10341cb0ef41Sopenharmony_ci EMIT(0xF7); 10351cb0ef41Sopenharmony_ci emit_operand(esi, src); 10361cb0ef41Sopenharmony_ci} 10371cb0ef41Sopenharmony_ci 10381cb0ef41Sopenharmony_civoid Assembler::imul(Register reg) { 10391cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10401cb0ef41Sopenharmony_ci EMIT(0xF7); 10411cb0ef41Sopenharmony_ci EMIT(0xE8 | reg.code()); 10421cb0ef41Sopenharmony_ci} 10431cb0ef41Sopenharmony_ci 10441cb0ef41Sopenharmony_civoid Assembler::imul(Register dst, Operand src) { 10451cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10461cb0ef41Sopenharmony_ci EMIT(0x0F); 10471cb0ef41Sopenharmony_ci EMIT(0xAF); 10481cb0ef41Sopenharmony_ci emit_operand(dst, src); 10491cb0ef41Sopenharmony_ci} 10501cb0ef41Sopenharmony_ci 10511cb0ef41Sopenharmony_civoid Assembler::imul(Register dst, Register src, int32_t imm32) { 10521cb0ef41Sopenharmony_ci imul(dst, Operand(src), imm32); 10531cb0ef41Sopenharmony_ci} 10541cb0ef41Sopenharmony_ci 10551cb0ef41Sopenharmony_civoid Assembler::imul(Register dst, Operand src, int32_t imm32) { 10561cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10571cb0ef41Sopenharmony_ci if (is_int8(imm32)) { 10581cb0ef41Sopenharmony_ci EMIT(0x6B); 10591cb0ef41Sopenharmony_ci emit_operand(dst, src); 10601cb0ef41Sopenharmony_ci EMIT(imm32); 10611cb0ef41Sopenharmony_ci } else { 10621cb0ef41Sopenharmony_ci EMIT(0x69); 10631cb0ef41Sopenharmony_ci emit_operand(dst, src); 10641cb0ef41Sopenharmony_ci emit(imm32); 10651cb0ef41Sopenharmony_ci } 10661cb0ef41Sopenharmony_ci} 10671cb0ef41Sopenharmony_ci 10681cb0ef41Sopenharmony_civoid Assembler::inc(Register dst) { 10691cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10701cb0ef41Sopenharmony_ci EMIT(0x40 | dst.code()); 10711cb0ef41Sopenharmony_ci} 10721cb0ef41Sopenharmony_ci 10731cb0ef41Sopenharmony_civoid Assembler::inc(Operand dst) { 10741cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10751cb0ef41Sopenharmony_ci EMIT(0xFF); 10761cb0ef41Sopenharmony_ci emit_operand(eax, dst); 10771cb0ef41Sopenharmony_ci} 10781cb0ef41Sopenharmony_ci 10791cb0ef41Sopenharmony_civoid Assembler::lea(Register dst, Operand src) { 10801cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10811cb0ef41Sopenharmony_ci EMIT(0x8D); 10821cb0ef41Sopenharmony_ci emit_operand(dst, src); 10831cb0ef41Sopenharmony_ci} 10841cb0ef41Sopenharmony_ci 10851cb0ef41Sopenharmony_civoid Assembler::mul(Register src) { 10861cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10871cb0ef41Sopenharmony_ci EMIT(0xF7); 10881cb0ef41Sopenharmony_ci EMIT(0xE0 | src.code()); 10891cb0ef41Sopenharmony_ci} 10901cb0ef41Sopenharmony_ci 10911cb0ef41Sopenharmony_civoid Assembler::neg(Register dst) { 10921cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10931cb0ef41Sopenharmony_ci EMIT(0xF7); 10941cb0ef41Sopenharmony_ci EMIT(0xD8 | dst.code()); 10951cb0ef41Sopenharmony_ci} 10961cb0ef41Sopenharmony_ci 10971cb0ef41Sopenharmony_civoid Assembler::neg(Operand dst) { 10981cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 10991cb0ef41Sopenharmony_ci EMIT(0xF7); 11001cb0ef41Sopenharmony_ci emit_operand(ebx, dst); 11011cb0ef41Sopenharmony_ci} 11021cb0ef41Sopenharmony_ci 11031cb0ef41Sopenharmony_civoid Assembler::not_(Register dst) { 11041cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11051cb0ef41Sopenharmony_ci EMIT(0xF7); 11061cb0ef41Sopenharmony_ci EMIT(0xD0 | dst.code()); 11071cb0ef41Sopenharmony_ci} 11081cb0ef41Sopenharmony_ci 11091cb0ef41Sopenharmony_civoid Assembler::not_(Operand dst) { 11101cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11111cb0ef41Sopenharmony_ci EMIT(0xF7); 11121cb0ef41Sopenharmony_ci emit_operand(edx, dst); 11131cb0ef41Sopenharmony_ci} 11141cb0ef41Sopenharmony_ci 11151cb0ef41Sopenharmony_civoid Assembler::or_(Register dst, int32_t imm32) { 11161cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11171cb0ef41Sopenharmony_ci emit_arith(1, Operand(dst), Immediate(imm32)); 11181cb0ef41Sopenharmony_ci} 11191cb0ef41Sopenharmony_ci 11201cb0ef41Sopenharmony_civoid Assembler::or_(Register dst, Operand src) { 11211cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11221cb0ef41Sopenharmony_ci EMIT(0x0B); 11231cb0ef41Sopenharmony_ci emit_operand(dst, src); 11241cb0ef41Sopenharmony_ci} 11251cb0ef41Sopenharmony_ci 11261cb0ef41Sopenharmony_civoid Assembler::or_(Operand dst, const Immediate& x) { 11271cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11281cb0ef41Sopenharmony_ci emit_arith(1, dst, x); 11291cb0ef41Sopenharmony_ci} 11301cb0ef41Sopenharmony_ci 11311cb0ef41Sopenharmony_civoid Assembler::or_(Operand dst, Register src) { 11321cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11331cb0ef41Sopenharmony_ci EMIT(0x09); 11341cb0ef41Sopenharmony_ci emit_operand(src, dst); 11351cb0ef41Sopenharmony_ci} 11361cb0ef41Sopenharmony_ci 11371cb0ef41Sopenharmony_civoid Assembler::rcl(Register dst, uint8_t imm8) { 11381cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11391cb0ef41Sopenharmony_ci DCHECK(is_uint5(imm8)); // illegal shift count 11401cb0ef41Sopenharmony_ci if (imm8 == 1) { 11411cb0ef41Sopenharmony_ci EMIT(0xD1); 11421cb0ef41Sopenharmony_ci EMIT(0xD0 | dst.code()); 11431cb0ef41Sopenharmony_ci } else { 11441cb0ef41Sopenharmony_ci EMIT(0xC1); 11451cb0ef41Sopenharmony_ci EMIT(0xD0 | dst.code()); 11461cb0ef41Sopenharmony_ci EMIT(imm8); 11471cb0ef41Sopenharmony_ci } 11481cb0ef41Sopenharmony_ci} 11491cb0ef41Sopenharmony_ci 11501cb0ef41Sopenharmony_civoid Assembler::rcr(Register dst, uint8_t imm8) { 11511cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11521cb0ef41Sopenharmony_ci DCHECK(is_uint5(imm8)); // illegal shift count 11531cb0ef41Sopenharmony_ci if (imm8 == 1) { 11541cb0ef41Sopenharmony_ci EMIT(0xD1); 11551cb0ef41Sopenharmony_ci EMIT(0xD8 | dst.code()); 11561cb0ef41Sopenharmony_ci } else { 11571cb0ef41Sopenharmony_ci EMIT(0xC1); 11581cb0ef41Sopenharmony_ci EMIT(0xD8 | dst.code()); 11591cb0ef41Sopenharmony_ci EMIT(imm8); 11601cb0ef41Sopenharmony_ci } 11611cb0ef41Sopenharmony_ci} 11621cb0ef41Sopenharmony_ci 11631cb0ef41Sopenharmony_civoid Assembler::rol(Operand dst, uint8_t imm8) { 11641cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11651cb0ef41Sopenharmony_ci DCHECK(is_uint5(imm8)); // illegal shift count 11661cb0ef41Sopenharmony_ci if (imm8 == 1) { 11671cb0ef41Sopenharmony_ci EMIT(0xD1); 11681cb0ef41Sopenharmony_ci emit_operand(eax, dst); 11691cb0ef41Sopenharmony_ci } else { 11701cb0ef41Sopenharmony_ci EMIT(0xC1); 11711cb0ef41Sopenharmony_ci emit_operand(eax, dst); 11721cb0ef41Sopenharmony_ci EMIT(imm8); 11731cb0ef41Sopenharmony_ci } 11741cb0ef41Sopenharmony_ci} 11751cb0ef41Sopenharmony_ci 11761cb0ef41Sopenharmony_civoid Assembler::rol_cl(Operand dst) { 11771cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11781cb0ef41Sopenharmony_ci EMIT(0xD3); 11791cb0ef41Sopenharmony_ci emit_operand(eax, dst); 11801cb0ef41Sopenharmony_ci} 11811cb0ef41Sopenharmony_ci 11821cb0ef41Sopenharmony_civoid Assembler::ror(Operand dst, uint8_t imm8) { 11831cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11841cb0ef41Sopenharmony_ci DCHECK(is_uint5(imm8)); // illegal shift count 11851cb0ef41Sopenharmony_ci if (imm8 == 1) { 11861cb0ef41Sopenharmony_ci EMIT(0xD1); 11871cb0ef41Sopenharmony_ci emit_operand(ecx, dst); 11881cb0ef41Sopenharmony_ci } else { 11891cb0ef41Sopenharmony_ci EMIT(0xC1); 11901cb0ef41Sopenharmony_ci emit_operand(ecx, dst); 11911cb0ef41Sopenharmony_ci EMIT(imm8); 11921cb0ef41Sopenharmony_ci } 11931cb0ef41Sopenharmony_ci} 11941cb0ef41Sopenharmony_ci 11951cb0ef41Sopenharmony_civoid Assembler::ror_cl(Operand dst) { 11961cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 11971cb0ef41Sopenharmony_ci EMIT(0xD3); 11981cb0ef41Sopenharmony_ci emit_operand(ecx, dst); 11991cb0ef41Sopenharmony_ci} 12001cb0ef41Sopenharmony_ci 12011cb0ef41Sopenharmony_civoid Assembler::sar(Operand dst, uint8_t imm8) { 12021cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12031cb0ef41Sopenharmony_ci DCHECK(is_uint5(imm8)); // illegal shift count 12041cb0ef41Sopenharmony_ci if (imm8 == 1) { 12051cb0ef41Sopenharmony_ci EMIT(0xD1); 12061cb0ef41Sopenharmony_ci emit_operand(edi, dst); 12071cb0ef41Sopenharmony_ci } else { 12081cb0ef41Sopenharmony_ci EMIT(0xC1); 12091cb0ef41Sopenharmony_ci emit_operand(edi, dst); 12101cb0ef41Sopenharmony_ci EMIT(imm8); 12111cb0ef41Sopenharmony_ci } 12121cb0ef41Sopenharmony_ci} 12131cb0ef41Sopenharmony_ci 12141cb0ef41Sopenharmony_civoid Assembler::sar_cl(Operand dst) { 12151cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12161cb0ef41Sopenharmony_ci EMIT(0xD3); 12171cb0ef41Sopenharmony_ci emit_operand(edi, dst); 12181cb0ef41Sopenharmony_ci} 12191cb0ef41Sopenharmony_ci 12201cb0ef41Sopenharmony_civoid Assembler::sbb(Register dst, Operand src) { 12211cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12221cb0ef41Sopenharmony_ci EMIT(0x1B); 12231cb0ef41Sopenharmony_ci emit_operand(dst, src); 12241cb0ef41Sopenharmony_ci} 12251cb0ef41Sopenharmony_ci 12261cb0ef41Sopenharmony_civoid Assembler::shld(Register dst, Register src, uint8_t shift) { 12271cb0ef41Sopenharmony_ci DCHECK(is_uint5(shift)); 12281cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12291cb0ef41Sopenharmony_ci EMIT(0x0F); 12301cb0ef41Sopenharmony_ci EMIT(0xA4); 12311cb0ef41Sopenharmony_ci emit_operand(src, Operand(dst)); 12321cb0ef41Sopenharmony_ci EMIT(shift); 12331cb0ef41Sopenharmony_ci} 12341cb0ef41Sopenharmony_ci 12351cb0ef41Sopenharmony_civoid Assembler::shld_cl(Register dst, Register src) { 12361cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12371cb0ef41Sopenharmony_ci EMIT(0x0F); 12381cb0ef41Sopenharmony_ci EMIT(0xA5); 12391cb0ef41Sopenharmony_ci emit_operand(src, Operand(dst)); 12401cb0ef41Sopenharmony_ci} 12411cb0ef41Sopenharmony_ci 12421cb0ef41Sopenharmony_civoid Assembler::shl(Operand dst, uint8_t imm8) { 12431cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12441cb0ef41Sopenharmony_ci DCHECK(is_uint5(imm8)); // illegal shift count 12451cb0ef41Sopenharmony_ci if (imm8 == 1) { 12461cb0ef41Sopenharmony_ci EMIT(0xD1); 12471cb0ef41Sopenharmony_ci emit_operand(esp, dst); 12481cb0ef41Sopenharmony_ci } else { 12491cb0ef41Sopenharmony_ci EMIT(0xC1); 12501cb0ef41Sopenharmony_ci emit_operand(esp, dst); 12511cb0ef41Sopenharmony_ci EMIT(imm8); 12521cb0ef41Sopenharmony_ci } 12531cb0ef41Sopenharmony_ci} 12541cb0ef41Sopenharmony_ci 12551cb0ef41Sopenharmony_civoid Assembler::shl_cl(Operand dst) { 12561cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12571cb0ef41Sopenharmony_ci EMIT(0xD3); 12581cb0ef41Sopenharmony_ci emit_operand(esp, dst); 12591cb0ef41Sopenharmony_ci} 12601cb0ef41Sopenharmony_ci 12611cb0ef41Sopenharmony_civoid Assembler::shr(Operand dst, uint8_t imm8) { 12621cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12631cb0ef41Sopenharmony_ci DCHECK(is_uint5(imm8)); // illegal shift count 12641cb0ef41Sopenharmony_ci if (imm8 == 1) { 12651cb0ef41Sopenharmony_ci EMIT(0xD1); 12661cb0ef41Sopenharmony_ci emit_operand(ebp, dst); 12671cb0ef41Sopenharmony_ci } else { 12681cb0ef41Sopenharmony_ci EMIT(0xC1); 12691cb0ef41Sopenharmony_ci emit_operand(ebp, dst); 12701cb0ef41Sopenharmony_ci EMIT(imm8); 12711cb0ef41Sopenharmony_ci } 12721cb0ef41Sopenharmony_ci} 12731cb0ef41Sopenharmony_ci 12741cb0ef41Sopenharmony_civoid Assembler::shr_cl(Operand dst) { 12751cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12761cb0ef41Sopenharmony_ci EMIT(0xD3); 12771cb0ef41Sopenharmony_ci emit_operand(ebp, dst); 12781cb0ef41Sopenharmony_ci} 12791cb0ef41Sopenharmony_ci 12801cb0ef41Sopenharmony_civoid Assembler::shrd(Register dst, Register src, uint8_t shift) { 12811cb0ef41Sopenharmony_ci DCHECK(is_uint5(shift)); 12821cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12831cb0ef41Sopenharmony_ci EMIT(0x0F); 12841cb0ef41Sopenharmony_ci EMIT(0xAC); 12851cb0ef41Sopenharmony_ci emit_operand(src, Operand(dst)); 12861cb0ef41Sopenharmony_ci EMIT(shift); 12871cb0ef41Sopenharmony_ci} 12881cb0ef41Sopenharmony_ci 12891cb0ef41Sopenharmony_civoid Assembler::shrd_cl(Operand dst, Register src) { 12901cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12911cb0ef41Sopenharmony_ci EMIT(0x0F); 12921cb0ef41Sopenharmony_ci EMIT(0xAD); 12931cb0ef41Sopenharmony_ci emit_operand(src, dst); 12941cb0ef41Sopenharmony_ci} 12951cb0ef41Sopenharmony_ci 12961cb0ef41Sopenharmony_civoid Assembler::sub(Operand dst, const Immediate& x) { 12971cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 12981cb0ef41Sopenharmony_ci emit_arith(5, dst, x); 12991cb0ef41Sopenharmony_ci} 13001cb0ef41Sopenharmony_ci 13011cb0ef41Sopenharmony_civoid Assembler::sub(Register dst, Operand src) { 13021cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13031cb0ef41Sopenharmony_ci EMIT(0x2B); 13041cb0ef41Sopenharmony_ci emit_operand(dst, src); 13051cb0ef41Sopenharmony_ci} 13061cb0ef41Sopenharmony_ci 13071cb0ef41Sopenharmony_civoid Assembler::sub(Operand dst, Register src) { 13081cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13091cb0ef41Sopenharmony_ci EMIT(0x29); 13101cb0ef41Sopenharmony_ci emit_operand(src, dst); 13111cb0ef41Sopenharmony_ci} 13121cb0ef41Sopenharmony_ci 13131cb0ef41Sopenharmony_civoid Assembler::sub_sp_32(uint32_t imm) { 13141cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13151cb0ef41Sopenharmony_ci EMIT(0x81); // using a literal 32-bit immediate. 13161cb0ef41Sopenharmony_ci static constexpr Register ireg = Register::from_code(5); 13171cb0ef41Sopenharmony_ci emit_operand(ireg, Operand(esp)); 13181cb0ef41Sopenharmony_ci emit(imm); 13191cb0ef41Sopenharmony_ci} 13201cb0ef41Sopenharmony_ci 13211cb0ef41Sopenharmony_civoid Assembler::test(Register reg, const Immediate& imm) { 13221cb0ef41Sopenharmony_ci if (imm.is_uint8()) { 13231cb0ef41Sopenharmony_ci test_b(reg, imm); 13241cb0ef41Sopenharmony_ci return; 13251cb0ef41Sopenharmony_ci } 13261cb0ef41Sopenharmony_ci 13271cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13281cb0ef41Sopenharmony_ci // This is not using emit_arith because test doesn't support 13291cb0ef41Sopenharmony_ci // sign-extension of 8-bit operands. 13301cb0ef41Sopenharmony_ci if (reg == eax) { 13311cb0ef41Sopenharmony_ci EMIT(0xA9); 13321cb0ef41Sopenharmony_ci } else { 13331cb0ef41Sopenharmony_ci EMIT(0xF7); 13341cb0ef41Sopenharmony_ci EMIT(0xC0 | reg.code()); 13351cb0ef41Sopenharmony_ci } 13361cb0ef41Sopenharmony_ci emit(imm); 13371cb0ef41Sopenharmony_ci} 13381cb0ef41Sopenharmony_ci 13391cb0ef41Sopenharmony_civoid Assembler::test(Register reg, Operand op) { 13401cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13411cb0ef41Sopenharmony_ci EMIT(0x85); 13421cb0ef41Sopenharmony_ci emit_operand(reg, op); 13431cb0ef41Sopenharmony_ci} 13441cb0ef41Sopenharmony_ci 13451cb0ef41Sopenharmony_civoid Assembler::test_b(Register reg, Operand op) { 13461cb0ef41Sopenharmony_ci CHECK(reg.is_byte_register()); 13471cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13481cb0ef41Sopenharmony_ci EMIT(0x84); 13491cb0ef41Sopenharmony_ci emit_operand(reg, op); 13501cb0ef41Sopenharmony_ci} 13511cb0ef41Sopenharmony_ci 13521cb0ef41Sopenharmony_civoid Assembler::test(Operand op, const Immediate& imm) { 13531cb0ef41Sopenharmony_ci if (op.is_reg_only()) { 13541cb0ef41Sopenharmony_ci test(op.reg(), imm); 13551cb0ef41Sopenharmony_ci return; 13561cb0ef41Sopenharmony_ci } 13571cb0ef41Sopenharmony_ci if (imm.is_uint8()) { 13581cb0ef41Sopenharmony_ci return test_b(op, imm); 13591cb0ef41Sopenharmony_ci } 13601cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13611cb0ef41Sopenharmony_ci EMIT(0xF7); 13621cb0ef41Sopenharmony_ci emit_operand(eax, op); 13631cb0ef41Sopenharmony_ci emit(imm); 13641cb0ef41Sopenharmony_ci} 13651cb0ef41Sopenharmony_ci 13661cb0ef41Sopenharmony_civoid Assembler::test_b(Register reg, Immediate imm8) { 13671cb0ef41Sopenharmony_ci DCHECK(imm8.is_uint8()); 13681cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13691cb0ef41Sopenharmony_ci // Only use test against byte for registers that have a byte 13701cb0ef41Sopenharmony_ci // variant: eax, ebx, ecx, and edx. 13711cb0ef41Sopenharmony_ci if (reg == eax) { 13721cb0ef41Sopenharmony_ci EMIT(0xA8); 13731cb0ef41Sopenharmony_ci emit_b(imm8); 13741cb0ef41Sopenharmony_ci } else if (reg.is_byte_register()) { 13751cb0ef41Sopenharmony_ci emit_arith_b(0xF6, 0xC0, reg, static_cast<uint8_t>(imm8.immediate())); 13761cb0ef41Sopenharmony_ci } else { 13771cb0ef41Sopenharmony_ci EMIT(0x66); 13781cb0ef41Sopenharmony_ci EMIT(0xF7); 13791cb0ef41Sopenharmony_ci EMIT(0xC0 | reg.code()); 13801cb0ef41Sopenharmony_ci emit_w(imm8); 13811cb0ef41Sopenharmony_ci } 13821cb0ef41Sopenharmony_ci} 13831cb0ef41Sopenharmony_ci 13841cb0ef41Sopenharmony_civoid Assembler::test_b(Operand op, Immediate imm8) { 13851cb0ef41Sopenharmony_ci if (op.is_reg_only()) { 13861cb0ef41Sopenharmony_ci test_b(op.reg(), imm8); 13871cb0ef41Sopenharmony_ci return; 13881cb0ef41Sopenharmony_ci } 13891cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13901cb0ef41Sopenharmony_ci EMIT(0xF6); 13911cb0ef41Sopenharmony_ci emit_operand(eax, op); 13921cb0ef41Sopenharmony_ci emit_b(imm8); 13931cb0ef41Sopenharmony_ci} 13941cb0ef41Sopenharmony_ci 13951cb0ef41Sopenharmony_civoid Assembler::test_w(Register reg, Immediate imm16) { 13961cb0ef41Sopenharmony_ci DCHECK(imm16.is_int16() || imm16.is_uint16()); 13971cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 13981cb0ef41Sopenharmony_ci if (reg == eax) { 13991cb0ef41Sopenharmony_ci EMIT(0xA9); 14001cb0ef41Sopenharmony_ci emit_w(imm16); 14011cb0ef41Sopenharmony_ci } else { 14021cb0ef41Sopenharmony_ci EMIT(0x66); 14031cb0ef41Sopenharmony_ci EMIT(0xF7); 14041cb0ef41Sopenharmony_ci EMIT(0xC0 | reg.code()); 14051cb0ef41Sopenharmony_ci emit_w(imm16); 14061cb0ef41Sopenharmony_ci } 14071cb0ef41Sopenharmony_ci} 14081cb0ef41Sopenharmony_ci 14091cb0ef41Sopenharmony_civoid Assembler::test_w(Register reg, Operand op) { 14101cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14111cb0ef41Sopenharmony_ci EMIT(0x66); 14121cb0ef41Sopenharmony_ci EMIT(0x85); 14131cb0ef41Sopenharmony_ci emit_operand(reg, op); 14141cb0ef41Sopenharmony_ci} 14151cb0ef41Sopenharmony_ci 14161cb0ef41Sopenharmony_civoid Assembler::test_w(Operand op, Immediate imm16) { 14171cb0ef41Sopenharmony_ci DCHECK(imm16.is_int16() || imm16.is_uint16()); 14181cb0ef41Sopenharmony_ci if (op.is_reg_only()) { 14191cb0ef41Sopenharmony_ci test_w(op.reg(), imm16); 14201cb0ef41Sopenharmony_ci return; 14211cb0ef41Sopenharmony_ci } 14221cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14231cb0ef41Sopenharmony_ci EMIT(0x66); 14241cb0ef41Sopenharmony_ci EMIT(0xF7); 14251cb0ef41Sopenharmony_ci emit_operand(eax, op); 14261cb0ef41Sopenharmony_ci emit_w(imm16); 14271cb0ef41Sopenharmony_ci} 14281cb0ef41Sopenharmony_ci 14291cb0ef41Sopenharmony_civoid Assembler::xor_(Register dst, int32_t imm32) { 14301cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14311cb0ef41Sopenharmony_ci emit_arith(6, Operand(dst), Immediate(imm32)); 14321cb0ef41Sopenharmony_ci} 14331cb0ef41Sopenharmony_ci 14341cb0ef41Sopenharmony_civoid Assembler::xor_(Register dst, Operand src) { 14351cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14361cb0ef41Sopenharmony_ci EMIT(0x33); 14371cb0ef41Sopenharmony_ci emit_operand(dst, src); 14381cb0ef41Sopenharmony_ci} 14391cb0ef41Sopenharmony_ci 14401cb0ef41Sopenharmony_civoid Assembler::xor_(Operand dst, Register src) { 14411cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14421cb0ef41Sopenharmony_ci EMIT(0x31); 14431cb0ef41Sopenharmony_ci emit_operand(src, dst); 14441cb0ef41Sopenharmony_ci} 14451cb0ef41Sopenharmony_ci 14461cb0ef41Sopenharmony_civoid Assembler::xor_(Operand dst, const Immediate& x) { 14471cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14481cb0ef41Sopenharmony_ci emit_arith(6, dst, x); 14491cb0ef41Sopenharmony_ci} 14501cb0ef41Sopenharmony_ci 14511cb0ef41Sopenharmony_civoid Assembler::bswap(Register dst) { 14521cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14531cb0ef41Sopenharmony_ci EMIT(0x0F); 14541cb0ef41Sopenharmony_ci EMIT(0xC8 + dst.code()); 14551cb0ef41Sopenharmony_ci} 14561cb0ef41Sopenharmony_ci 14571cb0ef41Sopenharmony_civoid Assembler::bt(Operand dst, Register src) { 14581cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14591cb0ef41Sopenharmony_ci EMIT(0x0F); 14601cb0ef41Sopenharmony_ci EMIT(0xA3); 14611cb0ef41Sopenharmony_ci emit_operand(src, dst); 14621cb0ef41Sopenharmony_ci} 14631cb0ef41Sopenharmony_ci 14641cb0ef41Sopenharmony_civoid Assembler::bts(Operand dst, Register src) { 14651cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14661cb0ef41Sopenharmony_ci EMIT(0x0F); 14671cb0ef41Sopenharmony_ci EMIT(0xAB); 14681cb0ef41Sopenharmony_ci emit_operand(src, dst); 14691cb0ef41Sopenharmony_ci} 14701cb0ef41Sopenharmony_ci 14711cb0ef41Sopenharmony_civoid Assembler::bsr(Register dst, Operand src) { 14721cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14731cb0ef41Sopenharmony_ci EMIT(0x0F); 14741cb0ef41Sopenharmony_ci EMIT(0xBD); 14751cb0ef41Sopenharmony_ci emit_operand(dst, src); 14761cb0ef41Sopenharmony_ci} 14771cb0ef41Sopenharmony_ci 14781cb0ef41Sopenharmony_civoid Assembler::bsf(Register dst, Operand src) { 14791cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14801cb0ef41Sopenharmony_ci EMIT(0x0F); 14811cb0ef41Sopenharmony_ci EMIT(0xBC); 14821cb0ef41Sopenharmony_ci emit_operand(dst, src); 14831cb0ef41Sopenharmony_ci} 14841cb0ef41Sopenharmony_ci 14851cb0ef41Sopenharmony_civoid Assembler::hlt() { 14861cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14871cb0ef41Sopenharmony_ci EMIT(0xF4); 14881cb0ef41Sopenharmony_ci} 14891cb0ef41Sopenharmony_ci 14901cb0ef41Sopenharmony_civoid Assembler::int3() { 14911cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14921cb0ef41Sopenharmony_ci EMIT(0xCC); 14931cb0ef41Sopenharmony_ci} 14941cb0ef41Sopenharmony_ci 14951cb0ef41Sopenharmony_civoid Assembler::nop() { 14961cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 14971cb0ef41Sopenharmony_ci EMIT(0x90); 14981cb0ef41Sopenharmony_ci} 14991cb0ef41Sopenharmony_ci 15001cb0ef41Sopenharmony_civoid Assembler::ret(int imm16) { 15011cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 15021cb0ef41Sopenharmony_ci DCHECK(is_uint16(imm16)); 15031cb0ef41Sopenharmony_ci if (imm16 == 0) { 15041cb0ef41Sopenharmony_ci EMIT(0xC3); 15051cb0ef41Sopenharmony_ci } else { 15061cb0ef41Sopenharmony_ci EMIT(0xC2); 15071cb0ef41Sopenharmony_ci EMIT(imm16 & 0xFF); 15081cb0ef41Sopenharmony_ci EMIT((imm16 >> 8) & 0xFF); 15091cb0ef41Sopenharmony_ci } 15101cb0ef41Sopenharmony_ci} 15111cb0ef41Sopenharmony_ci 15121cb0ef41Sopenharmony_civoid Assembler::ud2() { 15131cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 15141cb0ef41Sopenharmony_ci EMIT(0x0F); 15151cb0ef41Sopenharmony_ci EMIT(0x0B); 15161cb0ef41Sopenharmony_ci} 15171cb0ef41Sopenharmony_ci 15181cb0ef41Sopenharmony_ci// Labels refer to positions in the (to be) generated code. 15191cb0ef41Sopenharmony_ci// There are bound, linked, and unused labels. 15201cb0ef41Sopenharmony_ci// 15211cb0ef41Sopenharmony_ci// Bound labels refer to known positions in the already 15221cb0ef41Sopenharmony_ci// generated code. pos() is the position the label refers to. 15231cb0ef41Sopenharmony_ci// 15241cb0ef41Sopenharmony_ci// Linked labels refer to unknown positions in the code 15251cb0ef41Sopenharmony_ci// to be generated; pos() is the position of the 32bit 15261cb0ef41Sopenharmony_ci// Displacement of the last instruction using the label. 15271cb0ef41Sopenharmony_ci 15281cb0ef41Sopenharmony_civoid Assembler::print(const Label* L) { 15291cb0ef41Sopenharmony_ci if (L->is_unused()) { 15301cb0ef41Sopenharmony_ci PrintF("unused label\n"); 15311cb0ef41Sopenharmony_ci } else if (L->is_bound()) { 15321cb0ef41Sopenharmony_ci PrintF("bound label to %d\n", L->pos()); 15331cb0ef41Sopenharmony_ci } else if (L->is_linked()) { 15341cb0ef41Sopenharmony_ci Label l; 15351cb0ef41Sopenharmony_ci l.link_to(L->pos()); 15361cb0ef41Sopenharmony_ci PrintF("unbound label"); 15371cb0ef41Sopenharmony_ci while (l.is_linked()) { 15381cb0ef41Sopenharmony_ci Displacement disp = disp_at(&l); 15391cb0ef41Sopenharmony_ci PrintF("@ %d ", l.pos()); 15401cb0ef41Sopenharmony_ci disp.print(); 15411cb0ef41Sopenharmony_ci PrintF("\n"); 15421cb0ef41Sopenharmony_ci disp.next(&l); 15431cb0ef41Sopenharmony_ci } 15441cb0ef41Sopenharmony_ci } else { 15451cb0ef41Sopenharmony_ci PrintF("label in inconsistent state (pos = %d)\n", L->pos_); 15461cb0ef41Sopenharmony_ci } 15471cb0ef41Sopenharmony_ci} 15481cb0ef41Sopenharmony_ci 15491cb0ef41Sopenharmony_civoid Assembler::bind_to(Label* L, int pos) { 15501cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 15511cb0ef41Sopenharmony_ci DCHECK(0 <= pos && pos <= pc_offset()); // must have a valid binding position 15521cb0ef41Sopenharmony_ci while (L->is_linked()) { 15531cb0ef41Sopenharmony_ci Displacement disp = disp_at(L); 15541cb0ef41Sopenharmony_ci int fixup_pos = L->pos(); 15551cb0ef41Sopenharmony_ci if (disp.type() == Displacement::CODE_ABSOLUTE) { 15561cb0ef41Sopenharmony_ci long_at_put(fixup_pos, reinterpret_cast<int>(buffer_start_ + pos)); 15571cb0ef41Sopenharmony_ci internal_reference_positions_.push_back(fixup_pos); 15581cb0ef41Sopenharmony_ci } else if (disp.type() == Displacement::CODE_RELATIVE) { 15591cb0ef41Sopenharmony_ci // Relative to Code heap object pointer. 15601cb0ef41Sopenharmony_ci long_at_put(fixup_pos, pos + Code::kHeaderSize - kHeapObjectTag); 15611cb0ef41Sopenharmony_ci } else { 15621cb0ef41Sopenharmony_ci if (disp.type() == Displacement::UNCONDITIONAL_JUMP) { 15631cb0ef41Sopenharmony_ci DCHECK_EQ(byte_at(fixup_pos - 1), 0xE9); // jmp expected 15641cb0ef41Sopenharmony_ci } 15651cb0ef41Sopenharmony_ci // Relative address, relative to point after address. 15661cb0ef41Sopenharmony_ci int imm32 = pos - (fixup_pos + sizeof(int32_t)); 15671cb0ef41Sopenharmony_ci long_at_put(fixup_pos, imm32); 15681cb0ef41Sopenharmony_ci } 15691cb0ef41Sopenharmony_ci disp.next(L); 15701cb0ef41Sopenharmony_ci } 15711cb0ef41Sopenharmony_ci while (L->is_near_linked()) { 15721cb0ef41Sopenharmony_ci int fixup_pos = L->near_link_pos(); 15731cb0ef41Sopenharmony_ci int offset_to_next = 15741cb0ef41Sopenharmony_ci static_cast<int>(*reinterpret_cast<int8_t*>(addr_at(fixup_pos))); 15751cb0ef41Sopenharmony_ci DCHECK_LE(offset_to_next, 0); 15761cb0ef41Sopenharmony_ci // Relative address, relative to point after address. 15771cb0ef41Sopenharmony_ci int disp = pos - fixup_pos - sizeof(int8_t); 15781cb0ef41Sopenharmony_ci CHECK(0 <= disp && disp <= 127); 15791cb0ef41Sopenharmony_ci set_byte_at(fixup_pos, disp); 15801cb0ef41Sopenharmony_ci if (offset_to_next < 0) { 15811cb0ef41Sopenharmony_ci L->link_to(fixup_pos + offset_to_next, Label::kNear); 15821cb0ef41Sopenharmony_ci } else { 15831cb0ef41Sopenharmony_ci L->UnuseNear(); 15841cb0ef41Sopenharmony_ci } 15851cb0ef41Sopenharmony_ci } 15861cb0ef41Sopenharmony_ci 15871cb0ef41Sopenharmony_ci // Optimization stage 15881cb0ef41Sopenharmony_ci auto jump_opt = jump_optimization_info(); 15891cb0ef41Sopenharmony_ci if (jump_opt && jump_opt->is_optimizing()) { 15901cb0ef41Sopenharmony_ci auto it = label_farjmp_maps_.find(L); 15911cb0ef41Sopenharmony_ci if (it != label_farjmp_maps_.end()) { 15921cb0ef41Sopenharmony_ci auto& pos_vector = it->second; 15931cb0ef41Sopenharmony_ci for (auto fixup_pos : pos_vector) { 15941cb0ef41Sopenharmony_ci int disp = pos - (fixup_pos + sizeof(int8_t)); 15951cb0ef41Sopenharmony_ci CHECK(is_int8(disp)); 15961cb0ef41Sopenharmony_ci set_byte_at(fixup_pos, disp); 15971cb0ef41Sopenharmony_ci } 15981cb0ef41Sopenharmony_ci label_farjmp_maps_.erase(it); 15991cb0ef41Sopenharmony_ci } 16001cb0ef41Sopenharmony_ci } 16011cb0ef41Sopenharmony_ci L->bind_to(pos); 16021cb0ef41Sopenharmony_ci} 16031cb0ef41Sopenharmony_ci 16041cb0ef41Sopenharmony_civoid Assembler::bind(Label* L) { 16051cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 16061cb0ef41Sopenharmony_ci DCHECK(!L->is_bound()); // label can only be bound once 16071cb0ef41Sopenharmony_ci bind_to(L, pc_offset()); 16081cb0ef41Sopenharmony_ci} 16091cb0ef41Sopenharmony_ci 16101cb0ef41Sopenharmony_civoid Assembler::record_farjmp_position(Label* L, int pos) { 16111cb0ef41Sopenharmony_ci auto& pos_vector = label_farjmp_maps_[L]; 16121cb0ef41Sopenharmony_ci pos_vector.push_back(pos); 16131cb0ef41Sopenharmony_ci} 16141cb0ef41Sopenharmony_ci 16151cb0ef41Sopenharmony_cibool Assembler::is_optimizable_farjmp(int idx) { 16161cb0ef41Sopenharmony_ci if (predictable_code_size()) return false; 16171cb0ef41Sopenharmony_ci 16181cb0ef41Sopenharmony_ci auto jump_opt = jump_optimization_info(); 16191cb0ef41Sopenharmony_ci CHECK(jump_opt->is_optimizing()); 16201cb0ef41Sopenharmony_ci 16211cb0ef41Sopenharmony_ci auto& bitmap = jump_opt->farjmp_bitmap(); 16221cb0ef41Sopenharmony_ci CHECK(idx < static_cast<int>(bitmap.size() * 32)); 16231cb0ef41Sopenharmony_ci return !!(bitmap[idx / 32] & (1 << (idx & 31))); 16241cb0ef41Sopenharmony_ci} 16251cb0ef41Sopenharmony_ci 16261cb0ef41Sopenharmony_civoid Assembler::call(Label* L) { 16271cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 16281cb0ef41Sopenharmony_ci if (L->is_bound()) { 16291cb0ef41Sopenharmony_ci const int long_size = 5; 16301cb0ef41Sopenharmony_ci int offs = L->pos() - pc_offset(); 16311cb0ef41Sopenharmony_ci DCHECK_LE(offs, 0); 16321cb0ef41Sopenharmony_ci // 1110 1000 #32-bit disp. 16331cb0ef41Sopenharmony_ci EMIT(0xE8); 16341cb0ef41Sopenharmony_ci emit(offs - long_size); 16351cb0ef41Sopenharmony_ci } else { 16361cb0ef41Sopenharmony_ci // 1110 1000 #32-bit disp. 16371cb0ef41Sopenharmony_ci EMIT(0xE8); 16381cb0ef41Sopenharmony_ci emit_disp(L, Displacement::OTHER); 16391cb0ef41Sopenharmony_ci } 16401cb0ef41Sopenharmony_ci} 16411cb0ef41Sopenharmony_ci 16421cb0ef41Sopenharmony_civoid Assembler::call(Address entry, RelocInfo::Mode rmode) { 16431cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 16441cb0ef41Sopenharmony_ci DCHECK(!RelocInfo::IsCodeTarget(rmode)); 16451cb0ef41Sopenharmony_ci EMIT(0xE8); 16461cb0ef41Sopenharmony_ci if (RelocInfo::IsRuntimeEntry(rmode)) { 16471cb0ef41Sopenharmony_ci emit(entry, rmode); 16481cb0ef41Sopenharmony_ci } else { 16491cb0ef41Sopenharmony_ci emit(entry - (reinterpret_cast<Address>(pc_) + sizeof(int32_t)), rmode); 16501cb0ef41Sopenharmony_ci } 16511cb0ef41Sopenharmony_ci} 16521cb0ef41Sopenharmony_ci 16531cb0ef41Sopenharmony_civoid Assembler::wasm_call(Address entry, RelocInfo::Mode rmode) { 16541cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 16551cb0ef41Sopenharmony_ci EMIT(0xE8); 16561cb0ef41Sopenharmony_ci emit(entry, rmode); 16571cb0ef41Sopenharmony_ci} 16581cb0ef41Sopenharmony_ci 16591cb0ef41Sopenharmony_civoid Assembler::call(Operand adr) { 16601cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 16611cb0ef41Sopenharmony_ci EMIT(0xFF); 16621cb0ef41Sopenharmony_ci emit_operand(edx, adr); 16631cb0ef41Sopenharmony_ci} 16641cb0ef41Sopenharmony_ci 16651cb0ef41Sopenharmony_civoid Assembler::call(Handle<Code> code, RelocInfo::Mode rmode) { 16661cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 16671cb0ef41Sopenharmony_ci DCHECK(RelocInfo::IsCodeTarget(rmode)); 16681cb0ef41Sopenharmony_ci DCHECK(code->IsExecutable()); 16691cb0ef41Sopenharmony_ci EMIT(0xE8); 16701cb0ef41Sopenharmony_ci emit(code, rmode); 16711cb0ef41Sopenharmony_ci} 16721cb0ef41Sopenharmony_ci 16731cb0ef41Sopenharmony_civoid Assembler::jmp_rel(int offset) { 16741cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 16751cb0ef41Sopenharmony_ci const int short_size = 2; 16761cb0ef41Sopenharmony_ci const int long_size = 5; 16771cb0ef41Sopenharmony_ci if (is_int8(offset - short_size) && !predictable_code_size()) { 16781cb0ef41Sopenharmony_ci // 1110 1011 #8-bit disp. 16791cb0ef41Sopenharmony_ci EMIT(0xEB); 16801cb0ef41Sopenharmony_ci EMIT((offset - short_size) & 0xFF); 16811cb0ef41Sopenharmony_ci } else { 16821cb0ef41Sopenharmony_ci // 1110 1001 #32-bit disp. 16831cb0ef41Sopenharmony_ci EMIT(0xE9); 16841cb0ef41Sopenharmony_ci emit(offset - long_size); 16851cb0ef41Sopenharmony_ci } 16861cb0ef41Sopenharmony_ci} 16871cb0ef41Sopenharmony_ci 16881cb0ef41Sopenharmony_civoid Assembler::jmp(Label* L, Label::Distance distance) { 16891cb0ef41Sopenharmony_ci if (L->is_bound()) { 16901cb0ef41Sopenharmony_ci int offset = L->pos() - pc_offset(); 16911cb0ef41Sopenharmony_ci DCHECK_LE(offset, 0); // backward jump. 16921cb0ef41Sopenharmony_ci jmp_rel(offset); 16931cb0ef41Sopenharmony_ci return; 16941cb0ef41Sopenharmony_ci } 16951cb0ef41Sopenharmony_ci 16961cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 16971cb0ef41Sopenharmony_ci if (distance == Label::kNear) { 16981cb0ef41Sopenharmony_ci EMIT(0xEB); 16991cb0ef41Sopenharmony_ci emit_near_disp(L); 17001cb0ef41Sopenharmony_ci } else { 17011cb0ef41Sopenharmony_ci auto jump_opt = jump_optimization_info(); 17021cb0ef41Sopenharmony_ci if (V8_UNLIKELY(jump_opt)) { 17031cb0ef41Sopenharmony_ci if (jump_opt->is_optimizing() && is_optimizable_farjmp(farjmp_num_++)) { 17041cb0ef41Sopenharmony_ci EMIT(0xEB); 17051cb0ef41Sopenharmony_ci record_farjmp_position(L, pc_offset()); 17061cb0ef41Sopenharmony_ci EMIT(0); 17071cb0ef41Sopenharmony_ci return; 17081cb0ef41Sopenharmony_ci } 17091cb0ef41Sopenharmony_ci if (jump_opt->is_collecting()) { 17101cb0ef41Sopenharmony_ci farjmp_positions_.push_back(pc_offset() + 1); 17111cb0ef41Sopenharmony_ci } 17121cb0ef41Sopenharmony_ci } 17131cb0ef41Sopenharmony_ci // 1110 1001 #32-bit disp. 17141cb0ef41Sopenharmony_ci EMIT(0xE9); 17151cb0ef41Sopenharmony_ci emit_disp(L, Displacement::UNCONDITIONAL_JUMP); 17161cb0ef41Sopenharmony_ci } 17171cb0ef41Sopenharmony_ci} 17181cb0ef41Sopenharmony_ci 17191cb0ef41Sopenharmony_civoid Assembler::jmp(Address entry, RelocInfo::Mode rmode) { 17201cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 17211cb0ef41Sopenharmony_ci DCHECK(!RelocInfo::IsCodeTarget(rmode)); 17221cb0ef41Sopenharmony_ci EMIT(0xE9); 17231cb0ef41Sopenharmony_ci if (RelocInfo::IsRuntimeEntry(rmode) || RelocInfo::IsWasmCall(rmode)) { 17241cb0ef41Sopenharmony_ci emit(entry, rmode); 17251cb0ef41Sopenharmony_ci } else { 17261cb0ef41Sopenharmony_ci emit(entry - (reinterpret_cast<Address>(pc_) + sizeof(int32_t)), rmode); 17271cb0ef41Sopenharmony_ci } 17281cb0ef41Sopenharmony_ci} 17291cb0ef41Sopenharmony_ci 17301cb0ef41Sopenharmony_civoid Assembler::jmp(Operand adr) { 17311cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 17321cb0ef41Sopenharmony_ci EMIT(0xFF); 17331cb0ef41Sopenharmony_ci emit_operand(esp, adr); 17341cb0ef41Sopenharmony_ci} 17351cb0ef41Sopenharmony_ci 17361cb0ef41Sopenharmony_civoid Assembler::jmp(Handle<Code> code, RelocInfo::Mode rmode) { 17371cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 17381cb0ef41Sopenharmony_ci DCHECK(RelocInfo::IsCodeTarget(rmode)); 17391cb0ef41Sopenharmony_ci EMIT(0xE9); 17401cb0ef41Sopenharmony_ci emit(code, rmode); 17411cb0ef41Sopenharmony_ci} 17421cb0ef41Sopenharmony_ci 17431cb0ef41Sopenharmony_civoid Assembler::j(Condition cc, Label* L, Label::Distance distance) { 17441cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 17451cb0ef41Sopenharmony_ci DCHECK(0 <= cc && static_cast<int>(cc) < 16); 17461cb0ef41Sopenharmony_ci if (L->is_bound()) { 17471cb0ef41Sopenharmony_ci const int short_size = 2; 17481cb0ef41Sopenharmony_ci const int long_size = 6; 17491cb0ef41Sopenharmony_ci int offs = L->pos() - pc_offset(); 17501cb0ef41Sopenharmony_ci DCHECK_LE(offs, 0); 17511cb0ef41Sopenharmony_ci if (is_int8(offs - short_size)) { 17521cb0ef41Sopenharmony_ci // 0111 tttn #8-bit disp 17531cb0ef41Sopenharmony_ci EMIT(0x70 | cc); 17541cb0ef41Sopenharmony_ci EMIT((offs - short_size) & 0xFF); 17551cb0ef41Sopenharmony_ci } else { 17561cb0ef41Sopenharmony_ci // 0000 1111 1000 tttn #32-bit disp 17571cb0ef41Sopenharmony_ci EMIT(0x0F); 17581cb0ef41Sopenharmony_ci EMIT(0x80 | cc); 17591cb0ef41Sopenharmony_ci emit(offs - long_size); 17601cb0ef41Sopenharmony_ci } 17611cb0ef41Sopenharmony_ci } else if (distance == Label::kNear) { 17621cb0ef41Sopenharmony_ci EMIT(0x70 | cc); 17631cb0ef41Sopenharmony_ci emit_near_disp(L); 17641cb0ef41Sopenharmony_ci } else { 17651cb0ef41Sopenharmony_ci auto jump_opt = jump_optimization_info(); 17661cb0ef41Sopenharmony_ci if (V8_UNLIKELY(jump_opt)) { 17671cb0ef41Sopenharmony_ci if (jump_opt->is_optimizing() && is_optimizable_farjmp(farjmp_num_++)) { 17681cb0ef41Sopenharmony_ci // 0111 tttn #8-bit disp 17691cb0ef41Sopenharmony_ci EMIT(0x70 | cc); 17701cb0ef41Sopenharmony_ci record_farjmp_position(L, pc_offset()); 17711cb0ef41Sopenharmony_ci EMIT(0); 17721cb0ef41Sopenharmony_ci return; 17731cb0ef41Sopenharmony_ci } 17741cb0ef41Sopenharmony_ci if (jump_opt->is_collecting()) { 17751cb0ef41Sopenharmony_ci farjmp_positions_.push_back(pc_offset() + 2); 17761cb0ef41Sopenharmony_ci } 17771cb0ef41Sopenharmony_ci } 17781cb0ef41Sopenharmony_ci // 0000 1111 1000 tttn #32-bit disp 17791cb0ef41Sopenharmony_ci // Note: could eliminate cond. jumps to this jump if condition 17801cb0ef41Sopenharmony_ci // is the same however, seems to be rather unlikely case. 17811cb0ef41Sopenharmony_ci EMIT(0x0F); 17821cb0ef41Sopenharmony_ci EMIT(0x80 | cc); 17831cb0ef41Sopenharmony_ci emit_disp(L, Displacement::OTHER); 17841cb0ef41Sopenharmony_ci } 17851cb0ef41Sopenharmony_ci} 17861cb0ef41Sopenharmony_ci 17871cb0ef41Sopenharmony_civoid Assembler::j(Condition cc, byte* entry, RelocInfo::Mode rmode) { 17881cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 17891cb0ef41Sopenharmony_ci DCHECK((0 <= cc) && (static_cast<int>(cc) < 16)); 17901cb0ef41Sopenharmony_ci // 0000 1111 1000 tttn #32-bit disp. 17911cb0ef41Sopenharmony_ci EMIT(0x0F); 17921cb0ef41Sopenharmony_ci EMIT(0x80 | cc); 17931cb0ef41Sopenharmony_ci if (RelocInfo::IsRuntimeEntry(rmode)) { 17941cb0ef41Sopenharmony_ci emit(reinterpret_cast<uint32_t>(entry), rmode); 17951cb0ef41Sopenharmony_ci } else { 17961cb0ef41Sopenharmony_ci emit(entry - (pc_ + sizeof(int32_t)), rmode); 17971cb0ef41Sopenharmony_ci } 17981cb0ef41Sopenharmony_ci} 17991cb0ef41Sopenharmony_ci 18001cb0ef41Sopenharmony_civoid Assembler::j(Condition cc, Handle<Code> code, RelocInfo::Mode rmode) { 18011cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18021cb0ef41Sopenharmony_ci // 0000 1111 1000 tttn #32-bit disp 18031cb0ef41Sopenharmony_ci EMIT(0x0F); 18041cb0ef41Sopenharmony_ci EMIT(0x80 | cc); 18051cb0ef41Sopenharmony_ci emit(code, rmode); 18061cb0ef41Sopenharmony_ci} 18071cb0ef41Sopenharmony_ci 18081cb0ef41Sopenharmony_ci// FPU instructions. 18091cb0ef41Sopenharmony_ci 18101cb0ef41Sopenharmony_civoid Assembler::fld(int i) { 18111cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18121cb0ef41Sopenharmony_ci emit_farith(0xD9, 0xC0, i); 18131cb0ef41Sopenharmony_ci} 18141cb0ef41Sopenharmony_ci 18151cb0ef41Sopenharmony_civoid Assembler::fstp(int i) { 18161cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18171cb0ef41Sopenharmony_ci emit_farith(0xDD, 0xD8, i); 18181cb0ef41Sopenharmony_ci} 18191cb0ef41Sopenharmony_ci 18201cb0ef41Sopenharmony_civoid Assembler::fld1() { 18211cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18221cb0ef41Sopenharmony_ci EMIT(0xD9); 18231cb0ef41Sopenharmony_ci EMIT(0xE8); 18241cb0ef41Sopenharmony_ci} 18251cb0ef41Sopenharmony_ci 18261cb0ef41Sopenharmony_civoid Assembler::fldpi() { 18271cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18281cb0ef41Sopenharmony_ci EMIT(0xD9); 18291cb0ef41Sopenharmony_ci EMIT(0xEB); 18301cb0ef41Sopenharmony_ci} 18311cb0ef41Sopenharmony_ci 18321cb0ef41Sopenharmony_civoid Assembler::fldz() { 18331cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18341cb0ef41Sopenharmony_ci EMIT(0xD9); 18351cb0ef41Sopenharmony_ci EMIT(0xEE); 18361cb0ef41Sopenharmony_ci} 18371cb0ef41Sopenharmony_ci 18381cb0ef41Sopenharmony_civoid Assembler::fldln2() { 18391cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18401cb0ef41Sopenharmony_ci EMIT(0xD9); 18411cb0ef41Sopenharmony_ci EMIT(0xED); 18421cb0ef41Sopenharmony_ci} 18431cb0ef41Sopenharmony_ci 18441cb0ef41Sopenharmony_civoid Assembler::fld_s(Operand adr) { 18451cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18461cb0ef41Sopenharmony_ci EMIT(0xD9); 18471cb0ef41Sopenharmony_ci emit_operand(eax, adr); 18481cb0ef41Sopenharmony_ci} 18491cb0ef41Sopenharmony_ci 18501cb0ef41Sopenharmony_civoid Assembler::fld_d(Operand adr) { 18511cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18521cb0ef41Sopenharmony_ci EMIT(0xDD); 18531cb0ef41Sopenharmony_ci emit_operand(eax, adr); 18541cb0ef41Sopenharmony_ci} 18551cb0ef41Sopenharmony_ci 18561cb0ef41Sopenharmony_civoid Assembler::fstp_s(Operand adr) { 18571cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18581cb0ef41Sopenharmony_ci EMIT(0xD9); 18591cb0ef41Sopenharmony_ci emit_operand(ebx, adr); 18601cb0ef41Sopenharmony_ci} 18611cb0ef41Sopenharmony_ci 18621cb0ef41Sopenharmony_civoid Assembler::fst_s(Operand adr) { 18631cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18641cb0ef41Sopenharmony_ci EMIT(0xD9); 18651cb0ef41Sopenharmony_ci emit_operand(edx, adr); 18661cb0ef41Sopenharmony_ci} 18671cb0ef41Sopenharmony_ci 18681cb0ef41Sopenharmony_civoid Assembler::fstp_d(Operand adr) { 18691cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18701cb0ef41Sopenharmony_ci EMIT(0xDD); 18711cb0ef41Sopenharmony_ci emit_operand(ebx, adr); 18721cb0ef41Sopenharmony_ci} 18731cb0ef41Sopenharmony_ci 18741cb0ef41Sopenharmony_civoid Assembler::fst_d(Operand adr) { 18751cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18761cb0ef41Sopenharmony_ci EMIT(0xDD); 18771cb0ef41Sopenharmony_ci emit_operand(edx, adr); 18781cb0ef41Sopenharmony_ci} 18791cb0ef41Sopenharmony_ci 18801cb0ef41Sopenharmony_civoid Assembler::fild_s(Operand adr) { 18811cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18821cb0ef41Sopenharmony_ci EMIT(0xDB); 18831cb0ef41Sopenharmony_ci emit_operand(eax, adr); 18841cb0ef41Sopenharmony_ci} 18851cb0ef41Sopenharmony_ci 18861cb0ef41Sopenharmony_civoid Assembler::fild_d(Operand adr) { 18871cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18881cb0ef41Sopenharmony_ci EMIT(0xDF); 18891cb0ef41Sopenharmony_ci emit_operand(ebp, adr); 18901cb0ef41Sopenharmony_ci} 18911cb0ef41Sopenharmony_ci 18921cb0ef41Sopenharmony_civoid Assembler::fistp_s(Operand adr) { 18931cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 18941cb0ef41Sopenharmony_ci EMIT(0xDB); 18951cb0ef41Sopenharmony_ci emit_operand(ebx, adr); 18961cb0ef41Sopenharmony_ci} 18971cb0ef41Sopenharmony_ci 18981cb0ef41Sopenharmony_civoid Assembler::fisttp_s(Operand adr) { 18991cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE3)); 19001cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19011cb0ef41Sopenharmony_ci EMIT(0xDB); 19021cb0ef41Sopenharmony_ci emit_operand(ecx, adr); 19031cb0ef41Sopenharmony_ci} 19041cb0ef41Sopenharmony_ci 19051cb0ef41Sopenharmony_civoid Assembler::fisttp_d(Operand adr) { 19061cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE3)); 19071cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19081cb0ef41Sopenharmony_ci EMIT(0xDD); 19091cb0ef41Sopenharmony_ci emit_operand(ecx, adr); 19101cb0ef41Sopenharmony_ci} 19111cb0ef41Sopenharmony_ci 19121cb0ef41Sopenharmony_civoid Assembler::fist_s(Operand adr) { 19131cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19141cb0ef41Sopenharmony_ci EMIT(0xDB); 19151cb0ef41Sopenharmony_ci emit_operand(edx, adr); 19161cb0ef41Sopenharmony_ci} 19171cb0ef41Sopenharmony_ci 19181cb0ef41Sopenharmony_civoid Assembler::fistp_d(Operand adr) { 19191cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19201cb0ef41Sopenharmony_ci EMIT(0xDF); 19211cb0ef41Sopenharmony_ci emit_operand(edi, adr); 19221cb0ef41Sopenharmony_ci} 19231cb0ef41Sopenharmony_ci 19241cb0ef41Sopenharmony_civoid Assembler::fabs() { 19251cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19261cb0ef41Sopenharmony_ci EMIT(0xD9); 19271cb0ef41Sopenharmony_ci EMIT(0xE1); 19281cb0ef41Sopenharmony_ci} 19291cb0ef41Sopenharmony_ci 19301cb0ef41Sopenharmony_civoid Assembler::fchs() { 19311cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19321cb0ef41Sopenharmony_ci EMIT(0xD9); 19331cb0ef41Sopenharmony_ci EMIT(0xE0); 19341cb0ef41Sopenharmony_ci} 19351cb0ef41Sopenharmony_ci 19361cb0ef41Sopenharmony_civoid Assembler::fcos() { 19371cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19381cb0ef41Sopenharmony_ci EMIT(0xD9); 19391cb0ef41Sopenharmony_ci EMIT(0xFF); 19401cb0ef41Sopenharmony_ci} 19411cb0ef41Sopenharmony_ci 19421cb0ef41Sopenharmony_civoid Assembler::fsin() { 19431cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19441cb0ef41Sopenharmony_ci EMIT(0xD9); 19451cb0ef41Sopenharmony_ci EMIT(0xFE); 19461cb0ef41Sopenharmony_ci} 19471cb0ef41Sopenharmony_ci 19481cb0ef41Sopenharmony_civoid Assembler::fptan() { 19491cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19501cb0ef41Sopenharmony_ci EMIT(0xD9); 19511cb0ef41Sopenharmony_ci EMIT(0xF2); 19521cb0ef41Sopenharmony_ci} 19531cb0ef41Sopenharmony_ci 19541cb0ef41Sopenharmony_civoid Assembler::fyl2x() { 19551cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19561cb0ef41Sopenharmony_ci EMIT(0xD9); 19571cb0ef41Sopenharmony_ci EMIT(0xF1); 19581cb0ef41Sopenharmony_ci} 19591cb0ef41Sopenharmony_ci 19601cb0ef41Sopenharmony_civoid Assembler::f2xm1() { 19611cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19621cb0ef41Sopenharmony_ci EMIT(0xD9); 19631cb0ef41Sopenharmony_ci EMIT(0xF0); 19641cb0ef41Sopenharmony_ci} 19651cb0ef41Sopenharmony_ci 19661cb0ef41Sopenharmony_civoid Assembler::fscale() { 19671cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19681cb0ef41Sopenharmony_ci EMIT(0xD9); 19691cb0ef41Sopenharmony_ci EMIT(0xFD); 19701cb0ef41Sopenharmony_ci} 19711cb0ef41Sopenharmony_ci 19721cb0ef41Sopenharmony_civoid Assembler::fninit() { 19731cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19741cb0ef41Sopenharmony_ci EMIT(0xDB); 19751cb0ef41Sopenharmony_ci EMIT(0xE3); 19761cb0ef41Sopenharmony_ci} 19771cb0ef41Sopenharmony_ci 19781cb0ef41Sopenharmony_civoid Assembler::fadd(int i) { 19791cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19801cb0ef41Sopenharmony_ci emit_farith(0xDC, 0xC0, i); 19811cb0ef41Sopenharmony_ci} 19821cb0ef41Sopenharmony_ci 19831cb0ef41Sopenharmony_civoid Assembler::fadd_i(int i) { 19841cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19851cb0ef41Sopenharmony_ci emit_farith(0xD8, 0xC0, i); 19861cb0ef41Sopenharmony_ci} 19871cb0ef41Sopenharmony_ci 19881cb0ef41Sopenharmony_civoid Assembler::fsub(int i) { 19891cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19901cb0ef41Sopenharmony_ci emit_farith(0xDC, 0xE8, i); 19911cb0ef41Sopenharmony_ci} 19921cb0ef41Sopenharmony_ci 19931cb0ef41Sopenharmony_civoid Assembler::fsub_i(int i) { 19941cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 19951cb0ef41Sopenharmony_ci emit_farith(0xD8, 0xE0, i); 19961cb0ef41Sopenharmony_ci} 19971cb0ef41Sopenharmony_ci 19981cb0ef41Sopenharmony_civoid Assembler::fisub_s(Operand adr) { 19991cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20001cb0ef41Sopenharmony_ci EMIT(0xDA); 20011cb0ef41Sopenharmony_ci emit_operand(esp, adr); 20021cb0ef41Sopenharmony_ci} 20031cb0ef41Sopenharmony_ci 20041cb0ef41Sopenharmony_civoid Assembler::fmul_i(int i) { 20051cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20061cb0ef41Sopenharmony_ci emit_farith(0xD8, 0xC8, i); 20071cb0ef41Sopenharmony_ci} 20081cb0ef41Sopenharmony_ci 20091cb0ef41Sopenharmony_civoid Assembler::fmul(int i) { 20101cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20111cb0ef41Sopenharmony_ci emit_farith(0xDC, 0xC8, i); 20121cb0ef41Sopenharmony_ci} 20131cb0ef41Sopenharmony_ci 20141cb0ef41Sopenharmony_civoid Assembler::fdiv(int i) { 20151cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20161cb0ef41Sopenharmony_ci emit_farith(0xDC, 0xF8, i); 20171cb0ef41Sopenharmony_ci} 20181cb0ef41Sopenharmony_ci 20191cb0ef41Sopenharmony_civoid Assembler::fdiv_i(int i) { 20201cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20211cb0ef41Sopenharmony_ci emit_farith(0xD8, 0xF0, i); 20221cb0ef41Sopenharmony_ci} 20231cb0ef41Sopenharmony_ci 20241cb0ef41Sopenharmony_civoid Assembler::faddp(int i) { 20251cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20261cb0ef41Sopenharmony_ci emit_farith(0xDE, 0xC0, i); 20271cb0ef41Sopenharmony_ci} 20281cb0ef41Sopenharmony_ci 20291cb0ef41Sopenharmony_civoid Assembler::fsubp(int i) { 20301cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20311cb0ef41Sopenharmony_ci emit_farith(0xDE, 0xE8, i); 20321cb0ef41Sopenharmony_ci} 20331cb0ef41Sopenharmony_ci 20341cb0ef41Sopenharmony_civoid Assembler::fsubrp(int i) { 20351cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20361cb0ef41Sopenharmony_ci emit_farith(0xDE, 0xE0, i); 20371cb0ef41Sopenharmony_ci} 20381cb0ef41Sopenharmony_ci 20391cb0ef41Sopenharmony_civoid Assembler::fmulp(int i) { 20401cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20411cb0ef41Sopenharmony_ci emit_farith(0xDE, 0xC8, i); 20421cb0ef41Sopenharmony_ci} 20431cb0ef41Sopenharmony_ci 20441cb0ef41Sopenharmony_civoid Assembler::fdivp(int i) { 20451cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20461cb0ef41Sopenharmony_ci emit_farith(0xDE, 0xF8, i); 20471cb0ef41Sopenharmony_ci} 20481cb0ef41Sopenharmony_ci 20491cb0ef41Sopenharmony_civoid Assembler::fprem() { 20501cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20511cb0ef41Sopenharmony_ci EMIT(0xD9); 20521cb0ef41Sopenharmony_ci EMIT(0xF8); 20531cb0ef41Sopenharmony_ci} 20541cb0ef41Sopenharmony_ci 20551cb0ef41Sopenharmony_civoid Assembler::fprem1() { 20561cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20571cb0ef41Sopenharmony_ci EMIT(0xD9); 20581cb0ef41Sopenharmony_ci EMIT(0xF5); 20591cb0ef41Sopenharmony_ci} 20601cb0ef41Sopenharmony_ci 20611cb0ef41Sopenharmony_civoid Assembler::fxch(int i) { 20621cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20631cb0ef41Sopenharmony_ci emit_farith(0xD9, 0xC8, i); 20641cb0ef41Sopenharmony_ci} 20651cb0ef41Sopenharmony_ci 20661cb0ef41Sopenharmony_civoid Assembler::fincstp() { 20671cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20681cb0ef41Sopenharmony_ci EMIT(0xD9); 20691cb0ef41Sopenharmony_ci EMIT(0xF7); 20701cb0ef41Sopenharmony_ci} 20711cb0ef41Sopenharmony_ci 20721cb0ef41Sopenharmony_civoid Assembler::ffree(int i) { 20731cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20741cb0ef41Sopenharmony_ci emit_farith(0xDD, 0xC0, i); 20751cb0ef41Sopenharmony_ci} 20761cb0ef41Sopenharmony_ci 20771cb0ef41Sopenharmony_civoid Assembler::ftst() { 20781cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20791cb0ef41Sopenharmony_ci EMIT(0xD9); 20801cb0ef41Sopenharmony_ci EMIT(0xE4); 20811cb0ef41Sopenharmony_ci} 20821cb0ef41Sopenharmony_ci 20831cb0ef41Sopenharmony_civoid Assembler::fucomp(int i) { 20841cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20851cb0ef41Sopenharmony_ci emit_farith(0xDD, 0xE8, i); 20861cb0ef41Sopenharmony_ci} 20871cb0ef41Sopenharmony_ci 20881cb0ef41Sopenharmony_civoid Assembler::fucompp() { 20891cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20901cb0ef41Sopenharmony_ci EMIT(0xDA); 20911cb0ef41Sopenharmony_ci EMIT(0xE9); 20921cb0ef41Sopenharmony_ci} 20931cb0ef41Sopenharmony_ci 20941cb0ef41Sopenharmony_civoid Assembler::fucomi(int i) { 20951cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 20961cb0ef41Sopenharmony_ci EMIT(0xDB); 20971cb0ef41Sopenharmony_ci EMIT(0xE8 + i); 20981cb0ef41Sopenharmony_ci} 20991cb0ef41Sopenharmony_ci 21001cb0ef41Sopenharmony_civoid Assembler::fucomip() { 21011cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21021cb0ef41Sopenharmony_ci EMIT(0xDF); 21031cb0ef41Sopenharmony_ci EMIT(0xE9); 21041cb0ef41Sopenharmony_ci} 21051cb0ef41Sopenharmony_ci 21061cb0ef41Sopenharmony_civoid Assembler::fcompp() { 21071cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21081cb0ef41Sopenharmony_ci EMIT(0xDE); 21091cb0ef41Sopenharmony_ci EMIT(0xD9); 21101cb0ef41Sopenharmony_ci} 21111cb0ef41Sopenharmony_ci 21121cb0ef41Sopenharmony_civoid Assembler::fnstsw_ax() { 21131cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21141cb0ef41Sopenharmony_ci EMIT(0xDF); 21151cb0ef41Sopenharmony_ci EMIT(0xE0); 21161cb0ef41Sopenharmony_ci} 21171cb0ef41Sopenharmony_ci 21181cb0ef41Sopenharmony_civoid Assembler::fwait() { 21191cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21201cb0ef41Sopenharmony_ci EMIT(0x9B); 21211cb0ef41Sopenharmony_ci} 21221cb0ef41Sopenharmony_ci 21231cb0ef41Sopenharmony_civoid Assembler::frndint() { 21241cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21251cb0ef41Sopenharmony_ci EMIT(0xD9); 21261cb0ef41Sopenharmony_ci EMIT(0xFC); 21271cb0ef41Sopenharmony_ci} 21281cb0ef41Sopenharmony_ci 21291cb0ef41Sopenharmony_civoid Assembler::fnclex() { 21301cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21311cb0ef41Sopenharmony_ci EMIT(0xDB); 21321cb0ef41Sopenharmony_ci EMIT(0xE2); 21331cb0ef41Sopenharmony_ci} 21341cb0ef41Sopenharmony_ci 21351cb0ef41Sopenharmony_civoid Assembler::sahf() { 21361cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21371cb0ef41Sopenharmony_ci EMIT(0x9E); 21381cb0ef41Sopenharmony_ci} 21391cb0ef41Sopenharmony_ci 21401cb0ef41Sopenharmony_civoid Assembler::setcc(Condition cc, Register reg) { 21411cb0ef41Sopenharmony_ci DCHECK(reg.is_byte_register()); 21421cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21431cb0ef41Sopenharmony_ci EMIT(0x0F); 21441cb0ef41Sopenharmony_ci EMIT(0x90 | cc); 21451cb0ef41Sopenharmony_ci EMIT(0xC0 | reg.code()); 21461cb0ef41Sopenharmony_ci} 21471cb0ef41Sopenharmony_ci 21481cb0ef41Sopenharmony_civoid Assembler::cvttss2si(Register dst, Operand src) { 21491cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21501cb0ef41Sopenharmony_ci // The [src] might contain ebx's register code, but in 21511cb0ef41Sopenharmony_ci // this case, it refers to xmm3, so it is OK to emit. 21521cb0ef41Sopenharmony_ci EMIT(0xF3); 21531cb0ef41Sopenharmony_ci EMIT(0x0F); 21541cb0ef41Sopenharmony_ci EMIT(0x2C); 21551cb0ef41Sopenharmony_ci emit_operand(dst, src); 21561cb0ef41Sopenharmony_ci} 21571cb0ef41Sopenharmony_ci 21581cb0ef41Sopenharmony_civoid Assembler::cvttsd2si(Register dst, Operand src) { 21591cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21601cb0ef41Sopenharmony_ci // The [src] might contain ebx's register code, but in 21611cb0ef41Sopenharmony_ci // this case, it refers to xmm3, so it is OK to emit. 21621cb0ef41Sopenharmony_ci EMIT(0xF2); 21631cb0ef41Sopenharmony_ci EMIT(0x0F); 21641cb0ef41Sopenharmony_ci EMIT(0x2C); 21651cb0ef41Sopenharmony_ci emit_operand(dst, src); 21661cb0ef41Sopenharmony_ci} 21671cb0ef41Sopenharmony_ci 21681cb0ef41Sopenharmony_civoid Assembler::cvtsd2si(Register dst, XMMRegister src) { 21691cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21701cb0ef41Sopenharmony_ci EMIT(0xF2); 21711cb0ef41Sopenharmony_ci EMIT(0x0F); 21721cb0ef41Sopenharmony_ci EMIT(0x2D); 21731cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 21741cb0ef41Sopenharmony_ci} 21751cb0ef41Sopenharmony_ci 21761cb0ef41Sopenharmony_civoid Assembler::cvtsi2ss(XMMRegister dst, Operand src) { 21771cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21781cb0ef41Sopenharmony_ci EMIT(0xF3); 21791cb0ef41Sopenharmony_ci EMIT(0x0F); 21801cb0ef41Sopenharmony_ci EMIT(0x2A); 21811cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 21821cb0ef41Sopenharmony_ci} 21831cb0ef41Sopenharmony_ci 21841cb0ef41Sopenharmony_civoid Assembler::cvtsi2sd(XMMRegister dst, Operand src) { 21851cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21861cb0ef41Sopenharmony_ci EMIT(0xF2); 21871cb0ef41Sopenharmony_ci EMIT(0x0F); 21881cb0ef41Sopenharmony_ci EMIT(0x2A); 21891cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 21901cb0ef41Sopenharmony_ci} 21911cb0ef41Sopenharmony_ci 21921cb0ef41Sopenharmony_civoid Assembler::cvtss2sd(XMMRegister dst, Operand src) { 21931cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 21941cb0ef41Sopenharmony_ci EMIT(0xF3); 21951cb0ef41Sopenharmony_ci EMIT(0x0F); 21961cb0ef41Sopenharmony_ci EMIT(0x5A); 21971cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 21981cb0ef41Sopenharmony_ci} 21991cb0ef41Sopenharmony_ci 22001cb0ef41Sopenharmony_civoid Assembler::cvtdq2pd(XMMRegister dst, XMMRegister src) { 22011cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22021cb0ef41Sopenharmony_ci EMIT(0xF3); 22031cb0ef41Sopenharmony_ci EMIT(0x0F); 22041cb0ef41Sopenharmony_ci EMIT(0xE6); 22051cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22061cb0ef41Sopenharmony_ci} 22071cb0ef41Sopenharmony_ci 22081cb0ef41Sopenharmony_civoid Assembler::cvtpd2ps(XMMRegister dst, XMMRegister src) { 22091cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22101cb0ef41Sopenharmony_ci EMIT(0x66); 22111cb0ef41Sopenharmony_ci EMIT(0x0F); 22121cb0ef41Sopenharmony_ci EMIT(0x5A); 22131cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22141cb0ef41Sopenharmony_ci} 22151cb0ef41Sopenharmony_ci 22161cb0ef41Sopenharmony_civoid Assembler::cvttps2dq(XMMRegister dst, Operand src) { 22171cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22181cb0ef41Sopenharmony_ci EMIT(0xF3); 22191cb0ef41Sopenharmony_ci EMIT(0x0F); 22201cb0ef41Sopenharmony_ci EMIT(0x5B); 22211cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22221cb0ef41Sopenharmony_ci} 22231cb0ef41Sopenharmony_ci 22241cb0ef41Sopenharmony_civoid Assembler::cvttpd2dq(XMMRegister dst, XMMRegister src) { 22251cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22261cb0ef41Sopenharmony_ci EMIT(0x66); 22271cb0ef41Sopenharmony_ci EMIT(0x0F); 22281cb0ef41Sopenharmony_ci EMIT(0xE6); 22291cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22301cb0ef41Sopenharmony_ci} 22311cb0ef41Sopenharmony_ci 22321cb0ef41Sopenharmony_civoid Assembler::cmpps(XMMRegister dst, Operand src, uint8_t cmp) { 22331cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22341cb0ef41Sopenharmony_ci EMIT(0x0F); 22351cb0ef41Sopenharmony_ci EMIT(0xC2); 22361cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22371cb0ef41Sopenharmony_ci EMIT(cmp); 22381cb0ef41Sopenharmony_ci} 22391cb0ef41Sopenharmony_ci 22401cb0ef41Sopenharmony_civoid Assembler::cmppd(XMMRegister dst, Operand src, uint8_t cmp) { 22411cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22421cb0ef41Sopenharmony_ci EMIT(0x66); 22431cb0ef41Sopenharmony_ci EMIT(0x0F); 22441cb0ef41Sopenharmony_ci EMIT(0xC2); 22451cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22461cb0ef41Sopenharmony_ci EMIT(cmp); 22471cb0ef41Sopenharmony_ci} 22481cb0ef41Sopenharmony_ci 22491cb0ef41Sopenharmony_civoid Assembler::haddps(XMMRegister dst, Operand src) { 22501cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE3)); 22511cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22521cb0ef41Sopenharmony_ci EMIT(0xF2); 22531cb0ef41Sopenharmony_ci EMIT(0x0F); 22541cb0ef41Sopenharmony_ci EMIT(0x7C); 22551cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22561cb0ef41Sopenharmony_ci} 22571cb0ef41Sopenharmony_ci 22581cb0ef41Sopenharmony_civoid Assembler::ucomisd(XMMRegister dst, Operand src) { 22591cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22601cb0ef41Sopenharmony_ci EMIT(0x66); 22611cb0ef41Sopenharmony_ci EMIT(0x0F); 22621cb0ef41Sopenharmony_ci EMIT(0x2E); 22631cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22641cb0ef41Sopenharmony_ci} 22651cb0ef41Sopenharmony_ci 22661cb0ef41Sopenharmony_civoid Assembler::roundps(XMMRegister dst, XMMRegister src, RoundingMode mode) { 22671cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 22681cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22691cb0ef41Sopenharmony_ci EMIT(0x66); 22701cb0ef41Sopenharmony_ci EMIT(0x0F); 22711cb0ef41Sopenharmony_ci EMIT(0x3A); 22721cb0ef41Sopenharmony_ci EMIT(0x08); 22731cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22741cb0ef41Sopenharmony_ci // Mask precision exeption. 22751cb0ef41Sopenharmony_ci EMIT(static_cast<byte>(mode) | 0x8); 22761cb0ef41Sopenharmony_ci} 22771cb0ef41Sopenharmony_ci 22781cb0ef41Sopenharmony_civoid Assembler::roundpd(XMMRegister dst, XMMRegister src, RoundingMode mode) { 22791cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 22801cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22811cb0ef41Sopenharmony_ci EMIT(0x66); 22821cb0ef41Sopenharmony_ci EMIT(0x0F); 22831cb0ef41Sopenharmony_ci EMIT(0x3A); 22841cb0ef41Sopenharmony_ci EMIT(0x09); 22851cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22861cb0ef41Sopenharmony_ci // Mask precision exeption. 22871cb0ef41Sopenharmony_ci EMIT(static_cast<byte>(mode) | 0x8); 22881cb0ef41Sopenharmony_ci} 22891cb0ef41Sopenharmony_ci 22901cb0ef41Sopenharmony_civoid Assembler::roundss(XMMRegister dst, XMMRegister src, RoundingMode mode) { 22911cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 22921cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 22931cb0ef41Sopenharmony_ci EMIT(0x66); 22941cb0ef41Sopenharmony_ci EMIT(0x0F); 22951cb0ef41Sopenharmony_ci EMIT(0x3A); 22961cb0ef41Sopenharmony_ci EMIT(0x0A); 22971cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 22981cb0ef41Sopenharmony_ci // Mask precision exeption. 22991cb0ef41Sopenharmony_ci EMIT(static_cast<byte>(mode) | 0x8); 23001cb0ef41Sopenharmony_ci} 23011cb0ef41Sopenharmony_ci 23021cb0ef41Sopenharmony_civoid Assembler::roundsd(XMMRegister dst, XMMRegister src, RoundingMode mode) { 23031cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 23041cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23051cb0ef41Sopenharmony_ci EMIT(0x66); 23061cb0ef41Sopenharmony_ci EMIT(0x0F); 23071cb0ef41Sopenharmony_ci EMIT(0x3A); 23081cb0ef41Sopenharmony_ci EMIT(0x0B); 23091cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23101cb0ef41Sopenharmony_ci // Mask precision exeption. 23111cb0ef41Sopenharmony_ci EMIT(static_cast<byte>(mode) | 0x8); 23121cb0ef41Sopenharmony_ci} 23131cb0ef41Sopenharmony_ci 23141cb0ef41Sopenharmony_civoid Assembler::movmskpd(Register dst, XMMRegister src) { 23151cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23161cb0ef41Sopenharmony_ci EMIT(0x66); 23171cb0ef41Sopenharmony_ci EMIT(0x0F); 23181cb0ef41Sopenharmony_ci EMIT(0x50); 23191cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23201cb0ef41Sopenharmony_ci} 23211cb0ef41Sopenharmony_ci 23221cb0ef41Sopenharmony_civoid Assembler::movmskps(Register dst, XMMRegister src) { 23231cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23241cb0ef41Sopenharmony_ci EMIT(0x0F); 23251cb0ef41Sopenharmony_ci EMIT(0x50); 23261cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23271cb0ef41Sopenharmony_ci} 23281cb0ef41Sopenharmony_ci 23291cb0ef41Sopenharmony_civoid Assembler::pmovmskb(Register dst, XMMRegister src) { 23301cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23311cb0ef41Sopenharmony_ci EMIT(0x66); 23321cb0ef41Sopenharmony_ci EMIT(0x0F); 23331cb0ef41Sopenharmony_ci EMIT(0xD7); 23341cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23351cb0ef41Sopenharmony_ci} 23361cb0ef41Sopenharmony_ci 23371cb0ef41Sopenharmony_civoid Assembler::cmpltsd(XMMRegister dst, XMMRegister src) { 23381cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23391cb0ef41Sopenharmony_ci EMIT(0xF2); 23401cb0ef41Sopenharmony_ci EMIT(0x0F); 23411cb0ef41Sopenharmony_ci EMIT(0xC2); 23421cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23431cb0ef41Sopenharmony_ci EMIT(1); // LT == 1 23441cb0ef41Sopenharmony_ci} 23451cb0ef41Sopenharmony_ci 23461cb0ef41Sopenharmony_civoid Assembler::movaps(XMMRegister dst, Operand src) { 23471cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23481cb0ef41Sopenharmony_ci EMIT(0x0F); 23491cb0ef41Sopenharmony_ci EMIT(0x28); 23501cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23511cb0ef41Sopenharmony_ci} 23521cb0ef41Sopenharmony_ci 23531cb0ef41Sopenharmony_civoid Assembler::movups(XMMRegister dst, Operand src) { 23541cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23551cb0ef41Sopenharmony_ci EMIT(0x0F); 23561cb0ef41Sopenharmony_ci EMIT(0x10); 23571cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23581cb0ef41Sopenharmony_ci} 23591cb0ef41Sopenharmony_ci 23601cb0ef41Sopenharmony_civoid Assembler::movups(Operand dst, XMMRegister src) { 23611cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23621cb0ef41Sopenharmony_ci EMIT(0x0F); 23631cb0ef41Sopenharmony_ci EMIT(0x11); 23641cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 23651cb0ef41Sopenharmony_ci} 23661cb0ef41Sopenharmony_ci 23671cb0ef41Sopenharmony_civoid Assembler::movddup(XMMRegister dst, Operand src) { 23681cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE3)); 23691cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23701cb0ef41Sopenharmony_ci EMIT(0xF2); 23711cb0ef41Sopenharmony_ci EMIT(0x0F); 23721cb0ef41Sopenharmony_ci EMIT(0x12); 23731cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23741cb0ef41Sopenharmony_ci} 23751cb0ef41Sopenharmony_ci 23761cb0ef41Sopenharmony_civoid Assembler::movshdup(XMMRegister dst, XMMRegister src) { 23771cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE3)); 23781cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23791cb0ef41Sopenharmony_ci EMIT(0xF3); 23801cb0ef41Sopenharmony_ci EMIT(0x0F); 23811cb0ef41Sopenharmony_ci EMIT(0x16); 23821cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23831cb0ef41Sopenharmony_ci} 23841cb0ef41Sopenharmony_ci 23851cb0ef41Sopenharmony_civoid Assembler::shufps(XMMRegister dst, XMMRegister src, byte imm8) { 23861cb0ef41Sopenharmony_ci DCHECK(is_uint8(imm8)); 23871cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23881cb0ef41Sopenharmony_ci EMIT(0x0F); 23891cb0ef41Sopenharmony_ci EMIT(0xC6); 23901cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 23911cb0ef41Sopenharmony_ci EMIT(imm8); 23921cb0ef41Sopenharmony_ci} 23931cb0ef41Sopenharmony_ci 23941cb0ef41Sopenharmony_civoid Assembler::shufpd(XMMRegister dst, XMMRegister src, byte imm8) { 23951cb0ef41Sopenharmony_ci DCHECK(is_uint8(imm8)); 23961cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 23971cb0ef41Sopenharmony_ci EMIT(0x66); 23981cb0ef41Sopenharmony_ci EMIT(0x0F); 23991cb0ef41Sopenharmony_ci EMIT(0xC6); 24001cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 24011cb0ef41Sopenharmony_ci EMIT(imm8); 24021cb0ef41Sopenharmony_ci} 24031cb0ef41Sopenharmony_ci 24041cb0ef41Sopenharmony_civoid Assembler::movhlps(XMMRegister dst, XMMRegister src) { 24051cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24061cb0ef41Sopenharmony_ci EMIT(0x0F); 24071cb0ef41Sopenharmony_ci EMIT(0x12); 24081cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 24091cb0ef41Sopenharmony_ci} 24101cb0ef41Sopenharmony_ci 24111cb0ef41Sopenharmony_civoid Assembler::movlhps(XMMRegister dst, XMMRegister src) { 24121cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24131cb0ef41Sopenharmony_ci EMIT(0x0F); 24141cb0ef41Sopenharmony_ci EMIT(0x16); 24151cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 24161cb0ef41Sopenharmony_ci} 24171cb0ef41Sopenharmony_ci 24181cb0ef41Sopenharmony_civoid Assembler::movlps(XMMRegister dst, Operand src) { 24191cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24201cb0ef41Sopenharmony_ci EMIT(0x0F); 24211cb0ef41Sopenharmony_ci EMIT(0x12); 24221cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 24231cb0ef41Sopenharmony_ci} 24241cb0ef41Sopenharmony_ci 24251cb0ef41Sopenharmony_civoid Assembler::movlps(Operand dst, XMMRegister src) { 24261cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24271cb0ef41Sopenharmony_ci EMIT(0x0F); 24281cb0ef41Sopenharmony_ci EMIT(0x13); 24291cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 24301cb0ef41Sopenharmony_ci} 24311cb0ef41Sopenharmony_ci 24321cb0ef41Sopenharmony_civoid Assembler::movhps(XMMRegister dst, Operand src) { 24331cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24341cb0ef41Sopenharmony_ci EMIT(0x0F); 24351cb0ef41Sopenharmony_ci EMIT(0x16); 24361cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 24371cb0ef41Sopenharmony_ci} 24381cb0ef41Sopenharmony_ci 24391cb0ef41Sopenharmony_civoid Assembler::movhps(Operand dst, XMMRegister src) { 24401cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24411cb0ef41Sopenharmony_ci EMIT(0x0F); 24421cb0ef41Sopenharmony_ci EMIT(0x17); 24431cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 24441cb0ef41Sopenharmony_ci} 24451cb0ef41Sopenharmony_ci 24461cb0ef41Sopenharmony_civoid Assembler::movdqa(Operand dst, XMMRegister src) { 24471cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24481cb0ef41Sopenharmony_ci EMIT(0x66); 24491cb0ef41Sopenharmony_ci EMIT(0x0F); 24501cb0ef41Sopenharmony_ci EMIT(0x7F); 24511cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 24521cb0ef41Sopenharmony_ci} 24531cb0ef41Sopenharmony_ci 24541cb0ef41Sopenharmony_civoid Assembler::movdqa(XMMRegister dst, Operand src) { 24551cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24561cb0ef41Sopenharmony_ci EMIT(0x66); 24571cb0ef41Sopenharmony_ci EMIT(0x0F); 24581cb0ef41Sopenharmony_ci EMIT(0x6F); 24591cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 24601cb0ef41Sopenharmony_ci} 24611cb0ef41Sopenharmony_ci 24621cb0ef41Sopenharmony_civoid Assembler::movdqa(XMMRegister dst, XMMRegister src) { 24631cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24641cb0ef41Sopenharmony_ci EMIT(0x66); 24651cb0ef41Sopenharmony_ci EMIT(0x0F); 24661cb0ef41Sopenharmony_ci EMIT(0x6F); 24671cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 24681cb0ef41Sopenharmony_ci} 24691cb0ef41Sopenharmony_ci 24701cb0ef41Sopenharmony_civoid Assembler::movdqu(Operand dst, XMMRegister src) { 24711cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24721cb0ef41Sopenharmony_ci EMIT(0xF3); 24731cb0ef41Sopenharmony_ci EMIT(0x0F); 24741cb0ef41Sopenharmony_ci EMIT(0x7F); 24751cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 24761cb0ef41Sopenharmony_ci} 24771cb0ef41Sopenharmony_ci 24781cb0ef41Sopenharmony_civoid Assembler::movdqu(XMMRegister dst, Operand src) { 24791cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24801cb0ef41Sopenharmony_ci EMIT(0xF3); 24811cb0ef41Sopenharmony_ci EMIT(0x0F); 24821cb0ef41Sopenharmony_ci EMIT(0x6F); 24831cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 24841cb0ef41Sopenharmony_ci} 24851cb0ef41Sopenharmony_ci 24861cb0ef41Sopenharmony_civoid Assembler::movdqu(XMMRegister dst, XMMRegister src) { 24871cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24881cb0ef41Sopenharmony_ci EMIT(0xF3); 24891cb0ef41Sopenharmony_ci EMIT(0x0F); 24901cb0ef41Sopenharmony_ci EMIT(0x7F); 24911cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 24921cb0ef41Sopenharmony_ci} 24931cb0ef41Sopenharmony_ci 24941cb0ef41Sopenharmony_civoid Assembler::prefetch(Operand src, int level) { 24951cb0ef41Sopenharmony_ci DCHECK(is_uint2(level)); 24961cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 24971cb0ef41Sopenharmony_ci EMIT(0x0F); 24981cb0ef41Sopenharmony_ci EMIT(0x18); 24991cb0ef41Sopenharmony_ci // Emit hint number in Reg position of RegR/M. 25001cb0ef41Sopenharmony_ci XMMRegister code = XMMRegister::from_code(level); 25011cb0ef41Sopenharmony_ci emit_sse_operand(code, src); 25021cb0ef41Sopenharmony_ci} 25031cb0ef41Sopenharmony_ci 25041cb0ef41Sopenharmony_civoid Assembler::movsd(Operand dst, XMMRegister src) { 25051cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25061cb0ef41Sopenharmony_ci EMIT(0xF2); // double 25071cb0ef41Sopenharmony_ci EMIT(0x0F); 25081cb0ef41Sopenharmony_ci EMIT(0x11); // store 25091cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 25101cb0ef41Sopenharmony_ci} 25111cb0ef41Sopenharmony_ci 25121cb0ef41Sopenharmony_civoid Assembler::movsd(XMMRegister dst, Operand src) { 25131cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25141cb0ef41Sopenharmony_ci EMIT(0xF2); // double 25151cb0ef41Sopenharmony_ci EMIT(0x0F); 25161cb0ef41Sopenharmony_ci EMIT(0x10); // load 25171cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 25181cb0ef41Sopenharmony_ci} 25191cb0ef41Sopenharmony_ci 25201cb0ef41Sopenharmony_civoid Assembler::movss(Operand dst, XMMRegister src) { 25211cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25221cb0ef41Sopenharmony_ci EMIT(0xF3); // float 25231cb0ef41Sopenharmony_ci EMIT(0x0F); 25241cb0ef41Sopenharmony_ci EMIT(0x11); // store 25251cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 25261cb0ef41Sopenharmony_ci} 25271cb0ef41Sopenharmony_ci 25281cb0ef41Sopenharmony_civoid Assembler::movss(XMMRegister dst, Operand src) { 25291cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25301cb0ef41Sopenharmony_ci EMIT(0xF3); // float 25311cb0ef41Sopenharmony_ci EMIT(0x0F); 25321cb0ef41Sopenharmony_ci EMIT(0x10); // load 25331cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 25341cb0ef41Sopenharmony_ci} 25351cb0ef41Sopenharmony_ci 25361cb0ef41Sopenharmony_civoid Assembler::movd(XMMRegister dst, Operand src) { 25371cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25381cb0ef41Sopenharmony_ci EMIT(0x66); 25391cb0ef41Sopenharmony_ci EMIT(0x0F); 25401cb0ef41Sopenharmony_ci EMIT(0x6E); 25411cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 25421cb0ef41Sopenharmony_ci} 25431cb0ef41Sopenharmony_ci 25441cb0ef41Sopenharmony_civoid Assembler::movd(Operand dst, XMMRegister src) { 25451cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25461cb0ef41Sopenharmony_ci EMIT(0x66); 25471cb0ef41Sopenharmony_ci EMIT(0x0F); 25481cb0ef41Sopenharmony_ci EMIT(0x7E); 25491cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 25501cb0ef41Sopenharmony_ci} 25511cb0ef41Sopenharmony_ci 25521cb0ef41Sopenharmony_civoid Assembler::extractps(Operand dst, XMMRegister src, byte imm8) { 25531cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 25541cb0ef41Sopenharmony_ci DCHECK(is_uint8(imm8)); 25551cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25561cb0ef41Sopenharmony_ci EMIT(0x66); 25571cb0ef41Sopenharmony_ci EMIT(0x0F); 25581cb0ef41Sopenharmony_ci EMIT(0x3A); 25591cb0ef41Sopenharmony_ci EMIT(0x17); 25601cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 25611cb0ef41Sopenharmony_ci EMIT(imm8); 25621cb0ef41Sopenharmony_ci} 25631cb0ef41Sopenharmony_ci 25641cb0ef41Sopenharmony_civoid Assembler::extractps(Register dst, XMMRegister src, byte imm8) { 25651cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 25661cb0ef41Sopenharmony_ci DCHECK(is_uint8(imm8)); 25671cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25681cb0ef41Sopenharmony_ci EMIT(0x66); 25691cb0ef41Sopenharmony_ci EMIT(0x0F); 25701cb0ef41Sopenharmony_ci EMIT(0x3A); 25711cb0ef41Sopenharmony_ci EMIT(0x17); 25721cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 25731cb0ef41Sopenharmony_ci EMIT(imm8); 25741cb0ef41Sopenharmony_ci} 25751cb0ef41Sopenharmony_ci 25761cb0ef41Sopenharmony_civoid Assembler::pcmpgtq(XMMRegister dst, XMMRegister src) { 25771cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_2)); 25781cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25791cb0ef41Sopenharmony_ci EMIT(0x66); 25801cb0ef41Sopenharmony_ci EMIT(0x0F); 25811cb0ef41Sopenharmony_ci EMIT(0x38); 25821cb0ef41Sopenharmony_ci EMIT(0x37); 25831cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 25841cb0ef41Sopenharmony_ci} 25851cb0ef41Sopenharmony_ci 25861cb0ef41Sopenharmony_civoid Assembler::psllw(XMMRegister reg, uint8_t shift) { 25871cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25881cb0ef41Sopenharmony_ci EMIT(0x66); 25891cb0ef41Sopenharmony_ci EMIT(0x0F); 25901cb0ef41Sopenharmony_ci EMIT(0x71); 25911cb0ef41Sopenharmony_ci emit_sse_operand(esi, reg); // esi == 6 25921cb0ef41Sopenharmony_ci EMIT(shift); 25931cb0ef41Sopenharmony_ci} 25941cb0ef41Sopenharmony_ci 25951cb0ef41Sopenharmony_civoid Assembler::pslld(XMMRegister reg, uint8_t shift) { 25961cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 25971cb0ef41Sopenharmony_ci EMIT(0x66); 25981cb0ef41Sopenharmony_ci EMIT(0x0F); 25991cb0ef41Sopenharmony_ci EMIT(0x72); 26001cb0ef41Sopenharmony_ci emit_sse_operand(esi, reg); // esi == 6 26011cb0ef41Sopenharmony_ci EMIT(shift); 26021cb0ef41Sopenharmony_ci} 26031cb0ef41Sopenharmony_ci 26041cb0ef41Sopenharmony_civoid Assembler::psrlw(XMMRegister reg, uint8_t shift) { 26051cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26061cb0ef41Sopenharmony_ci EMIT(0x66); 26071cb0ef41Sopenharmony_ci EMIT(0x0F); 26081cb0ef41Sopenharmony_ci EMIT(0x71); 26091cb0ef41Sopenharmony_ci emit_sse_operand(edx, reg); // edx == 2 26101cb0ef41Sopenharmony_ci EMIT(shift); 26111cb0ef41Sopenharmony_ci} 26121cb0ef41Sopenharmony_ci 26131cb0ef41Sopenharmony_civoid Assembler::psrld(XMMRegister reg, uint8_t shift) { 26141cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26151cb0ef41Sopenharmony_ci EMIT(0x66); 26161cb0ef41Sopenharmony_ci EMIT(0x0F); 26171cb0ef41Sopenharmony_ci EMIT(0x72); 26181cb0ef41Sopenharmony_ci emit_sse_operand(edx, reg); // edx == 2 26191cb0ef41Sopenharmony_ci EMIT(shift); 26201cb0ef41Sopenharmony_ci} 26211cb0ef41Sopenharmony_ci 26221cb0ef41Sopenharmony_civoid Assembler::psraw(XMMRegister reg, uint8_t shift) { 26231cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26241cb0ef41Sopenharmony_ci EMIT(0x66); 26251cb0ef41Sopenharmony_ci EMIT(0x0F); 26261cb0ef41Sopenharmony_ci EMIT(0x71); 26271cb0ef41Sopenharmony_ci emit_sse_operand(esp, reg); // esp == 4 26281cb0ef41Sopenharmony_ci EMIT(shift); 26291cb0ef41Sopenharmony_ci} 26301cb0ef41Sopenharmony_ci 26311cb0ef41Sopenharmony_civoid Assembler::psrad(XMMRegister reg, uint8_t shift) { 26321cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26331cb0ef41Sopenharmony_ci EMIT(0x66); 26341cb0ef41Sopenharmony_ci EMIT(0x0F); 26351cb0ef41Sopenharmony_ci EMIT(0x72); 26361cb0ef41Sopenharmony_ci emit_sse_operand(esp, reg); // esp == 4 26371cb0ef41Sopenharmony_ci EMIT(shift); 26381cb0ef41Sopenharmony_ci} 26391cb0ef41Sopenharmony_ci 26401cb0ef41Sopenharmony_civoid Assembler::psllq(XMMRegister reg, uint8_t shift) { 26411cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26421cb0ef41Sopenharmony_ci EMIT(0x66); 26431cb0ef41Sopenharmony_ci EMIT(0x0F); 26441cb0ef41Sopenharmony_ci EMIT(0x73); 26451cb0ef41Sopenharmony_ci emit_sse_operand(esi, reg); // esi == 6 26461cb0ef41Sopenharmony_ci EMIT(shift); 26471cb0ef41Sopenharmony_ci} 26481cb0ef41Sopenharmony_ci 26491cb0ef41Sopenharmony_civoid Assembler::psrlq(XMMRegister reg, uint8_t shift) { 26501cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26511cb0ef41Sopenharmony_ci EMIT(0x66); 26521cb0ef41Sopenharmony_ci EMIT(0x0F); 26531cb0ef41Sopenharmony_ci EMIT(0x73); 26541cb0ef41Sopenharmony_ci emit_sse_operand(edx, reg); // edx == 2 26551cb0ef41Sopenharmony_ci EMIT(shift); 26561cb0ef41Sopenharmony_ci} 26571cb0ef41Sopenharmony_ci 26581cb0ef41Sopenharmony_civoid Assembler::pshufhw(XMMRegister dst, Operand src, uint8_t shuffle) { 26591cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26601cb0ef41Sopenharmony_ci EMIT(0xF3); 26611cb0ef41Sopenharmony_ci EMIT(0x0F); 26621cb0ef41Sopenharmony_ci EMIT(0x70); 26631cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 26641cb0ef41Sopenharmony_ci EMIT(shuffle); 26651cb0ef41Sopenharmony_ci} 26661cb0ef41Sopenharmony_ci 26671cb0ef41Sopenharmony_civoid Assembler::pshuflw(XMMRegister dst, Operand src, uint8_t shuffle) { 26681cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26691cb0ef41Sopenharmony_ci EMIT(0xF2); 26701cb0ef41Sopenharmony_ci EMIT(0x0F); 26711cb0ef41Sopenharmony_ci EMIT(0x70); 26721cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 26731cb0ef41Sopenharmony_ci EMIT(shuffle); 26741cb0ef41Sopenharmony_ci} 26751cb0ef41Sopenharmony_ci 26761cb0ef41Sopenharmony_civoid Assembler::pshufd(XMMRegister dst, Operand src, uint8_t shuffle) { 26771cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26781cb0ef41Sopenharmony_ci EMIT(0x66); 26791cb0ef41Sopenharmony_ci EMIT(0x0F); 26801cb0ef41Sopenharmony_ci EMIT(0x70); 26811cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 26821cb0ef41Sopenharmony_ci EMIT(shuffle); 26831cb0ef41Sopenharmony_ci} 26841cb0ef41Sopenharmony_ci 26851cb0ef41Sopenharmony_civoid Assembler::pblendw(XMMRegister dst, Operand src, uint8_t mask) { 26861cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 26871cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26881cb0ef41Sopenharmony_ci EMIT(0x66); 26891cb0ef41Sopenharmony_ci EMIT(0x0F); 26901cb0ef41Sopenharmony_ci EMIT(0x3A); 26911cb0ef41Sopenharmony_ci EMIT(0x0E); 26921cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 26931cb0ef41Sopenharmony_ci EMIT(mask); 26941cb0ef41Sopenharmony_ci} 26951cb0ef41Sopenharmony_ci 26961cb0ef41Sopenharmony_civoid Assembler::palignr(XMMRegister dst, Operand src, uint8_t mask) { 26971cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSSE3)); 26981cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 26991cb0ef41Sopenharmony_ci EMIT(0x66); 27001cb0ef41Sopenharmony_ci EMIT(0x0F); 27011cb0ef41Sopenharmony_ci EMIT(0x3A); 27021cb0ef41Sopenharmony_ci EMIT(0x0F); 27031cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 27041cb0ef41Sopenharmony_ci EMIT(mask); 27051cb0ef41Sopenharmony_ci} 27061cb0ef41Sopenharmony_ci 27071cb0ef41Sopenharmony_civoid Assembler::pextrb(Operand dst, XMMRegister src, uint8_t offset) { 27081cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 27091cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 27101cb0ef41Sopenharmony_ci EMIT(0x66); 27111cb0ef41Sopenharmony_ci EMIT(0x0F); 27121cb0ef41Sopenharmony_ci EMIT(0x3A); 27131cb0ef41Sopenharmony_ci EMIT(0x14); 27141cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 27151cb0ef41Sopenharmony_ci EMIT(offset); 27161cb0ef41Sopenharmony_ci} 27171cb0ef41Sopenharmony_ci 27181cb0ef41Sopenharmony_civoid Assembler::pextrw(Operand dst, XMMRegister src, uint8_t offset) { 27191cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 27201cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 27211cb0ef41Sopenharmony_ci EMIT(0x66); 27221cb0ef41Sopenharmony_ci EMIT(0x0F); 27231cb0ef41Sopenharmony_ci EMIT(0x3A); 27241cb0ef41Sopenharmony_ci EMIT(0x15); 27251cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 27261cb0ef41Sopenharmony_ci EMIT(offset); 27271cb0ef41Sopenharmony_ci} 27281cb0ef41Sopenharmony_ci 27291cb0ef41Sopenharmony_civoid Assembler::pextrd(Operand dst, XMMRegister src, uint8_t offset) { 27301cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 27311cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 27321cb0ef41Sopenharmony_ci EMIT(0x66); 27331cb0ef41Sopenharmony_ci EMIT(0x0F); 27341cb0ef41Sopenharmony_ci EMIT(0x3A); 27351cb0ef41Sopenharmony_ci EMIT(0x16); 27361cb0ef41Sopenharmony_ci emit_sse_operand(src, dst); 27371cb0ef41Sopenharmony_ci EMIT(offset); 27381cb0ef41Sopenharmony_ci} 27391cb0ef41Sopenharmony_ci 27401cb0ef41Sopenharmony_civoid Assembler::insertps(XMMRegister dst, Operand src, uint8_t offset) { 27411cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 27421cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 27431cb0ef41Sopenharmony_ci EMIT(0x66); 27441cb0ef41Sopenharmony_ci EMIT(0x0F); 27451cb0ef41Sopenharmony_ci EMIT(0x3A); 27461cb0ef41Sopenharmony_ci EMIT(0x21); 27471cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 27481cb0ef41Sopenharmony_ci EMIT(offset); 27491cb0ef41Sopenharmony_ci} 27501cb0ef41Sopenharmony_ci 27511cb0ef41Sopenharmony_civoid Assembler::pinsrb(XMMRegister dst, Operand src, uint8_t offset) { 27521cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 27531cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 27541cb0ef41Sopenharmony_ci EMIT(0x66); 27551cb0ef41Sopenharmony_ci EMIT(0x0F); 27561cb0ef41Sopenharmony_ci EMIT(0x3A); 27571cb0ef41Sopenharmony_ci EMIT(0x20); 27581cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 27591cb0ef41Sopenharmony_ci EMIT(offset); 27601cb0ef41Sopenharmony_ci} 27611cb0ef41Sopenharmony_ci 27621cb0ef41Sopenharmony_civoid Assembler::pinsrw(XMMRegister dst, Operand src, uint8_t offset) { 27631cb0ef41Sopenharmony_ci DCHECK(is_uint8(offset)); 27641cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 27651cb0ef41Sopenharmony_ci EMIT(0x66); 27661cb0ef41Sopenharmony_ci EMIT(0x0F); 27671cb0ef41Sopenharmony_ci EMIT(0xC4); 27681cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 27691cb0ef41Sopenharmony_ci EMIT(offset); 27701cb0ef41Sopenharmony_ci} 27711cb0ef41Sopenharmony_ci 27721cb0ef41Sopenharmony_civoid Assembler::pinsrd(XMMRegister dst, Operand src, uint8_t offset) { 27731cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 27741cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 27751cb0ef41Sopenharmony_ci EMIT(0x66); 27761cb0ef41Sopenharmony_ci EMIT(0x0F); 27771cb0ef41Sopenharmony_ci EMIT(0x3A); 27781cb0ef41Sopenharmony_ci EMIT(0x22); 27791cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 27801cb0ef41Sopenharmony_ci EMIT(offset); 27811cb0ef41Sopenharmony_ci} 27821cb0ef41Sopenharmony_ci 27831cb0ef41Sopenharmony_civoid Assembler::addss(XMMRegister dst, Operand src) { 27841cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 27851cb0ef41Sopenharmony_ci EMIT(0xF3); 27861cb0ef41Sopenharmony_ci EMIT(0x0F); 27871cb0ef41Sopenharmony_ci EMIT(0x58); 27881cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 27891cb0ef41Sopenharmony_ci} 27901cb0ef41Sopenharmony_ci 27911cb0ef41Sopenharmony_civoid Assembler::subss(XMMRegister dst, Operand src) { 27921cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 27931cb0ef41Sopenharmony_ci EMIT(0xF3); 27941cb0ef41Sopenharmony_ci EMIT(0x0F); 27951cb0ef41Sopenharmony_ci EMIT(0x5C); 27961cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 27971cb0ef41Sopenharmony_ci} 27981cb0ef41Sopenharmony_ci 27991cb0ef41Sopenharmony_civoid Assembler::mulss(XMMRegister dst, Operand src) { 28001cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 28011cb0ef41Sopenharmony_ci EMIT(0xF3); 28021cb0ef41Sopenharmony_ci EMIT(0x0F); 28031cb0ef41Sopenharmony_ci EMIT(0x59); 28041cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 28051cb0ef41Sopenharmony_ci} 28061cb0ef41Sopenharmony_ci 28071cb0ef41Sopenharmony_civoid Assembler::divss(XMMRegister dst, Operand src) { 28081cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 28091cb0ef41Sopenharmony_ci EMIT(0xF3); 28101cb0ef41Sopenharmony_ci EMIT(0x0F); 28111cb0ef41Sopenharmony_ci EMIT(0x5E); 28121cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 28131cb0ef41Sopenharmony_ci} 28141cb0ef41Sopenharmony_ci 28151cb0ef41Sopenharmony_civoid Assembler::sqrtss(XMMRegister dst, Operand src) { 28161cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 28171cb0ef41Sopenharmony_ci EMIT(0xF3); 28181cb0ef41Sopenharmony_ci EMIT(0x0F); 28191cb0ef41Sopenharmony_ci EMIT(0x51); 28201cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 28211cb0ef41Sopenharmony_ci} 28221cb0ef41Sopenharmony_ci 28231cb0ef41Sopenharmony_civoid Assembler::ucomiss(XMMRegister dst, Operand src) { 28241cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 28251cb0ef41Sopenharmony_ci EMIT(0x0F); 28261cb0ef41Sopenharmony_ci EMIT(0x2E); 28271cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 28281cb0ef41Sopenharmony_ci} 28291cb0ef41Sopenharmony_ci 28301cb0ef41Sopenharmony_civoid Assembler::maxss(XMMRegister dst, Operand src) { 28311cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 28321cb0ef41Sopenharmony_ci EMIT(0xF3); 28331cb0ef41Sopenharmony_ci EMIT(0x0F); 28341cb0ef41Sopenharmony_ci EMIT(0x5F); 28351cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 28361cb0ef41Sopenharmony_ci} 28371cb0ef41Sopenharmony_ci 28381cb0ef41Sopenharmony_civoid Assembler::minss(XMMRegister dst, Operand src) { 28391cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 28401cb0ef41Sopenharmony_ci EMIT(0xF3); 28411cb0ef41Sopenharmony_ci EMIT(0x0F); 28421cb0ef41Sopenharmony_ci EMIT(0x5D); 28431cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 28441cb0ef41Sopenharmony_ci} 28451cb0ef41Sopenharmony_ci 28461cb0ef41Sopenharmony_ci// Packed single-precision floating-point SSE instructions. 28471cb0ef41Sopenharmony_civoid Assembler::ps(byte opcode, XMMRegister dst, Operand src) { 28481cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 28491cb0ef41Sopenharmony_ci EMIT(0x0F); 28501cb0ef41Sopenharmony_ci EMIT(opcode); 28511cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 28521cb0ef41Sopenharmony_ci} 28531cb0ef41Sopenharmony_ci 28541cb0ef41Sopenharmony_ci// Packed double-precision floating-point SSE instructions. 28551cb0ef41Sopenharmony_civoid Assembler::pd(byte opcode, XMMRegister dst, Operand src) { 28561cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 28571cb0ef41Sopenharmony_ci EMIT(0x66); 28581cb0ef41Sopenharmony_ci EMIT(0x0F); 28591cb0ef41Sopenharmony_ci EMIT(opcode); 28601cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 28611cb0ef41Sopenharmony_ci} 28621cb0ef41Sopenharmony_ci 28631cb0ef41Sopenharmony_ci// AVX instructions 28641cb0ef41Sopenharmony_ci 28651cb0ef41Sopenharmony_civoid Assembler::vss(byte op, XMMRegister dst, XMMRegister src1, Operand src2) { 28661cb0ef41Sopenharmony_ci vinstr(op, dst, src1, src2, kF3, k0F, kWIG); 28671cb0ef41Sopenharmony_ci} 28681cb0ef41Sopenharmony_ci 28691cb0ef41Sopenharmony_civoid Assembler::vps(byte op, XMMRegister dst, XMMRegister src1, Operand src2) { 28701cb0ef41Sopenharmony_ci vinstr(op, dst, src1, src2, kNoPrefix, k0F, kWIG); 28711cb0ef41Sopenharmony_ci} 28721cb0ef41Sopenharmony_ci 28731cb0ef41Sopenharmony_civoid Assembler::vpd(byte op, XMMRegister dst, XMMRegister src1, Operand src2) { 28741cb0ef41Sopenharmony_ci vinstr(op, dst, src1, src2, k66, k0F, kWIG); 28751cb0ef41Sopenharmony_ci} 28761cb0ef41Sopenharmony_ci 28771cb0ef41Sopenharmony_civoid Assembler::vshufpd(XMMRegister dst, XMMRegister src1, Operand src2, 28781cb0ef41Sopenharmony_ci byte imm8) { 28791cb0ef41Sopenharmony_ci DCHECK(is_uint8(imm8)); 28801cb0ef41Sopenharmony_ci vpd(0xC6, dst, src1, src2); 28811cb0ef41Sopenharmony_ci EMIT(imm8); 28821cb0ef41Sopenharmony_ci} 28831cb0ef41Sopenharmony_ci 28841cb0ef41Sopenharmony_civoid Assembler::vmovhlps(XMMRegister dst, XMMRegister src1, XMMRegister src2) { 28851cb0ef41Sopenharmony_ci vinstr(0x12, dst, src1, src2, kNoPrefix, k0F, kWIG); 28861cb0ef41Sopenharmony_ci} 28871cb0ef41Sopenharmony_ci 28881cb0ef41Sopenharmony_civoid Assembler::vmovlhps(XMMRegister dst, XMMRegister src1, XMMRegister src2) { 28891cb0ef41Sopenharmony_ci vinstr(0x16, dst, src1, src2, kNoPrefix, k0F, kWIG); 28901cb0ef41Sopenharmony_ci} 28911cb0ef41Sopenharmony_ci 28921cb0ef41Sopenharmony_civoid Assembler::vmovlps(XMMRegister dst, XMMRegister src1, Operand src2) { 28931cb0ef41Sopenharmony_ci vinstr(0x12, dst, src1, src2, kNoPrefix, k0F, kWIG); 28941cb0ef41Sopenharmony_ci} 28951cb0ef41Sopenharmony_ci 28961cb0ef41Sopenharmony_civoid Assembler::vmovlps(Operand dst, XMMRegister src) { 28971cb0ef41Sopenharmony_ci vinstr(0x13, src, xmm0, dst, kNoPrefix, k0F, kWIG); 28981cb0ef41Sopenharmony_ci} 28991cb0ef41Sopenharmony_ci 29001cb0ef41Sopenharmony_civoid Assembler::vmovhps(XMMRegister dst, XMMRegister src1, Operand src2) { 29011cb0ef41Sopenharmony_ci vinstr(0x16, dst, src1, src2, kNoPrefix, k0F, kWIG); 29021cb0ef41Sopenharmony_ci} 29031cb0ef41Sopenharmony_ci 29041cb0ef41Sopenharmony_civoid Assembler::vmovhps(Operand dst, XMMRegister src) { 29051cb0ef41Sopenharmony_ci vinstr(0x17, src, xmm0, dst, kNoPrefix, k0F, kWIG); 29061cb0ef41Sopenharmony_ci} 29071cb0ef41Sopenharmony_ci 29081cb0ef41Sopenharmony_civoid Assembler::vcmpps(XMMRegister dst, XMMRegister src1, Operand src2, 29091cb0ef41Sopenharmony_ci uint8_t cmp) { 29101cb0ef41Sopenharmony_ci vps(0xC2, dst, src1, src2); 29111cb0ef41Sopenharmony_ci EMIT(cmp); 29121cb0ef41Sopenharmony_ci} 29131cb0ef41Sopenharmony_ci 29141cb0ef41Sopenharmony_civoid Assembler::vcmppd(XMMRegister dst, XMMRegister src1, Operand src2, 29151cb0ef41Sopenharmony_ci uint8_t cmp) { 29161cb0ef41Sopenharmony_ci vpd(0xC2, dst, src1, src2); 29171cb0ef41Sopenharmony_ci EMIT(cmp); 29181cb0ef41Sopenharmony_ci} 29191cb0ef41Sopenharmony_ci 29201cb0ef41Sopenharmony_civoid Assembler::vshufps(XMMRegister dst, XMMRegister src1, Operand src2, 29211cb0ef41Sopenharmony_ci byte imm8) { 29221cb0ef41Sopenharmony_ci DCHECK(is_uint8(imm8)); 29231cb0ef41Sopenharmony_ci vps(0xC6, dst, src1, src2); 29241cb0ef41Sopenharmony_ci EMIT(imm8); 29251cb0ef41Sopenharmony_ci} 29261cb0ef41Sopenharmony_ci 29271cb0ef41Sopenharmony_civoid Assembler::vpsllw(XMMRegister dst, XMMRegister src, uint8_t imm8) { 29281cb0ef41Sopenharmony_ci XMMRegister iop = XMMRegister::from_code(6); 29291cb0ef41Sopenharmony_ci vinstr(0x71, iop, dst, Operand(src), k66, k0F, kWIG); 29301cb0ef41Sopenharmony_ci EMIT(imm8); 29311cb0ef41Sopenharmony_ci} 29321cb0ef41Sopenharmony_ci 29331cb0ef41Sopenharmony_civoid Assembler::vpslld(XMMRegister dst, XMMRegister src, uint8_t imm8) { 29341cb0ef41Sopenharmony_ci XMMRegister iop = XMMRegister::from_code(6); 29351cb0ef41Sopenharmony_ci vinstr(0x72, iop, dst, Operand(src), k66, k0F, kWIG); 29361cb0ef41Sopenharmony_ci EMIT(imm8); 29371cb0ef41Sopenharmony_ci} 29381cb0ef41Sopenharmony_ci 29391cb0ef41Sopenharmony_civoid Assembler::vpsllq(XMMRegister dst, XMMRegister src, uint8_t imm8) { 29401cb0ef41Sopenharmony_ci XMMRegister iop = XMMRegister::from_code(6); 29411cb0ef41Sopenharmony_ci vinstr(0x73, iop, dst, Operand(src), k66, k0F, kWIG); 29421cb0ef41Sopenharmony_ci EMIT(imm8); 29431cb0ef41Sopenharmony_ci} 29441cb0ef41Sopenharmony_ci 29451cb0ef41Sopenharmony_civoid Assembler::vpsrlw(XMMRegister dst, XMMRegister src, uint8_t imm8) { 29461cb0ef41Sopenharmony_ci XMMRegister iop = XMMRegister::from_code(2); 29471cb0ef41Sopenharmony_ci vinstr(0x71, iop, dst, Operand(src), k66, k0F, kWIG); 29481cb0ef41Sopenharmony_ci EMIT(imm8); 29491cb0ef41Sopenharmony_ci} 29501cb0ef41Sopenharmony_ci 29511cb0ef41Sopenharmony_civoid Assembler::vpsrld(XMMRegister dst, XMMRegister src, uint8_t imm8) { 29521cb0ef41Sopenharmony_ci XMMRegister iop = XMMRegister::from_code(2); 29531cb0ef41Sopenharmony_ci vinstr(0x72, iop, dst, Operand(src), k66, k0F, kWIG); 29541cb0ef41Sopenharmony_ci EMIT(imm8); 29551cb0ef41Sopenharmony_ci} 29561cb0ef41Sopenharmony_ci 29571cb0ef41Sopenharmony_civoid Assembler::vpsrlq(XMMRegister dst, XMMRegister src, uint8_t imm8) { 29581cb0ef41Sopenharmony_ci XMMRegister iop = XMMRegister::from_code(2); 29591cb0ef41Sopenharmony_ci vinstr(0x73, iop, dst, Operand(src), k66, k0F, kWIG); 29601cb0ef41Sopenharmony_ci EMIT(imm8); 29611cb0ef41Sopenharmony_ci} 29621cb0ef41Sopenharmony_ci 29631cb0ef41Sopenharmony_civoid Assembler::vpsraw(XMMRegister dst, XMMRegister src, uint8_t imm8) { 29641cb0ef41Sopenharmony_ci XMMRegister iop = XMMRegister::from_code(4); 29651cb0ef41Sopenharmony_ci vinstr(0x71, iop, dst, Operand(src), k66, k0F, kWIG); 29661cb0ef41Sopenharmony_ci EMIT(imm8); 29671cb0ef41Sopenharmony_ci} 29681cb0ef41Sopenharmony_ci 29691cb0ef41Sopenharmony_civoid Assembler::vpsrad(XMMRegister dst, XMMRegister src, uint8_t imm8) { 29701cb0ef41Sopenharmony_ci XMMRegister iop = XMMRegister::from_code(4); 29711cb0ef41Sopenharmony_ci vinstr(0x72, iop, dst, Operand(src), k66, k0F, kWIG); 29721cb0ef41Sopenharmony_ci EMIT(imm8); 29731cb0ef41Sopenharmony_ci} 29741cb0ef41Sopenharmony_ci 29751cb0ef41Sopenharmony_civoid Assembler::vpshufhw(XMMRegister dst, Operand src, uint8_t shuffle) { 29761cb0ef41Sopenharmony_ci vinstr(0x70, dst, xmm0, src, kF3, k0F, kWIG); 29771cb0ef41Sopenharmony_ci EMIT(shuffle); 29781cb0ef41Sopenharmony_ci} 29791cb0ef41Sopenharmony_ci 29801cb0ef41Sopenharmony_civoid Assembler::vpshuflw(XMMRegister dst, Operand src, uint8_t shuffle) { 29811cb0ef41Sopenharmony_ci vinstr(0x70, dst, xmm0, src, kF2, k0F, kWIG); 29821cb0ef41Sopenharmony_ci EMIT(shuffle); 29831cb0ef41Sopenharmony_ci} 29841cb0ef41Sopenharmony_ci 29851cb0ef41Sopenharmony_civoid Assembler::vpshufd(XMMRegister dst, Operand src, uint8_t shuffle) { 29861cb0ef41Sopenharmony_ci vinstr(0x70, dst, xmm0, src, k66, k0F, kWIG); 29871cb0ef41Sopenharmony_ci EMIT(shuffle); 29881cb0ef41Sopenharmony_ci} 29891cb0ef41Sopenharmony_ci 29901cb0ef41Sopenharmony_civoid Assembler::vblendvps(XMMRegister dst, XMMRegister src1, XMMRegister src2, 29911cb0ef41Sopenharmony_ci XMMRegister mask) { 29921cb0ef41Sopenharmony_ci vinstr(0x4A, dst, src1, src2, k66, k0F3A, kW0); 29931cb0ef41Sopenharmony_ci EMIT(mask.code() << 4); 29941cb0ef41Sopenharmony_ci} 29951cb0ef41Sopenharmony_ci 29961cb0ef41Sopenharmony_civoid Assembler::vblendvpd(XMMRegister dst, XMMRegister src1, XMMRegister src2, 29971cb0ef41Sopenharmony_ci XMMRegister mask) { 29981cb0ef41Sopenharmony_ci vinstr(0x4B, dst, src1, src2, k66, k0F3A, kW0); 29991cb0ef41Sopenharmony_ci EMIT(mask.code() << 4); 30001cb0ef41Sopenharmony_ci} 30011cb0ef41Sopenharmony_ci 30021cb0ef41Sopenharmony_civoid Assembler::vpblendvb(XMMRegister dst, XMMRegister src1, XMMRegister src2, 30031cb0ef41Sopenharmony_ci XMMRegister mask) { 30041cb0ef41Sopenharmony_ci vinstr(0x4C, dst, src1, src2, k66, k0F3A, kW0); 30051cb0ef41Sopenharmony_ci EMIT(mask.code() << 4); 30061cb0ef41Sopenharmony_ci} 30071cb0ef41Sopenharmony_ci 30081cb0ef41Sopenharmony_civoid Assembler::vpblendw(XMMRegister dst, XMMRegister src1, Operand src2, 30091cb0ef41Sopenharmony_ci uint8_t mask) { 30101cb0ef41Sopenharmony_ci vinstr(0x0E, dst, src1, src2, k66, k0F3A, kWIG); 30111cb0ef41Sopenharmony_ci EMIT(mask); 30121cb0ef41Sopenharmony_ci} 30131cb0ef41Sopenharmony_ci 30141cb0ef41Sopenharmony_civoid Assembler::vpalignr(XMMRegister dst, XMMRegister src1, Operand src2, 30151cb0ef41Sopenharmony_ci uint8_t mask) { 30161cb0ef41Sopenharmony_ci vinstr(0x0F, dst, src1, src2, k66, k0F3A, kWIG); 30171cb0ef41Sopenharmony_ci EMIT(mask); 30181cb0ef41Sopenharmony_ci} 30191cb0ef41Sopenharmony_ci 30201cb0ef41Sopenharmony_civoid Assembler::vpextrb(Operand dst, XMMRegister src, uint8_t offset) { 30211cb0ef41Sopenharmony_ci vinstr(0x14, src, xmm0, dst, k66, k0F3A, kWIG); 30221cb0ef41Sopenharmony_ci EMIT(offset); 30231cb0ef41Sopenharmony_ci} 30241cb0ef41Sopenharmony_ci 30251cb0ef41Sopenharmony_civoid Assembler::vpextrw(Operand dst, XMMRegister src, uint8_t offset) { 30261cb0ef41Sopenharmony_ci vinstr(0x15, src, xmm0, dst, k66, k0F3A, kWIG); 30271cb0ef41Sopenharmony_ci EMIT(offset); 30281cb0ef41Sopenharmony_ci} 30291cb0ef41Sopenharmony_ci 30301cb0ef41Sopenharmony_civoid Assembler::vpextrd(Operand dst, XMMRegister src, uint8_t offset) { 30311cb0ef41Sopenharmony_ci vinstr(0x16, src, xmm0, dst, k66, k0F3A, kWIG); 30321cb0ef41Sopenharmony_ci EMIT(offset); 30331cb0ef41Sopenharmony_ci} 30341cb0ef41Sopenharmony_ci 30351cb0ef41Sopenharmony_civoid Assembler::vinsertps(XMMRegister dst, XMMRegister src1, Operand src2, 30361cb0ef41Sopenharmony_ci uint8_t offset) { 30371cb0ef41Sopenharmony_ci vinstr(0x21, dst, src1, src2, k66, k0F3A, kWIG); 30381cb0ef41Sopenharmony_ci EMIT(offset); 30391cb0ef41Sopenharmony_ci} 30401cb0ef41Sopenharmony_ci 30411cb0ef41Sopenharmony_civoid Assembler::vpinsrb(XMMRegister dst, XMMRegister src1, Operand src2, 30421cb0ef41Sopenharmony_ci uint8_t offset) { 30431cb0ef41Sopenharmony_ci vinstr(0x20, dst, src1, src2, k66, k0F3A, kWIG); 30441cb0ef41Sopenharmony_ci EMIT(offset); 30451cb0ef41Sopenharmony_ci} 30461cb0ef41Sopenharmony_ci 30471cb0ef41Sopenharmony_civoid Assembler::vpinsrw(XMMRegister dst, XMMRegister src1, Operand src2, 30481cb0ef41Sopenharmony_ci uint8_t offset) { 30491cb0ef41Sopenharmony_ci vinstr(0xC4, dst, src1, src2, k66, k0F, kWIG); 30501cb0ef41Sopenharmony_ci EMIT(offset); 30511cb0ef41Sopenharmony_ci} 30521cb0ef41Sopenharmony_ci 30531cb0ef41Sopenharmony_civoid Assembler::vpinsrd(XMMRegister dst, XMMRegister src1, Operand src2, 30541cb0ef41Sopenharmony_ci uint8_t offset) { 30551cb0ef41Sopenharmony_ci vinstr(0x22, dst, src1, src2, k66, k0F3A, kWIG); 30561cb0ef41Sopenharmony_ci EMIT(offset); 30571cb0ef41Sopenharmony_ci} 30581cb0ef41Sopenharmony_ci 30591cb0ef41Sopenharmony_civoid Assembler::vroundsd(XMMRegister dst, XMMRegister src1, XMMRegister src2, 30601cb0ef41Sopenharmony_ci RoundingMode mode) { 30611cb0ef41Sopenharmony_ci vinstr(0x0b, dst, src1, src2, k66, k0F3A, kWIG); 30621cb0ef41Sopenharmony_ci EMIT(static_cast<byte>(mode) | 0x8); // Mask precision exception. 30631cb0ef41Sopenharmony_ci} 30641cb0ef41Sopenharmony_civoid Assembler::vroundss(XMMRegister dst, XMMRegister src1, XMMRegister src2, 30651cb0ef41Sopenharmony_ci RoundingMode mode) { 30661cb0ef41Sopenharmony_ci vinstr(0x0a, dst, src1, src2, k66, k0F3A, kWIG); 30671cb0ef41Sopenharmony_ci EMIT(static_cast<byte>(mode) | 0x8); // Mask precision exception. 30681cb0ef41Sopenharmony_ci} 30691cb0ef41Sopenharmony_civoid Assembler::vroundps(XMMRegister dst, XMMRegister src, RoundingMode mode) { 30701cb0ef41Sopenharmony_ci vinstr(0x08, dst, xmm0, Operand(src), k66, k0F3A, kWIG); 30711cb0ef41Sopenharmony_ci EMIT(static_cast<byte>(mode) | 0x8); // Mask precision exception. 30721cb0ef41Sopenharmony_ci} 30731cb0ef41Sopenharmony_civoid Assembler::vroundpd(XMMRegister dst, XMMRegister src, RoundingMode mode) { 30741cb0ef41Sopenharmony_ci vinstr(0x09, dst, xmm0, Operand(src), k66, k0F3A, kWIG); 30751cb0ef41Sopenharmony_ci EMIT(static_cast<byte>(mode) | 0x8); // Mask precision exception. 30761cb0ef41Sopenharmony_ci} 30771cb0ef41Sopenharmony_ci 30781cb0ef41Sopenharmony_civoid Assembler::vmovmskpd(Register dst, XMMRegister src) { 30791cb0ef41Sopenharmony_ci DCHECK(IsEnabled(AVX)); 30801cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 30811cb0ef41Sopenharmony_ci emit_vex_prefix(xmm0, kL128, k66, k0F, kWIG); 30821cb0ef41Sopenharmony_ci EMIT(0x50); 30831cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 30841cb0ef41Sopenharmony_ci} 30851cb0ef41Sopenharmony_ci 30861cb0ef41Sopenharmony_civoid Assembler::vmovmskps(Register dst, XMMRegister src) { 30871cb0ef41Sopenharmony_ci DCHECK(IsEnabled(AVX)); 30881cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 30891cb0ef41Sopenharmony_ci emit_vex_prefix(xmm0, kL128, kNoPrefix, k0F, kWIG); 30901cb0ef41Sopenharmony_ci EMIT(0x50); 30911cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 30921cb0ef41Sopenharmony_ci} 30931cb0ef41Sopenharmony_ci 30941cb0ef41Sopenharmony_civoid Assembler::vpmovmskb(Register dst, XMMRegister src) { 30951cb0ef41Sopenharmony_ci DCHECK(IsEnabled(AVX)); 30961cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 30971cb0ef41Sopenharmony_ci emit_vex_prefix(xmm0, kL128, k66, k0F, kWIG); 30981cb0ef41Sopenharmony_ci EMIT(0xD7); 30991cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 31001cb0ef41Sopenharmony_ci} 31011cb0ef41Sopenharmony_ci 31021cb0ef41Sopenharmony_civoid Assembler::vextractps(Operand dst, XMMRegister src, byte imm8) { 31031cb0ef41Sopenharmony_ci vinstr(0x17, src, xmm0, dst, k66, k0F3A, VexW::kWIG); 31041cb0ef41Sopenharmony_ci EMIT(imm8); 31051cb0ef41Sopenharmony_ci} 31061cb0ef41Sopenharmony_ci 31071cb0ef41Sopenharmony_civoid Assembler::vpcmpgtq(XMMRegister dst, XMMRegister src1, XMMRegister src2) { 31081cb0ef41Sopenharmony_ci vinstr(0x37, dst, src1, src2, k66, k0F38, VexW::kWIG); 31091cb0ef41Sopenharmony_ci} 31101cb0ef41Sopenharmony_ci 31111cb0ef41Sopenharmony_civoid Assembler::bmi1(byte op, Register reg, Register vreg, Operand rm) { 31121cb0ef41Sopenharmony_ci DCHECK(IsEnabled(BMI1)); 31131cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31141cb0ef41Sopenharmony_ci emit_vex_prefix(vreg, kLZ, kNoPrefix, k0F38, kW0); 31151cb0ef41Sopenharmony_ci EMIT(op); 31161cb0ef41Sopenharmony_ci emit_operand(reg, rm); 31171cb0ef41Sopenharmony_ci} 31181cb0ef41Sopenharmony_ci 31191cb0ef41Sopenharmony_civoid Assembler::tzcnt(Register dst, Operand src) { 31201cb0ef41Sopenharmony_ci DCHECK(IsEnabled(BMI1)); 31211cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31221cb0ef41Sopenharmony_ci EMIT(0xF3); 31231cb0ef41Sopenharmony_ci EMIT(0x0F); 31241cb0ef41Sopenharmony_ci EMIT(0xBC); 31251cb0ef41Sopenharmony_ci emit_operand(dst, src); 31261cb0ef41Sopenharmony_ci} 31271cb0ef41Sopenharmony_ci 31281cb0ef41Sopenharmony_civoid Assembler::lzcnt(Register dst, Operand src) { 31291cb0ef41Sopenharmony_ci DCHECK(IsEnabled(LZCNT)); 31301cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31311cb0ef41Sopenharmony_ci EMIT(0xF3); 31321cb0ef41Sopenharmony_ci EMIT(0x0F); 31331cb0ef41Sopenharmony_ci EMIT(0xBD); 31341cb0ef41Sopenharmony_ci emit_operand(dst, src); 31351cb0ef41Sopenharmony_ci} 31361cb0ef41Sopenharmony_ci 31371cb0ef41Sopenharmony_civoid Assembler::popcnt(Register dst, Operand src) { 31381cb0ef41Sopenharmony_ci DCHECK(IsEnabled(POPCNT)); 31391cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31401cb0ef41Sopenharmony_ci EMIT(0xF3); 31411cb0ef41Sopenharmony_ci EMIT(0x0F); 31421cb0ef41Sopenharmony_ci EMIT(0xB8); 31431cb0ef41Sopenharmony_ci emit_operand(dst, src); 31441cb0ef41Sopenharmony_ci} 31451cb0ef41Sopenharmony_ci 31461cb0ef41Sopenharmony_civoid Assembler::bmi2(SIMDPrefix pp, byte op, Register reg, Register vreg, 31471cb0ef41Sopenharmony_ci Operand rm) { 31481cb0ef41Sopenharmony_ci DCHECK(IsEnabled(BMI2)); 31491cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31501cb0ef41Sopenharmony_ci emit_vex_prefix(vreg, kLZ, pp, k0F38, kW0); 31511cb0ef41Sopenharmony_ci EMIT(op); 31521cb0ef41Sopenharmony_ci emit_operand(reg, rm); 31531cb0ef41Sopenharmony_ci} 31541cb0ef41Sopenharmony_ci 31551cb0ef41Sopenharmony_civoid Assembler::rorx(Register dst, Operand src, byte imm8) { 31561cb0ef41Sopenharmony_ci DCHECK(IsEnabled(BMI2)); 31571cb0ef41Sopenharmony_ci DCHECK(is_uint8(imm8)); 31581cb0ef41Sopenharmony_ci Register vreg = Register::from_code(0); // VEX.vvvv unused 31591cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31601cb0ef41Sopenharmony_ci emit_vex_prefix(vreg, kLZ, kF2, k0F3A, kW0); 31611cb0ef41Sopenharmony_ci EMIT(0xF0); 31621cb0ef41Sopenharmony_ci emit_operand(dst, src); 31631cb0ef41Sopenharmony_ci EMIT(imm8); 31641cb0ef41Sopenharmony_ci} 31651cb0ef41Sopenharmony_ci 31661cb0ef41Sopenharmony_civoid Assembler::sse_instr(XMMRegister dst, Operand src, byte escape, 31671cb0ef41Sopenharmony_ci byte opcode) { 31681cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31691cb0ef41Sopenharmony_ci EMIT(escape); 31701cb0ef41Sopenharmony_ci EMIT(opcode); 31711cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 31721cb0ef41Sopenharmony_ci} 31731cb0ef41Sopenharmony_ci 31741cb0ef41Sopenharmony_civoid Assembler::sse2_instr(XMMRegister dst, Operand src, byte prefix, 31751cb0ef41Sopenharmony_ci byte escape, byte opcode) { 31761cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31771cb0ef41Sopenharmony_ci EMIT(prefix); 31781cb0ef41Sopenharmony_ci EMIT(escape); 31791cb0ef41Sopenharmony_ci EMIT(opcode); 31801cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 31811cb0ef41Sopenharmony_ci} 31821cb0ef41Sopenharmony_ci 31831cb0ef41Sopenharmony_civoid Assembler::ssse3_instr(XMMRegister dst, Operand src, byte prefix, 31841cb0ef41Sopenharmony_ci byte escape1, byte escape2, byte opcode) { 31851cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSSE3)); 31861cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31871cb0ef41Sopenharmony_ci EMIT(prefix); 31881cb0ef41Sopenharmony_ci EMIT(escape1); 31891cb0ef41Sopenharmony_ci EMIT(escape2); 31901cb0ef41Sopenharmony_ci EMIT(opcode); 31911cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 31921cb0ef41Sopenharmony_ci} 31931cb0ef41Sopenharmony_ci 31941cb0ef41Sopenharmony_civoid Assembler::sse4_instr(XMMRegister dst, Operand src, byte prefix, 31951cb0ef41Sopenharmony_ci byte escape1, byte escape2, byte opcode) { 31961cb0ef41Sopenharmony_ci DCHECK(IsEnabled(SSE4_1)); 31971cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 31981cb0ef41Sopenharmony_ci EMIT(prefix); 31991cb0ef41Sopenharmony_ci EMIT(escape1); 32001cb0ef41Sopenharmony_ci EMIT(escape2); 32011cb0ef41Sopenharmony_ci EMIT(opcode); 32021cb0ef41Sopenharmony_ci emit_sse_operand(dst, src); 32031cb0ef41Sopenharmony_ci} 32041cb0ef41Sopenharmony_ci 32051cb0ef41Sopenharmony_civoid Assembler::vinstr(byte op, XMMRegister dst, XMMRegister src1, 32061cb0ef41Sopenharmony_ci XMMRegister src2, SIMDPrefix pp, LeadingOpcode m, VexW w, 32071cb0ef41Sopenharmony_ci CpuFeature feature) { 32081cb0ef41Sopenharmony_ci vinstr(op, dst, src1, src2, kL128, pp, m, w, feature); 32091cb0ef41Sopenharmony_ci} 32101cb0ef41Sopenharmony_ci 32111cb0ef41Sopenharmony_civoid Assembler::vinstr(byte op, XMMRegister dst, XMMRegister src1, Operand src2, 32121cb0ef41Sopenharmony_ci SIMDPrefix pp, LeadingOpcode m, VexW w, 32131cb0ef41Sopenharmony_ci CpuFeature feature) { 32141cb0ef41Sopenharmony_ci vinstr(op, dst, src1, src2, kL128, pp, m, w, feature); 32151cb0ef41Sopenharmony_ci} 32161cb0ef41Sopenharmony_ci 32171cb0ef41Sopenharmony_civoid Assembler::vinstr(byte op, XMMRegister dst, XMMRegister src1, 32181cb0ef41Sopenharmony_ci XMMRegister src2, VectorLength l, SIMDPrefix pp, 32191cb0ef41Sopenharmony_ci LeadingOpcode m, VexW w, CpuFeature feature) { 32201cb0ef41Sopenharmony_ci DCHECK(IsEnabled(feature)); 32211cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 32221cb0ef41Sopenharmony_ci emit_vex_prefix(src1, l, pp, m, w); 32231cb0ef41Sopenharmony_ci EMIT(op); 32241cb0ef41Sopenharmony_ci emit_sse_operand(dst, src2); 32251cb0ef41Sopenharmony_ci} 32261cb0ef41Sopenharmony_ci 32271cb0ef41Sopenharmony_civoid Assembler::vinstr(byte op, XMMRegister dst, XMMRegister src1, Operand src2, 32281cb0ef41Sopenharmony_ci VectorLength l, SIMDPrefix pp, LeadingOpcode m, VexW w, 32291cb0ef41Sopenharmony_ci CpuFeature feature) { 32301cb0ef41Sopenharmony_ci DCHECK(IsEnabled(feature)); 32311cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 32321cb0ef41Sopenharmony_ci emit_vex_prefix(src1, l, pp, m, w); 32331cb0ef41Sopenharmony_ci EMIT(op); 32341cb0ef41Sopenharmony_ci emit_sse_operand(dst, src2); 32351cb0ef41Sopenharmony_ci} 32361cb0ef41Sopenharmony_ci 32371cb0ef41Sopenharmony_civoid Assembler::emit_sse_operand(XMMRegister reg, Operand adr) { 32381cb0ef41Sopenharmony_ci Register ireg = Register::from_code(reg.code()); 32391cb0ef41Sopenharmony_ci emit_operand(ireg, adr); 32401cb0ef41Sopenharmony_ci} 32411cb0ef41Sopenharmony_ci 32421cb0ef41Sopenharmony_civoid Assembler::emit_sse_operand(XMMRegister dst, XMMRegister src) { 32431cb0ef41Sopenharmony_ci EMIT(0xC0 | dst.code() << 3 | src.code()); 32441cb0ef41Sopenharmony_ci} 32451cb0ef41Sopenharmony_ci 32461cb0ef41Sopenharmony_civoid Assembler::emit_sse_operand(Register dst, XMMRegister src) { 32471cb0ef41Sopenharmony_ci EMIT(0xC0 | dst.code() << 3 | src.code()); 32481cb0ef41Sopenharmony_ci} 32491cb0ef41Sopenharmony_ci 32501cb0ef41Sopenharmony_civoid Assembler::emit_sse_operand(XMMRegister dst, Register src) { 32511cb0ef41Sopenharmony_ci EMIT(0xC0 | (dst.code() << 3) | src.code()); 32521cb0ef41Sopenharmony_ci} 32531cb0ef41Sopenharmony_ci 32541cb0ef41Sopenharmony_civoid Assembler::emit_vex_prefix(XMMRegister vreg, VectorLength l, SIMDPrefix pp, 32551cb0ef41Sopenharmony_ci LeadingOpcode mm, VexW w) { 32561cb0ef41Sopenharmony_ci if (mm != k0F || w != kW0) { 32571cb0ef41Sopenharmony_ci EMIT(0xC4); 32581cb0ef41Sopenharmony_ci // Change RXB from "110" to "111" to align with gdb disassembler. 32591cb0ef41Sopenharmony_ci EMIT(0xE0 | mm); 32601cb0ef41Sopenharmony_ci EMIT(w | ((~vreg.code() & 0xF) << 3) | l | pp); 32611cb0ef41Sopenharmony_ci } else { 32621cb0ef41Sopenharmony_ci EMIT(0xC5); 32631cb0ef41Sopenharmony_ci EMIT(((~vreg.code()) << 3) | l | pp); 32641cb0ef41Sopenharmony_ci } 32651cb0ef41Sopenharmony_ci} 32661cb0ef41Sopenharmony_ci 32671cb0ef41Sopenharmony_civoid Assembler::emit_vex_prefix(Register vreg, VectorLength l, SIMDPrefix pp, 32681cb0ef41Sopenharmony_ci LeadingOpcode mm, VexW w) { 32691cb0ef41Sopenharmony_ci XMMRegister ivreg = XMMRegister::from_code(vreg.code()); 32701cb0ef41Sopenharmony_ci emit_vex_prefix(ivreg, l, pp, mm, w); 32711cb0ef41Sopenharmony_ci} 32721cb0ef41Sopenharmony_ci 32731cb0ef41Sopenharmony_civoid Assembler::GrowBuffer() { 32741cb0ef41Sopenharmony_ci DCHECK(buffer_overflow()); 32751cb0ef41Sopenharmony_ci DCHECK_EQ(buffer_start_, buffer_->start()); 32761cb0ef41Sopenharmony_ci 32771cb0ef41Sopenharmony_ci // Compute new buffer size. 32781cb0ef41Sopenharmony_ci int old_size = buffer_->size(); 32791cb0ef41Sopenharmony_ci int new_size = 2 * old_size; 32801cb0ef41Sopenharmony_ci 32811cb0ef41Sopenharmony_ci // Some internal data structures overflow for very large buffers, 32821cb0ef41Sopenharmony_ci // they must ensure that kMaximalBufferSize is not too large. 32831cb0ef41Sopenharmony_ci if (new_size > kMaximalBufferSize) { 32841cb0ef41Sopenharmony_ci V8::FatalProcessOutOfMemory(nullptr, "Assembler::GrowBuffer"); 32851cb0ef41Sopenharmony_ci } 32861cb0ef41Sopenharmony_ci 32871cb0ef41Sopenharmony_ci // Set up new buffer. 32881cb0ef41Sopenharmony_ci std::unique_ptr<AssemblerBuffer> new_buffer = buffer_->Grow(new_size); 32891cb0ef41Sopenharmony_ci DCHECK_EQ(new_size, new_buffer->size()); 32901cb0ef41Sopenharmony_ci byte* new_start = new_buffer->start(); 32911cb0ef41Sopenharmony_ci 32921cb0ef41Sopenharmony_ci // Copy the data. 32931cb0ef41Sopenharmony_ci intptr_t pc_delta = new_start - buffer_start_; 32941cb0ef41Sopenharmony_ci intptr_t rc_delta = (new_start + new_size) - (buffer_start_ + old_size); 32951cb0ef41Sopenharmony_ci size_t reloc_size = (buffer_start_ + old_size) - reloc_info_writer.pos(); 32961cb0ef41Sopenharmony_ci MemMove(new_start, buffer_start_, pc_offset()); 32971cb0ef41Sopenharmony_ci MemMove(rc_delta + reloc_info_writer.pos(), reloc_info_writer.pos(), 32981cb0ef41Sopenharmony_ci reloc_size); 32991cb0ef41Sopenharmony_ci 33001cb0ef41Sopenharmony_ci // Switch buffers. 33011cb0ef41Sopenharmony_ci buffer_ = std::move(new_buffer); 33021cb0ef41Sopenharmony_ci buffer_start_ = new_start; 33031cb0ef41Sopenharmony_ci pc_ += pc_delta; 33041cb0ef41Sopenharmony_ci reloc_info_writer.Reposition(reloc_info_writer.pos() + rc_delta, 33051cb0ef41Sopenharmony_ci reloc_info_writer.last_pc() + pc_delta); 33061cb0ef41Sopenharmony_ci 33071cb0ef41Sopenharmony_ci // Relocate internal references. 33081cb0ef41Sopenharmony_ci for (auto pos : internal_reference_positions_) { 33091cb0ef41Sopenharmony_ci Address p = reinterpret_cast<Address>(buffer_start_ + pos); 33101cb0ef41Sopenharmony_ci WriteUnalignedValue(p, ReadUnalignedValue<int>(p) + pc_delta); 33111cb0ef41Sopenharmony_ci } 33121cb0ef41Sopenharmony_ci 33131cb0ef41Sopenharmony_ci // Relocate pc-relative references. 33141cb0ef41Sopenharmony_ci int mode_mask = RelocInfo::ModeMask(RelocInfo::OFF_HEAP_TARGET); 33151cb0ef41Sopenharmony_ci DCHECK_EQ(mode_mask, RelocInfo::kApplyMask & mode_mask); 33161cb0ef41Sopenharmony_ci base::Vector<byte> instructions{buffer_start_, 33171cb0ef41Sopenharmony_ci static_cast<size_t>(pc_offset())}; 33181cb0ef41Sopenharmony_ci base::Vector<const byte> reloc_info{reloc_info_writer.pos(), reloc_size}; 33191cb0ef41Sopenharmony_ci for (RelocIterator it(instructions, reloc_info, 0, mode_mask); !it.done(); 33201cb0ef41Sopenharmony_ci it.next()) { 33211cb0ef41Sopenharmony_ci it.rinfo()->apply(pc_delta); 33221cb0ef41Sopenharmony_ci } 33231cb0ef41Sopenharmony_ci 33241cb0ef41Sopenharmony_ci DCHECK(!buffer_overflow()); 33251cb0ef41Sopenharmony_ci} 33261cb0ef41Sopenharmony_ci 33271cb0ef41Sopenharmony_civoid Assembler::emit_arith_b(int op1, int op2, Register dst, int imm8) { 33281cb0ef41Sopenharmony_ci DCHECK(is_uint8(op1) && is_uint8(op2)); // wrong opcode 33291cb0ef41Sopenharmony_ci DCHECK(is_uint8(imm8)); 33301cb0ef41Sopenharmony_ci DCHECK_EQ(op1 & 0x01, 0); // should be 8bit operation 33311cb0ef41Sopenharmony_ci EMIT(op1); 33321cb0ef41Sopenharmony_ci EMIT(op2 | dst.code()); 33331cb0ef41Sopenharmony_ci EMIT(imm8); 33341cb0ef41Sopenharmony_ci} 33351cb0ef41Sopenharmony_ci 33361cb0ef41Sopenharmony_civoid Assembler::emit_arith(int sel, Operand dst, const Immediate& x) { 33371cb0ef41Sopenharmony_ci DCHECK((0 <= sel) && (sel <= 7)); 33381cb0ef41Sopenharmony_ci Register ireg = Register::from_code(sel); 33391cb0ef41Sopenharmony_ci if (x.is_int8()) { 33401cb0ef41Sopenharmony_ci EMIT(0x83); // using a sign-extended 8-bit immediate. 33411cb0ef41Sopenharmony_ci emit_operand(ireg, dst); 33421cb0ef41Sopenharmony_ci EMIT(x.immediate() & 0xFF); 33431cb0ef41Sopenharmony_ci } else if (dst.is_reg(eax)) { 33441cb0ef41Sopenharmony_ci EMIT((sel << 3) | 0x05); // short form if the destination is eax. 33451cb0ef41Sopenharmony_ci emit(x); 33461cb0ef41Sopenharmony_ci } else { 33471cb0ef41Sopenharmony_ci EMIT(0x81); // using a literal 32-bit immediate. 33481cb0ef41Sopenharmony_ci emit_operand(ireg, dst); 33491cb0ef41Sopenharmony_ci emit(x); 33501cb0ef41Sopenharmony_ci } 33511cb0ef41Sopenharmony_ci} 33521cb0ef41Sopenharmony_ci 33531cb0ef41Sopenharmony_civoid Assembler::emit_operand(Register reg, Operand adr) { 33541cb0ef41Sopenharmony_ci emit_operand(reg.code(), adr); 33551cb0ef41Sopenharmony_ci} 33561cb0ef41Sopenharmony_ci 33571cb0ef41Sopenharmony_civoid Assembler::emit_operand(XMMRegister reg, Operand adr) { 33581cb0ef41Sopenharmony_ci Register ireg = Register::from_code(reg.code()); 33591cb0ef41Sopenharmony_ci emit_operand(ireg, adr); 33601cb0ef41Sopenharmony_ci} 33611cb0ef41Sopenharmony_ci 33621cb0ef41Sopenharmony_civoid Assembler::emit_operand(int code, Operand adr) { 33631cb0ef41Sopenharmony_ci // Isolate-independent code may not embed relocatable addresses. 33641cb0ef41Sopenharmony_ci DCHECK_IMPLIES(options().isolate_independent_code, 33651cb0ef41Sopenharmony_ci adr.rmode() != RelocInfo::CODE_TARGET); 33661cb0ef41Sopenharmony_ci DCHECK_IMPLIES(options().isolate_independent_code, 33671cb0ef41Sopenharmony_ci adr.rmode() != RelocInfo::FULL_EMBEDDED_OBJECT); 33681cb0ef41Sopenharmony_ci DCHECK_IMPLIES(options().isolate_independent_code, 33691cb0ef41Sopenharmony_ci adr.rmode() != RelocInfo::EXTERNAL_REFERENCE); 33701cb0ef41Sopenharmony_ci 33711cb0ef41Sopenharmony_ci const unsigned length = adr.encoded_bytes().length(); 33721cb0ef41Sopenharmony_ci DCHECK_GT(length, 0); 33731cb0ef41Sopenharmony_ci 33741cb0ef41Sopenharmony_ci // Emit updated ModRM byte containing the given register. 33751cb0ef41Sopenharmony_ci EMIT((adr.encoded_bytes()[0] & ~0x38) | (code << 3)); 33761cb0ef41Sopenharmony_ci 33771cb0ef41Sopenharmony_ci // Emit the rest of the encoded operand. 33781cb0ef41Sopenharmony_ci for (unsigned i = 1; i < length; i++) EMIT(adr.encoded_bytes()[i]); 33791cb0ef41Sopenharmony_ci 33801cb0ef41Sopenharmony_ci // Emit relocation information if necessary. 33811cb0ef41Sopenharmony_ci if (length >= sizeof(int32_t) && !RelocInfo::IsNoInfo(adr.rmode())) { 33821cb0ef41Sopenharmony_ci pc_ -= sizeof(int32_t); // pc_ must be *at* disp32 33831cb0ef41Sopenharmony_ci RecordRelocInfo(adr.rmode()); 33841cb0ef41Sopenharmony_ci if (adr.rmode() == RelocInfo::INTERNAL_REFERENCE) { // Fixup for labels 33851cb0ef41Sopenharmony_ci emit_label(ReadUnalignedValue<Label*>(reinterpret_cast<Address>(pc_))); 33861cb0ef41Sopenharmony_ci } else { 33871cb0ef41Sopenharmony_ci pc_ += sizeof(int32_t); 33881cb0ef41Sopenharmony_ci } 33891cb0ef41Sopenharmony_ci } 33901cb0ef41Sopenharmony_ci} 33911cb0ef41Sopenharmony_ci 33921cb0ef41Sopenharmony_civoid Assembler::emit_label(Label* label) { 33931cb0ef41Sopenharmony_ci if (label->is_bound()) { 33941cb0ef41Sopenharmony_ci internal_reference_positions_.push_back(pc_offset()); 33951cb0ef41Sopenharmony_ci emit(reinterpret_cast<uint32_t>(buffer_start_ + label->pos())); 33961cb0ef41Sopenharmony_ci } else { 33971cb0ef41Sopenharmony_ci emit_disp(label, Displacement::CODE_ABSOLUTE); 33981cb0ef41Sopenharmony_ci } 33991cb0ef41Sopenharmony_ci} 34001cb0ef41Sopenharmony_ci 34011cb0ef41Sopenharmony_civoid Assembler::emit_farith(int b1, int b2, int i) { 34021cb0ef41Sopenharmony_ci DCHECK(is_uint8(b1) && is_uint8(b2)); // wrong opcode 34031cb0ef41Sopenharmony_ci DCHECK(0 <= i && i < 8); // illegal stack offset 34041cb0ef41Sopenharmony_ci EMIT(b1); 34051cb0ef41Sopenharmony_ci EMIT(b2 + i); 34061cb0ef41Sopenharmony_ci} 34071cb0ef41Sopenharmony_ci 34081cb0ef41Sopenharmony_civoid Assembler::db(uint8_t data) { 34091cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 34101cb0ef41Sopenharmony_ci EMIT(data); 34111cb0ef41Sopenharmony_ci} 34121cb0ef41Sopenharmony_ci 34131cb0ef41Sopenharmony_civoid Assembler::dd(uint32_t data, RelocInfo::Mode rmode) { 34141cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 34151cb0ef41Sopenharmony_ci if (!RelocInfo::IsNoInfo(rmode)) { 34161cb0ef41Sopenharmony_ci DCHECK(RelocInfo::IsDataEmbeddedObject(rmode) || 34171cb0ef41Sopenharmony_ci RelocInfo::IsLiteralConstant(rmode)); 34181cb0ef41Sopenharmony_ci RecordRelocInfo(rmode); 34191cb0ef41Sopenharmony_ci } 34201cb0ef41Sopenharmony_ci emit(data); 34211cb0ef41Sopenharmony_ci} 34221cb0ef41Sopenharmony_ci 34231cb0ef41Sopenharmony_civoid Assembler::dq(uint64_t data, RelocInfo::Mode rmode) { 34241cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 34251cb0ef41Sopenharmony_ci if (!RelocInfo::IsNoInfo(rmode)) { 34261cb0ef41Sopenharmony_ci DCHECK(RelocInfo::IsDataEmbeddedObject(rmode)); 34271cb0ef41Sopenharmony_ci RecordRelocInfo(rmode); 34281cb0ef41Sopenharmony_ci } 34291cb0ef41Sopenharmony_ci emit_q(data); 34301cb0ef41Sopenharmony_ci} 34311cb0ef41Sopenharmony_ci 34321cb0ef41Sopenharmony_civoid Assembler::dd(Label* label) { 34331cb0ef41Sopenharmony_ci EnsureSpace ensure_space(this); 34341cb0ef41Sopenharmony_ci RecordRelocInfo(RelocInfo::INTERNAL_REFERENCE); 34351cb0ef41Sopenharmony_ci emit_label(label); 34361cb0ef41Sopenharmony_ci} 34371cb0ef41Sopenharmony_ci 34381cb0ef41Sopenharmony_civoid Assembler::RecordRelocInfo(RelocInfo::Mode rmode, intptr_t data) { 34391cb0ef41Sopenharmony_ci if (!ShouldRecordRelocInfo(rmode)) return; 34401cb0ef41Sopenharmony_ci RelocInfo rinfo(reinterpret_cast<Address>(pc_), rmode, data, Code()); 34411cb0ef41Sopenharmony_ci reloc_info_writer.Write(&rinfo); 34421cb0ef41Sopenharmony_ci} 34431cb0ef41Sopenharmony_ci 34441cb0ef41Sopenharmony_ci#undef EMIT 34451cb0ef41Sopenharmony_ci 34461cb0ef41Sopenharmony_ci} // namespace internal 34471cb0ef41Sopenharmony_ci} // namespace v8 34481cb0ef41Sopenharmony_ci 34491cb0ef41Sopenharmony_ci#endif // V8_TARGET_ARCH_IA32 3450