virtual_machine.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <cstdint>
  17. #include "common.hpp"
  18. #include "program.hpp"
  19. /* Global namespace for C binding */
  20. class randomx_vm {
  21. public:
  22. virtual ~randomx_vm() = 0;
  23. virtual bool allocate() = 0;
  24. virtual void getFinalResult(void* out, size_t outSize) = 0;
  25. virtual void setDataset(randomx_dataset* dataset) { }
  26. virtual void setCache(randomx_cache* cache) { }
  27. virtual void initScratchpad(void* seed) = 0;
  28. virtual void run(void* seed) = 0;
  29. void resetRoundingMode();
  30. randomx::RegisterFile *getRegisterFile() {
  31. return &reg;
  32. }
  33. protected:
  34. void initialize();
  35. alignas(64) randomx::Program program;
  36. alignas(64) randomx::RegisterFile reg;
  37. alignas(16) randomx::ProgramConfiguration config;
  38. randomx::MemoryRegisters mem;
  39. uint8_t* scratchpad;
  40. };
  41. namespace randomx {
  42. template<class Allocator, bool softAes>
  43. class VmBase : public randomx_vm {
  44. public:
  45. ~VmBase() override;
  46. bool allocate() override;
  47. void initScratchpad(void* seed) override;
  48. void getFinalResult(void* out, size_t outSize) override;
  49. protected:
  50. void generateProgram(void* seed);
  51. };
  52. }