2018-12-13 22:11:55 +00:00
|
|
|
/*
|
2019-05-18 12:21:47 +00:00
|
|
|
Copyright (c) 2018-2019, tevador <tevador@gmail.com>
|
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
* Neither the name of the copyright holder nor the
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2018-12-13 22:11:55 +00:00
|
|
|
*/
|
2019-02-22 16:48:26 +00:00
|
|
|
|
2019-03-17 22:09:11 +00:00
|
|
|
#include <climits>
|
2019-04-20 14:53:06 +00:00
|
|
|
#include "assembly_generator_x86.hpp"
|
2018-12-13 22:11:55 +00:00
|
|
|
#include "common.hpp"
|
2019-02-22 16:48:26 +00:00
|
|
|
#include "reciprocal.h"
|
2019-04-20 14:53:06 +00:00
|
|
|
#include "program.hpp"
|
|
|
|
#include "superscalar.hpp"
|
2018-12-13 22:11:55 +00:00
|
|
|
|
2019-04-20 09:08:01 +00:00
|
|
|
namespace randomx {
|
2018-12-13 22:11:55 +00:00
|
|
|
|
2019-04-28 14:42:45 +00:00
|
|
|
static const char* regR[] = { "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" };
|
|
|
|
static const char* regR32[] = { "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d" };
|
|
|
|
static const char* regFE[] = { "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" };
|
|
|
|
static const char* regF[] = { "xmm0", "xmm1", "xmm2", "xmm3" };
|
|
|
|
static const char* regE[] = { "xmm4", "xmm5", "xmm6", "xmm7" };
|
|
|
|
static const char* regA[] = { "xmm8", "xmm9", "xmm10", "xmm11" };
|
2019-01-24 18:29:59 +00:00
|
|
|
|
2019-04-26 09:07:47 +00:00
|
|
|
static const char* tempRegx = "xmm12";
|
2019-04-30 19:14:50 +00:00
|
|
|
static const char* mantissaMaskReg = "xmm13";
|
|
|
|
static const char* exponentMaskReg = "xmm14";
|
|
|
|
static const char* scaleMaskReg = "xmm15";
|
2019-01-24 18:29:59 +00:00
|
|
|
static const char* regIc = "rbx";
|
|
|
|
static const char* regIc32 = "ebx";
|
2019-01-08 13:50:31 +00:00
|
|
|
static const char* regIc8 = "bl";
|
2019-01-04 18:44:15 +00:00
|
|
|
static const char* regScratchpadAddr = "rsi";
|
|
|
|
|
2019-04-07 13:38:51 +00:00
|
|
|
void AssemblyGeneratorX86::generateProgram(Program& prog) {
|
2019-04-29 21:38:23 +00:00
|
|
|
for (unsigned i = 0; i < RegistersCount; ++i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[i].lastUsed = -1;
|
|
|
|
registerUsage[i].count = 0;
|
2019-04-07 13:38:51 +00:00
|
|
|
}
|
|
|
|
asmCode.str(std::string()); //clear
|
|
|
|
for (unsigned i = 0; i < prog.getSize(); ++i) {
|
|
|
|
asmCode << "randomx_isn_" << i << ":" << std::endl;
|
|
|
|
Instruction& instr = prog(i);
|
|
|
|
instr.src %= RegistersCount;
|
|
|
|
instr.dst %= RegistersCount;
|
|
|
|
generateCode(instr, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 17:36:08 +00:00
|
|
|
void AssemblyGeneratorX86::generateAsm(SuperscalarProgram& prog) {
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode.str(std::string()); //clear
|
|
|
|
asmCode << "ALIGN 16" << std::endl;
|
|
|
|
for (unsigned i = 0; i < prog.getSize(); ++i) {
|
|
|
|
Instruction& instr = prog(i);
|
|
|
|
switch (instr.opcode)
|
|
|
|
{
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::ISUB_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "sub " << regR[instr.dst] << ", " << regR[instr.src] << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IXOR_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "xor " << regR[instr.dst] << ", " << regR[instr.src] << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IADD_RS:
|
2019-05-01 12:46:51 +00:00
|
|
|
asmCode << "lea " << regR[instr.dst] << ", [" << regR[instr.dst] << "+" << regR[instr.src] << "*" << (1 << (instr.getModShift())) << "]" << std::endl;
|
2019-04-07 13:38:51 +00:00
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IMUL_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "imul " << regR[instr.dst] << ", " << regR[instr.src] << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IROR_C:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "ror " << regR[instr.dst] << ", " << instr.getImm32() << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IADD_C7:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "add " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IXOR_C7:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "xor " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IADD_C8:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "add " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl;
|
|
|
|
asmCode << "nop" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IXOR_C8:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "xor " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl;
|
|
|
|
asmCode << "nop" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IADD_C9:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "add " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl;
|
|
|
|
asmCode << "xchg ax, ax ;nop" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IXOR_C9:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "xor " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl;
|
|
|
|
asmCode << "xchg ax, ax ;nop" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IMULH_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "mov rax, " << regR[instr.dst] << std::endl;
|
|
|
|
asmCode << "mul " << regR[instr.src] << std::endl;
|
|
|
|
asmCode << "mov " << regR[instr.dst] << ", rdx" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::ISMULH_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "mov rax, " << regR[instr.dst] << std::endl;
|
|
|
|
asmCode << "imul " << regR[instr.src] << std::endl;
|
|
|
|
asmCode << "mov " << regR[instr.dst] << ", rdx" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IMUL_RCP:
|
2019-04-20 14:53:06 +00:00
|
|
|
asmCode << "mov rax, " << (int64_t)randomx_reciprocal(instr.getImm32()) << std::endl;
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << "imul " << regR[instr.dst] << ", rax" << std::endl;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-12 17:36:08 +00:00
|
|
|
void AssemblyGeneratorX86::generateC(SuperscalarProgram& prog) {
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode.str(std::string()); //clear
|
|
|
|
asmCode << "#include <stdint.h>" << std::endl;
|
|
|
|
asmCode << "#if defined(__SIZEOF_INT128__)" << std::endl;
|
|
|
|
asmCode << " static inline uint64_t mulh(uint64_t a, uint64_t b) {" << std::endl;
|
|
|
|
asmCode << " return ((unsigned __int128)a * b) >> 64;" << std::endl;
|
|
|
|
asmCode << " }" << std::endl;
|
|
|
|
asmCode << " static inline int64_t smulh(int64_t a, int64_t b) {" << std::endl;
|
|
|
|
asmCode << " return ((__int128)a * b) >> 64;" << std::endl;
|
|
|
|
asmCode << " }" << std::endl;
|
|
|
|
asmCode << " #define HAVE_MULH" << std::endl;
|
|
|
|
asmCode << " #define HAVE_SMULH" << std::endl;
|
|
|
|
asmCode << "#endif" << std::endl;
|
|
|
|
asmCode << "#if defined(_MSC_VER)" << std::endl;
|
|
|
|
asmCode << " #define HAS_VALUE(X) X ## 0" << std::endl;
|
|
|
|
asmCode << " #define EVAL_DEFINE(X) HAS_VALUE(X)" << std::endl;
|
|
|
|
asmCode << " #include <intrin.h>" << std::endl;
|
|
|
|
asmCode << " #include <stdlib.h>" << std::endl;
|
|
|
|
asmCode << " static __inline uint64_t rotr(uint64_t x , int c) {" << std::endl;
|
|
|
|
asmCode << " return _rotr64(x, c);" << std::endl;
|
|
|
|
asmCode << " }" << std::endl;
|
|
|
|
asmCode << " #define HAVE_ROTR" << std::endl;
|
|
|
|
asmCode << " #if EVAL_DEFINE(__MACHINEARM64_X64(1))" << std::endl;
|
|
|
|
asmCode << " static __inline uint64_t mulh(uint64_t a, uint64_t b) {" << std::endl;
|
|
|
|
asmCode << " return __umulh(a, b);" << std::endl;
|
|
|
|
asmCode << " }" << std::endl;
|
|
|
|
asmCode << " #define HAVE_MULH" << std::endl;
|
|
|
|
asmCode << " #endif" << std::endl;
|
|
|
|
asmCode << " #if EVAL_DEFINE(__MACHINEX64(1))" << std::endl;
|
|
|
|
asmCode << " static __inline int64_t smulh(int64_t a, int64_t b) {" << std::endl;
|
|
|
|
asmCode << " int64_t hi;" << std::endl;
|
|
|
|
asmCode << " _mul128(a, b, &hi);" << std::endl;
|
|
|
|
asmCode << " return hi;" << std::endl;
|
|
|
|
asmCode << " }" << std::endl;
|
|
|
|
asmCode << " #define HAVE_SMULH" << std::endl;
|
|
|
|
asmCode << " #endif" << std::endl;
|
|
|
|
asmCode << "#endif" << std::endl;
|
|
|
|
asmCode << "#ifndef HAVE_ROTR" << std::endl;
|
|
|
|
asmCode << " static inline uint64_t rotr(uint64_t a, int b) {" << std::endl;
|
|
|
|
asmCode << " return (a >> b) | (a << (64 - b));" << std::endl;
|
|
|
|
asmCode << " }" << std::endl;
|
|
|
|
asmCode << " #define HAVE_ROTR" << std::endl;
|
|
|
|
asmCode << "#endif" << std::endl;
|
|
|
|
asmCode << "#if !defined(HAVE_MULH) || !defined(HAVE_SMULH) || !defined(HAVE_ROTR)" << std::endl;
|
|
|
|
asmCode << " #error \"Required functions are not defined\"" << std::endl;
|
|
|
|
asmCode << "#endif" << std::endl;
|
|
|
|
asmCode << "void superScalar(uint64_t r[8]) {" << std::endl;
|
|
|
|
asmCode << "uint64_t r8 = r[0], r9 = r[1], r10 = r[2], r11 = r[3], r12 = r[4], r13 = r[5], r14 = r[6], r15 = r[7];" << std::endl;
|
|
|
|
for (unsigned i = 0; i < prog.getSize(); ++i) {
|
|
|
|
Instruction& instr = prog(i);
|
|
|
|
switch (instr.opcode)
|
|
|
|
{
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::ISUB_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << regR[instr.dst] << " -= " << regR[instr.src] << ";" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IXOR_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << regR[instr.dst] << " ^= " << regR[instr.src] << ";" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IADD_RS:
|
2019-05-01 12:46:51 +00:00
|
|
|
asmCode << regR[instr.dst] << " += " << regR[instr.src] << "*" << (1 << (instr.getModShift())) << ";" << std::endl;
|
2019-04-07 13:38:51 +00:00
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IMUL_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << regR[instr.dst] << " *= " << regR[instr.src] << ";" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IROR_C:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << regR[instr.dst] << " = rotr(" << regR[instr.dst] << ", " << instr.getImm32() << ");" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IADD_C7:
|
|
|
|
case SuperscalarInstructionType::IADD_C8:
|
|
|
|
case SuperscalarInstructionType::IADD_C9:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << regR[instr.dst] << " += " << (int32_t)instr.getImm32() << ";" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IXOR_C7:
|
|
|
|
case SuperscalarInstructionType::IXOR_C8:
|
|
|
|
case SuperscalarInstructionType::IXOR_C9:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << regR[instr.dst] << " ^= " << (int32_t)instr.getImm32() << ";" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IMULH_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << regR[instr.dst] << " = mulh(" << regR[instr.dst] << ", " << regR[instr.src] << ");" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::ISMULH_R:
|
2019-04-07 13:38:51 +00:00
|
|
|
asmCode << regR[instr.dst] << " = smulh(" << regR[instr.dst] << ", " << regR[instr.src] << ");" << std::endl;
|
|
|
|
break;
|
2019-04-20 09:08:01 +00:00
|
|
|
case SuperscalarInstructionType::IMUL_RCP:
|
2019-04-20 14:53:06 +00:00
|
|
|
asmCode << regR[instr.dst] << " *= " << (int64_t)randomx_reciprocal(instr.getImm32()) << ";" << std::endl;
|
2019-04-07 13:38:51 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
asmCode << "r[0] = r8; r[1] = r9; r[2] = r10; r[3] = r11; r[4] = r12; r[5] = r13; r[6] = r14; r[7] = r15;" << std::endl;
|
|
|
|
asmCode << "}" << std::endl;
|
|
|
|
}
|
|
|
|
|
2019-02-16 22:18:45 +00:00
|
|
|
void AssemblyGeneratorX86::traceint(Instruction& instr) {
|
|
|
|
if (trace) {
|
|
|
|
asmCode << "\tpush " << regR[instr.dst] << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AssemblyGeneratorX86::traceflt(Instruction& instr) {
|
|
|
|
if (trace) {
|
|
|
|
asmCode << "\tpush 0" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AssemblyGeneratorX86::tracenop(Instruction& instr) {
|
|
|
|
if (trace) {
|
|
|
|
asmCode << "\tpush 0" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-13 22:11:55 +00:00
|
|
|
void AssemblyGeneratorX86::generateCode(Instruction& instr, int i) {
|
2019-01-24 18:29:59 +00:00
|
|
|
asmCode << "\t; " << instr;
|
2018-12-13 22:11:55 +00:00
|
|
|
auto generator = engine[instr.opcode];
|
|
|
|
(this->*generator)(instr, i);
|
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::genAddressReg(Instruction& instr, const char* reg = "eax") {
|
2019-04-14 15:21:26 +00:00
|
|
|
asmCode << "\tlea " << reg << ", [" << regR32[instr.src] << std::showpos << (int32_t)instr.getImm32() << std::noshowpos << "]" << std::endl;
|
2019-04-16 16:58:44 +00:00
|
|
|
asmCode << "\tand " << reg << ", " << ((instr.getModMem()) ? ScratchpadL1Mask : ScratchpadL2Mask) << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 09:52:30 +00:00
|
|
|
void AssemblyGeneratorX86::genAddressRegDst(Instruction& instr, int maskAlign = 8) {
|
2019-04-14 15:21:26 +00:00
|
|
|
asmCode << "\tlea eax, [" << regR32[instr.dst] << std::showpos << (int32_t)instr.getImm32() << std::noshowpos << "]" << std::endl;
|
2019-04-16 16:58:44 +00:00
|
|
|
int mask;
|
2019-04-29 21:38:23 +00:00
|
|
|
if (instr.getModCond() < StoreL3Condition) {
|
2019-04-16 16:58:44 +00:00
|
|
|
mask = instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mask = ScratchpadL3Mask;
|
|
|
|
}
|
|
|
|
asmCode << "\tand eax" << ", " << (mask & (-maskAlign)) << std::endl;
|
2019-01-27 09:52:30 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
int32_t AssemblyGeneratorX86::genAddressImm(Instruction& instr) {
|
2019-03-11 22:04:34 +00:00
|
|
|
return (int32_t)instr.getImm32() & ScratchpadL3Mask;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
|
|
|
|
2019-04-06 10:00:56 +00:00
|
|
|
void AssemblyGeneratorX86::h_IADD_RS(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-04-14 15:21:26 +00:00
|
|
|
if(instr.dst == RegisterNeedsDisplacement)
|
2019-04-29 21:38:23 +00:00
|
|
|
asmCode << "\tlea " << regR[instr.dst] << ", [" << regR[instr.dst] << "+" << regR[instr.src] << "*" << (1 << (instr.getModShift())) << std::showpos << (int32_t)instr.getImm32() << std::noshowpos << "]" << std::endl;
|
2019-04-06 10:00:56 +00:00
|
|
|
else
|
2019-04-29 21:38:23 +00:00
|
|
|
asmCode << "\tlea " << regR[instr.dst] << ", [" << regR[instr.dst] << "+" << regR[instr.src] << "*" << (1 << (instr.getModShift())) << "]" << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2019-01-11 15:53:52 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_IADD_M(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
genAddressReg(instr);
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tadd " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tadd " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_ISUB_R(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
asmCode << "\tsub " << regR[instr.dst] << ", " << regR[instr.src] << std::endl;
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
2019-01-24 18:29:59 +00:00
|
|
|
else {
|
2019-03-11 22:04:34 +00:00
|
|
|
asmCode << "\tsub " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl;
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_ISUB_M(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
genAddressReg(instr);
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tsub " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl;
|
2019-01-11 15:53:52 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tsub " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl;
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_IMUL_R(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
asmCode << "\timul " << regR[instr.dst] << ", " << regR[instr.src] << std::endl;
|
2019-01-18 22:51:18 +00:00
|
|
|
}
|
2019-01-24 18:29:59 +00:00
|
|
|
else {
|
2019-03-11 22:04:34 +00:00
|
|
|
asmCode << "\timul " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl;
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_IMUL_M(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
genAddressReg(instr);
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\timul " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl;
|
2018-12-15 22:13:17 +00:00
|
|
|
}
|
2019-01-24 18:29:59 +00:00
|
|
|
else {
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\timul " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl;
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_IMULH_R(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-02-09 14:45:26 +00:00
|
|
|
asmCode << "\tmov rax, " << regR[instr.dst] << std::endl;
|
|
|
|
asmCode << "\tmul " << regR[instr.src] << std::endl;
|
|
|
|
asmCode << "\tmov " << regR[instr.dst] << ", rdx" << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_IMULH_M(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
genAddressReg(instr, "ecx");
|
|
|
|
asmCode << "\tmov rax, " << regR[instr.dst] << std::endl;
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tmul qword ptr [" << regScratchpadAddr << "+rcx]" << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
asmCode << "\tmov rax, " << regR[instr.dst] << std::endl;
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tmul qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
|
|
|
asmCode << "\tmov " << regR[instr.dst] << ", rdx" << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_ISMULH_R(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-02-09 14:45:26 +00:00
|
|
|
asmCode << "\tmov rax, " << regR[instr.dst] << std::endl;
|
|
|
|
asmCode << "\timul " << regR[instr.src] << std::endl;
|
|
|
|
asmCode << "\tmov " << regR[instr.dst] << ", rdx" << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_ISMULH_M(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
genAddressReg(instr, "ecx");
|
|
|
|
asmCode << "\tmov rax, " << regR[instr.dst] << std::endl;
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\timul qword ptr [" << regScratchpadAddr << "+rcx]" << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
asmCode << "\tmov rax, " << regR[instr.dst] << std::endl;
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\timul qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
|
|
|
asmCode << "\tmov " << regR[instr.dst] << ", rdx" << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_INEG_R(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
asmCode << "\tneg " << regR[instr.dst] << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_IXOR_R(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
asmCode << "\txor " << regR[instr.dst] << ", " << regR[instr.src] << std::endl;
|
|
|
|
}
|
|
|
|
else {
|
2019-03-11 22:04:34 +00:00
|
|
|
asmCode << "\txor " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_IXOR_M(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
genAddressReg(instr);
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\txor " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\txor " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_IROR_R(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
asmCode << "\tmov ecx, " << regR32[instr.src] << std::endl;
|
|
|
|
asmCode << "\tror " << regR[instr.dst] << ", cl" << std::endl;
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-03-11 22:04:34 +00:00
|
|
|
asmCode << "\tror " << regR[instr.dst] << ", " << (instr.getImm32() & 63) << std::endl;
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_IROL_R(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-01-24 18:29:59 +00:00
|
|
|
if (instr.src != instr.dst) {
|
|
|
|
asmCode << "\tmov ecx, " << regR32[instr.src] << std::endl;
|
|
|
|
asmCode << "\trol " << regR[instr.dst] << ", cl" << std::endl;
|
|
|
|
}
|
|
|
|
else {
|
2019-03-11 22:04:34 +00:00
|
|
|
asmCode << "\trol " << regR[instr.dst] << ", " << (instr.getImm32() & 63) << std::endl;
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 16:48:26 +00:00
|
|
|
void AssemblyGeneratorX86::h_IMUL_RCP(Instruction& instr, int i) {
|
2019-05-04 16:00:17 +00:00
|
|
|
uint64_t divisor = instr.getImm32();
|
|
|
|
if (!isPowerOf2(divisor)) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
2019-05-04 16:00:17 +00:00
|
|
|
asmCode << "\tmov rax, " << randomx_reciprocal(divisor) << std::endl;
|
2019-02-22 16:48:26 +00:00
|
|
|
asmCode << "\timul " << regR[instr.dst] << ", rax" << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tracenop(instr);
|
|
|
|
}
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 16:07:00 +00:00
|
|
|
void AssemblyGeneratorX86::h_ISWAP_R(Instruction& instr, int i) {
|
|
|
|
if (instr.src != instr.dst) {
|
2019-04-30 08:20:28 +00:00
|
|
|
registerUsage[instr.dst].lastUsed = i;
|
|
|
|
registerUsage[instr.src].lastUsed = i;
|
2019-02-04 16:07:00 +00:00
|
|
|
asmCode << "\txchg " << regR[instr.dst] << ", " << regR[instr.src] << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceint(instr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tracenop(instr);
|
2019-02-04 16:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-05 22:43:57 +00:00
|
|
|
void AssemblyGeneratorX86::h_FSWAP_R(Instruction& instr, int i) {
|
2019-01-24 18:29:59 +00:00
|
|
|
asmCode << "\tshufpd " << regFE[instr.dst] << ", " << regFE[instr.dst] << ", 1" << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceflt(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 22:43:57 +00:00
|
|
|
void AssemblyGeneratorX86::h_FADD_R(Instruction& instr, int i) {
|
2019-04-28 14:42:45 +00:00
|
|
|
instr.dst %= RegisterCountFlt;
|
|
|
|
instr.src %= RegisterCountFlt;
|
2019-01-24 18:29:59 +00:00
|
|
|
asmCode << "\taddpd " << regF[instr.dst] << ", " << regA[instr.src] << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceflt(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 22:43:57 +00:00
|
|
|
void AssemblyGeneratorX86::h_FADD_M(Instruction& instr, int i) {
|
2019-04-28 14:42:45 +00:00
|
|
|
instr.dst %= RegisterCountFlt;
|
2019-01-24 18:29:59 +00:00
|
|
|
genAddressReg(instr);
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tcvtdq2pd " << tempRegx << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl;
|
|
|
|
asmCode << "\taddpd " << regF[instr.dst] << ", " << tempRegx << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceflt(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 22:43:57 +00:00
|
|
|
void AssemblyGeneratorX86::h_FSUB_R(Instruction& instr, int i) {
|
2019-04-28 14:42:45 +00:00
|
|
|
instr.dst %= RegisterCountFlt;
|
|
|
|
instr.src %= RegisterCountFlt;
|
2019-01-24 18:29:59 +00:00
|
|
|
asmCode << "\tsubpd " << regF[instr.dst] << ", " << regA[instr.src] << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceflt(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 22:43:57 +00:00
|
|
|
void AssemblyGeneratorX86::h_FSUB_M(Instruction& instr, int i) {
|
2019-04-28 14:42:45 +00:00
|
|
|
instr.dst %= RegisterCountFlt;
|
2019-01-24 18:29:59 +00:00
|
|
|
genAddressReg(instr);
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tcvtdq2pd " << tempRegx << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl;
|
|
|
|
asmCode << "\tsubpd " << regF[instr.dst] << ", " << tempRegx << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceflt(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-12 23:01:34 +00:00
|
|
|
void AssemblyGeneratorX86::h_FSCAL_R(Instruction& instr, int i) {
|
2019-04-28 14:42:45 +00:00
|
|
|
instr.dst %= RegisterCountFlt;
|
2019-04-30 19:14:50 +00:00
|
|
|
asmCode << "\txorps " << regF[instr.dst] << ", " << scaleMaskReg << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceflt(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 22:43:57 +00:00
|
|
|
void AssemblyGeneratorX86::h_FMUL_R(Instruction& instr, int i) {
|
2019-04-28 14:42:45 +00:00
|
|
|
instr.dst %= RegisterCountFlt;
|
|
|
|
instr.src %= RegisterCountFlt;
|
2019-01-24 18:29:59 +00:00
|
|
|
asmCode << "\tmulpd " << regE[instr.dst] << ", " << regA[instr.src] << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceflt(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 22:43:57 +00:00
|
|
|
void AssemblyGeneratorX86::h_FDIV_M(Instruction& instr, int i) {
|
2019-04-28 14:42:45 +00:00
|
|
|
instr.dst %= RegisterCountFlt;
|
2019-01-24 18:29:59 +00:00
|
|
|
genAddressReg(instr);
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tcvtdq2pd " << tempRegx << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl;
|
2019-04-30 19:14:50 +00:00
|
|
|
asmCode << "\tandps " << tempRegx << ", " << mantissaMaskReg << std::endl;
|
|
|
|
asmCode << "\torps " << tempRegx << ", " << exponentMaskReg << std::endl;
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tdivpd " << regE[instr.dst] << ", " << tempRegx << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceflt(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 22:43:57 +00:00
|
|
|
void AssemblyGeneratorX86::h_FSQRT_R(Instruction& instr, int i) {
|
2019-04-28 14:42:45 +00:00
|
|
|
instr.dst %= RegisterCountFlt;
|
2019-01-24 18:29:59 +00:00
|
|
|
asmCode << "\tsqrtpd " << regE[instr.dst] << ", " << regE[instr.dst] << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
traceflt(instr);
|
2019-01-24 18:29:59 +00:00
|
|
|
}
|
2018-12-13 22:11:55 +00:00
|
|
|
|
2019-01-24 18:29:59 +00:00
|
|
|
void AssemblyGeneratorX86::h_CFROUND(Instruction& instr, int i) {
|
2019-01-27 09:52:30 +00:00
|
|
|
asmCode << "\tmov rax, " << regR[instr.src] << std::endl;
|
2019-03-11 22:04:34 +00:00
|
|
|
int rotate = (13 - (instr.getImm32() & 63)) & 63;
|
2019-01-11 09:52:12 +00:00
|
|
|
if (rotate != 0)
|
|
|
|
asmCode << "\trol rax, " << rotate << std::endl;
|
2018-12-13 22:11:55 +00:00
|
|
|
asmCode << "\tand eax, 24576" << std::endl;
|
|
|
|
asmCode << "\tor eax, 40896" << std::endl;
|
2019-04-26 21:32:10 +00:00
|
|
|
asmCode << "\tpush rax" << std::endl;
|
|
|
|
asmCode << "\tldmxcsr dword ptr [rsp]" << std::endl;
|
|
|
|
asmCode << "\tpop rax" << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
tracenop(instr);
|
2018-12-13 22:11:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 21:38:23 +00:00
|
|
|
void AssemblyGeneratorX86::h_CBRANCH(Instruction& instr, int i) {
|
2019-04-30 08:20:28 +00:00
|
|
|
int reg = getConditionRegister(registerUsage);
|
|
|
|
int target = registerUsage[reg].lastUsed + 1;
|
|
|
|
registerUsage[reg].count++;
|
2019-05-03 12:02:40 +00:00
|
|
|
int shift = instr.getModCond() + ConditionOffset;
|
|
|
|
int32_t imm = instr.getImm32() | (1L << shift);
|
|
|
|
if (ConditionOffset > 0 || shift > 0)
|
|
|
|
imm &= ~(1L << (shift - 1));
|
|
|
|
asmCode << "\tadd " << regR[reg] << ", " << imm << std::endl;
|
2019-04-29 21:38:23 +00:00
|
|
|
asmCode << "\ttest " << regR[reg] << ", " << (ConditionMask << shift) << std::endl;
|
2019-03-17 22:09:11 +00:00
|
|
|
asmCode << "\tjz randomx_isn_" << target << std::endl;
|
2019-04-30 08:20:28 +00:00
|
|
|
//mark all registers as used
|
|
|
|
for (unsigned j = 0; j < RegistersCount; ++j) {
|
|
|
|
registerUsage[j].lastUsed = i;
|
2019-03-17 22:09:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-27 09:52:30 +00:00
|
|
|
void AssemblyGeneratorX86::h_ISTORE(Instruction& instr, int i) {
|
|
|
|
genAddressRegDst(instr);
|
2019-04-26 09:07:47 +00:00
|
|
|
asmCode << "\tmov qword ptr [" << regScratchpadAddr << "+rax], " << regR[instr.src] << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
tracenop(instr);
|
2019-01-27 09:52:30 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 17:19:49 +00:00
|
|
|
void AssemblyGeneratorX86::h_NOP(Instruction& instr, int i) {
|
|
|
|
asmCode << "\tnop" << std::endl;
|
2019-02-16 22:18:45 +00:00
|
|
|
tracenop(instr);
|
2019-01-27 17:19:49 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 14:53:06 +00:00
|
|
|
#include "instruction_weights.hpp"
|
2018-12-13 22:11:55 +00:00
|
|
|
#define INST_HANDLE(x) REPN(&AssemblyGeneratorX86::h_##x, WT(x))
|
|
|
|
|
|
|
|
InstructionGenerator AssemblyGeneratorX86::engine[256] = {
|
2019-04-06 10:00:56 +00:00
|
|
|
INST_HANDLE(IADD_RS)
|
2019-01-24 18:29:59 +00:00
|
|
|
INST_HANDLE(IADD_M)
|
|
|
|
INST_HANDLE(ISUB_R)
|
|
|
|
INST_HANDLE(ISUB_M)
|
|
|
|
INST_HANDLE(IMUL_R)
|
|
|
|
INST_HANDLE(IMUL_M)
|
|
|
|
INST_HANDLE(IMULH_R)
|
|
|
|
INST_HANDLE(IMULH_M)
|
|
|
|
INST_HANDLE(ISMULH_R)
|
|
|
|
INST_HANDLE(ISMULH_M)
|
2019-02-22 16:48:26 +00:00
|
|
|
INST_HANDLE(IMUL_RCP)
|
2019-01-24 18:29:59 +00:00
|
|
|
INST_HANDLE(INEG_R)
|
|
|
|
INST_HANDLE(IXOR_R)
|
|
|
|
INST_HANDLE(IXOR_M)
|
|
|
|
INST_HANDLE(IROR_R)
|
|
|
|
INST_HANDLE(IROL_R)
|
2019-02-04 16:07:00 +00:00
|
|
|
INST_HANDLE(ISWAP_R)
|
2019-02-05 22:43:57 +00:00
|
|
|
INST_HANDLE(FSWAP_R)
|
|
|
|
INST_HANDLE(FADD_R)
|
|
|
|
INST_HANDLE(FADD_M)
|
|
|
|
INST_HANDLE(FSUB_R)
|
|
|
|
INST_HANDLE(FSUB_M)
|
2019-02-12 23:01:34 +00:00
|
|
|
INST_HANDLE(FSCAL_R)
|
2019-02-05 22:43:57 +00:00
|
|
|
INST_HANDLE(FMUL_R)
|
|
|
|
INST_HANDLE(FDIV_M)
|
|
|
|
INST_HANDLE(FSQRT_R)
|
2019-04-29 21:38:23 +00:00
|
|
|
INST_HANDLE(CBRANCH)
|
2019-01-24 18:29:59 +00:00
|
|
|
INST_HANDLE(CFROUND)
|
2019-01-27 09:52:30 +00:00
|
|
|
INST_HANDLE(ISTORE)
|
2019-01-27 17:19:49 +00:00
|
|
|
INST_HANDLE(NOP)
|
2018-12-13 22:11:55 +00:00
|
|
|
};
|
|
|
|
}
|