Assembly code generator for Windows 64-bit

This commit is contained in:
tevador
2018-12-13 23:11:55 +01:00
parent c9102ee88c
commit cb0721056a
16 changed files with 8082 additions and 83 deletions
+37 -13
View File
@@ -18,6 +18,8 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
*/
//#define TRACE
#include "InterpretedVirtualMachine.hpp"
#include "CompiledVirtualMachine.hpp"
#include "AssemblyGeneratorX86.hpp"
#include "Stopwatch.hpp"
#include "blake2/blake2.h"
#include <fstream>
@@ -27,6 +29,7 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
#include <cstring>
#include "Program.hpp"
#include <string>
#include "instructions.hpp"
const uint8_t seed[32] = { 191, 182, 222, 175, 249, 89, 134, 104, 241, 68, 191, 62, 162, 166, 61, 64, 123, 191, 227, 193, 118, 60, 188, 53, 223, 133, 175, 24, 123, 230, 55, 74 };
@@ -73,16 +76,14 @@ std::ostream& operator<<(std::ostream& os, const RandomX::RegisterFile& rf) {
}
int main(int argc, char** argv) {
bool softAes, lightClient;
bool softAes, lightClient, genAsm, compiled;
int programCount;
readOption("--softAes", argc, argv, softAes);
readOption("--lightClient", argc, argv, lightClient);
readOption("--genAsm", argc, argv, genAsm);
readOption("--compiled", argc, argv, compiled);
readInt(argc, argv, programCount, 1000);
if (softAes)
std::cout << "Using software AES." << std::endl;
uint8_t hash[32];
char cumulative[32] = { 0 };
unsigned char blockTemplate[] = {
0x07, 0x07, 0xf7, 0xa4, 0xf0, 0xd6, 0x05, 0xb3, 0x03, 0x26, 0x08, 0x16, 0xba, 0x3f, 0x10, 0x90, 0x2e, 0x1a, 0x14,
0x5a, 0xc5, 0xfa, 0xd3, 0xaa, 0x3a, 0xf6, 0xea, 0x44, 0xc1, 0x18, 0x69, 0xdc, 0x4f, 0x85, 0x3f, 0x00, 0x2b, 0x2e,
@@ -90,11 +91,34 @@ int main(int argc, char** argv) {
0xc3, 0x8b, 0xde, 0xd3, 0x4d, 0x2d, 0xcd, 0xee, 0xf9, 0x5c, 0xd2, 0x0c, 0xef, 0xc1, 0x2f, 0x61, 0xd5, 0x61, 0x09
};
int* nonce = (int*)(blockTemplate + 39);
RandomX::InterpretedVirtualMachine vm(softAes);
uint8_t hash[32];
if (genAsm) {
*nonce = programCount;
blake2b(hash, sizeof(hash), blockTemplate, sizeof(blockTemplate), nullptr, 0);
RandomX::AssemblyGeneratorX86 asmX86;
asmX86.generateProgram(hash);
asmX86.printCode(std::cout);
return 0;
}
if (softAes)
std::cout << "Using software AES." << std::endl;
char cumulative[32] = { 0 };
RandomX::VirtualMachine* vm;
if (compiled) {
vm = new RandomX::CompiledVirtualMachine(softAes);
}
else {
vm = new RandomX::InterpretedVirtualMachine(softAes);
}
try {
std::cout << "Initializing..." << std::endl;
Stopwatch sw(true);
vm.initializeDataset(seed, lightClient);
vm->initializeDataset(seed, lightClient);
if(lightClient)
std::cout << "Cache (64 MiB) initialized in " << sw.getElapsed() << " s" << std::endl;
else
@@ -106,16 +130,15 @@ int main(int argc, char** argv) {
if (RandomX::trace) std::cout << "Nonce: " << i << " ";
blake2b(hash, sizeof(hash), blockTemplate, sizeof(blockTemplate), nullptr, 0);
int spIndex = hash[24] | ((hash[25] & 63) << 8);
vm.initializeScratchpad(spIndex);
vm->initializeScratchpad(spIndex);
//dump((const char *)vm.getScratchpad(), RandomX::ScratchpadSize, "scratchpad-before.txt");
//return 0;
vm.initializeProgram(hash);
vm.execute();
vm->initializeProgram(hash);
vm->execute();
/*std::string fileName("scratchpad-after-");
fileName = fileName + std::to_string(i) + ".txt";
dump((const char *)vm.getScratchpad(), RandomX::ScratchpadSize, fileName.c_str());*/
blake2b((void*)hash, sizeof(hash), &vm.getRegisterFile(), sizeof(RandomX::RegisterFile), nullptr, 0);
//std::cout << vm.getRegisterFile();
blake2b((void*)hash, sizeof(hash), &vm->getRegisterFile(), sizeof(RandomX::RegisterFile), nullptr, 0);
if (RandomX::trace) {
outputHex(std::cout, (char*)hash, sizeof(hash));
}
@@ -124,9 +147,10 @@ int main(int argc, char** argv) {
((uint64_t*)cumulative)[2] ^= ((uint64_t*)hash)[2];
((uint64_t*)cumulative)[3] ^= ((uint64_t*)hash)[3];
}
double elapsed = sw.getElapsed();
std::cout << "Cumulative output hash: ";
outputHex(std::cout, cumulative, sizeof(cumulative));
std::cout << "Performance: " << programCount / sw.getElapsed() << " programs per second" << std::endl;
std::cout << "Performance: " << programCount / elapsed << " programs per second" << std::endl;
}
catch (std::exception& e) {
std::cout << "ERROR: " << e.what() << std::endl;