mirror of
https://git.wownero.com/wownero/RandomWOW.git
synced 2025-01-03 05:38:54 +00:00
Debuggable assembly generator
This commit is contained in:
parent
fce6e75689
commit
55afe9646f
@ -49,6 +49,7 @@ namespace RandomX {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CompiledVirtualMachine::execute() {
|
void CompiledVirtualMachine::execute() {
|
||||||
|
//executeProgram(reg, mem, scratchpad, readDataset);
|
||||||
compiler.getProgramFunc()(reg, mem, scratchpad);
|
compiler.getProgramFunc()(reg, mem, scratchpad);
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
for (int32_t i = InstructionCount - 1; i >= 0; --i) {
|
for (int32_t i = InstructionCount - 1; i >= 0; --i) {
|
||||||
|
@ -34,9 +34,9 @@ namespace RandomX {
|
|||||||
return compiler.getCode();
|
return compiler.getCode();
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
JitCompilerX86 compiler;
|
|
||||||
#ifdef TRACE
|
#ifdef TRACE
|
||||||
convertible_t tracepad[InstructionCount];
|
convertible_t tracepad[InstructionCount];
|
||||||
#endif
|
#endif
|
||||||
|
JitCompilerX86 compiler;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -106,6 +106,6 @@ namespace RandomX {
|
|||||||
typedef void(*ProgramFunc)(RegisterFile&, MemoryRegisters&, convertible_t*);
|
typedef void(*ProgramFunc)(RegisterFile&, MemoryRegisters&, convertible_t*);
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void executeProgram(RegisterFile& registerFile, MemoryRegisters& memory, convertible_t* scratchpad);
|
void executeProgram(RegisterFile&, MemoryRegisters&, convertible_t*, DatasetReadFunc);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -71,7 +71,7 @@ executeProgram PROC
|
|||||||
push r13
|
push r13
|
||||||
push r14
|
push r14
|
||||||
push r15
|
push r15
|
||||||
sub rsp, 72
|
sub rsp, 64
|
||||||
movdqu xmmword ptr [rsp+48], xmm6
|
movdqu xmmword ptr [rsp+48], xmm6
|
||||||
movdqu xmmword ptr [rsp+32], xmm7
|
movdqu xmmword ptr [rsp+32], xmm7
|
||||||
movdqu xmmword ptr [rsp+16], xmm8
|
movdqu xmmword ptr [rsp+16], xmm8
|
||||||
@ -81,6 +81,7 @@ executeProgram PROC
|
|||||||
push rcx ; RegisterFile& registerFile
|
push rcx ; RegisterFile& registerFile
|
||||||
mov rbx, rdx ; MemoryRegisters& memory
|
mov rbx, rdx ; MemoryRegisters& memory
|
||||||
mov rsi, r8 ; convertible_t& scratchpad
|
mov rsi, r8 ; convertible_t& scratchpad
|
||||||
|
push r9
|
||||||
|
|
||||||
mov rbp, rsp ; beginning of VM stack
|
mov rbp, rsp ; beginning of VM stack
|
||||||
mov rdi, 1048576 ; number of VM instructions to execute
|
mov rdi, 1048576 ; number of VM instructions to execute
|
||||||
@ -115,6 +116,7 @@ rx_finish:
|
|||||||
|
|
||||||
; save VM register values
|
; save VM register values
|
||||||
pop rcx
|
pop rcx
|
||||||
|
pop rcx
|
||||||
mov qword ptr [rcx+0], r8
|
mov qword ptr [rcx+0], r8
|
||||||
mov qword ptr [rcx+8], r9
|
mov qword ptr [rcx+8], r9
|
||||||
mov qword ptr [rcx+16], r10
|
mov qword ptr [rcx+16], r10
|
||||||
@ -137,7 +139,7 @@ rx_finish:
|
|||||||
movdqu xmm8, xmmword ptr [rsp+16]
|
movdqu xmm8, xmmword ptr [rsp+16]
|
||||||
movdqu xmm7, xmmword ptr [rsp+32]
|
movdqu xmm7, xmmword ptr [rsp+32]
|
||||||
movdqu xmm6, xmmword ptr [rsp+48]
|
movdqu xmm6, xmmword ptr [rsp+48]
|
||||||
add rsp, 72
|
add rsp, 64
|
||||||
pop r15
|
pop r15
|
||||||
pop r14
|
pop r14
|
||||||
pop r13
|
pop r13
|
||||||
@ -150,11 +152,12 @@ rx_finish:
|
|||||||
; return
|
; return
|
||||||
ret 0
|
ret 0
|
||||||
|
|
||||||
rx_read_dataset_light:
|
rx_read_dataset:
|
||||||
push rdx
|
push r8
|
||||||
push r9
|
push r9
|
||||||
push r10
|
push r10
|
||||||
push r11
|
push r11
|
||||||
|
mov rdx, rbx
|
||||||
movd qword ptr [rsp - 8], xmm1
|
movd qword ptr [rsp - 8], xmm1
|
||||||
movd qword ptr [rsp - 16], xmm2
|
movd qword ptr [rsp - 16], xmm2
|
||||||
sub rsp, 48
|
sub rsp, 48
|
||||||
@ -165,10 +168,10 @@ rx_read_dataset_light:
|
|||||||
pop r11
|
pop r11
|
||||||
pop r10
|
pop r10
|
||||||
pop r9
|
pop r9
|
||||||
pop rdx
|
pop r8
|
||||||
ret 0
|
ret 0
|
||||||
|
|
||||||
rx_read_dataset:
|
rx_read_dataset_full:
|
||||||
mov edx, dword ptr [rbx] ; ma
|
mov edx, dword ptr [rbx] ; ma
|
||||||
mov rax, qword ptr [rbx+8] ; dataset
|
mov rax, qword ptr [rbx+8] ; dataset
|
||||||
mov rax, qword ptr [rax+rdx]
|
mov rax, qword ptr [rax+rdx]
|
||||||
|
22
src/main.cpp
22
src/main.cpp
@ -110,6 +110,22 @@ private:
|
|||||||
std::atomic<uint64_t> hash[4];
|
std::atomic<uint64_t> hash[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void generateAsm(int nonce) {
|
||||||
|
uint64_t hash[4];
|
||||||
|
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,
|
||||||
|
0xea, 0x00, 0x00, 0x00, 0x00, 0x77, 0xb2, 0x06, 0xa0, 0x2c, 0xa5, 0xb1, 0xd4, 0xce, 0x6b, 0xbf, 0xdf, 0x0a, 0xca,
|
||||||
|
0xc3, 0x8b, 0xde, 0xd3, 0x4d, 0x2d, 0xcd, 0xee, 0xf9, 0x5c, 0xd2, 0x0c, 0xef, 0xc1, 0x2f, 0x61, 0xd5, 0x61, 0x09
|
||||||
|
};
|
||||||
|
int* noncePtr = (int*)(blockTemplate + 39);
|
||||||
|
*noncePtr = nonce;
|
||||||
|
blake2b(hash, sizeof(hash), blockTemplate, sizeof(blockTemplate), nullptr, 0);
|
||||||
|
RandomX::AssemblyGeneratorX86 asmX86;
|
||||||
|
asmX86.generateProgram(hash);
|
||||||
|
asmX86.printCode(std::cout);
|
||||||
|
}
|
||||||
|
|
||||||
void mine(RandomX::VirtualMachine* vm, std::atomic<int>& atomicNonce, AtomicHash& result, int noncesCount, int thread) {
|
void mine(RandomX::VirtualMachine* vm, std::atomic<int>& atomicNonce, AtomicHash& result, int noncesCount, int thread) {
|
||||||
uint64_t hash[4];
|
uint64_t hash[4];
|
||||||
unsigned char blockTemplate[] = {
|
unsigned char blockTemplate[] = {
|
||||||
@ -128,6 +144,7 @@ void mine(RandomX::VirtualMachine* vm, std::atomic<int>& atomicNonce, AtomicHash
|
|||||||
int spIndex = ((uint8_t*)hash)[24] | ((((uint8_t*)hash)[25] & 63) << 8);
|
int spIndex = ((uint8_t*)hash)[24] | ((((uint8_t*)hash)[25] & 63) << 8);
|
||||||
vm->initializeScratchpad(spIndex);
|
vm->initializeScratchpad(spIndex);
|
||||||
vm->initializeProgram(hash);
|
vm->initializeProgram(hash);
|
||||||
|
//dump((char*)((RandomX::CompiledVirtualMachine*)vm)->getProgram(), RandomX::CodeSize, "code-1337-jmp.txt");
|
||||||
vm->execute();
|
vm->execute();
|
||||||
vm->getResult(hash);
|
vm->getResult(hash);
|
||||||
result.xorWith(hash);
|
result.xorWith(hash);
|
||||||
@ -150,6 +167,11 @@ int main(int argc, char** argv) {
|
|||||||
readIntOption("--threads", argc, argv, threadCount, 1);
|
readIntOption("--threads", argc, argv, threadCount, 1);
|
||||||
readIntOption("--nonces", argc, argv, programCount, 1000);
|
readIntOption("--nonces", argc, argv, programCount, 1000);
|
||||||
|
|
||||||
|
if (genAsm) {
|
||||||
|
generateAsm(programCount);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
std::atomic<int> atomicNonce(0);
|
std::atomic<int> atomicNonce(0);
|
||||||
AtomicHash result;
|
AtomicHash result;
|
||||||
std::vector<RandomX::VirtualMachine*> vms;
|
std::vector<RandomX::VirtualMachine*> vms;
|
||||||
|
Loading…
Reference in New Issue
Block a user