vm_compiled.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "vm_compiled.hpp"
  16. #include "common.hpp"
  17. namespace randomx {
  18. static_assert(sizeof(MemoryRegisters) == 2 * sizeof(addr_t) + sizeof(uintptr_t), "Invalid alignment of struct randomx::MemoryRegisters");
  19. static_assert(sizeof(RegisterFile) == 256, "Invalid alignment of struct randomx::RegisterFile");
  20. template<class Allocator, bool softAes>
  21. void CompiledVm<Allocator, softAes>::setDataset(randomx_dataset* dataset) {
  22. datasetPtr = dataset;
  23. }
  24. template<class Allocator, bool softAes>
  25. void CompiledVm<Allocator, softAes>::run(void* seed) {
  26. VmBase<Allocator, softAes>::generateProgram(seed);
  27. randomx_vm::initialize();
  28. compiler.generateProgram(program, config);
  29. mem.memory = datasetPtr->memory + datasetOffset;
  30. execute();
  31. }
  32. template<class Allocator, bool softAes>
  33. void CompiledVm<Allocator, softAes>::execute() {
  34. compiler.getProgramFunc()(reg, mem, scratchpad, RANDOMX_PROGRAM_ITERATIONS);
  35. }
  36. template class CompiledVm<AlignedAllocator<CacheLineSize>, false>;
  37. template class CompiledVm<AlignedAllocator<CacheLineSize>, true>;
  38. template class CompiledVm<LargePageAllocator, false>;
  39. template class CompiledVm<LargePageAllocator, true>;
  40. }