Operand allocation

This commit is contained in:
tevador 2019-04-01 00:38:17 +02:00
parent acef5ea0d7
commit 2b9209346e
4 changed files with 128 additions and 106 deletions

View File

@ -58,21 +58,6 @@ namespace RandomX {
return minIndex; return minIndex;
} }
void AssemblyGeneratorX86::generateProgram(Program& prog) {
for (unsigned i = 0; i < 8; ++i) {
registerUsage[i] = -1;
}
asmCode.str(std::string()); //clear
for (unsigned i = 0; i < RANDOMX_PROGRAM_SIZE; ++i) {
asmCode << "randomx_isn_" << i << ":" << std::endl;
Instruction& instr = prog(i);
instr.src %= RegistersCount;
instr.dst %= RegistersCount;
generateCode(instr, i);
//asmCode << std::endl;
}
}
void AssemblyGeneratorX86::traceint(Instruction& instr) { void AssemblyGeneratorX86::traceint(Instruction& instr) {
if (trace) { if (trace) {
asmCode << "\tpush " << regR[instr.dst] << std::endl; asmCode << "\tpush " << regR[instr.dst] << std::endl;

View File

@ -21,6 +21,7 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
#include "Instruction.hpp" #include "Instruction.hpp"
#include "configuration.h" #include "configuration.h"
#include "common.hpp"
#include <sstream> #include <sstream>
namespace RandomX { namespace RandomX {
@ -32,7 +33,21 @@ namespace RandomX {
class AssemblyGeneratorX86 { class AssemblyGeneratorX86 {
public: public:
void generateProgram(Program&); template<class P>
void generateProgram(P& prog) {
for (unsigned i = 0; i < 8; ++i) {
registerUsage[i] = -1;
}
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);
//asmCode << std::endl;
}
}
void printCode(std::ostream& os) { void printCode(std::ostream& os) {
os << asmCode.rdbuf(); os << asmCode.rdbuf();
} }

View File

@ -25,6 +25,7 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <stdexcept> #include <stdexcept>
#include <iomanip>
namespace RandomX { namespace RandomX {
// Intel Ivy Bridge reference // Intel Ivy Bridge reference
@ -142,11 +143,11 @@ namespace RandomX {
class RegisterInfo { class RegisterInfo {
public: public:
RegisterInfo() : lastOpGroup(-1), source(-1), value(0), latency(0) {} RegisterInfo() : latency(0), lastOpGroup(-1), source(-1), value(0) {}
int latency;
int lastOpGroup; int lastOpGroup;
int source; int source;
int value; int value;
int latency;
}; };
class MacroOp { class MacroOp {
@ -264,8 +265,8 @@ namespace RandomX {
ops_.push_back(MacroOp(op)); ops_.push_back(MacroOp(op));
} }
template <size_t N> template <size_t N>
LightInstructionInfo(const char* name, int type, const MacroOp(&arr)[N]) LightInstructionInfo(const char* name, int type, const MacroOp(&arr)[N], int resultOp, int dstOp, int srcOp)
: name_(name), type_(type), latency_(0) { : name_(name), type_(type), latency_(0), resultOp_(resultOp), dstOp_(dstOp), srcOp_(srcOp) {
for (unsigned i = 0; i < N; ++i) { for (unsigned i = 0; i < N; ++i) {
ops_.push_back(MacroOp(arr[i])); ops_.push_back(MacroOp(arr[i]));
latency_ += ops_.back().getLatency(); latency_ += ops_.back().getLatency();
@ -273,8 +274,8 @@ namespace RandomX {
static_assert(N > 1, "Invalid array size"); static_assert(N > 1, "Invalid array size");
} }
template <size_t N> template <size_t N>
LightInstructionInfo(const char* name, int type, const MacroOp*(&arr)[N], int latency) LightInstructionInfo(const char* name, int type, const MacroOp*(&arr)[N], int latency, int resultOp, int dstOp, int srcOp)
: name_(name), type_(type), latency_(latency) { : name_(name), type_(type), latency_(latency), resultOp_(resultOp), dstOp_(dstOp), srcOp_(srcOp) {
for (unsigned i = 0; i < N; ++i) { for (unsigned i = 0; i < N; ++i) {
ops_.push_back(MacroOp(arr[i])); ops_.push_back(MacroOp(arr[i]));
if (arr[i].isDependent()) { if (arr[i].isDependent()) {
@ -301,6 +302,15 @@ namespace RandomX {
int getType() const { int getType() const {
return type_; return type_;
} }
int getResultOp() const {
return resultOp_;
}
int getDstOp() const {
return dstOp_;
}
int getSrcOp() const {
return srcOp_;
}
static const LightInstructionInfo IADD_R; static const LightInstructionInfo IADD_R;
static const LightInstructionInfo IADD_C; static const LightInstructionInfo IADD_C;
static const LightInstructionInfo IADD_RC; static const LightInstructionInfo IADD_RC;
@ -322,6 +332,9 @@ namespace RandomX {
int type_; int type_;
std::vector<MacroOp> ops_; std::vector<MacroOp> ops_;
int latency_; int latency_;
int resultOp_ = 0;
int dstOp_ = 0;
int srcOp_ = 0;
LightInstructionInfo(const char* name) LightInstructionInfo(const char* name)
: name_(name), type_(-1), latency_(0) {} : name_(name), type_(-1), latency_(0) {}
@ -334,14 +347,14 @@ namespace RandomX {
const LightInstructionInfo LightInstructionInfo::IMUL_9C = LightInstructionInfo("IMUL_9C", LightInstructionType::IMUL_9C, MacroOp::Lea_sib); const LightInstructionInfo LightInstructionInfo::IMUL_9C = LightInstructionInfo("IMUL_9C", LightInstructionType::IMUL_9C, MacroOp::Lea_sib);
const LightInstructionInfo LightInstructionInfo::IMUL_R = LightInstructionInfo("IMUL_R", LightInstructionType::IMUL_R, MacroOp::Imul_rr); const LightInstructionInfo LightInstructionInfo::IMUL_R = LightInstructionInfo("IMUL_R", LightInstructionType::IMUL_R, MacroOp::Imul_rr);
const LightInstructionInfo LightInstructionInfo::IMUL_C = LightInstructionInfo("IMUL_C", LightInstructionType::IMUL_C, MacroOp::Imul_rri); const LightInstructionInfo LightInstructionInfo::IMUL_C = LightInstructionInfo("IMUL_C", LightInstructionType::IMUL_C, MacroOp::Imul_rri);
const LightInstructionInfo LightInstructionInfo::IMULH_R = LightInstructionInfo("IMULH_R", LightInstructionType::IMULH_R, IMULH_R_ops_array); const LightInstructionInfo LightInstructionInfo::IMULH_R = LightInstructionInfo("IMULH_R", LightInstructionType::IMULH_R, IMULH_R_ops_array, 1, 0, 1);
const LightInstructionInfo LightInstructionInfo::ISMULH_R = LightInstructionInfo("ISMULH_R", LightInstructionType::ISMULH_R, ISMULH_R_ops_array); const LightInstructionInfo LightInstructionInfo::ISMULH_R = LightInstructionInfo("ISMULH_R", LightInstructionType::ISMULH_R, ISMULH_R_ops_array, 1, 0, 1);
const LightInstructionInfo LightInstructionInfo::IMUL_RCP = LightInstructionInfo("IMUL_RCP", LightInstructionType::IMUL_RCP, IMUL_RCP_ops_array); const LightInstructionInfo LightInstructionInfo::IMUL_RCP = LightInstructionInfo("IMUL_RCP", LightInstructionType::IMUL_RCP, IMUL_RCP_ops_array, 1, 1, -1);
const LightInstructionInfo LightInstructionInfo::IXOR_R = LightInstructionInfo("IXOR_R", LightInstructionType::IXOR_R, MacroOp::Xor_rr); const LightInstructionInfo LightInstructionInfo::IXOR_R = LightInstructionInfo("IXOR_R", LightInstructionType::IXOR_R, MacroOp::Xor_rr);
const LightInstructionInfo LightInstructionInfo::IXOR_C = LightInstructionInfo("IXOR_C", LightInstructionType::IXOR_C, MacroOp::Xor_ri); const LightInstructionInfo LightInstructionInfo::IXOR_C = LightInstructionInfo("IXOR_C", LightInstructionType::IXOR_C, MacroOp::Xor_ri);
const LightInstructionInfo LightInstructionInfo::IROR_R = LightInstructionInfo("IROR_R", LightInstructionType::IROR_R, IROR_R_ops_array); const LightInstructionInfo LightInstructionInfo::IROR_R = LightInstructionInfo("IROR_R", LightInstructionType::IROR_R, IROR_R_ops_array, 1, 1, 0);
const LightInstructionInfo LightInstructionInfo::IROR_C = LightInstructionInfo("IROR_C", LightInstructionType::IROR_C, MacroOp::Ror_ri); const LightInstructionInfo LightInstructionInfo::IROR_C = LightInstructionInfo("IROR_C", LightInstructionType::IROR_C, MacroOp::Ror_ri);
const LightInstructionInfo LightInstructionInfo::COND_R = LightInstructionInfo("COND_R", LightInstructionType::COND_R, COND_R_ops_array); const LightInstructionInfo LightInstructionInfo::COND_R = LightInstructionInfo("COND_R", LightInstructionType::COND_R, COND_R_ops_array, 5, 5, 3);
const LightInstructionInfo LightInstructionInfo::NOP = LightInstructionInfo("NOP"); const LightInstructionInfo LightInstructionInfo::NOP = LightInstructionInfo("NOP");
const int buffer0[] = { 3, 3, 10 }; const int buffer0[] = { 3, 3, 10 };
@ -426,75 +439,68 @@ namespace RandomX {
const LightInstructionInfo* slot_8[] = { &LightInstructionInfo::IADD_RC, &LightInstructionInfo::IMUL_9C }; const LightInstructionInfo* slot_8[] = { &LightInstructionInfo::IADD_RC, &LightInstructionInfo::IMUL_9C };
const LightInstructionInfo* slot_10 = &LightInstructionInfo::IMUL_RCP; const LightInstructionInfo* slot_10 = &LightInstructionInfo::IMUL_RCP;
template<bool erase> static bool selectRegister(std::vector<int>& availableRegisters, Blake2Generator& gen, int& reg) {
static int selectRegister(std::vector<int>& availableRegisters, Blake2Generator& gen) {
if (availableRegisters.size() == 0)
throw std::runtime_error("No avialable registers");
int index; int index;
if (availableRegisters.size() == 0)
return false;
//throw std::runtime_error("No available registers");
if (availableRegisters.size() > 1) { if (availableRegisters.size() > 1) {
index = gen.getInt32() % availableRegisters.size(); index = gen.getInt32() % availableRegisters.size();
} }
else { else {
index = 0; index = 0;
} }
int select = availableRegisters[index]; reg = availableRegisters[index];
if (erase) return true;
availableRegisters.erase(availableRegisters.begin() + index);
return select;
} }
class LightInstruction { class LightInstruction {
public: public:
Instruction toInstr() { void toInstr(Instruction& instr) {
Instruction instr;
instr.opcode = lightInstructionOpcode[getType()]; instr.opcode = lightInstructionOpcode[getType()];
instr.dst = dst_; instr.dst = dst_;
instr.src = src_ >= 0 ? src_ : dst_; instr.src = src_ >= 0 ? src_ : dst_;
instr.mod = mod_; instr.mod = mod_;
instr.setImm32(imm32_); instr.setImm32(imm32_);
return instr;
} }
static LightInstruction createForSlot(Blake2Generator& gen, int slotSize, std::vector<int>& availableRegisters, bool isLast = false, bool isFirst = false) { static LightInstruction createForSlot(Blake2Generator& gen, int slotSize, bool isLast = false, bool isFirst = false) {
switch (slotSize) switch (slotSize)
{ {
case 3: case 3:
if (isLast) { if (isLast) {
return create(slot_3L[gen.getByte() & 7], availableRegisters, gen); return create(slot_3L[gen.getByte() & 7], gen);
} }
else if (isFirst) { else if (isFirst) {
return create(slot_3F[gen.getByte() & 3], availableRegisters, gen); return create(slot_3F[gen.getByte() & 3], gen);
} }
else { else {
return create(slot_3[gen.getByte() & 3], availableRegisters, gen); return create(slot_3[gen.getByte() & 3], gen);
} }
case 4: case 4:
return create(slot_4[gen.getByte() & 1], availableRegisters, gen); return create(slot_4[gen.getByte() & 1], gen);
case 7: case 7:
if (isLast) { if (isLast) {
return create(slot_7L, availableRegisters, gen); return create(slot_7L, gen);
} }
else { else {
return create(slot_7[gen.getByte() & 3], availableRegisters, gen); return create(slot_7[gen.getByte() & 3], gen);
} }
case 8: case 8:
return create(slot_8[gen.getByte() & 1], availableRegisters, gen); return create(slot_8[gen.getByte() & 1], gen);
case 10: case 10:
return create(slot_10, availableRegisters, gen); return create(slot_10, gen);
default: default:
break; break;
} }
} }
static LightInstruction create(const LightInstructionInfo* info, std::vector<int>& availableRegisters, Blake2Generator& gen) { static LightInstruction create(const LightInstructionInfo* info, Blake2Generator& gen) {
LightInstruction li(info); LightInstruction li(info);
switch (info->getType()) switch (info->getType())
{ {
case LightInstructionType::IADD_R: { case LightInstructionType::IADD_R: {
li.dst_ = gen.getByte() & 7;
do {
li.src_ = gen.getByte() & 7;
} while (li.dst_ == li.src_);
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = 0; li.imm32_ = 0;
li.opGroup_ = LightInstructionType::IADD_R; li.opGroup_ = LightInstructionType::IADD_R;
@ -502,8 +508,7 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IADD_C: { case LightInstructionType::IADD_C: {
li.dst_ = gen.getByte() & 7; li.hasSource_ = false;
li.src_ = -1;
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = gen.getInt32(); li.imm32_ = gen.getInt32();
li.opGroup_ = LightInstructionType::IADD_R; li.opGroup_ = LightInstructionType::IADD_R;
@ -511,10 +516,6 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IADD_RC: { case LightInstructionType::IADD_RC: {
li.dst_ = gen.getByte() & 7;
do {
li.src_ = gen.getByte() & 7;
} while (li.dst_ == li.src_);
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = gen.getInt32(); li.imm32_ = gen.getInt32();
li.opGroup_ = LightInstructionType::IADD_R; li.opGroup_ = LightInstructionType::IADD_R;
@ -522,10 +523,6 @@ namespace RandomX {
} break; } break;
case LightInstructionType::ISUB_R: { case LightInstructionType::ISUB_R: {
li.dst_ = gen.getByte() & 7;
do {
li.src_ = gen.getByte() & 7;
} while (li.dst_ == li.src_);
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = 0; li.imm32_ = 0;
li.opGroup_ = LightInstructionType::IADD_R; li.opGroup_ = LightInstructionType::IADD_R;
@ -533,10 +530,6 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IMUL_9C: { case LightInstructionType::IMUL_9C: {
li.dst_ = gen.getByte() & 7;
do {
li.src_ = gen.getByte() & 7;
} while (li.dst_ == li.src_);
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = gen.getInt32(); li.imm32_ = gen.getInt32();
li.opGroup_ = LightInstructionType::IMUL_C; li.opGroup_ = LightInstructionType::IMUL_C;
@ -544,10 +537,6 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IMUL_R: { case LightInstructionType::IMUL_R: {
li.dst_ = gen.getByte() & 7;
do {
li.src_ = gen.getByte() & 7;
} while (li.dst_ == li.src_);
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = 0; li.imm32_ = 0;
li.opGroup_ = LightInstructionType::IMUL_R; li.opGroup_ = LightInstructionType::IMUL_R;
@ -555,8 +544,7 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IMUL_C: { case LightInstructionType::IMUL_C: {
li.dst_ = gen.getByte() & 7; li.hasSource_ = false;
li.src_ = -1;
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = gen.getInt32(); li.imm32_ = gen.getInt32();
li.opGroup_ = LightInstructionType::IMUL_C; li.opGroup_ = LightInstructionType::IMUL_C;
@ -564,8 +552,7 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IMULH_R: { case LightInstructionType::IMULH_R: {
li.dst_ = gen.getByte() & 7; li.canReuse_ = true;
li.src_ = gen.getByte() & 7;
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = 0; li.imm32_ = 0;
li.opGroup_ = LightInstructionType::IMULH_R; li.opGroup_ = LightInstructionType::IMULH_R;
@ -573,8 +560,7 @@ namespace RandomX {
} break; } break;
case LightInstructionType::ISMULH_R: { case LightInstructionType::ISMULH_R: {
li.dst_ = gen.getByte() & 7; li.canReuse_ = true;
li.src_ = gen.getByte() & 7;
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = 0; li.imm32_ = 0;
li.opGroup_ = LightInstructionType::ISMULH_R; li.opGroup_ = LightInstructionType::ISMULH_R;
@ -582,8 +568,7 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IMUL_RCP: { case LightInstructionType::IMUL_RCP: {
li.dst_ = gen.getByte() & 7; li.hasSource_ = false;
li.src_ = -1;
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = gen.getInt32(); li.imm32_ = gen.getInt32();
li.opGroup_ = LightInstructionType::IMUL_C; li.opGroup_ = LightInstructionType::IMUL_C;
@ -591,10 +576,6 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IXOR_R: { case LightInstructionType::IXOR_R: {
li.dst_ = gen.getByte() & 7;
do {
li.src_ = gen.getByte() & 7;
} while (li.dst_ == li.src_);
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = 0; li.imm32_ = 0;
li.opGroup_ = LightInstructionType::IXOR_R; li.opGroup_ = LightInstructionType::IXOR_R;
@ -602,8 +583,7 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IXOR_C: { case LightInstructionType::IXOR_C: {
li.dst_ = gen.getByte() & 7; li.hasSource_ = false;
li.src_ = -1;
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = gen.getInt32(); li.imm32_ = gen.getInt32();
li.opGroup_ = LightInstructionType::IXOR_R; li.opGroup_ = LightInstructionType::IXOR_R;
@ -611,10 +591,6 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IROR_R: { case LightInstructionType::IROR_R: {
li.dst_ = gen.getByte() & 7;
do {
li.src_ = gen.getByte() & 7;
} while (li.dst_ == li.src_);
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = 0; li.imm32_ = 0;
li.opGroup_ = LightInstructionType::IROR_R; li.opGroup_ = LightInstructionType::IROR_R;
@ -622,8 +598,7 @@ namespace RandomX {
} break; } break;
case LightInstructionType::IROR_C: { case LightInstructionType::IROR_C: {
li.dst_ = gen.getByte() & 7; li.hasSource_ = false;
li.src_ = -1;
li.mod_ = 0; li.mod_ = 0;
li.imm32_ = gen.getByte(); li.imm32_ = gen.getByte();
li.opGroup_ = LightInstructionType::IROR_R; li.opGroup_ = LightInstructionType::IROR_R;
@ -631,8 +606,7 @@ namespace RandomX {
} break; } break;
case LightInstructionType::COND_R: { case LightInstructionType::COND_R: {
li.dst_ = gen.getByte() & 7; li.canReuse_ = true;
li.src_ = gen.getByte() & 7;
li.mod_ = gen.getByte(); li.mod_ = gen.getByte();
li.imm32_ = gen.getInt32(); li.imm32_ = gen.getInt32();
li.opGroup_ = LightInstructionType::COND_R; li.opGroup_ = LightInstructionType::COND_R;
@ -646,6 +620,24 @@ namespace RandomX {
return li; return li;
} }
bool selectDestination(int cycle, RegisterInfo (&registers)[8], Blake2Generator& gen) {
std::vector<int> availableRegisters;
for (unsigned i = 0; i < 8; ++i) {
if (registers[i].latency <= cycle)
availableRegisters.push_back(i);
}
return selectRegister(availableRegisters, gen, dst_);
}
bool selectSource(int cycle, RegisterInfo(&registers)[8], Blake2Generator& gen) {
std::vector<int> availableRegisters;
for (unsigned i = 0; i < 8; ++i) {
if (registers[i].latency <= cycle && (canReuse_ || i != dst_))
availableRegisters.push_back(i);
}
return selectRegister(availableRegisters, gen, src_);
}
int getType() { int getType() {
return info_.getType(); return info_.getType();
} }
@ -661,6 +653,9 @@ namespace RandomX {
int getGroupPar() { int getGroupPar() {
return opGroupPar_; return opGroupPar_;
} }
bool hasSource() {
return hasSource_;
}
LightInstructionInfo& getInfo() { LightInstructionInfo& getInfo() {
return info_; return info_;
@ -670,12 +665,14 @@ namespace RandomX {
private: private:
LightInstructionInfo info_; LightInstructionInfo info_;
int src_; int src_ = -1;
int dst_; int dst_ = -1;
int mod_; int mod_;
uint32_t imm32_; uint32_t imm32_;
int opGroup_; int opGroup_;
int opGroupPar_; int opGroupPar_;
bool hasSource_ = true;
bool canReuse_ = false;
LightInstruction(const LightInstructionInfo* info) : info_(*info) { LightInstruction(const LightInstructionInfo* info) : info_(*info) {
for (unsigned i = 0; i < info_.getSize(); ++i) { for (unsigned i = 0; i < info_.getSize(); ++i) {
@ -782,7 +779,6 @@ namespace RandomX {
RegisterInfo registers[8]; RegisterInfo registers[8];
Blake2Generator gen(seed); Blake2Generator gen(seed);
std::vector<LightInstruction> instructions; std::vector<LightInstruction> instructions;
std::vector<int> availableRegisters;
DecoderBuffer& fetchLine = DecoderBuffer::Default; DecoderBuffer& fetchLine = DecoderBuffer::Default;
LightInstruction currentInstruction = LightInstruction::Null; LightInstruction currentInstruction = LightInstruction::Null;
@ -794,22 +790,20 @@ namespace RandomX {
int depCycle = 0; int depCycle = 0;
int mopIndex = 0; int mopIndex = 0;
bool portsSaturated = false; bool portsSaturated = false;
int outIndex = 0;
while(!portsSaturated) { while(!portsSaturated) {
fetchLine = fetchLine.fetchNext(currentInstruction.getType(), gen); fetchLine = fetchLine.fetchNext(currentInstruction.getType(), gen);
std::cout << "; ------------- fetch cycle " << cycle << " (" << fetchLine.getName() << ")" << std::endl; std::cout << "; ------------- fetch cycle " << cycle << " (" << fetchLine.getName() << ")" << std::endl;
availableRegisters.clear();
for (unsigned i = 0; i < 8; ++i) {
if (registers[i].latency <= cycle)
availableRegisters.push_back(i);
}
mopIndex = 0; mopIndex = 0;
while (!portsSaturated && mopIndex < fetchLine.getSize()) { while (!portsSaturated && mopIndex < fetchLine.getSize()) {
if (instrIndex >= currentInstruction.getInfo().getSize()) { if (instrIndex >= currentInstruction.getInfo().getSize()) {
currentInstruction = LightInstruction::createForSlot(gen, fetchLine.getCounts()[mopIndex], availableRegisters, fetchLine.getSize() == mopIndex + 1, fetchLine.getIndex() == 0 && mopIndex == 0); if (currentInstruction.getType() >= 0) {
currentInstruction.toInstr(prog(outIndex++));
}
currentInstruction = LightInstruction::createForSlot(gen, fetchLine.getCounts()[mopIndex], fetchLine.getSize() == mopIndex + 1, fetchLine.getIndex() == 0 && mopIndex == 0);
instrIndex = 0; instrIndex = 0;
std::cout << "; " << currentInstruction.getInfo().getName() << std::endl; std::cout << "; " << currentInstruction.getInfo().getName() << std::endl;
rxOpCount++; rxOpCount++;
@ -821,16 +815,38 @@ namespace RandomX {
} }
std::cout << mop.getName() << " "; std::cout << mop.getName() << " ";
int scheduleCycle = scheduleUop(mop, portBusy, cycle, depCycle);
mop.setCycle(scheduleCycle);
if (instrIndex == currentInstruction.getInfo().getDstOp()) {
while (!currentInstruction.selectDestination(scheduleCycle, registers, gen)) {
std::cout << "; dst STALL at cycle " << cycle << std::endl;
++scheduleCycle;
++cycle;
}
std::cout << "; dst = r" << currentInstruction.getDestination() << std::endl;
}
if (currentInstruction.hasSource() && instrIndex == currentInstruction.getInfo().getSrcOp()) {
while (!currentInstruction.selectSource(scheduleCycle, registers, gen)) {
std::cout << "; src STALL at cycle " << cycle << std::endl;
++scheduleCycle;
++cycle;
}
std::cout << "; src = r" << currentInstruction.getSource() << std::endl;
}
if (instrIndex == currentInstruction.getInfo().getResultOp()) {
int depCycle = scheduleCycle + mop.getLatency();
registers[currentInstruction.getDestination()].latency = depCycle;
std::cout << "; RETIRED at cycle " << depCycle << std::endl;
}
codeSize += mop.getSize(); codeSize += mop.getSize();
mopIndex++; mopIndex++;
instrIndex++; instrIndex++;
macroOpCount++; macroOpCount++;
int scheduleCycle = scheduleUop(mop, portBusy, cycle, depCycle);
if (scheduleCycle >= RANDOMX_LPROG_LATENCY) { if (scheduleCycle >= RANDOMX_LPROG_LATENCY) {
portsSaturated = true; portsSaturated = true;
} }
mop.setCycle(scheduleCycle);
depCycle = scheduleCycle + mop.getLatency();
} }
++cycle; ++cycle;
} }
@ -857,11 +873,14 @@ namespace RandomX {
std::cout << "; RandomX instructions: " << rxOpCount << std::endl; std::cout << "; RandomX instructions: " << rxOpCount << std::endl;
for (int i = 0; i < RANDOMX_LPROG_LATENCY + 1; ++i) { for (int i = 0; i < RANDOMX_LPROG_LATENCY + 1; ++i) {
std::cout << std::setw(3) << i << " ";
for (int j = 0; j < 3; ++j) { for (int j = 0; j < 3; ++j) {
std::cout << (portBusy[i][j] ? '*' : '_'); std::cout << (portBusy[i][j] ? '*' : '_');
} }
std::cout << std::endl; std::cout << std::endl;
} }
prog.setSize(outIndex);
} }
void generateLightProgram(LightProgram& prog, const void* seed, int indexRegister) { void generateLightProgram(LightProgram& prog, const void* seed, int indexRegister) {

View File

@ -224,7 +224,10 @@ int main(int argc, char** argv) {
if (genLight) { if (genLight) {
RandomX::LightProgram p; RandomX::LightProgram p;
RandomX::generateLightProg2(p, seed, 0); RandomX::generateLightProg2(p, seed, 0);
//std::cout << p << std::endl; RandomX::AssemblyGeneratorX86 asmX86;
asmX86.generateProgram(p);
std::cout << "-------------------------------------------------------" << std::endl;
asmX86.printCode(std::cout);
return 0; return 0;
} }