CompiledVirtualMachine.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. //#define TRACEVM
  17. #include <new>
  18. #include "VirtualMachine.hpp"
  19. #include "JitCompilerX86.hpp"
  20. #include "intrinPortable.h"
  21. namespace RandomX {
  22. extern "C" {
  23. void executeProgram(RegisterFile&, MemoryRegisters&, uint8_t* /* scratchpad */, uint64_t);
  24. }
  25. class CompiledVirtualMachine : public VirtualMachine {
  26. public:
  27. void* operator new(size_t size) {
  28. void* ptr = _mm_malloc(size, 64);
  29. if (ptr == nullptr)
  30. throw std::bad_alloc();
  31. return ptr;
  32. }
  33. void operator delete(void* ptr) {
  34. _mm_free(ptr);
  35. }
  36. CompiledVirtualMachine();
  37. void setDataset(dataset_t ds, uint64_t size) override;
  38. void initialize() override;
  39. virtual void execute() override;
  40. void* getProgram() {
  41. return compiler.getCode();
  42. }
  43. protected:
  44. JitCompilerX86 compiler;
  45. uint8_t* datasetBasePtr;
  46. };
  47. }