2018-12-11 20:00:30 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "VirtualMachine.hpp"
|
|
|
|
#include "common.hpp"
|
2019-01-18 22:51:18 +00:00
|
|
|
#include "hashAes1Rx4.hpp"
|
2018-12-19 11:38:10 +00:00
|
|
|
#include "blake2/blake2.h"
|
2018-12-11 20:00:30 +00:00
|
|
|
#include <cstring>
|
2018-12-31 18:06:45 +00:00
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const RandomX::RegisterFile& rf) {
|
|
|
|
for (int i = 0; i < RandomX::RegistersCount; ++i)
|
|
|
|
os << std::hex << "r" << i << " = " << rf.r[i].u64 << std::endl << std::dec;
|
|
|
|
for (int i = 0; i < RandomX::RegistersCount; ++i)
|
|
|
|
os << std::hex << "f" << i << " = " << rf.f[i].hi.u64 << " (" << rf.f[i].hi.f64 << ")" << std::endl
|
|
|
|
<< " = " << rf.f[i].lo.u64 << " (" << rf.f[i].lo.f64 << ")" << std::endl << std::dec;
|
|
|
|
return os;
|
|
|
|
}
|
2018-12-11 20:00:30 +00:00
|
|
|
|
|
|
|
namespace RandomX {
|
2018-12-31 18:06:45 +00:00
|
|
|
|
2019-01-14 23:01:11 +00:00
|
|
|
VirtualMachine::VirtualMachine() {
|
2018-12-19 20:54:44 +00:00
|
|
|
mem.ds.dataset = nullptr;
|
2018-12-11 20:00:30 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 21:00:58 +00:00
|
|
|
void VirtualMachine::getResult(void* out) {
|
2019-01-18 22:51:18 +00:00
|
|
|
constexpr size_t smallStateLength = sizeof(RegisterFile) / sizeof(uint64_t) + 8;
|
|
|
|
alignas(16) uint64_t smallState[smallStateLength];
|
2018-12-19 11:38:10 +00:00
|
|
|
memcpy(smallState, ®, sizeof(RegisterFile));
|
2019-01-18 22:51:18 +00:00
|
|
|
hashAes1Rx4<false>(scratchpad, ScratchpadSize, smallState + 24);
|
2018-12-19 11:38:10 +00:00
|
|
|
blake2b(out, ResultSize, smallState, sizeof(smallState), nullptr, 0);
|
2018-12-18 21:00:58 +00:00
|
|
|
}
|
2018-12-11 20:00:30 +00:00
|
|
|
}
|