vm_compiled.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #pragma once
  16. #include <new>
  17. #include <cstdint>
  18. #include "virtual_machine.hpp"
  19. #include "jit_compiler_x86.hpp"
  20. #include "allocator.hpp"
  21. #include "dataset.hpp"
  22. namespace randomx {
  23. template<class Allocator, bool softAes>
  24. class CompiledVm : public VmBase<Allocator, softAes> {
  25. public:
  26. void* operator new(size_t size) {
  27. void* ptr = AlignedAllocator<CacheLineSize>::allocMemory(size);
  28. if (ptr == nullptr)
  29. throw std::bad_alloc();
  30. return ptr;
  31. }
  32. void operator delete(void* ptr) {
  33. AlignedAllocator<CacheLineSize>::freeMemory(ptr, sizeof(CompiledVm));
  34. }
  35. void setDataset(randomx_dataset* dataset) override;
  36. void run(void* seed) override;
  37. using VmBase<Allocator, softAes>::mem;
  38. using VmBase<Allocator, softAes>::program;
  39. using VmBase<Allocator, softAes>::config;
  40. using VmBase<Allocator, softAes>::reg;
  41. using VmBase<Allocator, softAes>::scratchpad;
  42. using VmBase<Allocator, softAes>::datasetBasePtr;
  43. using VmBase<Allocator, softAes>::datasetOffset;
  44. protected:
  45. void execute();
  46. JitCompilerX86 compiler;
  47. };
  48. using CompiledVmDefault = CompiledVm<AlignedAllocator<CacheLineSize>, true>;
  49. using CompiledVmHardAes = CompiledVm<AlignedAllocator<CacheLineSize>, false>;
  50. using CompiledVmLargePage = CompiledVm<LargePageAllocator, true>;
  51. using CompiledVmLargePageHardAes = CompiledVm<LargePageAllocator, false>;
  52. }