2018-12-13 22:11:55 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2018 tevador
|
|
|
|
|
|
|
|
This file is part of RandomX.
|
|
|
|
|
|
|
|
RandomX is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
RandomX is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with RandomX. If not, see<http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-04-28 14:42:45 +00:00
|
|
|
#include "common.hpp"
|
2018-12-13 22:11:55 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2019-04-20 09:08:01 +00:00
|
|
|
namespace randomx {
|
2018-12-13 22:11:55 +00:00
|
|
|
|
2019-02-09 14:45:26 +00:00
|
|
|
class Program;
|
2019-04-12 17:36:08 +00:00
|
|
|
class SuperscalarProgram;
|
2018-12-13 22:11:55 +00:00
|
|
|
class AssemblyGeneratorX86;
|
2019-04-20 14:53:06 +00:00
|
|
|
class Instruction;
|
2018-12-13 22:11:55 +00:00
|
|
|
|
|
|
|
typedef void(AssemblyGeneratorX86::*InstructionGenerator)(Instruction&, int);
|
|
|
|
|
|
|
|
class AssemblyGeneratorX86 {
|
|
|
|
public:
|
2019-04-07 13:38:51 +00:00
|
|
|
void generateProgram(Program& prog);
|
2019-04-12 17:36:08 +00:00
|
|
|
void generateAsm(SuperscalarProgram& prog);
|
|
|
|
void generateC(SuperscalarProgram& prog);
|
2018-12-13 22:11:55 +00:00
|
|
|
void printCode(std::ostream& os) {
|
|
|
|
os << asmCode.rdbuf();
|
|
|
|
}
|
|
|
|
private:
|
2019-01-24 18:29:59 +00:00
|
|
|
void genAddressReg(Instruction&, const char*);
|
2019-01-27 09:52:30 +00:00
|
|
|
void genAddressRegDst(Instruction&, int);
|
2019-01-24 18:29:59 +00:00
|
|
|
int32_t genAddressImm(Instruction&);
|
2019-03-17 22:09:11 +00:00
|
|
|
int getConditionRegister();
|
|
|
|
void handleCondition(Instruction&, int);
|
2018-12-13 22:11:55 +00:00
|
|
|
void generateCode(Instruction&, int);
|
2019-02-16 22:18:45 +00:00
|
|
|
void traceint(Instruction&);
|
|
|
|
void traceflt(Instruction&);
|
|
|
|
void tracenop(Instruction&);
|
2019-04-28 14:42:45 +00:00
|
|
|
void h_IADD_RS(Instruction&, int);
|
|
|
|
void h_IADD_M(Instruction&, int);
|
|
|
|
void h_ISUB_R(Instruction&, int);
|
|
|
|
void h_ISUB_M(Instruction&, int);
|
|
|
|
void h_IMUL_R(Instruction&, int);
|
|
|
|
void h_IMUL_M(Instruction&, int);
|
|
|
|
void h_IMULH_R(Instruction&, int);
|
|
|
|
void h_IMULH_M(Instruction&, int);
|
|
|
|
void h_ISMULH_R(Instruction&, int);
|
|
|
|
void h_ISMULH_M(Instruction&, int);
|
|
|
|
void h_IMUL_RCP(Instruction&, int);
|
|
|
|
void h_ISDIV_C(Instruction&, int);
|
|
|
|
void h_INEG_R(Instruction&, int);
|
|
|
|
void h_IXOR_R(Instruction&, int);
|
|
|
|
void h_IXOR_M(Instruction&, int);
|
|
|
|
void h_IROR_R(Instruction&, int);
|
|
|
|
void h_IROL_R(Instruction&, int);
|
|
|
|
void h_ISWAP_R(Instruction&, int);
|
|
|
|
void h_FSWAP_R(Instruction&, int);
|
|
|
|
void h_FADD_R(Instruction&, int);
|
|
|
|
void h_FADD_M(Instruction&, int);
|
|
|
|
void h_FSUB_R(Instruction&, int);
|
|
|
|
void h_FSUB_M(Instruction&, int);
|
|
|
|
void h_FSCAL_R(Instruction&, int);
|
|
|
|
void h_FMUL_R(Instruction&, int);
|
|
|
|
void h_FDIV_M(Instruction&, int);
|
|
|
|
void h_FSQRT_R(Instruction&, int);
|
|
|
|
void h_COND_R(Instruction&, int);
|
|
|
|
void h_CFROUND(Instruction&, int);
|
|
|
|
void h_ISTORE(Instruction&, int);
|
|
|
|
void h_NOP(Instruction&, int);
|
2019-04-20 14:53:06 +00:00
|
|
|
|
|
|
|
static InstructionGenerator engine[256];
|
|
|
|
std::stringstream asmCode;
|
2019-04-28 14:42:45 +00:00
|
|
|
int registerUsage[RegistersCount];
|
2018-12-13 22:11:55 +00:00
|
|
|
};
|
|
|
|
}
|