CompiledVirtualMachine.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright (c) 2018 tevador
  3. This file is part of RandomX.
  4. RandomX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. RandomX is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with RandomX. If not, see<http://www.gnu.org/licenses/>.
  14. */
  15. #include "CompiledVirtualMachine.hpp"
  16. #include "common.hpp"
  17. #include <stdexcept>
  18. namespace RandomX {
  19. //static_assert(sizeof(MemoryRegisters) == 2 * sizeof(addr_t) + sizeof(uintptr_t), "Invalid alignment of struct RandomX::MemoryRegisters");
  20. static_assert(sizeof(RegisterFile) == 256, "Invalid alignment of struct RandomX::RegisterFile");
  21. CompiledVirtualMachine::CompiledVirtualMachine() {
  22. }
  23. void CompiledVirtualMachine::setDataset(dataset_t ds, uint64_t size) {
  24. mem.ds = ds;
  25. datasetRange = (size - RANDOMX_DATASET_SIZE + CacheLineSize) / CacheLineSize;
  26. datasetBasePtr = ds.dataset.memory;
  27. }
  28. void CompiledVirtualMachine::initialize() {
  29. VirtualMachine::initialize();
  30. compiler.generateProgram(program);
  31. mem.ds.dataset.memory = datasetBasePtr + (datasetBase * CacheLineSize);
  32. }
  33. void CompiledVirtualMachine::execute() {
  34. //executeProgram(reg, mem, scratchpad, InstructionCount);
  35. compiler.getProgramFunc()(reg, mem, scratchpad, RANDOMX_PROGRAM_ITERATIONS);
  36. #ifdef TRACEVM
  37. for (int32_t i = InstructionCount - 1; i >= 0; --i) {
  38. std::cout << std::hex << tracepad[i].u64 << std::endl;
  39. }
  40. #endif
  41. }
  42. }