2015-06-07 15:57:57 -06:00
|
|
|
// Copyright 2015 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-12-09 19:22:16 -07:00
|
|
|
#include "Common/Arm64Emitter.h"
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
#include <algorithm>
|
2016-09-13 13:45:23 -06:00
|
|
|
#include <array>
|
2022-08-05 22:10:17 -06:00
|
|
|
#include <bit>
|
2015-10-22 13:32:11 -06:00
|
|
|
#include <cstring>
|
2020-12-30 17:59:48 -07:00
|
|
|
#include <optional>
|
|
|
|
#include <tuple>
|
2021-01-01 12:43:34 -07:00
|
|
|
#include <utility>
|
2015-06-07 15:57:57 -06:00
|
|
|
#include <vector>
|
2014-09-12 04:45:10 -06:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2016-11-27 03:56:22 -07:00
|
|
|
#include "Common/Align.h"
|
2015-09-26 14:39:47 -06:00
|
|
|
#include "Common/Assert.h"
|
2015-06-07 15:57:57 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2018-03-23 08:10:15 -06:00
|
|
|
#include "Common/MathUtil.h"
|
2023-08-21 08:12:49 -06:00
|
|
|
#include "Common/SmallVector.h"
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2020-02-11 16:07:56 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
2021-01-13 07:23:57 -07:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <libkern/OSCacheControl.h>
|
|
|
|
#endif
|
2020-02-11 16:07:56 -07:00
|
|
|
|
2014-02-04 18:56:23 -07:00
|
|
|
namespace Arm64Gen
|
|
|
|
{
|
2018-03-23 08:17:09 -06:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
// For ADD/SUB
|
2020-12-30 17:59:48 -07:00
|
|
|
std::optional<std::pair<u32, bool>> IsImmArithmetic(uint64_t input)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
if (input < 4096)
|
2020-12-30 17:59:48 -07:00
|
|
|
return std::pair{static_cast<u32>(input), false};
|
|
|
|
|
|
|
|
if ((input & 0xFFF000) == input)
|
|
|
|
return std::pair{static_cast<u32>(input >> 12), true};
|
|
|
|
|
|
|
|
return std::nullopt;
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2018-05-29 16:12:45 -06:00
|
|
|
float FPImm8ToFloat(u8 bits)
|
2018-03-23 08:17:09 -06:00
|
|
|
{
|
2018-05-29 16:12:45 -06:00
|
|
|
const u32 sign = bits >> 7;
|
|
|
|
const u32 bit6 = (bits >> 6) & 1;
|
|
|
|
const u32 exp = ((!bit6) << 7) | (0x7C * bit6) | ((bits >> 4) & 3);
|
|
|
|
const u32 mantissa = (bits & 0xF) << 19;
|
|
|
|
const u32 f = (sign << 31) | (exp << 23) | mantissa;
|
|
|
|
|
2022-08-05 22:10:17 -06:00
|
|
|
return std::bit_cast<float>(f);
|
2018-03-23 08:17:09 -06:00
|
|
|
}
|
|
|
|
|
2020-12-30 17:59:48 -07:00
|
|
|
std::optional<u8> FPImm8FromFloat(float value)
|
2018-03-23 08:17:09 -06:00
|
|
|
{
|
2022-08-05 22:10:17 -06:00
|
|
|
const u32 f = std::bit_cast<u32>(value);
|
2018-05-29 16:12:45 -06:00
|
|
|
const u32 mantissa4 = (f & 0x7FFFFF) >> 19;
|
|
|
|
const u32 exponent = (f >> 23) & 0xFF;
|
|
|
|
const u32 sign = f >> 31;
|
|
|
|
|
2018-03-23 08:17:09 -06:00
|
|
|
if ((exponent >> 7) == ((exponent >> 6) & 1))
|
2020-12-30 17:59:48 -07:00
|
|
|
return std::nullopt;
|
2018-05-29 16:12:45 -06:00
|
|
|
|
|
|
|
const u8 imm8 = (sign << 7) | ((!(exponent >> 7)) << 6) | ((exponent & 3) << 4) | mantissa4;
|
|
|
|
const float new_float = FPImm8ToFloat(imm8);
|
|
|
|
|
2020-12-30 17:59:48 -07:00
|
|
|
if (new_float != value)
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
return imm8;
|
2018-03-23 08:17:09 -06:00
|
|
|
}
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2021-08-22 06:21:54 -06:00
|
|
|
void ARM64XEmitter::SetCodePtrUnsafe(u8* ptr, u8* end, bool write_failed)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
m_code = ptr;
|
2021-08-22 06:21:54 -06:00
|
|
|
m_code_end = end;
|
|
|
|
m_write_failed = write_failed;
|
2015-08-15 02:26:59 -06:00
|
|
|
}
|
|
|
|
|
2020-05-01 16:42:29 -06:00
|
|
|
void ARM64XEmitter::SetCodePtr(u8* ptr, u8* end, bool write_failed)
|
2015-08-15 02:26:59 -06:00
|
|
|
{
|
2021-08-22 06:21:54 -06:00
|
|
|
SetCodePtrUnsafe(ptr, end, write_failed);
|
2015-08-15 02:26:59 -06:00
|
|
|
m_lastCacheFlushEnd = ptr;
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::ReserveCodeSpace(u32 bytes)
|
|
|
|
{
|
|
|
|
for (u32 i = 0; i < bytes / 4; i++)
|
|
|
|
BRK(0);
|
|
|
|
}
|
|
|
|
|
2018-08-27 07:42:56 -06:00
|
|
|
u8* ARM64XEmitter::AlignCode16()
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
int c = int((u64)m_code & 15);
|
2014-02-04 18:56:23 -07:00
|
|
|
if (c)
|
|
|
|
ReserveCodeSpace(16 - c);
|
2014-09-08 20:52:52 -06:00
|
|
|
return m_code;
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2018-08-27 07:42:56 -06:00
|
|
|
u8* ARM64XEmitter::AlignCodePage()
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
int c = int((u64)m_code & 4095);
|
2014-02-04 18:56:23 -07:00
|
|
|
if (c)
|
|
|
|
ReserveCodeSpace(4096 - c);
|
2014-09-08 20:52:52 -06:00
|
|
|
return m_code;
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2015-10-22 13:32:11 -06:00
|
|
|
void ARM64XEmitter::Write32(u32 value)
|
|
|
|
{
|
2021-08-22 06:21:54 -06:00
|
|
|
if (m_code + sizeof(u32) > m_code_end)
|
|
|
|
{
|
|
|
|
m_code = m_code_end;
|
|
|
|
m_write_failed = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:32:11 -06:00
|
|
|
std::memcpy(m_code, &value, sizeof(u32));
|
|
|
|
m_code += sizeof(u32);
|
|
|
|
}
|
|
|
|
|
2014-02-04 18:56:23 -07:00
|
|
|
void ARM64XEmitter::FlushIcache()
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
FlushIcacheSection(m_lastCacheFlushEnd, m_code);
|
|
|
|
m_lastCacheFlushEnd = m_code;
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2014-09-08 20:52:52 -06:00
|
|
|
void ARM64XEmitter::FlushIcacheSection(u8* start, u8* end)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2015-07-11 04:22:13 -06:00
|
|
|
if (start == end)
|
|
|
|
return;
|
|
|
|
|
2021-01-16 21:31:48 -07:00
|
|
|
#if defined(IOS) || defined(__APPLE__)
|
2014-02-04 18:56:23 -07:00
|
|
|
// Header file says this is equivalent to: sys_icache_invalidate(start, end - start);
|
|
|
|
sys_cache_control(kCacheFunctionPrepareForExecution, start, end - start);
|
2019-11-25 21:31:45 -07:00
|
|
|
#elif defined(WIN32)
|
|
|
|
FlushInstructionCache(GetCurrentProcess(), start, end - start);
|
2014-02-04 18:56:23 -07:00
|
|
|
#else
|
2016-09-09 18:31:07 -06:00
|
|
|
// Don't rely on GCC's __clear_cache implementation, as it caches
|
|
|
|
// icache/dcache cache line sizes, that can vary between cores on
|
|
|
|
// big.LITTLE architectures.
|
|
|
|
u64 addr, ctr_el0;
|
|
|
|
static size_t icache_line_size = 0xffff, dcache_line_size = 0xffff;
|
|
|
|
size_t isize, dsize;
|
|
|
|
|
|
|
|
__asm__ volatile("mrs %0, ctr_el0" : "=r"(ctr_el0));
|
|
|
|
isize = 4 << ((ctr_el0 >> 0) & 0xf);
|
|
|
|
dsize = 4 << ((ctr_el0 >> 16) & 0xf);
|
|
|
|
|
|
|
|
// use the global minimum cache line size
|
|
|
|
icache_line_size = isize = icache_line_size < isize ? icache_line_size : isize;
|
|
|
|
dcache_line_size = dsize = dcache_line_size < dsize ? dcache_line_size : dsize;
|
|
|
|
|
|
|
|
addr = (u64)start & ~(u64)(dsize - 1);
|
|
|
|
for (; addr < (u64)end; addr += dsize)
|
2016-09-10 00:05:16 -06:00
|
|
|
// use "civac" instead of "cvau", as this is the suggested workaround for
|
|
|
|
// Cortex-A53 errata 819472, 826319, 827319 and 824069.
|
2016-09-09 18:31:07 -06:00
|
|
|
__asm__ volatile("dc civac, %0" : : "r"(addr) : "memory");
|
|
|
|
__asm__ volatile("dsb ish" : : : "memory");
|
|
|
|
|
|
|
|
addr = (u64)start & ~(u64)(isize - 1);
|
|
|
|
for (; addr < (u64)end; addr += isize)
|
|
|
|
__asm__ volatile("ic ivau, %0" : : "r"(addr) : "memory");
|
|
|
|
|
|
|
|
__asm__ volatile("dsb ish" : : : "memory");
|
|
|
|
__asm__ volatile("isb" : : : "memory");
|
2014-02-04 18:56:23 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exception generation
|
2014-11-25 21:12:15 -07:00
|
|
|
static const u32 ExcEnc[][3] = {
|
2014-02-04 18:56:23 -07:00
|
|
|
{0, 0, 1}, // SVC
|
|
|
|
{0, 0, 2}, // HVC
|
|
|
|
{0, 0, 3}, // SMC
|
|
|
|
{1, 0, 0}, // BRK
|
|
|
|
{2, 0, 0}, // HLT
|
|
|
|
{5, 0, 1}, // DCPS1
|
|
|
|
{5, 0, 2}, // DCPS2
|
|
|
|
{5, 0, 3}, // DCPS3
|
|
|
|
};
|
|
|
|
|
|
|
|
// Arithmetic generation
|
2014-11-25 21:12:15 -07:00
|
|
|
static const u32 ArithEnc[] = {
|
2014-02-04 18:56:23 -07:00
|
|
|
0x058, // ADD
|
|
|
|
0x258, // SUB
|
|
|
|
};
|
|
|
|
|
|
|
|
// Conditional Select
|
2014-11-25 21:12:15 -07:00
|
|
|
static const u32 CondSelectEnc[][2] = {
|
2014-02-04 18:56:23 -07:00
|
|
|
{0, 0}, // CSEL
|
|
|
|
{0, 1}, // CSINC
|
|
|
|
{1, 0}, // CSINV
|
|
|
|
{1, 1}, // CSNEG
|
|
|
|
};
|
|
|
|
|
|
|
|
// Data-Processing (1 source)
|
2014-11-25 21:12:15 -07:00
|
|
|
static const u32 Data1SrcEnc[][2] = {
|
2014-02-04 18:56:23 -07:00
|
|
|
{0, 0}, // RBIT
|
|
|
|
{0, 1}, // REV16
|
|
|
|
{0, 2}, // REV32
|
|
|
|
{0, 3}, // REV64
|
|
|
|
{0, 4}, // CLZ
|
|
|
|
{0, 5}, // CLS
|
|
|
|
};
|
|
|
|
|
|
|
|
// Data-Processing (2 source)
|
2014-11-25 21:12:15 -07:00
|
|
|
static const u32 Data2SrcEnc[] = {
|
2014-02-04 18:56:23 -07:00
|
|
|
0x02, // UDIV
|
|
|
|
0x03, // SDIV
|
|
|
|
0x08, // LSLV
|
|
|
|
0x09, // LSRV
|
|
|
|
0x0A, // ASRV
|
|
|
|
0x0B, // RORV
|
|
|
|
0x10, // CRC32B
|
|
|
|
0x11, // CRC32H
|
|
|
|
0x12, // CRC32W
|
|
|
|
0x14, // CRC32CB
|
|
|
|
0x15, // CRC32CH
|
|
|
|
0x16, // CRC32CW
|
|
|
|
0x13, // CRC32X (64bit Only)
|
|
|
|
0x17, // XRC32CX (64bit Only)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Data-Processing (3 source)
|
2014-11-25 21:12:15 -07:00
|
|
|
static const u32 Data3SrcEnc[][2] = {
|
2014-02-04 18:56:23 -07:00
|
|
|
{0, 0}, // MADD
|
|
|
|
{0, 1}, // MSUB
|
|
|
|
{1, 0}, // SMADDL (64Bit Only)
|
|
|
|
{1, 1}, // SMSUBL (64Bit Only)
|
|
|
|
{2, 0}, // SMULH (64Bit Only)
|
|
|
|
{5, 0}, // UMADDL (64Bit Only)
|
|
|
|
{5, 1}, // UMSUBL (64Bit Only)
|
|
|
|
{6, 0}, // UMULH (64Bit Only)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Logical (shifted register)
|
2014-11-25 21:12:15 -07:00
|
|
|
static const u32 LogicalEnc[][2] = {
|
2014-02-04 18:56:23 -07:00
|
|
|
{0, 0}, // AND
|
|
|
|
{0, 1}, // BIC
|
|
|
|
{1, 0}, // OOR
|
|
|
|
{1, 1}, // ORN
|
|
|
|
{2, 0}, // EOR
|
|
|
|
{2, 1}, // EON
|
|
|
|
{3, 0}, // ANDS
|
|
|
|
{3, 1}, // BICS
|
|
|
|
};
|
|
|
|
|
|
|
|
// Load/Store Exclusive
|
2015-07-02 09:09:01 -06:00
|
|
|
static const u32 LoadStoreExcEnc[][5] = {
|
2014-02-04 18:56:23 -07:00
|
|
|
{0, 0, 0, 0, 0}, // STXRB
|
|
|
|
{0, 0, 0, 0, 1}, // STLXRB
|
|
|
|
{0, 0, 1, 0, 0}, // LDXRB
|
|
|
|
{0, 0, 1, 0, 1}, // LDAXRB
|
|
|
|
{0, 1, 0, 0, 1}, // STLRB
|
|
|
|
{0, 1, 1, 0, 1}, // LDARB
|
|
|
|
{1, 0, 0, 0, 0}, // STXRH
|
|
|
|
{1, 0, 0, 0, 1}, // STLXRH
|
|
|
|
{1, 0, 1, 0, 0}, // LDXRH
|
|
|
|
{1, 0, 1, 0, 1}, // LDAXRH
|
|
|
|
{1, 1, 0, 0, 1}, // STLRH
|
|
|
|
{1, 1, 1, 0, 1}, // LDARH
|
|
|
|
{2, 0, 0, 0, 0}, // STXR
|
|
|
|
{3, 0, 0, 0, 0}, // (64bit) STXR
|
|
|
|
{2, 0, 0, 0, 1}, // STLXR
|
|
|
|
{3, 0, 0, 0, 1}, // (64bit) STLXR
|
|
|
|
{2, 0, 0, 1, 0}, // STXP
|
|
|
|
{3, 0, 0, 1, 0}, // (64bit) STXP
|
|
|
|
{2, 0, 0, 1, 1}, // STLXP
|
|
|
|
{3, 0, 0, 1, 1}, // (64bit) STLXP
|
|
|
|
{2, 0, 1, 0, 0}, // LDXR
|
|
|
|
{3, 0, 1, 0, 0}, // (64bit) LDXR
|
|
|
|
{2, 0, 1, 0, 1}, // LDAXR
|
|
|
|
{3, 0, 1, 0, 1}, // (64bit) LDAXR
|
|
|
|
{2, 0, 1, 1, 0}, // LDXP
|
|
|
|
{3, 0, 1, 1, 0}, // (64bit) LDXP
|
|
|
|
{2, 0, 1, 1, 1}, // LDAXP
|
|
|
|
{3, 0, 1, 1, 1}, // (64bit) LDAXP
|
|
|
|
{2, 1, 0, 0, 1}, // STLR
|
|
|
|
{3, 1, 0, 0, 1}, // (64bit) STLR
|
|
|
|
{2, 1, 1, 0, 1}, // LDAR
|
|
|
|
{3, 1, 1, 0, 1}, // (64bit) LDAR
|
|
|
|
};
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeCompareBranchInst(u32 op, ARM64Reg Rt, const void* ptr)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rt);
|
2015-02-12 17:43:50 -07:00
|
|
|
s64 distance = (s64)ptr - (s64)m_code;
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(distance & 0x3), "Distance must be a multiple of 4: {}", distance);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
distance >>= 2;
|
|
|
|
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, distance >= -0x40000 && distance <= 0x3FFFF,
|
2021-11-10 15:42:49 -07:00
|
|
|
"Received too large distance: {}", distance);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((b64Bit << 31) | (0x34 << 24) | (op << 24) | (((u32)distance << 5) & 0xFFFFE0) |
|
|
|
|
DecodeReg(Rt));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeTestBranchInst(u32 op, ARM64Reg Rt, u8 bits, const void* ptr)
|
|
|
|
{
|
2021-07-07 04:07:42 -06:00
|
|
|
u8 b40 = bits & 0x1F;
|
|
|
|
u8 b5 = (bits >> 5) & 0x1;
|
2015-02-12 17:43:50 -07:00
|
|
|
s64 distance = (s64)ptr - (s64)m_code;
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(distance & 0x3), "distance must be a multiple of 4: {}", distance);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
distance >>= 2;
|
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, distance >= -0x3FFF && distance < 0x3FFF, "Received too large distance: {}",
|
|
|
|
distance);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-07-07 04:07:42 -06:00
|
|
|
Write32((b5 << 31) | (0x36 << 24) | (op << 24) | (b40 << 19) |
|
|
|
|
((static_cast<u32>(distance) << 5) & 0x7FFE0) | DecodeReg(Rt));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeUnconditionalBranchInst(u32 op, const void* ptr)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
s64 distance = (s64)ptr - s64(m_code);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(distance & 0x3), "distance must be a multiple of 4: {}", distance);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
distance >>= 2;
|
|
|
|
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, distance >= -0x2000000LL && distance <= 0x1FFFFFFLL,
|
2021-11-10 15:42:49 -07:00
|
|
|
"Received too large distance: {}", distance);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
Write32((op << 31) | (0x5 << 26) | (distance & 0x3FFFFFF));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeUnconditionalBranchInst(u32 opc, u32 op2, u32 op3, u32 op4, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((0x6B << 25) | (opc << 21) | (op2 << 16) | (op3 << 10) | (DecodeReg(Rn) << 5) | op4);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeExceptionInst(u32 instenc, u32 imm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & ~0xFFFF), "Exception instruction too large immediate: {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
Write32((0xD4 << 24) | (ExcEnc[instenc][0] << 21) | (imm << 5) | (ExcEnc[instenc][1] << 2) |
|
|
|
|
ExcEnc[instenc][2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeSystemInst(u32 op0, u32 op1, u32 CRn, u32 CRm, u32 op2, ARM64Reg Rt)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((0x354 << 22) | (op0 << 19) | (op1 << 16) | (CRn << 12) | (CRm << 8) | (op2 << 5) |
|
|
|
|
DecodeReg(Rt));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeArithmeticInst(u32 instenc, bool flags, ARM64Reg Rd, ARM64Reg Rn,
|
|
|
|
ARM64Reg Rm, ArithOption Option)
|
|
|
|
{
|
2015-01-18 15:25:40 -07:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
|
|
|
|
|
|
|
Write32((b64Bit << 31) | (flags << 29) | (ArithEnc[instenc] << 21) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(Option.IsExtended() ? (1 << 21) : 0) | (DecodeReg(Rm) << 16) | Option.GetData() |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeArithmeticCarryInst(u32 op, bool flags, ARM64Reg Rd, ARM64Reg Rn,
|
|
|
|
ARM64Reg Rm)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((b64Bit << 31) | (op << 30) | (flags << 29) | (0xD0 << 21) | (DecodeReg(Rm) << 16) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeCondCompareImmInst(u32 op, ARM64Reg Rn, u32 imm, u32 nzcv, CCFlags cond)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & ~0x1F), "too large immediate: {}", imm);
|
|
|
|
ASSERT_MSG(DYNA_REC, !(nzcv & ~0xF), "Flags out of range: {}", nzcv);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
Write32((b64Bit << 31) | (op << 30) | (1 << 29) | (0xD2 << 21) | (imm << 16) | (cond << 12) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(1 << 11) | (DecodeReg(Rn) << 5) | nzcv);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeCondCompareRegInst(u32 op, ARM64Reg Rn, ARM64Reg Rm, u32 nzcv,
|
|
|
|
CCFlags cond)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(nzcv & ~0xF), "Flags out of range: {}", nzcv);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((b64Bit << 31) | (op << 30) | (1 << 29) | (0xD2 << 21) | (DecodeReg(Rm) << 16) |
|
|
|
|
(cond << 12) | (DecodeReg(Rn) << 5) | nzcv);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeCondSelectInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm,
|
|
|
|
CCFlags cond)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((b64Bit << 31) | (CondSelectEnc[instenc][0] << 30) | (0xD4 << 21) |
|
|
|
|
(DecodeReg(Rm) << 16) | (cond << 12) | (CondSelectEnc[instenc][1] << 10) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeData1SrcInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
Write32((b64Bit << 31) | (0x2D6 << 21) | (Data1SrcEnc[instenc][0] << 16) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(Data1SrcEnc[instenc][1] << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeData2SrcInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((b64Bit << 31) | (0x0D6 << 21) | (DecodeReg(Rm) << 16) | (Data2SrcEnc[instenc] << 10) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeData3SrcInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm,
|
|
|
|
ARM64Reg Ra)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((b64Bit << 31) | (0xD8 << 21) | (Data3SrcEnc[instenc][0] << 21) | (DecodeReg(Rm) << 16) |
|
|
|
|
(Data3SrcEnc[instenc][1] << 15) | (DecodeReg(Ra) << 10) | (DecodeReg(Rn) << 5) |
|
|
|
|
DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeLogicalInst(u32 instenc, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm,
|
|
|
|
ArithOption Shift)
|
|
|
|
{
|
2015-01-18 15:25:40 -07:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
Write32((b64Bit << 31) | (LogicalEnc[instenc][0] << 29) | (0x5 << 25) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(LogicalEnc[instenc][1] << 21) | Shift.GetData() | (DecodeReg(Rm) << 16) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeLoadRegisterInst(u32 bitop, ARM64Reg Rt, u32 imm)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rt);
|
|
|
|
bool bVec = IsVector(Rt);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & 0xFFFFF), "offset too large {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
if (b64Bit && bitop != 0x2) // LDRSW(0x2) uses 64bit reg, doesn't have 64bit bit set
|
|
|
|
bitop |= 0x1;
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((bitop << 30) | (bVec << 26) | (0x18 << 24) | (imm << 5) | DecodeReg(Rt));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeLoadStoreExcInst(u32 instenc, ARM64Reg Rs, ARM64Reg Rt2, ARM64Reg Rn,
|
|
|
|
ARM64Reg Rt)
|
|
|
|
{
|
|
|
|
Write32((LoadStoreExcEnc[instenc][0] << 30) | (0x8 << 24) | (LoadStoreExcEnc[instenc][1] << 23) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(LoadStoreExcEnc[instenc][2] << 22) | (LoadStoreExcEnc[instenc][3] << 21) |
|
|
|
|
(DecodeReg(Rs) << 16) | (LoadStoreExcEnc[instenc][4] << 15) | (DecodeReg(Rt2) << 10) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeLoadStorePairedInst(u32 op, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn,
|
|
|
|
u32 imm)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rt);
|
2015-01-07 12:05:55 -07:00
|
|
|
bool b128Bit = IsQuad(Rt);
|
2014-09-08 20:52:52 -06:00
|
|
|
bool bVec = IsVector(Rt);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
if (b128Bit)
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0xf) == 0, "128-bit load/store must use aligned offset: {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
imm >>= 4;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
else if (b64Bit)
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x7) == 0, "64-bit load/store must use aligned offset: {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
imm >>= 3;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x3) == 0, "32-bit load/store must use aligned offset: {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
imm >>= 2;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2022-07-14 21:00:12 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, (imm & ~0xF) == 0, "offset too large {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
u32 opc = 0;
|
|
|
|
if (b128Bit)
|
|
|
|
opc = 2;
|
|
|
|
else if (b64Bit && bVec)
|
|
|
|
opc = 1;
|
|
|
|
else if (b64Bit && !bVec)
|
|
|
|
opc = 2;
|
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((opc << 30) | (bVec << 26) | (op << 22) | (imm << 15) | (DecodeReg(Rt2) << 10) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::EncodeLoadStoreIndexedInst(u32 op, u32 op2, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rt);
|
|
|
|
bool bVec = IsVector(Rt);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2014-12-15 13:23:09 -07:00
|
|
|
u32 offset = imm & 0x1FF;
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm < -256 || imm > 255), "offset too large {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((b64Bit << 30) | (op << 22) | (bVec << 26) | (offset << 12) | (op2 << 10) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2015-01-07 11:58:37 -07:00
|
|
|
void ARM64XEmitter::EncodeLoadStoreIndexedInst(u32 op, ARM64Reg Rt, ARM64Reg Rn, s32 imm, u8 size)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rt);
|
|
|
|
bool bVec = IsVector(Rt);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2015-01-07 11:58:37 -07:00
|
|
|
if (size == 64)
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x7) == 0, "64-bit load/store must use aligned offset: {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
imm >>= 3;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
2015-01-07 11:58:37 -07:00
|
|
|
else if (size == 32)
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x3) == 0, "32-bit load/store must use aligned offset: {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
imm >>= 2;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
2015-01-07 11:58:37 -07:00
|
|
|
else if (size == 16)
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x1) == 0, "16-bit load/store must use aligned offset: {}", imm);
|
2015-01-07 11:58:37 -07:00
|
|
|
imm >>= 1;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, imm >= 0, "(IndexType::Unsigned): offset must be positive {}", imm);
|
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & ~0xFFF), "(IndexType::Unsigned): offset too large {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((b64Bit << 30) | (op << 22) | (bVec << 26) | (imm << 10) | (DecodeReg(Rn) << 5) |
|
|
|
|
DecodeReg(Rt));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeMOVWideInst(u32 op, ARM64Reg Rd, u32 imm, ShiftAmount pos)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & ~0xFFFF), "immediate out of range: {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2020-12-30 18:29:57 -07:00
|
|
|
Write32((b64Bit << 31) | (op << 29) | (0x25 << 23) | (static_cast<u32>(pos) << 21) | (imm << 5) |
|
2021-02-06 11:50:33 -07:00
|
|
|
DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeBitfieldMOVInst(u32 op, ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
Write32((b64Bit << 31) | (op << 29) | (0x26 << 23) | (b64Bit << 22) | (immr << 16) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(imms << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::EncodeLoadStoreRegisterOffset(u32 size, u32 opc, ARM64Reg Rt, ARM64Reg Rn,
|
|
|
|
ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
const int decoded_Rm = DecodeReg(Rm.GetReg());
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
Write32((size << 30) | (opc << 22) | (0x1C1 << 21) | (decoded_Rm << 16) | Rm.GetData() |
|
2021-02-06 11:50:33 -07:00
|
|
|
(1 << 11) | (DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EncodeAddSubImmInst(u32 op, bool flags, u32 shift, u32 imm, ARM64Reg Rn,
|
|
|
|
ARM64Reg Rd)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & ~0xFFF), "immediate too large: {}", imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
Write32((b64Bit << 31) | (op << 30) | (flags << 29) | (0x11 << 24) | (shift << 22) | (imm << 10) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2021-07-12 04:05:34 -06:00
|
|
|
void ARM64XEmitter::EncodeLogicalImmInst(u32 op, ARM64Reg Rd, ARM64Reg Rn, LogicalImm imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-11-10 19:34:28 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, imm.valid, "Invalid logical immediate");
|
2021-07-12 04:05:34 -06:00
|
|
|
|
2014-02-04 18:56:23 -07:00
|
|
|
// Sometimes Rd is fixed to SP, but can still be 32bit or 64bit.
|
|
|
|
// Use Rn to determine bitness here.
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-11-10 19:34:28 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, b64Bit || !imm.n,
|
|
|
|
"64-bit logical immediate does not fit in 32-bit register");
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2021-07-12 04:05:34 -06:00
|
|
|
Write32((b64Bit << 31) | (op << 29) | (0x24 << 23) | (imm.n << 22) | (imm.r << 16) |
|
|
|
|
(imm.s << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2021-07-06 08:22:23 -06:00
|
|
|
}
|
|
|
|
|
2014-12-02 17:08:40 -07:00
|
|
|
void ARM64XEmitter::EncodeLoadStorePair(u32 op, u32 load, IndexType type, ARM64Reg Rt, ARM64Reg Rt2,
|
|
|
|
ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
bool b64Bit = Is64Bit(Rt);
|
|
|
|
u32 type_encode = 0;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
case IndexType::Signed:
|
2014-12-02 17:08:40 -07:00
|
|
|
type_encode = 0b010;
|
|
|
|
break;
|
2021-01-16 00:27:11 -07:00
|
|
|
case IndexType::Post:
|
2014-12-02 17:08:40 -07:00
|
|
|
type_encode = 0b001;
|
|
|
|
break;
|
2021-01-16 00:27:11 -07:00
|
|
|
case IndexType::Pre:
|
2014-12-02 17:08:40 -07:00
|
|
|
type_encode = 0b011;
|
|
|
|
break;
|
2021-01-16 00:27:11 -07:00
|
|
|
case IndexType::Unsigned:
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, false, "IndexType::Unsigned is not supported!");
|
2015-03-02 02:41:19 -07:00
|
|
|
break;
|
2014-12-02 17:08:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b64Bit)
|
|
|
|
{
|
|
|
|
op |= 0b10;
|
2022-07-14 21:00:12 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x7) == 0, "64-bit load/store must use aligned offset: {}", imm);
|
2014-12-02 17:08:40 -07:00
|
|
|
imm >>= 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-14 21:00:12 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x3) == 0, "32-bit load/store must use aligned offset: {}", imm);
|
2014-12-02 17:08:40 -07:00
|
|
|
imm >>= 2;
|
|
|
|
}
|
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, imm >= -64 && imm < 64, "imm too large for load/store pair! {}", imm);
|
2021-01-29 15:13:58 -07:00
|
|
|
|
2014-12-02 17:08:40 -07:00
|
|
|
Write32((op << 30) | (0b101 << 27) | (type_encode << 23) | (load << 22) | ((imm & 0x7F) << 15) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(DecodeReg(Rt2) << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2014-12-02 17:08:40 -07:00
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::EncodeAddressInst(u32 op, ARM64Reg Rd, s32 imm)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((op << 31) | ((imm & 0x3) << 29) | (0x10 << 24) | ((imm & 0x1FFFFC) << 3) |
|
|
|
|
DecodeReg(Rd));
|
2014-12-15 13:23:09 -07:00
|
|
|
}
|
|
|
|
|
2015-02-16 21:00:43 -07:00
|
|
|
void ARM64XEmitter::EncodeLoadStoreUnscaled(u32 size, u32 op, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm < -256 || imm > 255), "offset too large: {}", imm);
|
2015-02-16 21:00:43 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((size << 30) | (0b111 << 27) | (op << 22) | ((imm & 0x1FF) << 12) | (DecodeReg(Rn) << 5) |
|
|
|
|
DecodeReg(Rt));
|
2015-02-16 21:00:43 -07:00
|
|
|
}
|
|
|
|
|
2015-10-22 13:20:35 -06:00
|
|
|
static constexpr bool IsInRangeImm19(s64 distance)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
return (distance >= -0x40000 && distance <= 0x3FFFF);
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:20:35 -06:00
|
|
|
static constexpr bool IsInRangeImm14(s64 distance)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
return (distance >= -0x2000 && distance <= 0x1FFF);
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:20:35 -06:00
|
|
|
static constexpr bool IsInRangeImm26(s64 distance)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
return (distance >= -0x2000000 && distance <= 0x1FFFFFF);
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:20:35 -06:00
|
|
|
static constexpr u32 MaskImm19(s64 distance)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
return distance & 0x7FFFF;
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:20:35 -06:00
|
|
|
static constexpr u32 MaskImm14(s64 distance)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
return distance & 0x3FFF;
|
|
|
|
}
|
|
|
|
|
2015-10-22 13:20:35 -06:00
|
|
|
static constexpr u32 MaskImm26(s64 distance)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
return distance & 0x3FFFFFF;
|
|
|
|
}
|
|
|
|
|
2014-02-04 18:56:23 -07:00
|
|
|
// FixupBranch branching
|
2014-09-08 20:52:52 -06:00
|
|
|
void ARM64XEmitter::SetJumpTarget(FixupBranch const& branch)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-08-22 06:21:54 -06:00
|
|
|
if (!branch.ptr)
|
|
|
|
return;
|
|
|
|
|
2014-02-04 18:56:23 -07:00
|
|
|
bool Not = false;
|
|
|
|
u32 inst = 0;
|
2014-09-08 20:52:52 -06:00
|
|
|
s64 distance = (s64)(m_code - branch.ptr);
|
2014-02-04 18:56:23 -07:00
|
|
|
distance >>= 2;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2014-02-04 18:56:23 -07:00
|
|
|
switch (branch.type)
|
|
|
|
{
|
2020-12-30 18:12:05 -07:00
|
|
|
case FixupBranch::Type::CBNZ:
|
2014-02-04 18:56:23 -07:00
|
|
|
Not = true;
|
2020-12-30 18:07:02 -07:00
|
|
|
[[fallthrough]];
|
2020-12-30 18:12:05 -07:00
|
|
|
case FixupBranch::Type::CBZ:
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, IsInRangeImm19(distance),
|
2022-01-12 17:47:26 -07:00
|
|
|
"Branch type {}: Received too large distance: {}", static_cast<int>(branch.type),
|
|
|
|
distance);
|
2020-12-30 18:12:05 -07:00
|
|
|
const bool b64Bit = Is64Bit(branch.reg);
|
2021-02-06 11:50:33 -07:00
|
|
|
inst = (b64Bit << 31) | (0x1A << 25) | (Not << 24) | (MaskImm19(distance) << 5) |
|
|
|
|
DecodeReg(branch.reg);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
break;
|
2020-12-30 18:12:05 -07:00
|
|
|
case FixupBranch::Type::BConditional:
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, IsInRangeImm19(distance),
|
2022-01-12 17:47:26 -07:00
|
|
|
"Branch type {}: Received too large distance: {}", static_cast<int>(branch.type),
|
|
|
|
distance);
|
2015-06-07 15:57:57 -06:00
|
|
|
inst = (0x2A << 25) | (MaskImm19(distance) << 5) | branch.cond;
|
2014-02-04 18:56:23 -07:00
|
|
|
break;
|
2020-12-30 18:12:05 -07:00
|
|
|
case FixupBranch::Type::TBNZ:
|
2014-02-04 18:56:23 -07:00
|
|
|
Not = true;
|
2020-12-30 18:07:02 -07:00
|
|
|
[[fallthrough]];
|
2020-12-30 18:12:05 -07:00
|
|
|
case FixupBranch::Type::TBZ:
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, IsInRangeImm14(distance),
|
2022-01-12 17:47:26 -07:00
|
|
|
"Branch type {}: Received too large distance: {}", static_cast<int>(branch.type),
|
|
|
|
distance);
|
2015-06-07 15:57:57 -06:00
|
|
|
inst = ((branch.bit & 0x20) << 26) | (0x1B << 25) | (Not << 24) | ((branch.bit & 0x1F) << 19) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(MaskImm14(distance) << 5) | DecodeReg(branch.reg);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
break;
|
2020-12-30 18:12:05 -07:00
|
|
|
case FixupBranch::Type::B:
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, IsInRangeImm26(distance),
|
2022-01-12 17:47:26 -07:00
|
|
|
"Branch type {}: Received too large distance: {}", static_cast<int>(branch.type),
|
|
|
|
distance);
|
2015-06-07 15:57:57 -06:00
|
|
|
inst = (0x5 << 26) | MaskImm26(distance);
|
2014-02-04 18:56:23 -07:00
|
|
|
break;
|
2020-12-30 18:12:05 -07:00
|
|
|
case FixupBranch::Type::BL:
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, IsInRangeImm26(distance),
|
2022-01-12 17:47:26 -07:00
|
|
|
"Branch type {}: Received too large distance: {}", static_cast<int>(branch.type),
|
|
|
|
distance);
|
2015-06-07 15:57:57 -06:00
|
|
|
inst = (0x25 << 26) | MaskImm26(distance);
|
2014-02-04 18:56:23 -07:00
|
|
|
break;
|
|
|
|
}
|
2018-08-14 21:45:42 -06:00
|
|
|
|
|
|
|
std::memcpy(branch.ptr, &inst, sizeof(inst));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2021-08-22 06:21:54 -06:00
|
|
|
FixupBranch ARM64XEmitter::WriteFixupBranch()
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2020-12-30 18:12:05 -07:00
|
|
|
FixupBranch branch{};
|
2014-09-08 20:52:52 -06:00
|
|
|
branch.ptr = m_code;
|
2021-08-22 06:21:54 -06:00
|
|
|
BRK(0);
|
|
|
|
|
|
|
|
// If we couldn't write the full jump instruction, indicate that in the returned FixupBranch by
|
|
|
|
// setting the branch's address to null. This will prevent a later SetJumpTarget() from writing to
|
|
|
|
// invalid memory.
|
|
|
|
if (HasWriteFailed())
|
|
|
|
branch.ptr = nullptr;
|
|
|
|
|
|
|
|
return branch;
|
|
|
|
}
|
|
|
|
|
|
|
|
FixupBranch ARM64XEmitter::CBZ(ARM64Reg Rt)
|
|
|
|
{
|
|
|
|
FixupBranch branch = WriteFixupBranch();
|
2020-12-30 18:12:05 -07:00
|
|
|
branch.type = FixupBranch::Type::CBZ;
|
2014-02-04 18:56:23 -07:00
|
|
|
branch.reg = Rt;
|
|
|
|
return branch;
|
|
|
|
}
|
|
|
|
FixupBranch ARM64XEmitter::CBNZ(ARM64Reg Rt)
|
|
|
|
{
|
2021-08-22 06:21:54 -06:00
|
|
|
FixupBranch branch = WriteFixupBranch();
|
2020-12-30 18:12:05 -07:00
|
|
|
branch.type = FixupBranch::Type::CBNZ;
|
2014-02-04 18:56:23 -07:00
|
|
|
branch.reg = Rt;
|
|
|
|
return branch;
|
|
|
|
}
|
|
|
|
FixupBranch ARM64XEmitter::B(CCFlags cond)
|
|
|
|
{
|
2021-08-22 06:21:54 -06:00
|
|
|
FixupBranch branch = WriteFixupBranch();
|
2020-12-30 18:12:05 -07:00
|
|
|
branch.type = FixupBranch::Type::BConditional;
|
2014-02-04 18:56:23 -07:00
|
|
|
branch.cond = cond;
|
|
|
|
return branch;
|
|
|
|
}
|
|
|
|
FixupBranch ARM64XEmitter::TBZ(ARM64Reg Rt, u8 bit)
|
|
|
|
{
|
2021-08-22 06:21:54 -06:00
|
|
|
FixupBranch branch = WriteFixupBranch();
|
2020-12-30 18:12:05 -07:00
|
|
|
branch.type = FixupBranch::Type::TBZ;
|
2014-02-04 18:56:23 -07:00
|
|
|
branch.reg = Rt;
|
|
|
|
branch.bit = bit;
|
|
|
|
return branch;
|
|
|
|
}
|
|
|
|
FixupBranch ARM64XEmitter::TBNZ(ARM64Reg Rt, u8 bit)
|
|
|
|
{
|
2021-08-22 06:21:54 -06:00
|
|
|
FixupBranch branch = WriteFixupBranch();
|
2020-12-30 18:12:05 -07:00
|
|
|
branch.type = FixupBranch::Type::TBNZ;
|
2014-02-04 18:56:23 -07:00
|
|
|
branch.reg = Rt;
|
|
|
|
branch.bit = bit;
|
|
|
|
return branch;
|
|
|
|
}
|
|
|
|
FixupBranch ARM64XEmitter::B()
|
|
|
|
{
|
2021-08-22 06:21:54 -06:00
|
|
|
FixupBranch branch = WriteFixupBranch();
|
2020-12-30 18:12:05 -07:00
|
|
|
branch.type = FixupBranch::Type::B;
|
2014-02-04 18:56:23 -07:00
|
|
|
return branch;
|
|
|
|
}
|
|
|
|
FixupBranch ARM64XEmitter::BL()
|
|
|
|
{
|
2021-08-22 06:21:54 -06:00
|
|
|
FixupBranch branch = WriteFixupBranch();
|
2020-12-30 18:12:05 -07:00
|
|
|
branch.type = FixupBranch::Type::BL;
|
2014-02-04 18:56:23 -07:00
|
|
|
return branch;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compare and Branch
|
|
|
|
void ARM64XEmitter::CBZ(ARM64Reg Rt, const void* ptr)
|
|
|
|
{
|
|
|
|
EncodeCompareBranchInst(0, Rt, ptr);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CBNZ(ARM64Reg Rt, const void* ptr)
|
|
|
|
{
|
|
|
|
EncodeCompareBranchInst(1, Rt, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conditional Branch
|
|
|
|
void ARM64XEmitter::B(CCFlags cond, const void* ptr)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
s64 distance = (s64)ptr - (s64)m_code;
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
distance >>= 2;
|
2014-02-04 18:56:23 -07:00
|
|
|
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, IsInRangeImm19(distance),
|
2021-11-10 15:42:49 -07:00
|
|
|
"Received too large distance: {}->{} (dist {} {:#x})", fmt::ptr(m_code), fmt::ptr(ptr),
|
2018-03-16 11:27:11 -06:00
|
|
|
distance, distance);
|
2015-06-07 15:57:57 -06:00
|
|
|
Write32((0x54 << 24) | (MaskImm19(distance) << 5) | cond);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test and Branch
|
|
|
|
void ARM64XEmitter::TBZ(ARM64Reg Rt, u8 bits, const void* ptr)
|
|
|
|
{
|
|
|
|
EncodeTestBranchInst(0, Rt, bits, ptr);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::TBNZ(ARM64Reg Rt, u8 bits, const void* ptr)
|
|
|
|
{
|
|
|
|
EncodeTestBranchInst(1, Rt, bits, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unconditional Branch
|
2014-09-08 20:52:52 -06:00
|
|
|
void ARM64XEmitter::B(const void* ptr)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
|
|
|
EncodeUnconditionalBranchInst(0, ptr);
|
|
|
|
}
|
2014-09-08 20:52:52 -06:00
|
|
|
void ARM64XEmitter::BL(const void* ptr)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
|
|
|
EncodeUnconditionalBranchInst(1, ptr);
|
|
|
|
}
|
|
|
|
|
2016-01-21 13:16:51 -07:00
|
|
|
void ARM64XEmitter::QuickCallFunction(ARM64Reg scratchreg, const void* func)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
s64 distance = (s64)func - (s64)m_code;
|
|
|
|
distance >>= 2; // Can only branch to opcode-aligned (4) addresses
|
|
|
|
if (!IsInRangeImm26(distance))
|
|
|
|
{
|
|
|
|
MOVI2R(scratchreg, (uintptr_t)func);
|
|
|
|
BLR(scratchreg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BL(func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-04 18:56:23 -07:00
|
|
|
// Unconditional Branch (register)
|
|
|
|
void ARM64XEmitter::BR(ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EncodeUnconditionalBranchInst(0, 0x1F, 0, 0, Rn);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::BLR(ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EncodeUnconditionalBranchInst(1, 0x1F, 0, 0, Rn);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::RET(ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EncodeUnconditionalBranchInst(2, 0x1F, 0, 0, Rn);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::ERET()
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeUnconditionalBranchInst(4, 0x1F, 0, 0, ARM64Reg::SP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::DRPS()
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeUnconditionalBranchInst(5, 0x1F, 0, 0, ARM64Reg::SP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Exception generation
|
|
|
|
void ARM64XEmitter::SVC(u32 imm)
|
|
|
|
{
|
|
|
|
EncodeExceptionInst(0, imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::HVC(u32 imm)
|
|
|
|
{
|
|
|
|
EncodeExceptionInst(1, imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::SMC(u32 imm)
|
|
|
|
{
|
|
|
|
EncodeExceptionInst(2, imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::BRK(u32 imm)
|
|
|
|
{
|
|
|
|
EncodeExceptionInst(3, imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::HLT(u32 imm)
|
|
|
|
{
|
|
|
|
EncodeExceptionInst(4, imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::DCPS1(u32 imm)
|
|
|
|
{
|
|
|
|
EncodeExceptionInst(5, imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::DCPS2(u32 imm)
|
|
|
|
{
|
|
|
|
EncodeExceptionInst(6, imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::DCPS3(u32 imm)
|
|
|
|
{
|
|
|
|
EncodeExceptionInst(7, imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// System
|
|
|
|
void ARM64XEmitter::_MSR(PStateField field, u8 imm)
|
|
|
|
{
|
|
|
|
u32 op1 = 0, op2 = 0;
|
|
|
|
switch (field)
|
|
|
|
{
|
2020-12-30 18:20:47 -07:00
|
|
|
case PStateField::SPSel:
|
2015-06-07 15:57:57 -06:00
|
|
|
op1 = 0;
|
|
|
|
op2 = 5;
|
|
|
|
break;
|
2020-12-30 18:20:47 -07:00
|
|
|
case PStateField::DAIFSet:
|
2015-06-07 15:57:57 -06:00
|
|
|
op1 = 3;
|
|
|
|
op2 = 6;
|
|
|
|
break;
|
2020-12-30 18:20:47 -07:00
|
|
|
case PStateField::DAIFClr:
|
2015-06-07 15:57:57 -06:00
|
|
|
op1 = 3;
|
|
|
|
op2 = 7;
|
2016-06-24 02:43:46 -06:00
|
|
|
break;
|
2015-06-07 15:57:57 -06:00
|
|
|
default:
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, false, "Invalid PStateField to do a imm move to");
|
2015-06-07 15:57:57 -06:00
|
|
|
break;
|
|
|
|
}
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeSystemInst(0, op1, 4, imm, op2, ARM64Reg::WSP);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2016-01-21 13:27:56 -07:00
|
|
|
static void GetSystemReg(PStateField field, int& o0, int& op1, int& CRn, int& CRm, int& op2)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
switch (field)
|
|
|
|
{
|
2020-12-30 18:20:47 -07:00
|
|
|
case PStateField::NZCV:
|
2015-06-07 15:57:57 -06:00
|
|
|
o0 = 3;
|
|
|
|
op1 = 3;
|
|
|
|
CRn = 4;
|
|
|
|
CRm = 2;
|
|
|
|
op2 = 0;
|
2014-02-04 18:56:23 -07:00
|
|
|
break;
|
2020-12-30 18:20:47 -07:00
|
|
|
case PStateField::FPCR:
|
2015-06-07 15:57:57 -06:00
|
|
|
o0 = 3;
|
|
|
|
op1 = 3;
|
|
|
|
CRn = 4;
|
|
|
|
CRm = 4;
|
|
|
|
op2 = 0;
|
2014-02-04 18:56:23 -07:00
|
|
|
break;
|
2020-12-30 18:20:47 -07:00
|
|
|
case PStateField::FPSR:
|
2015-06-07 15:57:57 -06:00
|
|
|
o0 = 3;
|
|
|
|
op1 = 3;
|
|
|
|
CRn = 4;
|
|
|
|
CRm = 4;
|
|
|
|
op2 = 1;
|
|
|
|
break;
|
2020-12-30 18:20:47 -07:00
|
|
|
case PStateField::PMCR_EL0:
|
2015-08-07 01:32:16 -06:00
|
|
|
o0 = 3;
|
|
|
|
op1 = 3;
|
|
|
|
CRn = 9;
|
|
|
|
CRm = 6;
|
|
|
|
op2 = 0;
|
|
|
|
break;
|
2020-12-30 18:20:47 -07:00
|
|
|
case PStateField::PMCCNTR_EL0:
|
2015-08-07 01:32:16 -06:00
|
|
|
o0 = 3;
|
|
|
|
op1 = 3;
|
|
|
|
CRn = 9;
|
|
|
|
CRm = 7;
|
|
|
|
op2 = 0;
|
|
|
|
break;
|
2015-06-07 15:57:57 -06:00
|
|
|
default:
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, false, "Invalid PStateField to do a register move from/to");
|
2014-02-04 18:56:23 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
|
|
|
|
void ARM64XEmitter::_MSR(PStateField field, ARM64Reg Rt)
|
|
|
|
{
|
|
|
|
int o0 = 0, op1 = 0, CRn = 0, CRm = 0, op2 = 0;
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, Is64Bit(Rt), "MSR: Rt must be 64-bit");
|
2015-06-07 15:57:57 -06:00
|
|
|
GetSystemReg(field, o0, op1, CRn, CRm, op2);
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeSystemInst(o0, op1, CRn, CRm, op2, Rt);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::MRS(ARM64Reg Rt, PStateField field)
|
|
|
|
{
|
|
|
|
int o0 = 0, op1 = 0, CRn = 0, CRm = 0, op2 = 0;
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, Is64Bit(Rt), "MRS: Rt must be 64-bit");
|
2015-06-07 15:57:57 -06:00
|
|
|
GetSystemReg(field, o0, op1, CRn, CRm, op2);
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeSystemInst(o0 | 4, op1, CRn, CRm, op2, Rt);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2017-08-12 17:51:37 -06:00
|
|
|
void ARM64XEmitter::CNTVCT(Arm64Gen::ARM64Reg Rt)
|
|
|
|
{
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, Is64Bit(Rt), "CNTVCT: Rt must be 64-bit");
|
2017-08-12 17:51:37 -06:00
|
|
|
|
|
|
|
// MRS <Xt>, CNTVCT_EL0 ; Read CNTVCT_EL0 into Xt
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeSystemInst(3 | 4, 3, 0xe, 0, 2, Rt);
|
2017-08-12 17:51:37 -06:00
|
|
|
}
|
|
|
|
|
2014-02-04 18:56:23 -07:00
|
|
|
void ARM64XEmitter::HINT(SystemHint op)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeSystemInst(0, 3, 2, 0, static_cast<u32>(op), ARM64Reg::WSP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::CLREX()
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeSystemInst(0, 3, 3, 0, 2, ARM64Reg::WSP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::DSB(BarrierType type)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeSystemInst(0, 3, 3, static_cast<u32>(type), 4, ARM64Reg::WSP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::DMB(BarrierType type)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeSystemInst(0, 3, 3, static_cast<u32>(type), 5, ARM64Reg::WSP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::ISB(BarrierType type)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeSystemInst(0, 3, 3, static_cast<u32>(type), 6, ARM64Reg::WSP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add/Subtract (extended register)
|
|
|
|
void ARM64XEmitter::ADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-01-16 02:26:23 -07:00
|
|
|
ADD(Rd, Rn, Rm, ArithOption(Rd, ShiftType::LSL, 0));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::ADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option)
|
|
|
|
{
|
|
|
|
EncodeArithmeticInst(0, false, Rd, Rn, Rm, Option);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::ADDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-01-16 02:26:23 -07:00
|
|
|
EncodeArithmeticInst(0, true, Rd, Rn, Rm, ArithOption(Rd, ShiftType::LSL, 0));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::ADDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option)
|
|
|
|
{
|
|
|
|
EncodeArithmeticInst(0, true, Rd, Rn, Rm, Option);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::SUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-01-16 02:26:23 -07:00
|
|
|
SUB(Rd, Rn, Rm, ArithOption(Rd, ShiftType::LSL, 0));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::SUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option)
|
|
|
|
{
|
|
|
|
EncodeArithmeticInst(1, false, Rd, Rn, Rm, Option);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::SUBS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-01-16 02:26:23 -07:00
|
|
|
EncodeArithmeticInst(1, true, Rd, Rn, Rm, ArithOption(Rd, ShiftType::LSL, 0));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::SUBS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Option)
|
|
|
|
{
|
|
|
|
EncodeArithmeticInst(1, true, Rd, Rn, Rm, Option);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::CMN(ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-01-16 02:26:23 -07:00
|
|
|
CMN(Rn, Rm, ArithOption(Rn, ShiftType::LSL, 0));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::CMN(ARM64Reg Rn, ARM64Reg Rm, ArithOption Option)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeArithmeticInst(0, true, Is64Bit(Rn) ? ARM64Reg::ZR : ARM64Reg::WZR, Rn, Rm, Option);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::CMP(ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-01-16 02:26:23 -07:00
|
|
|
CMP(Rn, Rm, ArithOption(Rn, ShiftType::LSL, 0));
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::CMP(ARM64Reg Rn, ARM64Reg Rm, ArithOption Option)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeArithmeticInst(1, true, Is64Bit(Rn) ? ARM64Reg::ZR : ARM64Reg::WZR, Rn, Rm, Option);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add/Subtract (with carry)
|
|
|
|
void ARM64XEmitter::ADC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeArithmeticCarryInst(0, false, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::ADCS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeArithmeticCarryInst(0, true, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::SBC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeArithmeticCarryInst(1, false, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::SBCS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeArithmeticCarryInst(1, true, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conditional Compare (immediate)
|
|
|
|
void ARM64XEmitter::CCMN(ARM64Reg Rn, u32 imm, u32 nzcv, CCFlags cond)
|
|
|
|
{
|
|
|
|
EncodeCondCompareImmInst(0, Rn, imm, nzcv, cond);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CCMP(ARM64Reg Rn, u32 imm, u32 nzcv, CCFlags cond)
|
|
|
|
{
|
|
|
|
EncodeCondCompareImmInst(1, Rn, imm, nzcv, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conditiona Compare (register)
|
|
|
|
void ARM64XEmitter::CCMN(ARM64Reg Rn, ARM64Reg Rm, u32 nzcv, CCFlags cond)
|
|
|
|
{
|
|
|
|
EncodeCondCompareRegInst(0, Rn, Rm, nzcv, cond);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CCMP(ARM64Reg Rn, ARM64Reg Rm, u32 nzcv, CCFlags cond)
|
|
|
|
{
|
|
|
|
EncodeCondCompareRegInst(1, Rn, Rm, nzcv, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conditional Select
|
|
|
|
void ARM64XEmitter::CSEL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond)
|
|
|
|
{
|
|
|
|
EncodeCondSelectInst(0, Rd, Rn, Rm, cond);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CSINC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond)
|
|
|
|
{
|
|
|
|
EncodeCondSelectInst(1, Rd, Rn, Rm, cond);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CSINV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond)
|
|
|
|
{
|
|
|
|
EncodeCondSelectInst(2, Rd, Rn, Rm, cond);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CSNEG(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond)
|
|
|
|
{
|
|
|
|
EncodeCondSelectInst(3, Rd, Rn, Rm, cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data-Processing 1 source
|
|
|
|
void ARM64XEmitter::RBIT(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EncodeData1SrcInst(0, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::REV16(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EncodeData1SrcInst(1, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::REV32(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EncodeData1SrcInst(2, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::REV64(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EncodeData1SrcInst(3, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CLZ(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EncodeData1SrcInst(4, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CLS(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EncodeData1SrcInst(5, Rd, Rn);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data-Processing 2 source
|
|
|
|
void ARM64XEmitter::UDIV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(0, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::SDIV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(1, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LSLV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(2, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LSRV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(3, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::ASRV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(4, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::RORV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(5, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CRC32B(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(6, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CRC32H(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(7, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CRC32W(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(8, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CRC32CB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(9, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CRC32CH(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(10, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CRC32CW(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(11, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CRC32X(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(12, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CRC32CX(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EncodeData2SrcInst(13, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Data-Processing 3 source
|
|
|
|
void ARM64XEmitter::MADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EncodeData3SrcInst(0, Rd, Rn, Rm, Ra);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::MSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EncodeData3SrcInst(1, Rd, Rn, Rm, Ra);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::SMADDL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EncodeData3SrcInst(2, Rd, Rn, Rm, Ra);
|
|
|
|
}
|
2015-02-12 17:47:06 -07:00
|
|
|
void ARM64XEmitter::SMULL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
SMADDL(Rd, Rn, Rm, ARM64Reg::SP);
|
2015-02-12 17:47:06 -07:00
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
void ARM64XEmitter::SMSUBL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EncodeData3SrcInst(3, Rd, Rn, Rm, Ra);
|
|
|
|
}
|
2015-01-22 17:08:49 -07:00
|
|
|
void ARM64XEmitter::SMULH(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeData3SrcInst(4, Rd, Rn, Rm, ARM64Reg::SP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::UMADDL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EncodeData3SrcInst(5, Rd, Rn, Rm, Ra);
|
|
|
|
}
|
2016-03-04 13:58:17 -07:00
|
|
|
void ARM64XEmitter::UMULL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
UMADDL(Rd, Rn, Rm, ARM64Reg::SP);
|
2016-03-04 13:58:17 -07:00
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
void ARM64XEmitter::UMSUBL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EncodeData3SrcInst(6, Rd, Rn, Rm, Ra);
|
|
|
|
}
|
2015-01-22 17:08:49 -07:00
|
|
|
void ARM64XEmitter::UMULH(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeData3SrcInst(7, Rd, Rn, Rm, ARM64Reg::SP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-07 12:03:01 -07:00
|
|
|
void ARM64XEmitter::MUL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeData3SrcInst(0, Rd, Rn, Rm, ARM64Reg::SP);
|
2015-01-07 12:03:01 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::MNEG(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeData3SrcInst(1, Rd, Rn, Rm, ARM64Reg::SP);
|
2015-01-07 12:03:01 -07:00
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
// Logical (shifted register)
|
|
|
|
void ARM64XEmitter::AND(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift)
|
|
|
|
{
|
|
|
|
EncodeLogicalInst(0, Rd, Rn, Rm, Shift);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::BIC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift)
|
|
|
|
{
|
|
|
|
EncodeLogicalInst(1, Rd, Rn, Rm, Shift);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::ORR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift)
|
|
|
|
{
|
|
|
|
EncodeLogicalInst(2, Rd, Rn, Rm, Shift);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::ORN(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift)
|
|
|
|
{
|
|
|
|
EncodeLogicalInst(3, Rd, Rn, Rm, Shift);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::EOR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift)
|
|
|
|
{
|
|
|
|
EncodeLogicalInst(4, Rd, Rn, Rm, Shift);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::EON(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift)
|
|
|
|
{
|
|
|
|
EncodeLogicalInst(5, Rd, Rn, Rm, Shift);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::ANDS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift)
|
|
|
|
{
|
|
|
|
EncodeLogicalInst(6, Rd, Rn, Rm, Shift);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::BICS(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ArithOption Shift)
|
|
|
|
{
|
|
|
|
EncodeLogicalInst(7, Rd, Rn, Rm, Shift);
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
|
|
|
|
void ARM64XEmitter::MOV(ARM64Reg Rd, ARM64Reg Rm, ArithOption Shift)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ORR(Rd, Is64Bit(Rd) ? ARM64Reg::ZR : ARM64Reg::WZR, Rm, Shift);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2014-09-18 15:30:40 -06:00
|
|
|
void ARM64XEmitter::MOV(ARM64Reg Rd, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
if (IsGPR(Rd) && IsGPR(Rm))
|
2021-02-06 11:50:33 -07:00
|
|
|
ORR(Rd, Is64Bit(Rd) ? ARM64Reg::ZR : ARM64Reg::WZR, Rm, ArithOption(Rm, ShiftType::LSL, 0));
|
2015-06-07 15:57:57 -06:00
|
|
|
else
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, false, "Non-GPRs not supported in MOV");
|
2014-09-18 15:30:40 -06:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::MVN(ARM64Reg Rd, ARM64Reg Rm)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ORN(Rd, Is64Bit(Rd) ? ARM64Reg::ZR : ARM64Reg::WZR, Rm, ArithOption(Rm, ShiftType::LSL, 0));
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LSL(ARM64Reg Rd, ARM64Reg Rm, int shift)
|
|
|
|
{
|
2017-08-11 15:41:15 -06:00
|
|
|
int bits = Is64Bit(Rd) ? 64 : 32;
|
|
|
|
UBFM(Rd, Rm, (bits - shift) & (bits - 1), bits - shift - 1);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LSR(ARM64Reg Rd, ARM64Reg Rm, int shift)
|
|
|
|
{
|
2017-08-11 15:41:15 -06:00
|
|
|
int bits = Is64Bit(Rd) ? 64 : 32;
|
|
|
|
UBFM(Rd, Rm, shift, bits - 1);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::ASR(ARM64Reg Rd, ARM64Reg Rm, int shift)
|
|
|
|
{
|
2017-08-11 15:41:15 -06:00
|
|
|
int bits = Is64Bit(Rd) ? 64 : 32;
|
|
|
|
SBFM(Rd, Rm, shift, bits - 1);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::ROR(ARM64Reg Rd, ARM64Reg Rm, int shift)
|
|
|
|
{
|
2017-08-11 15:41:15 -06:00
|
|
|
EXTR(Rd, Rm, Rm, shift);
|
2014-09-18 15:30:40 -06:00
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
// Logical (immediate)
|
2021-07-06 08:22:23 -06:00
|
|
|
void ARM64XEmitter::AND(ARM64Reg Rd, ARM64Reg Rn, LogicalImm imm)
|
|
|
|
{
|
|
|
|
EncodeLogicalImmInst(0, Rd, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::ANDS(ARM64Reg Rd, ARM64Reg Rn, LogicalImm imm)
|
|
|
|
{
|
|
|
|
EncodeLogicalImmInst(3, Rd, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::EOR(ARM64Reg Rd, ARM64Reg Rn, LogicalImm imm)
|
|
|
|
{
|
|
|
|
EncodeLogicalImmInst(2, Rd, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::ORR(ARM64Reg Rd, ARM64Reg Rn, LogicalImm imm)
|
|
|
|
{
|
|
|
|
EncodeLogicalImmInst(1, Rd, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::TST(ARM64Reg Rn, LogicalImm imm)
|
|
|
|
{
|
|
|
|
EncodeLogicalImmInst(3, Is64Bit(Rn) ? ARM64Reg::ZR : ARM64Reg::WZR, Rn, imm);
|
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
// Add/subtract (immediate)
|
|
|
|
void ARM64XEmitter::ADD(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift)
|
|
|
|
{
|
|
|
|
EncodeAddSubImmInst(0, false, shift, imm, Rn, Rd);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::ADDS(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift)
|
|
|
|
{
|
|
|
|
EncodeAddSubImmInst(0, true, shift, imm, Rn, Rd);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::SUB(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift)
|
|
|
|
{
|
|
|
|
EncodeAddSubImmInst(1, false, shift, imm, Rn, Rd);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::SUBS(ARM64Reg Rd, ARM64Reg Rn, u32 imm, bool shift)
|
|
|
|
{
|
|
|
|
EncodeAddSubImmInst(1, true, shift, imm, Rn, Rd);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::CMP(ARM64Reg Rn, u32 imm, bool shift)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeAddSubImmInst(1, true, shift, imm, Rn, Is64Bit(Rn) ? ARM64Reg::SP : ARM64Reg::WSP);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2021-08-21 08:28:51 -06:00
|
|
|
void ARM64XEmitter::CMN(ARM64Reg Rn, u32 imm, bool shift)
|
|
|
|
{
|
|
|
|
EncodeAddSubImmInst(0, true, shift, imm, Rn, Is64Bit(Rn) ? ARM64Reg::SP : ARM64Reg::WSP);
|
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
// Data Processing (Immediate)
|
|
|
|
void ARM64XEmitter::MOVZ(ARM64Reg Rd, u32 imm, ShiftAmount pos)
|
|
|
|
{
|
|
|
|
EncodeMOVWideInst(2, Rd, imm, pos);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::MOVN(ARM64Reg Rd, u32 imm, ShiftAmount pos)
|
|
|
|
{
|
|
|
|
EncodeMOVWideInst(0, Rd, imm, pos);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::MOVK(ARM64Reg Rd, u32 imm, ShiftAmount pos)
|
|
|
|
{
|
|
|
|
EncodeMOVWideInst(3, Rd, imm, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bitfield move
|
|
|
|
void ARM64XEmitter::BFM(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms)
|
|
|
|
{
|
|
|
|
EncodeBitfieldMOVInst(1, Rd, Rn, immr, imms);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::SBFM(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms)
|
|
|
|
{
|
|
|
|
EncodeBitfieldMOVInst(0, Rd, Rn, immr, imms);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::UBFM(ARM64Reg Rd, ARM64Reg Rn, u32 immr, u32 imms)
|
|
|
|
{
|
|
|
|
EncodeBitfieldMOVInst(2, Rd, Rn, immr, imms);
|
|
|
|
}
|
2015-06-29 18:00:22 -06:00
|
|
|
|
|
|
|
void ARM64XEmitter::BFI(ARM64Reg Rd, ARM64Reg Rn, u32 lsb, u32 width)
|
|
|
|
{
|
|
|
|
u32 size = Is64Bit(Rn) ? 64 : 32;
|
2021-01-31 04:50:34 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, lsb < size && width >= 1 && width <= size - lsb,
|
2021-11-10 15:42:49 -07:00
|
|
|
"lsb {} and width {} is greater than the register size {}!", lsb, width, size);
|
2021-01-31 04:48:39 -07:00
|
|
|
BFM(Rd, Rn, (size - lsb) % size, width - 1);
|
2015-06-29 18:00:22 -06:00
|
|
|
}
|
2020-12-27 13:47:53 -07:00
|
|
|
void ARM64XEmitter::BFXIL(ARM64Reg Rd, ARM64Reg Rn, u32 lsb, u32 width)
|
|
|
|
{
|
|
|
|
u32 size = Is64Bit(Rn) ? 64 : 32;
|
|
|
|
ASSERT_MSG(DYNA_REC, lsb < size && width >= 1 && width <= size - lsb,
|
2021-11-10 15:42:49 -07:00
|
|
|
"lsb {} and width {} is greater than the register size {}!", lsb, width, size);
|
2021-01-31 04:48:39 -07:00
|
|
|
BFM(Rd, Rn, lsb, lsb + width - 1);
|
2020-12-27 13:47:53 -07:00
|
|
|
}
|
2015-06-29 18:00:22 -06:00
|
|
|
void ARM64XEmitter::UBFIZ(ARM64Reg Rd, ARM64Reg Rn, u32 lsb, u32 width)
|
|
|
|
{
|
|
|
|
u32 size = Is64Bit(Rn) ? 64 : 32;
|
2021-01-31 04:50:34 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, lsb < size && width >= 1 && width <= size - lsb,
|
2021-11-10 15:42:49 -07:00
|
|
|
"lsb {} and width {} is greater than the register size {}!", lsb, width, size);
|
2021-01-31 04:48:39 -07:00
|
|
|
UBFM(Rd, Rn, (size - lsb) % size, width - 1);
|
2015-06-29 18:00:22 -06:00
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64XEmitter::EXTR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u32 shift)
|
|
|
|
{
|
|
|
|
bool sf = Is64Bit(Rd);
|
|
|
|
bool N = sf;
|
2021-02-06 11:50:33 -07:00
|
|
|
|
|
|
|
Write32((sf << 31) | (0x27 << 23) | (N << 22) | (DecodeReg(Rm) << 16) | (shift << 10) |
|
|
|
|
(DecodeReg(Rm) << 5) | DecodeReg(Rd));
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
2014-09-10 16:52:54 -06:00
|
|
|
void ARM64XEmitter::SXTB(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
SBFM(Rd, Rn, 0, 7);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::SXTH(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
SBFM(Rd, Rn, 0, 15);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::SXTW(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, Is64Bit(Rd), "64bit register required as destination");
|
2014-09-10 16:52:54 -06:00
|
|
|
SBFM(Rd, Rn, 0, 31);
|
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::UXTB(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
UBFM(Rd, Rn, 0, 7);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::UXTH(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
UBFM(Rd, Rn, 0, 15);
|
|
|
|
}
|
2014-02-04 18:56:23 -07:00
|
|
|
|
|
|
|
// Load Register (Literal)
|
|
|
|
void ARM64XEmitter::LDR(ARM64Reg Rt, u32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadRegisterInst(0, Rt, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDRSW(ARM64Reg Rt, u32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadRegisterInst(2, Rt, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::PRFM(ARM64Reg Rt, u32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadRegisterInst(3, Rt, imm);
|
|
|
|
}
|
|
|
|
|
2014-12-02 17:08:40 -07:00
|
|
|
// Load/Store pair
|
|
|
|
void ARM64XEmitter::LDP(IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStorePair(0, 1, type, Rt, Rt2, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDPSW(IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStorePair(1, 1, type, Rt, Rt2, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::STP(IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStorePair(0, 0, type, Rt, Rt2, Rn, imm);
|
|
|
|
}
|
|
|
|
|
2014-02-04 18:56:23 -07:00
|
|
|
// Load/Store Exclusive
|
|
|
|
void ARM64XEmitter::STXRB(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(0, Rs, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STLXRB(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(1, Rs, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDXRB(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(2, ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDAXRB(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(3, ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STLRB(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(4, ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDARB(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(5, ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STXRH(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(6, Rs, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STLXRH(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(7, Rs, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDXRH(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(8, ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDAXRH(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(9, ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STLRH(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(10, ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDARH(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(11, ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STXR(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(12 + Is64Bit(Rt), Rs, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STLXR(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(14 + Is64Bit(Rt), Rs, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STXP(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
EncodeLoadStoreExcInst(16 + Is64Bit(Rt), Rs, Rt2, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STLXP(ARM64Reg Rs, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn)
|
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
EncodeLoadStoreExcInst(18 + Is64Bit(Rt), Rs, Rt2, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDXR(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(20 + Is64Bit(Rt), ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDAXR(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(22 + Is64Bit(Rt), ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDXP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(24 + Is64Bit(Rt), ARM64Reg::SP, Rt2, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDAXP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(26 + Is64Bit(Rt), ARM64Reg::SP, Rt2, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::STLR(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(28 + Is64Bit(Rt), ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDAR(ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
EncodeLoadStoreExcInst(30 + Is64Bit(Rt), ARM64Reg::SP, ARM64Reg::SP, Rt, Rn);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load/Store no-allocate pair (offset)
|
|
|
|
void ARM64XEmitter::STNP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, u32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStorePairedInst(0xA0, Rt, Rt2, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDNP(ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn, u32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStorePairedInst(0xA1, Rt, Rt2, Rn, imm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load/Store register (immediate post-indexed)
|
|
|
|
// XXX: Most of these support vectors
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::STRB(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 11:58:37 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x0E4, Rt, Rn, imm, 8);
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2021-01-16 00:27:11 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x0E0, type == IndexType::Post ? 1 : 3, Rt, Rn, imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::LDRB(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 11:58:37 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x0E5, Rt, Rn, imm, 8);
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2021-01-16 00:27:11 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x0E1, type == IndexType::Post ? 1 : 3, Rt, Rn, imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::LDRSB(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 11:58:37 -07:00
|
|
|
EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x0E6 : 0x0E7, Rt, Rn, imm, 8);
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2021-01-16 00:27:11 -07:00
|
|
|
EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x0E2 : 0x0E3, type == IndexType::Post ? 1 : 3, Rt, Rn,
|
2014-02-04 18:56:23 -07:00
|
|
|
imm);
|
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::STRH(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 11:58:37 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x1E4, Rt, Rn, imm, 16);
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2021-01-16 00:27:11 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x1E0, type == IndexType::Post ? 1 : 3, Rt, Rn, imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::LDRH(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 11:58:37 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x1E5, Rt, Rn, imm, 16);
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2021-01-16 00:27:11 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x1E1, type == IndexType::Post ? 1 : 3, Rt, Rn, imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::LDRSH(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 11:58:37 -07:00
|
|
|
EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x1E6 : 0x1E7, Rt, Rn, imm, 16);
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2021-01-16 00:27:11 -07:00
|
|
|
EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x1E2 : 0x1E3, type == IndexType::Post ? 1 : 3, Rt, Rn,
|
2014-02-04 18:56:23 -07:00
|
|
|
imm);
|
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::STR(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 11:58:37 -07:00
|
|
|
EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x3E4 : 0x2E4, Rt, Rn, imm, Is64Bit(Rt) ? 64 : 32);
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2021-01-16 00:27:11 -07:00
|
|
|
EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x3E0 : 0x2E0, type == IndexType::Post ? 1 : 3, Rt, Rn,
|
2014-02-04 18:56:23 -07:00
|
|
|
imm);
|
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::LDR(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 11:58:37 -07:00
|
|
|
EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x3E5 : 0x2E5, Rt, Rn, imm, Is64Bit(Rt) ? 64 : 32);
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2021-01-16 00:27:11 -07:00
|
|
|
EncodeLoadStoreIndexedInst(Is64Bit(Rt) ? 0x3E1 : 0x2E1, type == IndexType::Post ? 1 : 3, Rt, Rn,
|
2014-02-04 18:56:23 -07:00
|
|
|
imm);
|
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::LDRSW(IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 11:58:37 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x2E6, Rt, Rn, imm, 32);
|
2014-02-04 18:56:23 -07:00
|
|
|
else
|
2021-01-16 00:27:11 -07:00
|
|
|
EncodeLoadStoreIndexedInst(0x2E2, type == IndexType::Post ? 1 : 3, Rt, Rn, imm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load/Store register (register offset)
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::STRB(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(0, 0, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::LDRB(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(0, 1, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::LDRSB(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rt);
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(0, 3 - b64Bit, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::STRH(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(1, 0, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::LDRH(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(1, 1, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::LDRSH(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rt);
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(1, 3 - b64Bit, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::STR(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rt);
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(2 + b64Bit, 0, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::LDR(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2014-09-08 20:52:52 -06:00
|
|
|
bool b64Bit = Is64Bit(Rt);
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(2 + b64Bit, 1, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::LDRSW(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(2, 2, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64XEmitter::PRFM(ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2015-01-18 15:25:40 -07:00
|
|
|
EncodeLoadStoreRegisterOffset(3, 2, Rt, Rn, Rm);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2015-02-16 21:00:43 -07:00
|
|
|
// Load/Store register (unscaled offset)
|
|
|
|
void ARM64XEmitter::STURB(ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreUnscaled(0, 0, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDURB(ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreUnscaled(0, 1, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDURSB(ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreUnscaled(0, Is64Bit(Rt) ? 2 : 3, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::STURH(ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreUnscaled(1, 0, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDURH(ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreUnscaled(1, 1, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDURSH(ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreUnscaled(1, Is64Bit(Rt) ? 2 : 3, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::STUR(ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreUnscaled(Is64Bit(Rt) ? 3 : 2, 0, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDUR(ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreUnscaled(Is64Bit(Rt) ? 3 : 2, 1, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64XEmitter::LDURSW(ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !Is64Bit(Rt), "Must have a 64bit destination register!");
|
2015-02-16 21:00:43 -07:00
|
|
|
EncodeLoadStoreUnscaled(2, 2, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
|
2014-12-15 13:23:09 -07:00
|
|
|
// Address of label/page PC-relative
|
|
|
|
void ARM64XEmitter::ADR(ARM64Reg Rd, s32 imm)
|
|
|
|
{
|
|
|
|
EncodeAddressInst(0, Rd, imm);
|
|
|
|
}
|
2021-01-13 03:04:13 -07:00
|
|
|
void ARM64XEmitter::ADRP(ARM64Reg Rd, s64 imm)
|
2014-12-15 13:23:09 -07:00
|
|
|
{
|
2021-01-13 03:04:13 -07:00
|
|
|
EncodeAddressInst(1, Rd, static_cast<s32>(imm >> 12));
|
2014-12-15 13:23:09 -07:00
|
|
|
}
|
|
|
|
|
2023-06-03 01:24:10 -06:00
|
|
|
// This is using a hand-rolled algorithm. The goal is zero memory allocations, not necessarily
|
|
|
|
// the best JIT-time time complexity. (The number of moves is usually very small.)
|
|
|
|
void ARM64XEmitter::ParallelMoves(RegisterMove* begin, RegisterMove* end,
|
|
|
|
std::array<u8, 32>* source_gpr_usages)
|
|
|
|
{
|
|
|
|
// X0-X7 are used for passing arguments.
|
|
|
|
// X18-X31 are either callee saved or used for special purposes.
|
|
|
|
constexpr size_t temp_reg_begin = 8;
|
|
|
|
constexpr size_t temp_reg_end = 18;
|
|
|
|
|
|
|
|
while (begin != end)
|
|
|
|
{
|
|
|
|
bool removed_moves_during_this_loop_iteration = false;
|
|
|
|
|
2024-04-21 08:20:59 -06:00
|
|
|
RegisterMove* current_move = end;
|
|
|
|
while (current_move != begin)
|
2023-06-03 01:24:10 -06:00
|
|
|
{
|
2024-04-21 08:20:59 -06:00
|
|
|
RegisterMove* prev_move = current_move;
|
|
|
|
--current_move;
|
|
|
|
if ((*source_gpr_usages)[DecodeReg(current_move->dst)] == 0)
|
2023-06-03 01:24:10 -06:00
|
|
|
{
|
2024-04-21 08:20:59 -06:00
|
|
|
MOV(current_move->dst, current_move->src);
|
|
|
|
(*source_gpr_usages)[DecodeReg(current_move->src)]--;
|
|
|
|
std::move(prev_move, end, current_move);
|
2023-06-03 01:24:10 -06:00
|
|
|
--end;
|
|
|
|
removed_moves_during_this_loop_iteration = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!removed_moves_during_this_loop_iteration)
|
|
|
|
{
|
|
|
|
// We need to break a cycle using a temporary register.
|
|
|
|
|
|
|
|
size_t temp_reg = temp_reg_begin;
|
|
|
|
while ((*source_gpr_usages)[temp_reg] != 0)
|
|
|
|
{
|
|
|
|
++temp_reg;
|
2024-04-21 08:19:10 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, temp_reg != temp_reg_end, "Out of registers");
|
2023-06-03 01:24:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
const ARM64Reg src = begin->src;
|
|
|
|
const ARM64Reg dst =
|
|
|
|
(Is64Bit(src) ? EncodeRegTo64 : EncodeRegTo32)(static_cast<ARM64Reg>(temp_reg));
|
|
|
|
|
|
|
|
MOV(dst, src);
|
|
|
|
(*source_gpr_usages)[DecodeReg(dst)] = (*source_gpr_usages)[DecodeReg(src)];
|
|
|
|
(*source_gpr_usages)[DecodeReg(src)] = 0;
|
|
|
|
|
|
|
|
std::for_each(begin, end, [src, dst](RegisterMove& move) {
|
|
|
|
if (move.src == src)
|
|
|
|
move.src = dst;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-01 12:43:34 -07:00
|
|
|
template <typename T>
|
|
|
|
void ARM64XEmitter::MOVI2RImpl(ARM64Reg Rd, T imm)
|
|
|
|
{
|
|
|
|
enum class Approach
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-02-15 15:46:08 -07:00
|
|
|
MOVZBase,
|
|
|
|
MOVNBase,
|
|
|
|
ADRBase,
|
|
|
|
ADRPBase,
|
|
|
|
ORRBase,
|
2021-01-01 12:43:34 -07:00
|
|
|
};
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-01-01 12:43:34 -07:00
|
|
|
struct Part
|
2014-12-15 13:23:09 -07:00
|
|
|
{
|
2021-01-01 12:43:34 -07:00
|
|
|
Part() = default;
|
|
|
|
Part(u16 imm_, ShiftAmount shift_) : imm(imm_), shift(shift_) {}
|
|
|
|
|
|
|
|
u16 imm;
|
|
|
|
ShiftAmount shift;
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr size_t max_parts = sizeof(T) / 2;
|
|
|
|
|
2023-08-21 08:12:49 -06:00
|
|
|
Common::SmallVector<Part, max_parts> best_parts;
|
2021-01-01 12:43:34 -07:00
|
|
|
Approach best_approach;
|
2021-01-03 05:36:37 -07:00
|
|
|
u64 best_base;
|
|
|
|
|
2023-08-21 08:12:49 -06:00
|
|
|
const auto instructions_required = [](const Common::SmallVector<Part, max_parts>& parts,
|
2021-01-03 05:36:37 -07:00
|
|
|
Approach approach) {
|
2021-02-15 15:46:08 -07:00
|
|
|
return parts.size() + (approach > Approach::MOVNBase);
|
2021-01-03 05:36:37 -07:00
|
|
|
};
|
2021-01-01 12:43:34 -07:00
|
|
|
|
|
|
|
const auto try_base = [&](T base, Approach approach, bool first_time) {
|
2023-08-21 08:12:49 -06:00
|
|
|
Common::SmallVector<Part, max_parts> parts;
|
2021-01-01 12:43:34 -07:00
|
|
|
|
|
|
|
for (size_t i = 0; i < max_parts; ++i)
|
2014-12-15 13:23:09 -07:00
|
|
|
{
|
2021-01-01 12:43:34 -07:00
|
|
|
const size_t shift = i * 16;
|
|
|
|
const u16 imm_shifted = static_cast<u16>(imm >> shift);
|
|
|
|
const u16 base_shifted = static_cast<u16>(base >> shift);
|
|
|
|
if (imm_shifted != base_shifted)
|
|
|
|
parts.emplace_back(imm_shifted, static_cast<ShiftAmount>(i));
|
2014-12-15 13:23:09 -07:00
|
|
|
}
|
2021-01-01 12:43:34 -07:00
|
|
|
|
2021-01-03 05:36:37 -07:00
|
|
|
if (first_time ||
|
|
|
|
instructions_required(parts, approach) < instructions_required(best_parts, best_approach))
|
2014-12-15 13:23:09 -07:00
|
|
|
{
|
2021-01-01 12:43:34 -07:00
|
|
|
best_parts = std::move(parts);
|
|
|
|
best_approach = approach;
|
2021-01-03 05:36:37 -07:00
|
|
|
best_base = base;
|
2014-12-15 13:23:09 -07:00
|
|
|
}
|
2021-01-01 12:43:34 -07:00
|
|
|
};
|
|
|
|
|
2021-01-03 05:36:37 -07:00
|
|
|
// Try MOVZ/MOVN
|
2021-02-15 15:46:08 -07:00
|
|
|
try_base(T(0), Approach::MOVZBase, true);
|
|
|
|
try_base(~T(0), Approach::MOVNBase, false);
|
2021-01-03 05:36:37 -07:00
|
|
|
|
|
|
|
// Try PC-relative approaches
|
2021-01-01 12:43:34 -07:00
|
|
|
const auto sext_21_bit = [](u64 x) {
|
|
|
|
return static_cast<s64>((x & 0x1FFFFF) | (x & 0x100000 ? ~0x1FFFFF : 0));
|
|
|
|
};
|
|
|
|
const u64 pc = reinterpret_cast<u64>(GetCodePtr());
|
|
|
|
const s64 adrp_offset = sext_21_bit((imm >> 12) - (pc >> 12)) << 12;
|
|
|
|
const s64 adr_offset = sext_21_bit(imm - pc);
|
|
|
|
const u64 adrp_base = (pc & ~0xFFF) + adrp_offset;
|
|
|
|
const u64 adr_base = pc + adr_offset;
|
|
|
|
if constexpr (sizeof(T) == 8)
|
|
|
|
{
|
2021-02-15 15:46:08 -07:00
|
|
|
try_base(adrp_base, Approach::ADRPBase, false);
|
|
|
|
try_base(adr_base, Approach::ADRBase, false);
|
2021-01-01 12:43:34 -07:00
|
|
|
}
|
|
|
|
|
2021-01-03 05:36:37 -07:00
|
|
|
// Try ORR (or skip it if we already have a 1-instruction encoding - these tests are non-trivial)
|
|
|
|
if (instructions_required(best_parts, best_approach) > 1)
|
|
|
|
{
|
|
|
|
if constexpr (sizeof(T) == 8)
|
|
|
|
{
|
|
|
|
for (u64 orr_imm : {(imm << 32) | (imm & 0x0000'0000'FFFF'FFFF),
|
|
|
|
(imm & 0xFFFF'FFFF'0000'0000) | (imm >> 32),
|
|
|
|
(imm << 48) | (imm & 0x0000'FFFF'FFFF'0000) | (imm >> 48)})
|
|
|
|
{
|
2023-12-16 05:27:13 -07:00
|
|
|
if (LogicalImm(orr_imm, GPRSize::B64))
|
2021-02-15 15:46:08 -07:00
|
|
|
try_base(orr_imm, Approach::ORRBase, false);
|
2021-01-03 05:36:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-16 05:27:13 -07:00
|
|
|
if (LogicalImm(imm, GPRSize::B32))
|
2021-02-15 15:46:08 -07:00
|
|
|
try_base(imm, Approach::ORRBase, false);
|
2021-01-03 05:36:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-01 12:43:34 -07:00
|
|
|
size_t parts_uploaded = 0;
|
|
|
|
|
|
|
|
// To kill any dependencies, we start with an instruction that overwrites the entire register
|
|
|
|
switch (best_approach)
|
|
|
|
{
|
2021-02-15 15:46:08 -07:00
|
|
|
case Approach::MOVZBase:
|
2021-01-01 12:43:34 -07:00
|
|
|
if (best_parts.empty())
|
|
|
|
best_parts.emplace_back(u16(0), ShiftAmount::Shift0);
|
|
|
|
|
|
|
|
MOVZ(Rd, best_parts[0].imm, best_parts[0].shift);
|
|
|
|
++parts_uploaded;
|
|
|
|
break;
|
|
|
|
|
2021-02-15 15:46:08 -07:00
|
|
|
case Approach::MOVNBase:
|
2021-01-01 12:43:34 -07:00
|
|
|
if (best_parts.empty())
|
|
|
|
best_parts.emplace_back(u16(0xFFFF), ShiftAmount::Shift0);
|
|
|
|
|
|
|
|
MOVN(Rd, static_cast<u16>(~best_parts[0].imm), best_parts[0].shift);
|
|
|
|
++parts_uploaded;
|
|
|
|
break;
|
|
|
|
|
2021-02-15 15:46:08 -07:00
|
|
|
case Approach::ADRBase:
|
2021-01-01 12:43:34 -07:00
|
|
|
ADR(Rd, adr_offset);
|
|
|
|
break;
|
|
|
|
|
2021-02-15 15:46:08 -07:00
|
|
|
case Approach::ADRPBase:
|
2021-01-01 12:43:34 -07:00
|
|
|
ADRP(Rd, adrp_offset);
|
|
|
|
break;
|
2021-01-03 05:36:37 -07:00
|
|
|
|
2021-02-15 15:46:08 -07:00
|
|
|
case Approach::ORRBase:
|
2021-02-06 11:50:33 -07:00
|
|
|
constexpr ARM64Reg zero_reg = sizeof(T) == 8 ? ARM64Reg::ZR : ARM64Reg::WZR;
|
2021-01-03 05:36:37 -07:00
|
|
|
const bool success = TryORRI2R(Rd, zero_reg, best_base);
|
|
|
|
ASSERT(success);
|
|
|
|
break;
|
2014-12-15 13:23:09 -07:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-01-01 12:43:34 -07:00
|
|
|
// And then we use MOVK for the remaining parts
|
|
|
|
for (; parts_uploaded < best_parts.size(); ++parts_uploaded)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-01 12:43:34 -07:00
|
|
|
const Part& part = best_parts[parts_uploaded];
|
|
|
|
|
2021-02-15 15:46:08 -07:00
|
|
|
if (best_approach == Approach::ADRPBase && part.shift == ShiftAmount::Shift0)
|
2014-02-04 18:56:23 -07:00
|
|
|
{
|
2021-01-01 12:43:34 -07:00
|
|
|
// The combination of ADRP followed by ADD immediate is specifically optimized in hardware
|
|
|
|
ASSERT(part.imm == (adrp_base & 0xF000) + (part.imm & 0xFFF));
|
|
|
|
ADD(Rd, Rd, part.imm & 0xFFF);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-01 12:43:34 -07:00
|
|
|
MOVK(Rd, part.imm, part.shift);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
}
|
|
|
|
|
2021-01-01 12:43:34 -07:00
|
|
|
template void ARM64XEmitter::MOVI2RImpl(ARM64Reg Rd, u64 imm);
|
|
|
|
template void ARM64XEmitter::MOVI2RImpl(ARM64Reg Rd, u32 imm);
|
|
|
|
|
|
|
|
void ARM64XEmitter::MOVI2R(ARM64Reg Rd, u64 imm)
|
|
|
|
{
|
|
|
|
if (Is64Bit(Rd))
|
|
|
|
MOVI2RImpl<u64>(Rd, imm);
|
|
|
|
else
|
|
|
|
MOVI2RImpl<u32>(Rd, static_cast<u32>(imm));
|
|
|
|
}
|
|
|
|
|
2016-10-27 01:14:01 -06:00
|
|
|
bool ARM64XEmitter::MOVI2R2(ARM64Reg Rd, u64 imm1, u64 imm2)
|
|
|
|
{
|
|
|
|
// TODO: Also optimize for performance, not just for code size.
|
|
|
|
u8* start_pointer = GetWritableCodePtr();
|
|
|
|
|
|
|
|
MOVI2R(Rd, imm1);
|
|
|
|
int size1 = GetCodePtr() - start_pointer;
|
|
|
|
|
2021-08-22 06:21:54 -06:00
|
|
|
m_code = start_pointer;
|
2016-10-27 01:14:01 -06:00
|
|
|
|
|
|
|
MOVI2R(Rd, imm2);
|
|
|
|
int size2 = GetCodePtr() - start_pointer;
|
|
|
|
|
2021-08-22 06:21:54 -06:00
|
|
|
m_code = start_pointer;
|
2016-10-27 01:14:01 -06:00
|
|
|
|
|
|
|
bool element = size1 > size2;
|
|
|
|
|
|
|
|
MOVI2R(Rd, element ? imm2 : imm1);
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
2014-12-15 13:23:09 -07:00
|
|
|
void ARM64XEmitter::ABI_PushRegisters(BitSet32 registers)
|
|
|
|
{
|
2017-02-09 01:25:31 -07:00
|
|
|
int num_regs = registers.Count();
|
|
|
|
int stack_size = (num_regs + (num_regs & 1)) * 8;
|
|
|
|
auto it = registers.begin();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-09 01:25:31 -07:00
|
|
|
if (!num_regs)
|
|
|
|
return;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-09 01:25:31 -07:00
|
|
|
// 8 byte per register, but 16 byte alignment, so we may have to padd one register.
|
|
|
|
// Only update the SP on the last write to avoid the dependency between those stores.
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-09 01:25:31 -07:00
|
|
|
// The first push must adjust the SP, else a context switch may invalidate everything below SP.
|
|
|
|
if (num_regs & 1)
|
2018-08-30 00:37:44 -06:00
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
STR(IndexType::Pre, ARM64Reg::X0 + *it++, ARM64Reg::SP, -stack_size);
|
2018-08-30 00:37:44 -06:00
|
|
|
}
|
2014-12-15 13:23:09 -07:00
|
|
|
else
|
2018-08-30 00:37:44 -06:00
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ARM64Reg first_reg = ARM64Reg::X0 + *it++;
|
|
|
|
ARM64Reg second_reg = ARM64Reg::X0 + *it++;
|
|
|
|
STP(IndexType::Pre, first_reg, second_reg, ARM64Reg::SP, -stack_size);
|
2018-08-30 00:37:44 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-09 01:25:31 -07:00
|
|
|
// Fast store for all other registers, this is always an even number.
|
|
|
|
for (int i = 0; i < (num_regs - 1) / 2; i++)
|
2018-08-30 00:37:44 -06:00
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ARM64Reg odd_reg = ARM64Reg::X0 + *it++;
|
|
|
|
ARM64Reg even_reg = ARM64Reg::X0 + *it++;
|
|
|
|
STP(IndexType::Signed, odd_reg, even_reg, ARM64Reg::SP, 16 * (i + 1));
|
2018-08-30 00:37:44 -06:00
|
|
|
}
|
2017-02-09 01:25:31 -07:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, it == registers.end(), "Registers don't match: {:b}", registers.m_val);
|
2014-12-15 13:23:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::ABI_PopRegisters(BitSet32 registers, BitSet32 ignore_mask)
|
|
|
|
{
|
|
|
|
int num_regs = registers.Count();
|
2017-02-09 01:25:31 -07:00
|
|
|
int stack_size = (num_regs + (num_regs & 1)) * 8;
|
|
|
|
auto it = registers.begin();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-09 01:25:31 -07:00
|
|
|
if (!num_regs)
|
|
|
|
return;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-09 01:25:31 -07:00
|
|
|
// We must adjust the SP in the end, so load the first (two) registers at least.
|
2021-02-06 11:50:33 -07:00
|
|
|
ARM64Reg first = ARM64Reg::X0 + *it++;
|
2017-02-09 01:25:31 -07:00
|
|
|
ARM64Reg second;
|
|
|
|
if (!(num_regs & 1))
|
2021-02-06 11:50:33 -07:00
|
|
|
second = ARM64Reg::X0 + *it++;
|
2019-11-25 21:31:45 -07:00
|
|
|
else
|
|
|
|
second = {};
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-09 01:25:31 -07:00
|
|
|
// 8 byte per register, but 16 byte alignment, so we may have to padd one register.
|
|
|
|
// Only update the SP on the last load to avoid the dependency between those loads.
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-09 01:25:31 -07:00
|
|
|
// Fast load for all but the first (two) registers, this is always an even number.
|
|
|
|
for (int i = 0; i < (num_regs - 1) / 2; i++)
|
2018-08-30 00:37:44 -06:00
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ARM64Reg odd_reg = ARM64Reg::X0 + *it++;
|
|
|
|
ARM64Reg even_reg = ARM64Reg::X0 + *it++;
|
|
|
|
LDP(IndexType::Signed, odd_reg, even_reg, ARM64Reg::SP, 16 * (i + 1));
|
2018-08-30 00:37:44 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-02-09 01:25:31 -07:00
|
|
|
// Post loading the first (two) registers.
|
|
|
|
if (num_regs & 1)
|
2021-02-06 11:50:33 -07:00
|
|
|
LDR(IndexType::Post, first, ARM64Reg::SP, stack_size);
|
2017-02-09 01:25:31 -07:00
|
|
|
else
|
2021-02-06 11:50:33 -07:00
|
|
|
LDP(IndexType::Post, first, second, ARM64Reg::SP, stack_size);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, it == registers.end(), "Registers don't match: {:b}", registers.m_val);
|
2014-02-04 18:56:23 -07:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
// Float Emitter
|
|
|
|
void ARM64FloatEmitter::EmitLoadStoreImmediate(u8 size, u32 opc, IndexType type, ARM64Reg Rt,
|
|
|
|
ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
u32 encoded_size = 0;
|
|
|
|
u32 encoded_imm = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
if (size == 8)
|
|
|
|
encoded_size = 0;
|
|
|
|
else if (size == 16)
|
|
|
|
encoded_size = 1;
|
|
|
|
else if (size == 32)
|
|
|
|
encoded_size = 2;
|
|
|
|
else if (size == 64)
|
|
|
|
encoded_size = 3;
|
|
|
|
else if (size == 128)
|
|
|
|
encoded_size = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Unsigned)
|
2015-01-07 12:42:36 -07:00
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, imm >= 0, "(IndexType::Unsigned) immediate offset must be positive! ({})",
|
|
|
|
imm);
|
2015-01-07 12:42:36 -07:00
|
|
|
if (size == 16)
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x1) == 0, "16-bit load/store must use aligned offset: {}", imm);
|
2015-01-07 12:42:36 -07:00
|
|
|
imm >>= 1;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
else if (size == 32)
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x3) == 0, "32-bit load/store must use aligned offset: {}", imm);
|
2015-01-07 12:42:36 -07:00
|
|
|
imm >>= 2;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
else if (size == 64)
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0x7) == 0, "64-bit load/store must use aligned offset: {}", imm);
|
2015-01-07 12:42:36 -07:00
|
|
|
imm >>= 3;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
else if (size == 128)
|
2022-07-14 21:00:12 -06:00
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0xf) == 0, "128-bit load/store must use aligned offset: {}", imm);
|
2015-01-07 12:42:36 -07:00
|
|
|
imm >>= 4;
|
2022-07-14 21:00:12 -06:00
|
|
|
}
|
|
|
|
ASSERT_MSG(DYNA_REC, imm <= 0xFFF, "Immediate value is too big: {}", imm);
|
2015-01-07 12:42:36 -07:00
|
|
|
encoded_imm = (imm & 0xFFF);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm < -256 || imm > 255),
|
2021-11-10 15:42:49 -07:00
|
|
|
"immediate offset must be within range of -256 to 256! {}", imm);
|
2015-01-07 12:42:36 -07:00
|
|
|
encoded_imm = (imm & 0x1FF) << 2;
|
2021-01-16 00:27:11 -07:00
|
|
|
if (type == IndexType::Post)
|
2015-01-07 12:42:36 -07:00
|
|
|
encoded_imm |= 1;
|
|
|
|
else
|
|
|
|
encoded_imm |= 3;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-01-16 00:27:11 -07:00
|
|
|
Write32((encoded_size << 30) | (0xF << 26) | (type == IndexType::Unsigned ? (1 << 24) : 0) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(size == 128 ? (1 << 23) : 0) | (opc << 22) | (encoded_imm << 10) | (DecodeReg(Rn) << 5) |
|
|
|
|
DecodeReg(Rt));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::EmitScalar2Source(bool M, bool S, u32 type, u32 opcode, ARM64Reg Rd,
|
|
|
|
ARM64Reg Rn, ARM64Reg Rm)
|
2015-01-07 12:42:36 -07:00
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "Only double and single registers are supported!");
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((M << 31) | (S << 29) | (0b11110001 << 21) | (type << 22) | (DecodeReg(Rm) << 16) |
|
|
|
|
(opcode << 12) | (1 << 11) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-05-15 07:41:28 -06:00
|
|
|
void ARM64FloatEmitter::EmitScalarThreeSame(bool U, u32 size, u32 opcode, ARM64Reg Rd, ARM64Reg Rn,
|
|
|
|
ARM64Reg Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "Only double and single registers are supported!");
|
2021-05-15 07:41:28 -06:00
|
|
|
|
|
|
|
Write32((1 << 30) | (U << 29) | (0b11110001 << 21) | (size << 22) | (DecodeReg(Rm) << 16) |
|
|
|
|
(opcode << 11) | (1 << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::EmitThreeSame(bool U, u32 size, u32 opcode, ARM64Reg Rd, ARM64Reg Rn,
|
|
|
|
ARM64Reg Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsSingle(Rd), "Singles are not supported!");
|
2015-01-07 12:42:36 -07:00
|
|
|
bool quad = IsQuad(Rd);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((quad << 30) | (U << 29) | (0b1110001 << 21) | (size << 22) | (DecodeReg(Rm) << 16) |
|
|
|
|
(opcode << 11) | (1 << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::EmitCopy(bool Q, u32 op, u32 imm5, u32 imm4, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Write32((Q << 30) | (op << 29) | (0b111 << 25) | (imm5 << 16) | (imm4 << 11) | (1 << 10) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
|
2021-05-02 14:12:00 -06:00
|
|
|
void ARM64FloatEmitter::EmitScalar2RegMisc(bool U, u32 size, u32 opcode, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Write32((1 << 30) | (U << 29) | (0b11110001 << 21) | (size << 22) | (opcode << 12) | (1 << 11) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
|
|
|
}
|
|
|
|
|
2022-12-03 09:37:51 -07:00
|
|
|
void ARM64FloatEmitter::EmitScalarPairwise(bool U, u32 size, u32 opcode, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Write32((1 << 30) | (U << 29) | (0b111100011 << 20) | (size << 22) | (opcode << 12) | (1 << 11) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::Emit2RegMisc(bool Q, bool U, u32 size, u32 opcode, ARM64Reg Rd, ARM64Reg Rn)
|
2015-01-07 12:42:36 -07:00
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsSingle(Rd), "Singles are not supported!");
|
2015-01-07 12:42:36 -07:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
Write32((Q << 30) | (U << 29) | (0b1110001 << 21) | (size << 22) | (opcode << 12) | (1 << 11) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::EmitLoadStoreSingleStructure(bool L, bool R, u32 opcode, bool S, u32 size,
|
|
|
|
ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsSingle(Rt), "Singles are not supported!");
|
2015-01-07 12:42:36 -07:00
|
|
|
bool quad = IsQuad(Rt);
|
|
|
|
|
|
|
|
Write32((quad << 30) | (0b1101 << 24) | (L << 22) | (R << 21) | (opcode << 13) | (S << 12) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(size << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64FloatEmitter::EmitLoadStoreSingleStructure(bool L, bool R, u32 opcode, bool S, u32 size,
|
|
|
|
ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsSingle(Rt), "Singles are not supported!");
|
2015-01-18 15:25:40 -07:00
|
|
|
bool quad = IsQuad(Rt);
|
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((quad << 30) | (0x1B << 23) | (L << 22) | (R << 21) | (DecodeReg(Rm) << 16) |
|
|
|
|
(opcode << 13) | (S << 12) | (size << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::Emit1Source(bool M, bool S, u32 type, u32 opcode, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "Vector is not supported!");
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
Write32((M << 31) | (S << 29) | (0xF1 << 21) | (type << 22) | (opcode << 15) | (1 << 14) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::EmitConversion(bool sf, bool S, u32 type, u32 rmode, u32 opcode,
|
|
|
|
ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, Rn <= ARM64Reg::SP, "Only GPRs are supported as source!");
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
Write32((sf << 31) | (S << 29) | (0xF1 << 21) | (type << 22) | (rmode << 19) | (opcode << 16) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::EmitConvertScalarToInt(ARM64Reg Rd, ARM64Reg Rn, RoundingMode round,
|
|
|
|
bool sign)
|
|
|
|
{
|
2018-03-14 18:34:35 -06:00
|
|
|
DEBUG_ASSERT_MSG(DYNA_REC, IsScalar(Rn), "fcvts: Rn must be floating point");
|
2015-06-07 15:57:57 -06:00
|
|
|
if (IsGPR(Rd))
|
|
|
|
{
|
|
|
|
// Use the encoding that transfers the result to a GPR.
|
2020-12-30 18:24:41 -07:00
|
|
|
const bool sf = Is64Bit(Rd);
|
|
|
|
const int type = IsDouble(Rn) ? 1 : 0;
|
2015-06-07 15:57:57 -06:00
|
|
|
int opcode = (sign ? 1 : 0);
|
|
|
|
int rmode = 0;
|
|
|
|
switch (round)
|
|
|
|
{
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::A:
|
2015-06-07 15:57:57 -06:00
|
|
|
rmode = 0;
|
|
|
|
opcode |= 4;
|
|
|
|
break;
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::P:
|
2015-06-07 15:57:57 -06:00
|
|
|
rmode = 1;
|
|
|
|
break;
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::M:
|
2015-06-07 15:57:57 -06:00
|
|
|
rmode = 2;
|
|
|
|
break;
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::Z:
|
2015-06-07 15:57:57 -06:00
|
|
|
rmode = 3;
|
|
|
|
break;
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::N:
|
2015-06-07 15:57:57 -06:00
|
|
|
rmode = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
EmitConversion2(sf, 0, true, type, rmode, opcode, 0, Rd, Rn);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Use the encoding (vector, single) that keeps the result in the fp register.
|
|
|
|
int sz = IsDouble(Rn);
|
|
|
|
int opcode = 0;
|
|
|
|
switch (round)
|
|
|
|
{
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::A:
|
2015-06-07 15:57:57 -06:00
|
|
|
opcode = 0x1C;
|
|
|
|
break;
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::N:
|
2015-06-07 15:57:57 -06:00
|
|
|
opcode = 0x1A;
|
|
|
|
break;
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::M:
|
2015-06-07 15:57:57 -06:00
|
|
|
opcode = 0x1B;
|
|
|
|
break;
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::P:
|
2015-06-07 15:57:57 -06:00
|
|
|
opcode = 0x1A;
|
|
|
|
sz |= 2;
|
|
|
|
break;
|
2020-12-30 18:24:41 -07:00
|
|
|
case RoundingMode::Z:
|
2015-06-07 15:57:57 -06:00
|
|
|
opcode = 0x1B;
|
|
|
|
sz |= 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Write32((0x5E << 24) | (sign << 29) | (sz << 22) | (1 << 21) | (opcode << 12) | (2 << 10) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::FCVTS(ARM64Reg Rd, ARM64Reg Rn, RoundingMode round)
|
|
|
|
{
|
|
|
|
EmitConvertScalarToInt(Rd, Rn, round, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::FCVTU(ARM64Reg Rd, ARM64Reg Rn, RoundingMode round)
|
|
|
|
{
|
|
|
|
EmitConvertScalarToInt(Rd, Rn, round, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::EmitConversion2(bool sf, bool S, bool direction, u32 type, u32 rmode,
|
|
|
|
u32 opcode, int scale, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Write32((sf << 31) | (S << 29) | (0xF0 << 21) | (direction << 21) | (type << 22) | (rmode << 19) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(opcode << 16) | (scale << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::EmitCompare(bool M, bool S, u32 op, u32 opcode2, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsQuad(Rn), "Vector is not supported!");
|
2015-01-25 02:19:36 -07:00
|
|
|
bool is_double = IsDouble(Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((M << 31) | (S << 29) | (0xF1 << 21) | (is_double << 22) | (DecodeReg(Rm) << 16) |
|
|
|
|
(op << 14) | (1 << 13) | (DecodeReg(Rn) << 5) | opcode2);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::EmitCondSelect(bool M, bool S, CCFlags cond, ARM64Reg Rd, ARM64Reg Rn,
|
|
|
|
ARM64Reg Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "Vector is not supported!");
|
2015-01-25 02:19:36 -07:00
|
|
|
bool is_double = IsDouble(Rd);
|
2015-01-07 12:42:36 -07:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((M << 31) | (S << 29) | (0xF1 << 21) | (is_double << 22) | (DecodeReg(Rm) << 16) |
|
|
|
|
(cond << 12) | (3 << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::EmitPermute(u32 size, u32 op, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsSingle(Rd), "Singles are not supported!");
|
2015-01-07 12:42:36 -07:00
|
|
|
|
|
|
|
bool quad = IsQuad(Rd);
|
|
|
|
|
|
|
|
u32 encoded_size = 0;
|
|
|
|
if (size == 16)
|
|
|
|
encoded_size = 1;
|
|
|
|
else if (size == 32)
|
|
|
|
encoded_size = 2;
|
|
|
|
else if (size == 64)
|
|
|
|
encoded_size = 3;
|
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((quad << 30) | (7 << 25) | (encoded_size << 22) | (DecodeReg(Rm) << 16) | (op << 12) |
|
|
|
|
(1 << 11) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
|
2022-11-26 09:57:16 -07:00
|
|
|
void ARM64FloatEmitter::EmitExtract(u32 imm4, u32 op, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
ASSERT_MSG(DYNA_REC, !IsSingle(Rd), "Singles are not supported!");
|
|
|
|
|
|
|
|
bool quad = IsQuad(Rd);
|
|
|
|
|
|
|
|
Write32((quad << 30) | (23 << 25) | (op << 22) | (DecodeReg(Rm) << 16) | (imm4 << 11) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::EmitScalarImm(bool M, bool S, u32 type, u32 imm5, ARM64Reg Rd, u32 imm8)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "Vector is not supported!");
|
2015-01-18 15:25:40 -07:00
|
|
|
|
|
|
|
bool is_double = !IsSingle(Rd);
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
Write32((M << 31) | (S << 29) | (0xF1 << 21) | (is_double << 22) | (type << 22) | (imm8 << 13) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(1 << 12) | (imm5 << 5) | DecodeReg(Rd));
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2022-10-19 12:20:39 -06:00
|
|
|
void ARM64FloatEmitter::EmitShiftImm(bool Q, bool U, u32 imm, u32 opcode, ARM64Reg Rd, ARM64Reg Rn)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
2022-10-19 12:20:39 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, (imm & 0b1111000) != 0, "Can't have zero immh");
|
2015-01-18 15:25:40 -07:00
|
|
|
|
2022-10-19 12:20:39 -06:00
|
|
|
Write32((Q << 30) | (U << 29) | (0xF << 24) | (imm << 16) | (opcode << 11) | (1 << 10) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
|
2022-10-19 12:20:39 -06:00
|
|
|
void ARM64FloatEmitter::EmitScalarShiftImm(bool U, u32 imm, u32 opcode, ARM64Reg Rd, ARM64Reg Rn)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2022-10-19 11:35:10 -06:00
|
|
|
Write32((1 << 30) | (U << 29) | (0x3E << 23) | (imm << 16) | (opcode << 11) | (1 << 10) |
|
2022-10-19 12:20:39 -06:00
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64FloatEmitter::EmitLoadStoreMultipleStructure(u32 size, bool L, u32 opcode, ARM64Reg Rt,
|
|
|
|
ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
bool quad = IsQuad(Rt);
|
|
|
|
u32 encoded_size = 0;
|
|
|
|
|
|
|
|
if (size == 16)
|
|
|
|
encoded_size = 1;
|
|
|
|
else if (size == 32)
|
|
|
|
encoded_size = 2;
|
|
|
|
else if (size == 64)
|
|
|
|
encoded_size = 3;
|
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((quad << 30) | (3 << 26) | (L << 22) | (opcode << 12) | (encoded_size << 10) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
void ARM64FloatEmitter::EmitLoadStoreMultipleStructurePost(u32 size, bool L, u32 opcode,
|
|
|
|
ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
bool quad = IsQuad(Rt);
|
|
|
|
u32 encoded_size = 0;
|
|
|
|
|
2015-06-07 18:53:05 -06:00
|
|
|
if (size == 16)
|
2015-02-28 03:39:15 -07:00
|
|
|
encoded_size = 1;
|
2015-03-02 02:41:19 -07:00
|
|
|
else if (size == 32)
|
2015-02-28 03:39:15 -07:00
|
|
|
encoded_size = 2;
|
2015-03-02 02:41:19 -07:00
|
|
|
else if (size == 64)
|
2015-02-28 03:39:15 -07:00
|
|
|
encoded_size = 3;
|
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((quad << 30) | (0b11001 << 23) | (L << 22) | (DecodeReg(Rm) << 16) | (opcode << 12) |
|
|
|
|
(encoded_size << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2015-02-28 03:39:15 -07:00
|
|
|
}
|
|
|
|
|
2015-01-20 15:34:32 -07:00
|
|
|
void ARM64FloatEmitter::EmitScalar1Source(bool M, bool S, u32 type, u32 opcode, ARM64Reg Rd,
|
|
|
|
ARM64Reg Rn)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsQuad(Rd), "Vector is not supported!");
|
2015-01-20 15:34:32 -07:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
Write32((M << 31) | (S << 29) | (0xF1 << 21) | (type << 22) | (opcode << 15) | (1 << 14) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-20 15:34:32 -07:00
|
|
|
}
|
|
|
|
|
2015-02-12 17:47:06 -07:00
|
|
|
void ARM64FloatEmitter::EmitVectorxElement(bool U, u32 size, bool L, u32 opcode, bool H,
|
|
|
|
ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
bool quad = IsQuad(Rd);
|
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((quad << 30) | (U << 29) | (0xF << 24) | (size << 22) | (L << 21) |
|
|
|
|
(DecodeReg(Rm) << 16) | (opcode << 12) | (H << 11) | (DecodeReg(Rn) << 5) |
|
|
|
|
DecodeReg(Rd));
|
2015-02-12 17:47:06 -07:00
|
|
|
}
|
|
|
|
|
2015-02-16 21:00:43 -07:00
|
|
|
void ARM64FloatEmitter::EmitLoadStoreUnscaled(u32 size, u32 op, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm < -256 || imm > 255), "received too large offset: {}", imm);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((size << 30) | (0xF << 26) | (op << 22) | ((imm & 0x1FF) << 12) | (DecodeReg(Rn) << 5) |
|
|
|
|
DecodeReg(Rt));
|
2015-02-16 21:00:43 -07:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 02:41:19 -07:00
|
|
|
void ARM64FloatEmitter::EncodeLoadStorePair(u32 size, bool load, IndexType type, ARM64Reg Rt,
|
|
|
|
ARM64Reg Rt2, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
u32 type_encode = 0;
|
|
|
|
u32 opc = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 02:41:19 -07:00
|
|
|
switch (type)
|
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
case IndexType::Signed:
|
2015-03-02 02:41:19 -07:00
|
|
|
type_encode = 0b010;
|
|
|
|
break;
|
2021-01-16 00:27:11 -07:00
|
|
|
case IndexType::Post:
|
2015-03-02 02:41:19 -07:00
|
|
|
type_encode = 0b001;
|
|
|
|
break;
|
2021-01-16 00:27:11 -07:00
|
|
|
case IndexType::Pre:
|
2015-03-02 02:41:19 -07:00
|
|
|
type_encode = 0b011;
|
|
|
|
break;
|
2021-01-16 00:27:11 -07:00
|
|
|
case IndexType::Unsigned:
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, false, "IndexType::Unsigned is unsupported!");
|
2015-03-02 02:41:19 -07:00
|
|
|
break;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 02:41:19 -07:00
|
|
|
if (size == 128)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & 0xF), "Invalid offset {:#x}! (size {})", imm, size);
|
2015-03-02 02:41:19 -07:00
|
|
|
opc = 2;
|
|
|
|
imm >>= 4;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & 0x7), "Invalid offset {:#x}! (size {})", imm, size);
|
2015-03-02 02:41:19 -07:00
|
|
|
opc = 1;
|
|
|
|
imm >>= 3;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & 0x3), "Invalid offset {:#x}! (size {})", imm, size);
|
2015-03-02 02:41:19 -07:00
|
|
|
opc = 0;
|
|
|
|
imm >>= 2;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, imm >= -64 && imm < 64, "imm too large for load/store pair! {}", imm);
|
2021-01-29 15:13:58 -07:00
|
|
|
|
2015-03-02 02:41:19 -07:00
|
|
|
Write32((opc << 30) | (0b1011 << 26) | (type_encode << 23) | (load << 22) | ((imm & 0x7F) << 15) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(DecodeReg(Rt2) << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2015-03-02 02:41:19 -07:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 18:53:05 -06:00
|
|
|
void ARM64FloatEmitter::EncodeLoadStoreRegisterOffset(u32 size, bool load, ARM64Reg Rt, ARM64Reg Rn,
|
|
|
|
ArithOption Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, Rm.IsExtended(), "Must contain an extended reg as Rm!");
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 18:53:05 -06:00
|
|
|
u32 encoded_size = 0;
|
|
|
|
u32 encoded_op = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 18:53:05 -06:00
|
|
|
if (size == 8)
|
|
|
|
{
|
|
|
|
encoded_size = 0;
|
|
|
|
encoded_op = 0;
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
|
|
|
encoded_size = 1;
|
|
|
|
encoded_op = 0;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
|
|
|
encoded_size = 2;
|
|
|
|
encoded_op = 0;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
encoded_size = 3;
|
|
|
|
encoded_op = 0;
|
|
|
|
}
|
|
|
|
else if (size == 128)
|
|
|
|
{
|
|
|
|
encoded_size = 0;
|
|
|
|
encoded_op = 2;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 18:53:05 -06:00
|
|
|
if (load)
|
|
|
|
encoded_op |= 1;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
const int decoded_Rm = DecodeReg(Rm.GetReg());
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 18:53:05 -06:00
|
|
|
Write32((encoded_size << 30) | (encoded_op << 22) | (0b111100001 << 21) | (decoded_Rm << 16) |
|
2021-02-06 11:50:33 -07:00
|
|
|
Rm.GetData() | (1 << 11) | (DecodeReg(Rn) << 5) | DecodeReg(Rt));
|
2015-06-07 18:53:05 -06:00
|
|
|
}
|
|
|
|
|
2015-08-23 14:34:53 -06:00
|
|
|
void ARM64FloatEmitter::EncodeModImm(bool Q, u8 op, u8 cmode, u8 o2, ARM64Reg Rd, u8 abcdefgh)
|
|
|
|
{
|
2017-01-04 04:45:40 -07:00
|
|
|
union
|
|
|
|
{
|
2015-08-23 14:34:53 -06:00
|
|
|
u8 hex;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned defgh : 5;
|
|
|
|
unsigned abc : 3;
|
|
|
|
};
|
|
|
|
} v;
|
|
|
|
v.hex = abcdefgh;
|
|
|
|
Write32((Q << 30) | (op << 29) | (0xF << 24) | (v.abc << 16) | (cmode << 12) | (o2 << 11) |
|
2021-02-06 11:50:33 -07:00
|
|
|
(1 << 10) | (v.defgh << 5) | DecodeReg(Rd));
|
2015-08-23 14:34:53 -06:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::LDR(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EmitLoadStoreImmediate(size, 1, type, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::STR(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
EmitLoadStoreImmediate(size, 0, type, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
|
2015-02-16 21:00:43 -07:00
|
|
|
// Loadstore unscaled
|
|
|
|
void ARM64FloatEmitter::LDUR(u8 size, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
u32 encoded_size = 0;
|
|
|
|
u32 encoded_op = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-16 21:00:43 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
|
|
|
encoded_size = 0;
|
|
|
|
encoded_op = 1;
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
|
|
|
encoded_size = 1;
|
|
|
|
encoded_op = 1;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
|
|
|
encoded_size = 2;
|
|
|
|
encoded_op = 1;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
encoded_size = 3;
|
|
|
|
encoded_op = 1;
|
|
|
|
}
|
|
|
|
else if (size == 128)
|
|
|
|
{
|
|
|
|
encoded_size = 0;
|
|
|
|
encoded_op = 3;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-16 21:00:43 -07:00
|
|
|
EmitLoadStoreUnscaled(encoded_size, encoded_op, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::STUR(u8 size, ARM64Reg Rt, ARM64Reg Rn, s32 imm)
|
|
|
|
{
|
|
|
|
u32 encoded_size = 0;
|
|
|
|
u32 encoded_op = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-16 21:00:43 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
|
|
|
encoded_size = 0;
|
|
|
|
encoded_op = 0;
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
|
|
|
encoded_size = 1;
|
|
|
|
encoded_op = 0;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
|
|
|
encoded_size = 2;
|
|
|
|
encoded_op = 0;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
encoded_size = 3;
|
|
|
|
encoded_op = 0;
|
|
|
|
}
|
|
|
|
else if (size == 128)
|
|
|
|
{
|
|
|
|
encoded_size = 0;
|
|
|
|
encoded_op = 2;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-16 21:00:43 -07:00
|
|
|
EmitLoadStoreUnscaled(encoded_size, encoded_op, Rt, Rn, imm);
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
// Loadstore single structure
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64FloatEmitter::LD1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
bool S = 0;
|
|
|
|
u32 opcode = 0;
|
|
|
|
u32 encoded_size = 0;
|
2021-02-06 11:50:33 -07:00
|
|
|
ARM64Reg encoded_reg = ARM64Reg::INVALID_REG;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 4) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 0;
|
|
|
|
encoded_size = index & 3;
|
|
|
|
if (index & 8)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 2) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 2;
|
|
|
|
encoded_size = (index & 1) << 1;
|
|
|
|
if (index & 4)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 1) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 4;
|
|
|
|
encoded_size = 0;
|
|
|
|
if (index & 2)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
S = 0;
|
|
|
|
opcode = 4;
|
|
|
|
encoded_size = 1;
|
|
|
|
if (index == 1)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
EmitLoadStoreSingleStructure(1, 0, opcode, S, encoded_size, encoded_reg, Rn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::LD1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
bool S = 0;
|
|
|
|
u32 opcode = 0;
|
|
|
|
u32 encoded_size = 0;
|
2021-02-06 11:50:33 -07:00
|
|
|
ARM64Reg encoded_reg = ARM64Reg::INVALID_REG;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 4) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 0;
|
|
|
|
encoded_size = index & 3;
|
|
|
|
if (index & 8)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 2) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 2;
|
|
|
|
encoded_size = (index & 1) << 1;
|
|
|
|
if (index & 4)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 1) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 4;
|
|
|
|
encoded_size = 0;
|
|
|
|
if (index & 2)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
S = 0;
|
|
|
|
opcode = 4;
|
|
|
|
encoded_size = 1;
|
|
|
|
if (index == 1)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
EmitLoadStoreSingleStructure(1, 0, opcode, S, encoded_size, encoded_reg, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::LD1R(u8 size, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitLoadStoreSingleStructure(1, 0, 6, 0, size >> 4, Rt, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2015-06-09 16:42:15 -06:00
|
|
|
void ARM64FloatEmitter::LD2R(u8 size, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EmitLoadStoreSingleStructure(1, 1, 6, 0, size >> 4, Rt, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::LD1R(u8 size, ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitLoadStoreSingleStructure(1, 0, 6, 0, size >> 4, Rt, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::LD2R(u8 size, ARM64Reg Rt, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitLoadStoreSingleStructure(1, 1, 6, 0, size >> 4, Rt, Rn, Rm);
|
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64FloatEmitter::ST1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
bool S = 0;
|
|
|
|
u32 opcode = 0;
|
|
|
|
u32 encoded_size = 0;
|
2021-02-06 11:50:33 -07:00
|
|
|
ARM64Reg encoded_reg = ARM64Reg::INVALID_REG;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 4) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 0;
|
|
|
|
encoded_size = index & 3;
|
|
|
|
if (index & 8)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 2) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 2;
|
|
|
|
encoded_size = (index & 1) << 1;
|
|
|
|
if (index & 4)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 1) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 4;
|
|
|
|
encoded_size = 0;
|
|
|
|
if (index & 2)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
S = 0;
|
|
|
|
opcode = 4;
|
|
|
|
encoded_size = 1;
|
|
|
|
if (index == 1)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
EmitLoadStoreSingleStructure(0, 0, opcode, S, encoded_size, encoded_reg, Rn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::ST1(u8 size, ARM64Reg Rt, u8 index, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
bool S = 0;
|
|
|
|
u32 opcode = 0;
|
|
|
|
u32 encoded_size = 0;
|
2021-02-06 11:50:33 -07:00
|
|
|
ARM64Reg encoded_reg = ARM64Reg::INVALID_REG;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 4) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 0;
|
|
|
|
encoded_size = index & 3;
|
|
|
|
if (index & 8)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 2) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 2;
|
|
|
|
encoded_size = (index & 1) << 1;
|
|
|
|
if (index & 4)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
S = (index & 1) != 0;
|
2015-01-18 15:25:40 -07:00
|
|
|
opcode = 4;
|
|
|
|
encoded_size = 0;
|
|
|
|
if (index & 2)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
S = 0;
|
|
|
|
opcode = 4;
|
|
|
|
encoded_size = 1;
|
|
|
|
if (index == 1)
|
|
|
|
encoded_reg = EncodeRegToQuad(Rt);
|
|
|
|
else
|
|
|
|
encoded_reg = EncodeRegToDouble(Rt);
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
EmitLoadStoreSingleStructure(0, 0, opcode, S, encoded_size, encoded_reg, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loadstore multiple structure
|
|
|
|
void ARM64FloatEmitter::LD1(u8 size, u8 count, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(count == 0 || count > 4), "Must have a count of 1 to 4 registers! ({})",
|
|
|
|
count);
|
2015-01-18 15:25:40 -07:00
|
|
|
u32 opcode = 0;
|
|
|
|
if (count == 1)
|
|
|
|
opcode = 0b111;
|
|
|
|
else if (count == 2)
|
|
|
|
opcode = 0b1010;
|
|
|
|
else if (count == 3)
|
|
|
|
opcode = 0b0110;
|
|
|
|
else if (count == 4)
|
|
|
|
opcode = 0b0010;
|
|
|
|
EmitLoadStoreMultipleStructure(size, 1, opcode, Rt, Rn);
|
|
|
|
}
|
2015-02-28 03:39:15 -07:00
|
|
|
void ARM64FloatEmitter::LD1(u8 size, u8 count, IndexType type, ARM64Reg Rt, ARM64Reg Rn,
|
|
|
|
ARM64Reg Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(count == 0 || count > 4), "Must have a count of 1 to 4 registers! ({})",
|
|
|
|
count);
|
|
|
|
ASSERT_MSG(DYNA_REC, type == IndexType::Post, "Only post indexing is supported!");
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
u32 opcode = 0;
|
|
|
|
if (count == 1)
|
|
|
|
opcode = 0b111;
|
|
|
|
else if (count == 2)
|
|
|
|
opcode = 0b1010;
|
|
|
|
else if (count == 3)
|
|
|
|
opcode = 0b0110;
|
|
|
|
else if (count == 4)
|
|
|
|
opcode = 0b0010;
|
|
|
|
EmitLoadStoreMultipleStructurePost(size, 1, opcode, Rt, Rn, Rm);
|
|
|
|
}
|
2015-02-12 17:47:06 -07:00
|
|
|
void ARM64FloatEmitter::ST1(u8 size, u8 count, ARM64Reg Rt, ARM64Reg Rn)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(count == 0 || count > 4), "Must have a count of 1 to 4 registers! ({})",
|
|
|
|
count);
|
2015-02-12 17:47:06 -07:00
|
|
|
u32 opcode = 0;
|
|
|
|
if (count == 1)
|
|
|
|
opcode = 0b111;
|
|
|
|
else if (count == 2)
|
|
|
|
opcode = 0b1010;
|
|
|
|
else if (count == 3)
|
|
|
|
opcode = 0b0110;
|
|
|
|
else if (count == 4)
|
|
|
|
opcode = 0b0010;
|
|
|
|
EmitLoadStoreMultipleStructure(size, 0, opcode, Rt, Rn);
|
|
|
|
}
|
2015-02-28 03:39:15 -07:00
|
|
|
void ARM64FloatEmitter::ST1(u8 size, u8 count, IndexType type, ARM64Reg Rt, ARM64Reg Rn,
|
|
|
|
ARM64Reg Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(count == 0 || count > 4), "Must have a count of 1 to 4 registers! ({})",
|
|
|
|
count);
|
|
|
|
ASSERT_MSG(DYNA_REC, type == IndexType::Post, "Only post indexing is supporte!");
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
u32 opcode = 0;
|
|
|
|
if (count == 1)
|
|
|
|
opcode = 0b111;
|
|
|
|
else if (count == 2)
|
|
|
|
opcode = 0b1010;
|
|
|
|
else if (count == 3)
|
|
|
|
opcode = 0b0110;
|
|
|
|
else if (count == 4)
|
|
|
|
opcode = 0b0010;
|
|
|
|
EmitLoadStoreMultipleStructurePost(size, 0, opcode, Rt, Rn, Rm);
|
|
|
|
}
|
2015-02-12 17:47:06 -07:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
// Scalar - 1 Source
|
|
|
|
void ARM64FloatEmitter::FMOV(ARM64Reg Rd, ARM64Reg Rn, bool top)
|
|
|
|
{
|
|
|
|
if (IsScalar(Rd) && IsScalar(Rn))
|
|
|
|
{
|
|
|
|
EmitScalar1Source(0, 0, IsDouble(Rd), 0, Rd, Rn);
|
|
|
|
}
|
2021-04-10 04:43:02 -06:00
|
|
|
else if (IsGPR(Rd) != IsGPR(Rn))
|
|
|
|
{
|
|
|
|
const ARM64Reg gpr = IsGPR(Rn) ? Rn : Rd;
|
|
|
|
const ARM64Reg fpr = IsGPR(Rn) ? Rd : Rn;
|
|
|
|
|
|
|
|
const int sf = Is64Bit(gpr) ? 1 : 0;
|
|
|
|
const int type = Is64Bit(gpr) ? (top ? 2 : 1) : 0;
|
|
|
|
const int rmode = top ? 1 : 0;
|
|
|
|
const int opcode = IsGPR(Rn) ? 7 : 6;
|
|
|
|
|
|
|
|
ASSERT_MSG(DYNA_REC, !top || IsQuad(fpr), "FMOV: top can only be used with quads");
|
|
|
|
|
|
|
|
// TODO: Should this check be more lenient? Sometimes you do want to do things like
|
|
|
|
// read the lower 32 bits of a double
|
|
|
|
ASSERT_MSG(DYNA_REC,
|
|
|
|
(!Is64Bit(gpr) && IsSingle(fpr)) ||
|
|
|
|
(Is64Bit(gpr) && ((IsDouble(fpr) && !top) || (IsQuad(fpr) && top))),
|
|
|
|
"FMOV: Mismatched sizes");
|
|
|
|
|
|
|
|
Write32((sf << 31) | (0x1e << 24) | (type << 22) | (1 << 21) | (rmode << 19) | (opcode << 16) |
|
|
|
|
(DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
else
|
|
|
|
{
|
2021-04-10 04:43:02 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, 0, "FMOV: Unsupported case");
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 02:41:19 -07:00
|
|
|
// Loadstore paired
|
|
|
|
void ARM64FloatEmitter::LDP(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn,
|
|
|
|
s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStorePair(size, true, type, Rt, Rt2, Rn, imm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::STP(u8 size, IndexType type, ARM64Reg Rt, ARM64Reg Rt2, ARM64Reg Rn,
|
|
|
|
s32 imm)
|
|
|
|
{
|
|
|
|
EncodeLoadStorePair(size, false, type, Rt, Rt2, Rn, imm);
|
|
|
|
}
|
|
|
|
|
2015-06-07 18:53:05 -06:00
|
|
|
// Loadstore register offset
|
|
|
|
void ARM64FloatEmitter::STR(u8 size, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreRegisterOffset(size, false, Rt, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::LDR(u8 size, ARM64Reg Rt, ARM64Reg Rn, ArithOption Rm)
|
|
|
|
{
|
|
|
|
EncodeLoadStoreRegisterOffset(size, true, Rt, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
2015-01-20 15:34:32 -07:00
|
|
|
void ARM64FloatEmitter::FABS(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EmitScalar1Source(0, 0, IsDouble(Rd), 1, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FNEG(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitScalar1Source(0, 0, IsDouble(Rd), 2, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FSQRT(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EmitScalar1Source(0, 0, IsDouble(Rd), 3, Rd, Rn);
|
2015-01-20 15:34:32 -07:00
|
|
|
}
|
2021-11-06 13:15:26 -06:00
|
|
|
void ARM64FloatEmitter::FRINTI(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EmitScalar1Source(0, 0, IsDouble(Rd), 15, Rd, Rn);
|
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
|
2021-05-02 14:12:00 -06:00
|
|
|
void ARM64FloatEmitter::FRECPE(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2021-05-28 07:34:08 -06:00
|
|
|
EmitScalar2RegMisc(0, IsDouble(Rd) ? 3 : 2, 0x1D, Rd, Rn);
|
2021-05-02 14:12:00 -06:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FRSQRTE(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2021-05-28 07:34:08 -06:00
|
|
|
EmitScalar2RegMisc(1, IsDouble(Rd) ? 3 : 2, 0x1D, Rd, Rn);
|
2021-05-02 14:12:00 -06:00
|
|
|
}
|
|
|
|
|
2022-12-03 09:37:51 -07:00
|
|
|
// Scalar - pairwise
|
|
|
|
void ARM64FloatEmitter::FADDP(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EmitScalarPairwise(1, IsDouble(Rd), 0b01101, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMAXP(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EmitScalarPairwise(1, IsDouble(Rd), 0b01111, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMINP(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EmitScalarPairwise(1, IsDouble(Rd) ? 3 : 2, 0b01111, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMAXNMP(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EmitScalarPairwise(1, IsDouble(Rd), 0b01100, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMINNMP(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
EmitScalarPairwise(1, IsDouble(Rd) ? 3 : 2, 0b01100, Rd, Rn);
|
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
// Scalar - 2 Source
|
2021-05-15 07:41:28 -06:00
|
|
|
void ARM64FloatEmitter::ADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, IsDouble(Rd), "Only double registers are supported!");
|
2021-05-15 07:41:28 -06:00
|
|
|
EmitScalarThreeSame(0, 3, 0b10000, Rd, Rn, Rm);
|
|
|
|
}
|
2015-01-20 15:34:32 -07:00
|
|
|
void ARM64FloatEmitter::FADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitScalar2Source(0, 0, IsDouble(Rd), 2, Rd, Rn, Rm);
|
2015-01-20 15:34:32 -07:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::FMUL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitScalar2Source(0, 0, IsDouble(Rd), 0, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2015-01-20 15:34:32 -07:00
|
|
|
void ARM64FloatEmitter::FSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitScalar2Source(0, 0, IsDouble(Rd), 3, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FDIV(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitScalar2Source(0, 0, IsDouble(Rd), 1, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMAX(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitScalar2Source(0, 0, IsDouble(Rd), 4, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMIN(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitScalar2Source(0, 0, IsDouble(Rd), 5, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMAXNM(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitScalar2Source(0, 0, IsDouble(Rd), 6, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMINNM(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitScalar2Source(0, 0, IsDouble(Rd), 7, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FNMUL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitScalar2Source(0, 0, IsDouble(Rd), 8, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::FMADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EmitScalar3Source(IsDouble(Rd), Rd, Rn, Rm, Ra, 0);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EmitScalar3Source(IsDouble(Rd), Rd, Rn, Rm, Ra, 1);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FNMADD(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EmitScalar3Source(IsDouble(Rd), Rd, Rn, Rm, Ra, 2);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FNMSUB(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, ARM64Reg Ra)
|
|
|
|
{
|
|
|
|
EmitScalar3Source(IsDouble(Rd), Rd, Rn, Rm, Ra, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::EmitScalar3Source(bool isDouble, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm,
|
|
|
|
ARM64Reg Ra, int opcode)
|
|
|
|
{
|
|
|
|
int type = isDouble ? 1 : 0;
|
|
|
|
int o1 = opcode >> 1;
|
|
|
|
int o0 = opcode & 1;
|
2021-02-06 11:50:33 -07:00
|
|
|
m_emit->Write32((0x1F << 24) | (type << 22) | (o1 << 21) | (DecodeReg(Rm) << 16) | (o0 << 15) |
|
|
|
|
(DecodeReg(Ra) << 10) | (DecodeReg(Rn) << 5) | DecodeReg(Rd));
|
2015-01-20 15:34:32 -07:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
// Scalar floating point immediate
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::FMOV(ARM64Reg Rd, uint8_t imm8)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitScalarImm(0, 0, 0, 0, Rd, imm8);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
// Vector
|
2021-05-15 07:41:28 -06:00
|
|
|
void ARM64FloatEmitter::ADD(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2023-04-15 01:27:35 -06:00
|
|
|
EmitThreeSame(0, MathUtil::IntLog2(size) - 3, 0b10000, Rd, Rn, Rm);
|
2021-05-15 07:41:28 -06:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::AND(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(0, 0, 3, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2021-05-15 07:41:28 -06:00
|
|
|
void ARM64FloatEmitter::BIC(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(0, 1, 3, Rd, Rn, Rm);
|
|
|
|
}
|
2021-07-31 04:34:04 -06:00
|
|
|
void ARM64FloatEmitter::BIF(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(1, 3, 3, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::BIT(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(1, 2, 3, Rd, Rn, Rm);
|
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::BSL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(1, 1, 3, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::DUP(u8 size, ARM64Reg Rd, ARM64Reg Rn, u8 index)
|
|
|
|
{
|
|
|
|
u32 imm5 = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
|
|
|
imm5 = 1;
|
|
|
|
imm5 |= index << 1;
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
|
|
|
imm5 = 2;
|
|
|
|
imm5 |= index << 2;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
|
|
|
imm5 = 4;
|
|
|
|
imm5 |= index << 3;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
imm5 = 8;
|
|
|
|
imm5 |= index << 4;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
EmitCopy(IsQuad(Rd), 0, imm5, 0, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FABS(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0xF, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FADD(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(0, size >> 6, 0x1A, Rd, Rn, Rm);
|
|
|
|
}
|
2015-06-09 16:42:15 -06:00
|
|
|
void ARM64FloatEmitter::FMAX(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(0, size >> 6, 0b11110, Rd, Rn, Rm);
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::FMLA(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(0, size >> 6, 0x19, Rd, Rn, Rm);
|
2015-06-09 16:42:15 -06:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMIN(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(0, 2 | size >> 6, 0b11110, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCVTL(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(false, 0, size >> 6, 0x17, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCVTL2(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Emit2RegMisc(true, 0, size >> 6, 0x17, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64FloatEmitter::FCVTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, dest_size >> 5, 0x16, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCVTZS(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0x1B, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCVTZU(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0x1B, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::FDIV(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(1, size >> 6, 0x1F, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMUL(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(1, size >> 6, 0x1B, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FNEG(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0xF, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2017-05-03 00:52:26 -06:00
|
|
|
void ARM64FloatEmitter::FRECPE(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0x1D, Rd, Rn);
|
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::FRSQRTE(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0x1D, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FSUB(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(0, 2 | (size >> 6), 0x1A, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FMLS(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(0, 2 | (size >> 6), 0x19, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::NOT(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 1, 0, 5, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::ORR(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(0, 2, 3, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2021-05-15 07:41:28 -06:00
|
|
|
void ARM64FloatEmitter::ORN(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(0, 3, 3, Rd, Rn, Rm);
|
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::REV16(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, size >> 4, 1, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::REV32(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 1, size >> 4, 0, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::REV64(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, size >> 4, 0, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64FloatEmitter::SCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, size >> 6, 0x1D, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::UCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 1, size >> 6, 0x1D, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::SCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn, int scale)
|
|
|
|
{
|
2022-10-19 12:20:39 -06:00
|
|
|
EmitShiftImm(IsQuad(Rd), 0, size * 2 - scale, 0x1C, Rd, Rn);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::UCVTF(u8 size, ARM64Reg Rd, ARM64Reg Rn, int scale)
|
|
|
|
{
|
2022-10-19 12:20:39 -06:00
|
|
|
EmitShiftImm(IsQuad(Rd), 1, size * 2 - scale, 0x1C, Rd, Rn);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
2015-06-13 22:16:17 -06:00
|
|
|
void ARM64FloatEmitter::SQXTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Emit2RegMisc(false, 0, dest_size >> 4, 0b10100, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::SQXTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Emit2RegMisc(true, 0, dest_size >> 4, 0b10100, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::UQXTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Emit2RegMisc(false, 1, dest_size >> 4, 0b10100, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::UQXTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Emit2RegMisc(true, 1, dest_size >> 4, 0b10100, Rd, Rn);
|
|
|
|
}
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64FloatEmitter::XTN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-13 22:16:17 -06:00
|
|
|
Emit2RegMisc(false, 0, dest_size >> 4, 0b10010, Rd, Rn);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::XTN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
Emit2RegMisc(true, 0, dest_size >> 4, 0b10010, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
|
|
|
|
// Move
|
|
|
|
void ARM64FloatEmitter::DUP(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
u32 imm5 = 0;
|
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
if (size == 8)
|
2015-06-07 15:57:57 -06:00
|
|
|
imm5 = 1;
|
|
|
|
else if (size == 16)
|
2015-01-18 15:25:40 -07:00
|
|
|
imm5 = 2;
|
|
|
|
else if (size == 32)
|
|
|
|
imm5 = 4;
|
|
|
|
else if (size == 64)
|
|
|
|
imm5 = 8;
|
2015-01-07 12:42:36 -07:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitCopy(IsQuad(Rd), 0, imm5, 1, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::INS(u8 size, ARM64Reg Rd, u8 index, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
u32 imm5 = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
|
|
|
imm5 = 1;
|
|
|
|
imm5 |= index << 1;
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
|
|
|
imm5 = 2;
|
|
|
|
imm5 |= index << 2;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
|
|
|
imm5 = 4;
|
|
|
|
imm5 |= index << 3;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
imm5 = 8;
|
|
|
|
imm5 |= index << 4;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitCopy(1, 0, imm5, 3, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::INS(u8 size, ARM64Reg Rd, u8 index1, ARM64Reg Rn, u8 index2)
|
|
|
|
{
|
|
|
|
u32 imm5 = 0, imm4 = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
|
|
|
imm5 = 1;
|
|
|
|
imm5 |= index1 << 1;
|
|
|
|
imm4 = index2;
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
|
|
|
imm5 = 2;
|
|
|
|
imm5 |= index1 << 2;
|
|
|
|
imm4 = index2 << 1;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
|
|
|
imm5 = 4;
|
|
|
|
imm5 |= index1 << 3;
|
|
|
|
imm4 = index2 << 2;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
imm5 = 8;
|
|
|
|
imm5 |= index1 << 4;
|
|
|
|
imm4 = index2 << 3;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
EmitCopy(1, 1, imm5, imm4, Rd, Rn);
|
|
|
|
}
|
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64FloatEmitter::UMOV(u8 size, ARM64Reg Rd, ARM64Reg Rn, u8 index)
|
|
|
|
{
|
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, Rd < ARM64Reg::SP, "Destination must be a GPR!");
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, !(b64Bit && size != 64),
|
2021-11-10 15:42:49 -07:00
|
|
|
"Must have a size of 64 when destination is 64bit!");
|
2015-01-18 15:25:40 -07:00
|
|
|
u32 imm5 = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
|
|
|
imm5 = 1;
|
|
|
|
imm5 |= index << 1;
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
|
|
|
imm5 = 2;
|
|
|
|
imm5 |= index << 2;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
|
|
|
imm5 = 4;
|
|
|
|
imm5 |= index << 3;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
imm5 = 8;
|
|
|
|
imm5 |= index << 4;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitCopy(b64Bit, 0, imm5, 7, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::SMOV(u8 size, ARM64Reg Rd, ARM64Reg Rn, u8 index)
|
|
|
|
{
|
|
|
|
bool b64Bit = Is64Bit(Rd);
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, Rd < ARM64Reg::SP, "Destination must be a GPR!");
|
|
|
|
ASSERT_MSG(DYNA_REC, size != 64, "SMOV doesn't support 64bit destination. Use UMOV!");
|
2015-01-18 15:25:40 -07:00
|
|
|
u32 imm5 = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-01-18 15:25:40 -07:00
|
|
|
if (size == 8)
|
|
|
|
{
|
|
|
|
imm5 = 1;
|
|
|
|
imm5 |= index << 1;
|
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
|
|
|
imm5 = 2;
|
|
|
|
imm5 |= index << 2;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
|
|
|
imm5 = 4;
|
|
|
|
imm5 |= index << 3;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitCopy(b64Bit, 0, imm5, 5, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
// One source
|
|
|
|
void ARM64FloatEmitter::FCVT(u8 size_to, u8 size_from, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
u32 dst_encoding = 0;
|
|
|
|
u32 src_encoding = 0;
|
|
|
|
|
|
|
|
if (size_to == 16)
|
|
|
|
dst_encoding = 3;
|
|
|
|
else if (size_to == 32)
|
|
|
|
dst_encoding = 0;
|
|
|
|
else if (size_to == 64)
|
|
|
|
dst_encoding = 1;
|
|
|
|
|
|
|
|
if (size_from == 16)
|
|
|
|
src_encoding = 3;
|
|
|
|
else if (size_from == 32)
|
|
|
|
src_encoding = 0;
|
|
|
|
else if (size_from == 64)
|
|
|
|
src_encoding = 1;
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit1Source(0, 0, src_encoding, 4 | dst_encoding, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::SCVTF(ARM64Reg Rd, ARM64Reg Rn)
|
2015-01-07 12:42:36 -07:00
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
if (IsScalar(Rn))
|
2015-01-07 12:42:36 -07:00
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
// Source is in FP register (like destination!). We must use a vector encoding.
|
|
|
|
bool sign = false;
|
|
|
|
int sz = IsDouble(Rn);
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((0x5e << 24) | (sign << 29) | (sz << 22) | (0x876 << 10) | (DecodeReg(Rn) << 5) |
|
|
|
|
DecodeReg(Rd));
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool sf = Is64Bit(Rn);
|
|
|
|
u32 type = 0;
|
|
|
|
if (IsDouble(Rd))
|
2015-01-07 12:42:36 -07:00
|
|
|
type = 1;
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitConversion(sf, 0, type, 0, 2, Rd, Rn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::UCVTF(ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
if (IsScalar(Rn))
|
|
|
|
{
|
|
|
|
// Source is in FP register (like destination!). We must use a vector encoding.
|
|
|
|
bool sign = true;
|
|
|
|
int sz = IsDouble(Rn);
|
2021-02-06 11:50:33 -07:00
|
|
|
Write32((0x5e << 24) | (sign << 29) | (sz << 22) | (0x876 << 10) | (DecodeReg(Rn) << 5) |
|
|
|
|
DecodeReg(Rd));
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
else
|
|
|
|
{
|
|
|
|
bool sf = Is64Bit(Rn);
|
|
|
|
u32 type = 0;
|
|
|
|
if (IsDouble(Rd))
|
|
|
|
type = 1;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitConversion(sf, 0, type, 0, 3, Rd, Rn);
|
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::SCVTF(ARM64Reg Rd, ARM64Reg Rn, int scale)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
|
|
|
bool sf = Is64Bit(Rn);
|
|
|
|
u32 type = 0;
|
|
|
|
if (IsDouble(Rd))
|
|
|
|
type = 1;
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitConversion2(sf, 0, false, type, 0, 2, 64 - scale, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::UCVTF(ARM64Reg Rd, ARM64Reg Rn, int scale)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
|
|
|
bool sf = Is64Bit(Rn);
|
|
|
|
u32 type = 0;
|
|
|
|
if (IsDouble(Rd))
|
|
|
|
type = 1;
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitConversion2(sf, 0, false, type, 0, 3, 64 - scale, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:42:36 -07:00
|
|
|
void ARM64FloatEmitter::FCMP(ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitCompare(0, 0, 0, 0, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMP(ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitCompare(0, 0, 0, 8, Rn, (ARM64Reg)0);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMPE(ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitCompare(0, 0, 0, 0x10, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMPE(ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitCompare(0, 0, 0, 0x18, Rn, (ARM64Reg)0);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMEQ(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(0, size >> 6, 0x1C, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMEQ(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-08-10 17:38:10 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0xD, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMGE(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(1, size >> 6, 0x1C, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMGE(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-08-09 13:54:55 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0x0C, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMGT(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitThreeSame(1, 2 | (size >> 6), 0x1C, Rd, Rn, Rm);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMGT(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0x0C, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMLE(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 1, 2 | (size >> 6), 0xD, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FCMLT(u8 size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
Emit2RegMisc(IsQuad(Rd), 0, 2 | (size >> 6), 0xE, Rd, Rn);
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2021-02-01 14:14:16 -07:00
|
|
|
void ARM64FloatEmitter::FACGE(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(1, size >> 6, 0x1D, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::FACGT(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitThreeSame(1, 2 | (size >> 6), 0x1D, Rd, Rn, Rm);
|
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
|
|
|
|
void ARM64FloatEmitter::FCSEL(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, CCFlags cond)
|
|
|
|
{
|
|
|
|
EmitCondSelect(0, 0, cond, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Permute
|
|
|
|
void ARM64FloatEmitter::UZP1(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitPermute(size, 0b001, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::TRN1(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitPermute(size, 0b010, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::ZIP1(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitPermute(size, 0b011, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::UZP2(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitPermute(size, 0b101, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::TRN2(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitPermute(size, 0b110, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::ZIP2(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm)
|
|
|
|
{
|
|
|
|
EmitPermute(size, 0b111, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
2022-11-26 09:57:16 -07:00
|
|
|
// Extract
|
|
|
|
void ARM64FloatEmitter::EXT(ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u32 index)
|
|
|
|
{
|
|
|
|
EmitExtract(index, 0, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
2022-10-19 11:35:10 -06:00
|
|
|
// Scalar shift by immediate
|
|
|
|
void ARM64FloatEmitter::SHL(ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
|
|
|
{
|
|
|
|
constexpr size_t src_size = 64;
|
|
|
|
ASSERT_MSG(DYNA_REC, IsDouble(Rd), "Only double registers are supported!");
|
2022-12-10 03:18:57 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, shift < src_size, "Shift amount must be less than the element size! {} {}",
|
2022-10-19 11:35:10 -06:00
|
|
|
shift, src_size);
|
|
|
|
EmitScalarShiftImm(0, src_size | shift, 0b01010, Rd, Rn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::URSHR(ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
|
|
|
{
|
|
|
|
constexpr size_t src_size = 64;
|
|
|
|
ASSERT_MSG(DYNA_REC, IsDouble(Rd), "Only double registers are supported!");
|
2022-12-10 03:18:57 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, shift < src_size, "Shift amount must be less than the element size! {} {}",
|
2022-10-19 11:35:10 -06:00
|
|
|
shift, src_size);
|
|
|
|
EmitScalarShiftImm(1, src_size * 2 - shift, 0b00100, Rd, Rn);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vector shift by immediate
|
2015-01-18 15:25:40 -07:00
|
|
|
void ARM64FloatEmitter::SSHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
|
|
|
SSHLL(src_size, Rd, Rn, shift, false);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::SSHLL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
|
|
|
{
|
|
|
|
SSHLL(src_size, Rd, Rn, shift, true);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::SHRN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
|
|
|
{
|
|
|
|
SHRN(dest_size, Rd, Rn, shift, false);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::SHRN2(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
|
|
|
{
|
|
|
|
SHRN(dest_size, Rd, Rn, shift, true);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::USHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
|
|
|
{
|
|
|
|
USHLL(src_size, Rd, Rn, shift, false);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::USHLL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
|
|
|
{
|
|
|
|
USHLL(src_size, Rd, Rn, shift, true);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::SXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
SXTL(src_size, Rd, Rn, false);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::SXTL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
SXTL(src_size, Rd, Rn, true);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::UXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
UXTL(src_size, Rd, Rn, false);
|
|
|
|
}
|
|
|
|
void ARM64FloatEmitter::UXTL2(u8 src_size, ARM64Reg Rd, ARM64Reg Rn)
|
|
|
|
{
|
|
|
|
UXTL(src_size, Rd, Rn, true);
|
|
|
|
}
|
|
|
|
|
2022-10-19 11:35:10 -06:00
|
|
|
void ARM64FloatEmitter::SHL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
|
|
|
{
|
2022-12-10 03:18:57 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, shift < src_size, "Shift amount must be less than the element size! {} {}",
|
2022-10-19 11:35:10 -06:00
|
|
|
shift, src_size);
|
|
|
|
EmitShiftImm(1, 0, src_size | shift, 0b01010, Rd, Rn);
|
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::SSHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift, bool upper)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
2022-10-19 12:20:39 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, shift < src_size, "Shift amount must be less than the element size! {} {}",
|
2021-11-10 15:42:49 -07:00
|
|
|
shift, src_size);
|
2022-10-19 12:20:39 -06:00
|
|
|
EmitShiftImm(upper, 0, src_size | shift, 0b10100, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2022-10-19 11:35:10 -06:00
|
|
|
void ARM64FloatEmitter::URSHR(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift)
|
|
|
|
{
|
2022-12-10 03:18:57 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, shift < src_size, "Shift amount must be less than the element size! {} {}",
|
2022-10-19 11:35:10 -06:00
|
|
|
shift, src_size);
|
|
|
|
EmitShiftImm(1, 1, src_size * 2 - shift, 0b00100, Rd, Rn);
|
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::USHLL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift, bool upper)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
2022-10-19 12:20:39 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, shift < src_size, "Shift amount must be less than the element size! {} {}",
|
2021-11-10 15:42:49 -07:00
|
|
|
shift, src_size);
|
2022-10-19 12:20:39 -06:00
|
|
|
EmitShiftImm(upper, 1, src_size | shift, 0b10100, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::SHRN(u8 dest_size, ARM64Reg Rd, ARM64Reg Rn, u32 shift, bool upper)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
2022-10-19 12:20:39 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, shift < dest_size, "Shift amount must be less than the element size! {} {}",
|
2021-11-10 15:42:49 -07:00
|
|
|
shift, dest_size);
|
2022-12-10 03:18:57 -07:00
|
|
|
EmitShiftImm(upper, 1, dest_size * 2 - shift, 0b10000, Rd, Rn);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::SXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, bool upper)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
SSHLL(src_size, Rd, Rn, 0, upper);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64FloatEmitter::UXTL(u8 src_size, ARM64Reg Rd, ARM64Reg Rn, bool upper)
|
2015-01-18 15:25:40 -07:00
|
|
|
{
|
2015-06-07 15:57:57 -06:00
|
|
|
USHLL(src_size, Rd, Rn, 0, upper);
|
2015-01-18 15:25:40 -07:00
|
|
|
}
|
|
|
|
|
2015-02-12 17:47:06 -07:00
|
|
|
// vector x indexed element
|
|
|
|
void ARM64FloatEmitter::FMUL(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u8 index)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, size == 32 || size == 64, "Only 32bit or 64bit sizes are supported! {}",
|
|
|
|
size);
|
2015-02-12 17:47:06 -07:00
|
|
|
|
|
|
|
bool L = false;
|
|
|
|
bool H = false;
|
2015-06-07 15:57:57 -06:00
|
|
|
if (size == 32)
|
|
|
|
{
|
|
|
|
L = index & 1;
|
|
|
|
H = (index >> 1) & 1;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
H = index == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitVectorxElement(0, 2 | (size >> 6), L, 0x9, H, Rd, Rn, Rm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::FMLA(u8 size, ARM64Reg Rd, ARM64Reg Rn, ARM64Reg Rm, u8 index)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, size == 32 || size == 64, "Only 32bit or 64bit sizes are supported! {}",
|
|
|
|
size);
|
2015-02-12 17:47:06 -07:00
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
bool L = false;
|
|
|
|
bool H = false;
|
2015-02-12 17:47:06 -07:00
|
|
|
if (size == 32)
|
|
|
|
{
|
|
|
|
L = index & 1;
|
|
|
|
H = (index >> 1) & 1;
|
|
|
|
}
|
|
|
|
else if (size == 64)
|
|
|
|
{
|
|
|
|
H = index == 1;
|
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
EmitVectorxElement(0, 2 | (size >> 6), L, 1, H, Rd, Rn, Rm);
|
2015-02-12 17:47:06 -07:00
|
|
|
}
|
|
|
|
|
2015-08-23 14:34:53 -06:00
|
|
|
// Modified Immediate
|
|
|
|
void ARM64FloatEmitter::MOVI(u8 size, ARM64Reg Rd, u64 imm, u8 shift)
|
|
|
|
{
|
|
|
|
bool Q = IsQuad(Rd);
|
|
|
|
u8 cmode = 0;
|
|
|
|
u8 op = 0;
|
|
|
|
u8 abcdefgh = imm & 0xFF;
|
|
|
|
if (size == 8)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, shift == 0, "size8 doesn't support shift! ({})", shift);
|
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & ~0xFFULL), "size8 only supports 8bit values! ({})", imm);
|
2015-08-23 14:34:53 -06:00
|
|
|
}
|
|
|
|
else if (size == 16)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, shift == 0 || shift == 8, "size16 only supports shift of 0 or 8! ({})",
|
|
|
|
shift);
|
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & ~0xFFULL), "size16 only supports 8bit values! ({})", imm);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-08-23 14:34:53 -06:00
|
|
|
if (shift == 8)
|
|
|
|
cmode |= 2;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, shift == 0 || shift == 8 || shift == 16 || shift == 24,
|
2021-11-10 15:42:49 -07:00
|
|
|
"size32 only supports shift of 0, 8, 16, or 24! ({})", shift);
|
2015-08-23 14:34:53 -06:00
|
|
|
// XXX: Implement support for MOVI - shifting ones variant
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, !(imm & ~0xFFULL), "size32 only supports 8bit values! ({})", imm);
|
2015-08-23 14:34:53 -06:00
|
|
|
switch (shift)
|
|
|
|
{
|
|
|
|
case 8:
|
|
|
|
cmode |= 2;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
cmode |= 4;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
cmode |= 6;
|
|
|
|
break;
|
|
|
|
default:
|
2016-06-24 02:43:46 -06:00
|
|
|
break;
|
2015-08-23 14:34:53 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2015-08-23 14:34:53 -06:00
|
|
|
else // 64
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, shift == 0, "size64 doesn't support shift! ({})", shift);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-08-23 14:34:53 -06:00
|
|
|
op = 1;
|
|
|
|
cmode = 0xE;
|
|
|
|
abcdefgh = 0;
|
|
|
|
for (int i = 0; i < 8; ++i)
|
|
|
|
{
|
|
|
|
u8 tmp = (imm >> (i << 3)) & 0xFF;
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, tmp == 0xFF || tmp == 0, "size64 Invalid immediate! ({} -> {})", imm,
|
|
|
|
tmp);
|
2015-08-23 14:34:53 -06:00
|
|
|
if (tmp == 0xFF)
|
|
|
|
abcdefgh |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EncodeModImm(Q, op, cmode, 0, Rd, abcdefgh);
|
|
|
|
}
|
|
|
|
|
2021-05-15 07:41:28 -06:00
|
|
|
void ARM64FloatEmitter::ORR_BIC(u8 size, ARM64Reg Rd, u8 imm, u8 shift, u8 op)
|
2015-08-23 14:34:53 -06:00
|
|
|
{
|
|
|
|
bool Q = IsQuad(Rd);
|
|
|
|
u8 cmode = 1;
|
|
|
|
if (size == 16)
|
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, shift == 0 || shift == 8, "size16 only supports shift of 0 or 8! {}",
|
|
|
|
shift);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-08-23 14:34:53 -06:00
|
|
|
if (shift == 8)
|
|
|
|
cmode |= 2;
|
|
|
|
}
|
|
|
|
else if (size == 32)
|
|
|
|
{
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, shift == 0 || shift == 8 || shift == 16 || shift == 24,
|
2021-11-10 15:42:49 -07:00
|
|
|
"size32 only supports shift of 0, 8, 16, or 24! ({})", shift);
|
2015-08-23 14:34:53 -06:00
|
|
|
// XXX: Implement support for MOVI - shifting ones variant
|
|
|
|
switch (shift)
|
|
|
|
{
|
|
|
|
case 8:
|
|
|
|
cmode |= 2;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
cmode |= 4;
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
cmode |= 6;
|
|
|
|
break;
|
|
|
|
default:
|
2016-06-24 02:43:46 -06:00
|
|
|
break;
|
2015-08-23 14:34:53 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2015-08-23 14:34:53 -06:00
|
|
|
else
|
2018-03-14 18:34:35 -06:00
|
|
|
{
|
2021-11-10 15:42:49 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, false, "Only size of 16 or 32 is supported! ({})", size);
|
2018-03-14 18:34:35 -06:00
|
|
|
}
|
2015-08-23 14:34:53 -06:00
|
|
|
EncodeModImm(Q, op, cmode, 0, Rd, imm);
|
|
|
|
}
|
|
|
|
|
2021-05-15 07:41:28 -06:00
|
|
|
void ARM64FloatEmitter::ORR(u8 size, ARM64Reg Rd, u8 imm, u8 shift)
|
|
|
|
{
|
|
|
|
ORR_BIC(size, Rd, imm, shift, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::BIC(u8 size, ARM64Reg Rd, u8 imm, u8 shift)
|
|
|
|
{
|
|
|
|
ORR_BIC(size, Rd, imm, shift, 1);
|
|
|
|
}
|
|
|
|
|
2015-03-02 10:21:15 -07:00
|
|
|
void ARM64FloatEmitter::ABI_PushRegisters(BitSet32 registers, ARM64Reg tmp)
|
2015-01-07 12:42:36 -07:00
|
|
|
{
|
2015-02-28 03:39:15 -07:00
|
|
|
bool bundled_loadstore = false;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
for (int i = 0; i < 32; ++i)
|
|
|
|
{
|
|
|
|
if (!registers[i])
|
|
|
|
continue;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
int count = 0;
|
|
|
|
while (++count < 4 && (i + count) < 32 && registers[i + count])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
bundled_loadstore = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
if (bundled_loadstore && tmp != ARM64Reg::INVALID_REG)
|
2015-02-28 03:39:15 -07:00
|
|
|
{
|
2024-05-05 15:26:51 -06:00
|
|
|
DEBUG_ASSERT_MSG(DYNA_REC, Is64Bit(tmp), "Expected a 64-bit temporary register!");
|
|
|
|
|
2015-03-02 22:50:33 -07:00
|
|
|
int num_regs = registers.Count();
|
2021-02-06 11:50:33 -07:00
|
|
|
m_emit->SUB(ARM64Reg::SP, ARM64Reg::SP, num_regs * 16);
|
|
|
|
m_emit->ADD(tmp, ARM64Reg::SP, 0);
|
2015-03-02 22:50:33 -07:00
|
|
|
std::vector<ARM64Reg> island_regs;
|
2015-02-28 03:39:15 -07:00
|
|
|
for (int i = 0; i < 32; ++i)
|
|
|
|
{
|
|
|
|
if (!registers[i])
|
|
|
|
continue;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
int count = 0;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
// 0 = true
|
|
|
|
// 1 < 4 && registers[i + 1] true!
|
|
|
|
// 2 < 4 && registers[i + 2] true!
|
|
|
|
// 3 < 4 && registers[i + 3] true!
|
|
|
|
// 4 < 4 && registers[i + 4] false!
|
|
|
|
while (++count < 4 && (i + count) < 32 && registers[i + count])
|
|
|
|
{
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 22:50:33 -07:00
|
|
|
if (count == 1)
|
2021-02-06 11:50:33 -07:00
|
|
|
island_regs.push_back(ARM64Reg::Q0 + i);
|
2015-03-02 22:50:33 -07:00
|
|
|
else
|
2021-02-06 11:50:33 -07:00
|
|
|
ST1(64, count, IndexType::Post, ARM64Reg::Q0 + i, tmp);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
i += count - 1;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 22:50:33 -07:00
|
|
|
// Handle island registers
|
|
|
|
std::vector<ARM64Reg> pair_regs;
|
|
|
|
for (auto& it : island_regs)
|
|
|
|
{
|
|
|
|
pair_regs.push_back(it);
|
|
|
|
if (pair_regs.size() == 2)
|
|
|
|
{
|
2021-01-16 00:27:11 -07:00
|
|
|
STP(128, IndexType::Post, pair_regs[0], pair_regs[1], tmp, 32);
|
2015-03-02 22:50:33 -07:00
|
|
|
pair_regs.clear();
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2015-03-02 22:50:33 -07:00
|
|
|
if (pair_regs.size())
|
2021-01-16 00:27:11 -07:00
|
|
|
STR(128, IndexType::Post, pair_regs[0], tmp, 16);
|
2015-03-02 10:21:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-02 22:50:33 -07:00
|
|
|
std::vector<ARM64Reg> pair_regs;
|
2015-03-02 10:21:15 -07:00
|
|
|
for (auto it : registers)
|
2015-03-02 22:50:33 -07:00
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
pair_regs.push_back(ARM64Reg::Q0 + it);
|
2015-03-02 22:50:33 -07:00
|
|
|
if (pair_regs.size() == 2)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
STP(128, IndexType::Pre, pair_regs[0], pair_regs[1], ARM64Reg::SP, -32);
|
2015-03-02 22:50:33 -07:00
|
|
|
pair_regs.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pair_regs.size())
|
2021-02-06 11:50:33 -07:00
|
|
|
STR(128, IndexType::Pre, pair_regs[0], ARM64Reg::SP, -16);
|
2015-02-28 03:39:15 -07:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
2015-03-02 10:21:15 -07:00
|
|
|
void ARM64FloatEmitter::ABI_PopRegisters(BitSet32 registers, ARM64Reg tmp)
|
2015-01-07 12:42:36 -07:00
|
|
|
{
|
2015-02-28 03:39:15 -07:00
|
|
|
bool bundled_loadstore = false;
|
2015-03-02 02:41:45 -07:00
|
|
|
int num_regs = registers.Count();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
for (int i = 0; i < 32; ++i)
|
2015-01-07 12:42:36 -07:00
|
|
|
{
|
|
|
|
if (!registers[i])
|
|
|
|
continue;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-02-28 03:39:15 -07:00
|
|
|
int count = 0;
|
|
|
|
while (++count < 4 && (i + count) < 32 && registers[i + count])
|
|
|
|
{
|
|
|
|
}
|
|
|
|
if (count > 1)
|
|
|
|
{
|
|
|
|
bundled_loadstore = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
if (bundled_loadstore && tmp != ARM64Reg::INVALID_REG)
|
2015-02-28 03:39:15 -07:00
|
|
|
{
|
2015-03-02 10:21:15 -07:00
|
|
|
// The temporary register is only used to indicate that we can use this code path
|
2015-03-02 22:50:33 -07:00
|
|
|
std::vector<ARM64Reg> island_regs;
|
2015-03-02 10:21:15 -07:00
|
|
|
for (int i = 0; i < 32; ++i)
|
2015-02-28 03:39:15 -07:00
|
|
|
{
|
|
|
|
if (!registers[i])
|
|
|
|
continue;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 10:21:15 -07:00
|
|
|
int count = 0;
|
|
|
|
while (++count < 4 && (i + count) < 32 && registers[i + count])
|
|
|
|
{
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 22:50:33 -07:00
|
|
|
if (count == 1)
|
2021-02-06 11:50:33 -07:00
|
|
|
island_regs.push_back(ARM64Reg::Q0 + i);
|
2015-03-02 22:50:33 -07:00
|
|
|
else
|
2021-02-06 11:50:33 -07:00
|
|
|
LD1(64, count, IndexType::Post, ARM64Reg::Q0 + i, ARM64Reg::SP);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 10:21:15 -07:00
|
|
|
i += count - 1;
|
2015-02-28 03:39:15 -07:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 22:50:33 -07:00
|
|
|
// Handle island registers
|
|
|
|
std::vector<ARM64Reg> pair_regs;
|
|
|
|
for (auto& it : island_regs)
|
|
|
|
{
|
|
|
|
pair_regs.push_back(it);
|
|
|
|
if (pair_regs.size() == 2)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
LDP(128, IndexType::Post, pair_regs[0], pair_regs[1], ARM64Reg::SP, 32);
|
2015-03-02 22:50:33 -07:00
|
|
|
pair_regs.clear();
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2015-03-02 22:50:33 -07:00
|
|
|
if (pair_regs.size())
|
2021-02-06 11:50:33 -07:00
|
|
|
LDR(128, IndexType::Post, pair_regs[0], ARM64Reg::SP, 16);
|
2015-02-28 03:39:15 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-02 22:50:33 -07:00
|
|
|
bool odd = num_regs % 2;
|
|
|
|
std::vector<ARM64Reg> pair_regs;
|
2015-03-02 10:21:15 -07:00
|
|
|
for (int i = 31; i >= 0; --i)
|
2015-02-28 03:39:15 -07:00
|
|
|
{
|
|
|
|
if (!registers[i])
|
|
|
|
continue;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2015-03-02 22:50:33 -07:00
|
|
|
if (odd)
|
|
|
|
{
|
|
|
|
// First load must be a regular LDR if odd
|
|
|
|
odd = false;
|
2021-02-06 11:50:33 -07:00
|
|
|
LDR(128, IndexType::Post, ARM64Reg::Q0 + i, ARM64Reg::SP, 16);
|
2015-03-02 22:50:33 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
pair_regs.push_back(ARM64Reg::Q0 + i);
|
2015-03-02 22:50:33 -07:00
|
|
|
if (pair_regs.size() == 2)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
LDP(128, IndexType::Post, pair_regs[1], pair_regs[0], ARM64Reg::SP, 32);
|
2015-03-02 22:50:33 -07:00
|
|
|
pair_regs.clear();
|
|
|
|
}
|
|
|
|
}
|
2015-02-28 03:39:15 -07:00
|
|
|
}
|
2015-01-07 12:42:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64XEmitter::ANDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
|
|
|
{
|
|
|
|
if (!Is64Bit(Rn))
|
2023-12-17 09:51:46 -07:00
|
|
|
{
|
|
|
|
// To handle 32-bit logical immediates, the very easiest thing is to repeat
|
|
|
|
// the input value twice to make a 64-bit word. The correct encoding of that
|
|
|
|
// as a logical immediate will also be the correct encoding of the 32-bit
|
|
|
|
// value.
|
|
|
|
//
|
|
|
|
// Doing this here instead of in the LogicalImm constructor makes it easier
|
|
|
|
// to check if the input is all ones.
|
|
|
|
|
|
|
|
imm = (imm << 32) | (imm & 0xFFFFFFFF);
|
|
|
|
}
|
2020-12-30 17:59:48 -07:00
|
|
|
|
2023-12-21 12:51:32 -07:00
|
|
|
if (imm == 0)
|
2023-12-17 09:15:03 -07:00
|
|
|
{
|
2023-12-21 12:51:32 -07:00
|
|
|
MOVZ(Rd, 0);
|
2023-12-17 09:15:03 -07:00
|
|
|
}
|
2023-12-21 12:51:32 -07:00
|
|
|
else if ((~imm) == 0)
|
2023-12-17 09:24:13 -07:00
|
|
|
{
|
2023-12-21 12:51:32 -07:00
|
|
|
if (Rd != Rn)
|
|
|
|
MOV(Rd, Rn);
|
2023-12-17 09:24:13 -07:00
|
|
|
}
|
2023-12-17 09:51:46 -07:00
|
|
|
else if (const auto result = LogicalImm(imm, GPRSize::B64))
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2021-07-06 08:22:23 -06:00
|
|
|
AND(Rd, Rn, result);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, scratch != ARM64Reg::INVALID_REG,
|
2021-11-10 15:42:49 -07:00
|
|
|
"ANDI2R - failed to construct logical immediate value from {:#10x}, need scratch",
|
|
|
|
imm);
|
2015-06-07 15:57:57 -06:00
|
|
|
MOVI2R(scratch, imm);
|
|
|
|
AND(Rd, Rn, scratch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::ORRI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
|
|
|
{
|
2023-12-17 09:51:46 -07:00
|
|
|
if (!Is64Bit(Rn))
|
|
|
|
{
|
|
|
|
// To handle 32-bit logical immediates, the very easiest thing is to repeat
|
|
|
|
// the input value twice to make a 64-bit word. The correct encoding of that
|
|
|
|
// as a logical immediate will also be the correct encoding of the 32-bit
|
|
|
|
// value.
|
|
|
|
//
|
|
|
|
// Doing this here instead of in the LogicalImm constructor makes it easier
|
|
|
|
// to check if the input is all ones.
|
|
|
|
|
|
|
|
imm = (imm << 32) | (imm & 0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
2023-12-17 09:15:03 -07:00
|
|
|
if (imm == 0)
|
|
|
|
{
|
2023-12-21 12:51:32 -07:00
|
|
|
if (Rd != Rn)
|
|
|
|
MOV(Rd, Rn);
|
2023-12-17 09:15:03 -07:00
|
|
|
}
|
2023-12-17 09:51:46 -07:00
|
|
|
else if ((~imm) == 0)
|
2023-12-17 09:24:13 -07:00
|
|
|
{
|
|
|
|
MOVN(Rd, 0);
|
|
|
|
}
|
2023-12-17 09:51:46 -07:00
|
|
|
else if (const auto result = LogicalImm(imm, GPRSize::B64))
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2021-07-06 08:22:23 -06:00
|
|
|
ORR(Rd, Rn, result);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, scratch != ARM64Reg::INVALID_REG,
|
2021-11-10 15:42:49 -07:00
|
|
|
"ORRI2R - failed to construct logical immediate value from {:#10x}, need scratch",
|
|
|
|
imm);
|
2015-06-07 15:57:57 -06:00
|
|
|
MOVI2R(scratch, imm);
|
|
|
|
ORR(Rd, Rn, scratch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::EORI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
|
|
|
{
|
2023-12-17 09:51:46 -07:00
|
|
|
if (!Is64Bit(Rn))
|
|
|
|
{
|
|
|
|
// To handle 32-bit logical immediates, the very easiest thing is to repeat
|
|
|
|
// the input value twice to make a 64-bit word. The correct encoding of that
|
|
|
|
// as a logical immediate will also be the correct encoding of the 32-bit
|
|
|
|
// value.
|
|
|
|
//
|
|
|
|
// Doing this here instead of in the LogicalImm constructor makes it easier
|
|
|
|
// to check if the input is all ones.
|
|
|
|
|
|
|
|
imm = (imm << 32) | (imm & 0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
2023-12-17 09:15:03 -07:00
|
|
|
if (imm == 0)
|
|
|
|
{
|
2023-12-21 12:51:32 -07:00
|
|
|
if (Rd != Rn)
|
|
|
|
MOV(Rd, Rn);
|
2023-12-17 09:15:03 -07:00
|
|
|
}
|
2023-12-17 09:51:46 -07:00
|
|
|
else if ((~imm) == 0)
|
2023-12-17 09:24:13 -07:00
|
|
|
{
|
|
|
|
MVN(Rd, Rn);
|
|
|
|
}
|
2023-12-17 09:51:46 -07:00
|
|
|
else if (const auto result = LogicalImm(imm, GPRSize::B64))
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2021-07-06 08:22:23 -06:00
|
|
|
EOR(Rd, Rn, result);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, scratch != ARM64Reg::INVALID_REG,
|
2021-11-10 15:42:49 -07:00
|
|
|
"EORI2R - failed to construct logical immediate value from {:#10x}, need scratch",
|
|
|
|
imm);
|
2015-06-07 15:57:57 -06:00
|
|
|
MOVI2R(scratch, imm);
|
|
|
|
EOR(Rd, Rn, scratch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::ANDSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
|
|
|
{
|
2023-12-17 09:51:46 -07:00
|
|
|
if (!Is64Bit(Rn))
|
|
|
|
{
|
|
|
|
// To handle 32-bit logical immediates, the very easiest thing is to repeat
|
|
|
|
// the input value twice to make a 64-bit word. The correct encoding of that
|
|
|
|
// as a logical immediate will also be the correct encoding of the 32-bit
|
|
|
|
// value.
|
|
|
|
//
|
|
|
|
// Doing this here instead of in the LogicalImm constructor makes it easier
|
|
|
|
// to check if the input is all ones.
|
|
|
|
|
|
|
|
imm = (imm << 32) | (imm & 0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
|
2023-12-17 09:24:13 -07:00
|
|
|
if (imm == 0)
|
|
|
|
{
|
|
|
|
ANDS(Rd, Is64Bit(Rn) ? ARM64Reg::ZR : ARM64Reg::WZR,
|
|
|
|
Is64Bit(Rn) ? ARM64Reg::ZR : ARM64Reg::WZR);
|
|
|
|
}
|
2023-12-17 09:51:46 -07:00
|
|
|
else if ((~imm) == 0)
|
2023-12-17 09:24:13 -07:00
|
|
|
{
|
|
|
|
ANDS(Rd, Rn, Rn);
|
|
|
|
}
|
2023-12-17 09:51:46 -07:00
|
|
|
else if (const auto result = LogicalImm(imm, GPRSize::B64))
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2021-07-06 08:22:23 -06:00
|
|
|
ANDS(Rd, Rn, result);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, scratch != ARM64Reg::INVALID_REG,
|
2021-11-10 15:42:49 -07:00
|
|
|
"ANDSI2R - failed to construct logical immediate value from {:#10x}, need scratch",
|
|
|
|
imm);
|
2015-06-07 15:57:57 -06:00
|
|
|
MOVI2R(scratch, imm);
|
|
|
|
ANDS(Rd, Rn, scratch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Arm64Emitter: extract lambda to AddImmediate()
Fixes warning:
```
Source/Core/Common/Arm64Emitter.cpp:4108:31: error: declaration shadows a local variable [-Werror,-Wshadow]
auto addi = [this](ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags) {
^
/var/lib/buildbot/slave/pr-android/build/Source/Core/Common/Arm64Emitter.cpp:4105:46: note: previous declaration is here
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
^
```
2017-03-25 15:04:31 -06:00
|
|
|
void ARM64XEmitter::AddImmediate(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative,
|
|
|
|
bool flags)
|
|
|
|
{
|
2019-11-25 21:31:45 -07:00
|
|
|
if (!negative)
|
Arm64Emitter: extract lambda to AddImmediate()
Fixes warning:
```
Source/Core/Common/Arm64Emitter.cpp:4108:31: error: declaration shadows a local variable [-Werror,-Wshadow]
auto addi = [this](ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags) {
^
/var/lib/buildbot/slave/pr-android/build/Source/Core/Common/Arm64Emitter.cpp:4105:46: note: previous declaration is here
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
^
```
2017-03-25 15:04:31 -06:00
|
|
|
{
|
2019-11-25 21:31:45 -07:00
|
|
|
if (!flags)
|
|
|
|
ADD(Rd, Rn, imm, shift);
|
|
|
|
else
|
|
|
|
ADDS(Rd, Rn, imm, shift);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!flags)
|
|
|
|
SUB(Rd, Rn, imm, shift);
|
|
|
|
else
|
|
|
|
SUBS(Rd, Rn, imm, shift);
|
Arm64Emitter: extract lambda to AddImmediate()
Fixes warning:
```
Source/Core/Common/Arm64Emitter.cpp:4108:31: error: declaration shadows a local variable [-Werror,-Wshadow]
auto addi = [this](ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags) {
^
/var/lib/buildbot/slave/pr-android/build/Source/Core/Common/Arm64Emitter.cpp:4105:46: note: previous declaration is here
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
^
```
2017-03-25 15:04:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 10:11:51 -06:00
|
|
|
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
|
|
|
|
ARM64Reg scratch)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2023-12-01 13:26:22 -07:00
|
|
|
DEBUG_ASSERT(Is64Bit(Rd) == Is64Bit(Rn));
|
|
|
|
|
2023-12-01 13:18:37 -07:00
|
|
|
if (!Is64Bit(Rd))
|
|
|
|
imm &= 0xFFFFFFFFULL;
|
|
|
|
|
2021-02-06 11:50:33 -07:00
|
|
|
bool has_scratch = scratch != ARM64Reg::INVALID_REG;
|
2019-11-25 21:31:45 -07:00
|
|
|
u64 imm_neg = Is64Bit(Rd) ? u64(-s64(imm)) : u64(-s64(imm)) & 0xFFFFFFFFuLL;
|
2016-10-27 10:11:51 -06:00
|
|
|
bool neg_neg = negative ? false : true;
|
|
|
|
|
2023-12-01 13:26:22 -07:00
|
|
|
// Special path for zeroes
|
|
|
|
if (imm == 0 && !flags)
|
|
|
|
{
|
2024-02-06 13:58:07 -07:00
|
|
|
if (Rd == Rn)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (DecodeReg(Rd) != DecodeReg(ARM64Reg::SP) && DecodeReg(Rn) != DecodeReg(ARM64Reg::SP))
|
|
|
|
{
|
2023-12-01 13:26:22 -07:00
|
|
|
MOV(Rd, Rn);
|
2024-02-06 13:58:07 -07:00
|
|
|
return;
|
|
|
|
}
|
2023-12-01 13:26:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Regular fast paths, aarch64 immediate instructions
|
2016-10-27 10:11:51 -06:00
|
|
|
// Try them all first
|
|
|
|
if (imm <= 0xFFF)
|
2016-10-26 13:17:29 -06:00
|
|
|
{
|
Arm64Emitter: extract lambda to AddImmediate()
Fixes warning:
```
Source/Core/Common/Arm64Emitter.cpp:4108:31: error: declaration shadows a local variable [-Werror,-Wshadow]
auto addi = [this](ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags) {
^
/var/lib/buildbot/slave/pr-android/build/Source/Core/Common/Arm64Emitter.cpp:4105:46: note: previous declaration is here
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
^
```
2017-03-25 15:04:31 -06:00
|
|
|
AddImmediate(Rd, Rn, imm, false, negative, flags);
|
2016-10-27 10:11:51 -06:00
|
|
|
return;
|
2016-10-26 13:17:29 -06:00
|
|
|
}
|
2016-10-27 10:11:51 -06:00
|
|
|
if (imm <= 0xFFFFFF && (imm & 0xFFF) == 0)
|
2016-10-27 01:14:01 -06:00
|
|
|
{
|
Arm64Emitter: extract lambda to AddImmediate()
Fixes warning:
```
Source/Core/Common/Arm64Emitter.cpp:4108:31: error: declaration shadows a local variable [-Werror,-Wshadow]
auto addi = [this](ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags) {
^
/var/lib/buildbot/slave/pr-android/build/Source/Core/Common/Arm64Emitter.cpp:4105:46: note: previous declaration is here
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
^
```
2017-03-25 15:04:31 -06:00
|
|
|
AddImmediate(Rd, Rn, imm >> 12, true, negative, flags);
|
2016-10-27 10:11:51 -06:00
|
|
|
return;
|
2016-10-27 01:14:01 -06:00
|
|
|
}
|
2016-10-27 10:11:51 -06:00
|
|
|
if (imm_neg <= 0xFFF)
|
2016-10-27 01:14:01 -06:00
|
|
|
{
|
Arm64Emitter: extract lambda to AddImmediate()
Fixes warning:
```
Source/Core/Common/Arm64Emitter.cpp:4108:31: error: declaration shadows a local variable [-Werror,-Wshadow]
auto addi = [this](ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags) {
^
/var/lib/buildbot/slave/pr-android/build/Source/Core/Common/Arm64Emitter.cpp:4105:46: note: previous declaration is here
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
^
```
2017-03-25 15:04:31 -06:00
|
|
|
AddImmediate(Rd, Rn, imm_neg, false, neg_neg, flags);
|
2016-10-27 10:11:51 -06:00
|
|
|
return;
|
2016-10-27 01:14:01 -06:00
|
|
|
}
|
2016-10-27 10:11:51 -06:00
|
|
|
if (imm_neg <= 0xFFFFFF && (imm_neg & 0xFFF) == 0)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
Arm64Emitter: extract lambda to AddImmediate()
Fixes warning:
```
Source/Core/Common/Arm64Emitter.cpp:4108:31: error: declaration shadows a local variable [-Werror,-Wshadow]
auto addi = [this](ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags) {
^
/var/lib/buildbot/slave/pr-android/build/Source/Core/Common/Arm64Emitter.cpp:4105:46: note: previous declaration is here
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
^
```
2017-03-25 15:04:31 -06:00
|
|
|
AddImmediate(Rd, Rn, imm_neg >> 12, true, neg_neg, flags);
|
2016-10-27 10:11:51 -06:00
|
|
|
return;
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2016-10-27 10:11:51 -06:00
|
|
|
// ADD+ADD is slower than MOVK+ADD, but inplace.
|
|
|
|
// But it supports a few more bits, so use it to avoid MOVK+MOVK+ADD.
|
|
|
|
// As this splits the addition in two parts, this must not be done on setting flags.
|
|
|
|
if (!flags && (imm >= 0x10000u || !has_scratch) && imm < 0x1000000u)
|
2016-10-26 12:47:03 -06:00
|
|
|
{
|
Arm64Emitter: extract lambda to AddImmediate()
Fixes warning:
```
Source/Core/Common/Arm64Emitter.cpp:4108:31: error: declaration shadows a local variable [-Werror,-Wshadow]
auto addi = [this](ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags) {
^
/var/lib/buildbot/slave/pr-android/build/Source/Core/Common/Arm64Emitter.cpp:4105:46: note: previous declaration is here
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
^
```
2017-03-25 15:04:31 -06:00
|
|
|
AddImmediate(Rd, Rn, imm & 0xFFF, false, negative, false);
|
|
|
|
AddImmediate(Rd, Rd, imm >> 12, true, negative, false);
|
2016-10-27 10:11:51 -06:00
|
|
|
return;
|
2016-10-26 12:47:03 -06:00
|
|
|
}
|
2016-10-27 10:11:51 -06:00
|
|
|
if (!flags && (imm_neg >= 0x10000u || !has_scratch) && imm_neg < 0x1000000u)
|
2016-10-26 13:17:29 -06:00
|
|
|
{
|
Arm64Emitter: extract lambda to AddImmediate()
Fixes warning:
```
Source/Core/Common/Arm64Emitter.cpp:4108:31: error: declaration shadows a local variable [-Werror,-Wshadow]
auto addi = [this](ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool shift, bool negative, bool flags) {
^
/var/lib/buildbot/slave/pr-android/build/Source/Core/Common/Arm64Emitter.cpp:4105:46: note: previous declaration is here
void ARM64XEmitter::ADDI2R_internal(ARM64Reg Rd, ARM64Reg Rn, u64 imm, bool negative, bool flags,
^
```
2017-03-25 15:04:31 -06:00
|
|
|
AddImmediate(Rd, Rn, imm_neg & 0xFFF, false, neg_neg, false);
|
|
|
|
AddImmediate(Rd, Rd, imm_neg >> 12, true, neg_neg, false);
|
2016-10-27 10:11:51 -06:00
|
|
|
return;
|
2016-10-26 13:17:29 -06:00
|
|
|
}
|
2016-10-27 10:11:51 -06:00
|
|
|
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, has_scratch,
|
2021-11-10 15:42:49 -07:00
|
|
|
"ADDI2R - failed to construct arithmetic immediate value from {:#10x}, need scratch",
|
|
|
|
imm);
|
2016-10-27 10:11:51 -06:00
|
|
|
|
|
|
|
negative ^= MOVI2R2(scratch, imm, imm_neg);
|
2019-11-25 21:31:45 -07:00
|
|
|
if (!negative)
|
2016-10-26 12:47:03 -06:00
|
|
|
{
|
2019-11-25 21:31:45 -07:00
|
|
|
if (!flags)
|
|
|
|
ADD(Rd, Rn, scratch);
|
|
|
|
else
|
|
|
|
ADDS(Rd, Rn, scratch);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!flags)
|
|
|
|
SUB(Rd, Rn, scratch);
|
|
|
|
else
|
|
|
|
SUBS(Rd, Rn, scratch);
|
2016-10-26 12:47:03 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 10:11:51 -06:00
|
|
|
void ARM64XEmitter::ADDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
|
|
|
{
|
|
|
|
ADDI2R_internal(Rd, Rn, imm, false, false, scratch);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64XEmitter::ADDSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
|
|
|
{
|
|
|
|
ADDI2R_internal(Rd, Rn, imm, false, true, scratch);
|
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64XEmitter::SUBI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
|
|
|
{
|
2016-10-27 10:11:51 -06:00
|
|
|
ADDI2R_internal(Rd, Rn, imm, true, false, scratch);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2016-10-26 12:47:03 -06:00
|
|
|
void ARM64XEmitter::SUBSI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
|
|
|
{
|
2016-10-27 10:11:51 -06:00
|
|
|
ADDI2R_internal(Rd, Rn, imm, true, true, scratch);
|
2016-10-26 12:47:03 -06:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:57:57 -06:00
|
|
|
void ARM64XEmitter::CMPI2R(ARM64Reg Rn, u64 imm, ARM64Reg scratch)
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ADDI2R_internal(Is64Bit(Rn) ? ARM64Reg::ZR : ARM64Reg::WZR, Rn, imm, true, true, scratch);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2021-01-03 05:36:37 -07:00
|
|
|
bool ARM64XEmitter::TryADDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2020-12-30 17:59:48 -07:00
|
|
|
if (const auto result = IsImmArithmetic(imm))
|
|
|
|
{
|
|
|
|
const auto [val, shift] = *result;
|
2015-06-07 15:57:57 -06:00
|
|
|
ADD(Rd, Rn, val, shift);
|
2020-12-30 17:59:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
|
2020-12-30 17:59:48 -07:00
|
|
|
return false;
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2021-01-03 05:36:37 -07:00
|
|
|
bool ARM64XEmitter::TrySUBI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2020-12-30 17:59:48 -07:00
|
|
|
if (const auto result = IsImmArithmetic(imm))
|
|
|
|
{
|
|
|
|
const auto [val, shift] = *result;
|
2015-06-07 15:57:57 -06:00
|
|
|
SUB(Rd, Rn, val, shift);
|
2020-12-30 17:59:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
|
2020-12-30 17:59:48 -07:00
|
|
|
return false;
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2021-01-03 05:36:37 -07:00
|
|
|
bool ARM64XEmitter::TryCMPI2R(ARM64Reg Rn, u64 imm)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2020-12-30 17:59:48 -07:00
|
|
|
if (const auto result = IsImmArithmetic(imm))
|
|
|
|
{
|
|
|
|
const auto [val, shift] = *result;
|
2015-06-07 15:57:57 -06:00
|
|
|
CMP(Rn, val, shift);
|
2020-12-30 17:59:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
|
2020-12-30 17:59:48 -07:00
|
|
|
return false;
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
2021-01-03 05:36:37 -07:00
|
|
|
bool ARM64XEmitter::TryANDI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2023-12-16 05:27:13 -07:00
|
|
|
if (const auto result = LogicalImm(imm, Is64Bit(Rd) ? GPRSize::B64 : GPRSize::B32))
|
2020-12-30 17:59:48 -07:00
|
|
|
{
|
2021-07-06 08:22:23 -06:00
|
|
|
AND(Rd, Rn, result);
|
2020-12-30 17:59:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
|
2020-12-30 17:59:48 -07:00
|
|
|
return false;
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
2021-01-03 05:36:37 -07:00
|
|
|
|
|
|
|
bool ARM64XEmitter::TryORRI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2023-12-16 05:27:13 -07:00
|
|
|
if (const auto result = LogicalImm(imm, Is64Bit(Rd) ? GPRSize::B64 : GPRSize::B32))
|
2020-12-30 17:59:48 -07:00
|
|
|
{
|
2021-07-06 08:22:23 -06:00
|
|
|
ORR(Rd, Rn, result);
|
2020-12-30 17:59:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
|
2020-12-30 17:59:48 -07:00
|
|
|
return false;
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
2021-01-03 05:36:37 -07:00
|
|
|
|
|
|
|
bool ARM64XEmitter::TryEORI2R(ARM64Reg Rd, ARM64Reg Rn, u64 imm)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2023-12-16 05:27:13 -07:00
|
|
|
if (const auto result = LogicalImm(imm, Is64Bit(Rd) ? GPRSize::B64 : GPRSize::B32))
|
2020-12-30 17:59:48 -07:00
|
|
|
{
|
2021-07-06 08:22:23 -06:00
|
|
|
EOR(Rd, Rn, result);
|
2020-12-30 17:59:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-07 15:57:57 -06:00
|
|
|
|
2020-12-30 17:59:48 -07:00
|
|
|
return false;
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM64FloatEmitter::MOVI2F(ARM64Reg Rd, float value, ARM64Reg scratch, bool negate)
|
|
|
|
{
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT_MSG(DYNA_REC, !IsDouble(Rd), "MOVI2F does not yet support double precision");
|
2020-12-30 17:59:48 -07:00
|
|
|
|
|
|
|
if (value == 0.0f)
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
FMOV(Rd, IsDouble(Rd) ? ARM64Reg::ZR : ARM64Reg::WZR);
|
2015-06-07 15:57:57 -06:00
|
|
|
if (negate)
|
|
|
|
FNEG(Rd, Rd);
|
|
|
|
// TODO: There are some other values we could generate with the float-imm instruction, like
|
|
|
|
// 1.0...
|
|
|
|
}
|
2020-12-30 17:59:48 -07:00
|
|
|
else if (const auto imm = FPImm8FromFloat(value))
|
2015-06-07 15:57:57 -06:00
|
|
|
{
|
2020-12-30 17:59:48 -07:00
|
|
|
FMOV(Rd, *imm);
|
2015-06-07 15:57:57 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-06 11:50:33 -07:00
|
|
|
ASSERT_MSG(DYNA_REC, scratch != ARM64Reg::INVALID_REG,
|
2021-11-10 15:42:49 -07:00
|
|
|
"Failed to find a way to generate FP immediate {} without scratch", value);
|
2015-06-07 15:57:57 -06:00
|
|
|
if (negate)
|
|
|
|
value = -value;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2022-08-05 22:10:17 -06:00
|
|
|
const u32 ival = std::bit_cast<u32>(value);
|
2015-06-07 15:57:57 -06:00
|
|
|
m_emit->MOVI2R(scratch, ival);
|
|
|
|
FMOV(Rd, scratch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Quite a few values could be generated easily using the MOVI instruction and friends.
|
|
|
|
void ARM64FloatEmitter::MOVI2FDUP(ARM64Reg Rd, float value, ARM64Reg scratch)
|
|
|
|
{
|
|
|
|
// TODO: Make it work with more element sizes
|
|
|
|
// TODO: Optimize - there are shorter solution for many values
|
2021-02-06 11:50:33 -07:00
|
|
|
ARM64Reg s = ARM64Reg::S0 + DecodeReg(Rd);
|
2015-06-07 15:57:57 -06:00
|
|
|
MOVI2F(s, value, scratch);
|
|
|
|
DUP(32, Rd, Rd, 0);
|
|
|
|
}
|
|
|
|
|
2019-05-05 17:48:12 -06:00
|
|
|
} // namespace Arm64Gen
|