2018-12-13 23:11:55 +01: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
|
|
|
|
|
|
|
|
#include "Instruction.hpp"
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
namespace RandomX {
|
|
|
|
|
|
|
|
class AssemblyGeneratorX86;
|
|
|
|
|
|
|
|
typedef void(AssemblyGeneratorX86::*InstructionGenerator)(Instruction&, int);
|
|
|
|
|
|
|
|
class AssemblyGeneratorX86 {
|
|
|
|
public:
|
|
|
|
void generateProgram(const void* seed);
|
|
|
|
void printCode(std::ostream& os) {
|
|
|
|
os << asmCode.rdbuf();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
static InstructionGenerator engine[256];
|
|
|
|
std::stringstream asmCode;
|
|
|
|
|
2019-01-24 19:29:59 +01:00
|
|
|
void genAddressReg(Instruction&, const char*);
|
2019-01-27 10:52:30 +01:00
|
|
|
void genAddressRegDst(Instruction&, int);
|
2019-01-24 19:29:59 +01:00
|
|
|
int32_t genAddressImm(Instruction&);
|
2018-12-13 23:11:55 +01:00
|
|
|
|
|
|
|
void generateCode(Instruction&, int);
|
|
|
|
|
2019-01-24 19:29:59 +01:00
|
|
|
void h_IADD_R(Instruction&, int);
|
|
|
|
void h_IADD_M(Instruction&, int);
|
|
|
|
void h_IADD_RC(Instruction&, int);
|
|
|
|
void h_ISUB_R(Instruction&, int);
|
|
|
|
void h_ISUB_M(Instruction&, int);
|
|
|
|
void h_IMUL_9C(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_IDIV_C(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_FPSWAP_R(Instruction&, int);
|
|
|
|
void h_FPADD_R(Instruction&, int);
|
|
|
|
void h_FPADD_M(Instruction&, int);
|
|
|
|
void h_FPSUB_R(Instruction&, int);
|
|
|
|
void h_FPSUB_M(Instruction&, int);
|
|
|
|
void h_FPNEG_R(Instruction&, int);
|
|
|
|
void h_FPMUL_R(Instruction&, int);
|
|
|
|
void h_FPMUL_M(Instruction&, int);
|
|
|
|
void h_FPDIV_R(Instruction&, int);
|
|
|
|
void h_FPDIV_M(Instruction&, int);
|
|
|
|
void h_FPSQRT_R(Instruction&, int);
|
|
|
|
void h_COND_R(Instruction&, int);
|
|
|
|
void h_COND_M(Instruction&, int);
|
|
|
|
void h_CFROUND(Instruction&, int);
|
2019-01-27 10:52:30 +01:00
|
|
|
void h_ISTORE(Instruction&, int);
|
|
|
|
void h_FSTORE(Instruction&, int);
|
2018-12-13 23:11:55 +01:00
|
|
|
};
|
|
|
|
}
|