vm_compiled_light.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright (c) 2019 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 "vm_compiled.hpp"
  18. namespace randomx {
  19. template<class Allocator, bool softAes>
  20. class CompiledLightVm : public CompiledVm<Allocator, softAes> {
  21. public:
  22. void* operator new(size_t size) {
  23. void* ptr = AlignedAllocator<CacheLineSize>::allocMemory(size);
  24. if (ptr == nullptr)
  25. throw std::bad_alloc();
  26. return ptr;
  27. }
  28. void operator delete(void* ptr) {
  29. AlignedAllocator<CacheLineSize>::freeMemory(ptr, sizeof(CompiledLightVm));
  30. }
  31. void setCache(randomx_cache* cache) override;
  32. void setDataset(randomx_dataset* dataset) override { }
  33. void run(void* seed) override;
  34. using CompiledVm<Allocator, softAes>::mem;
  35. using CompiledVm<Allocator, softAes>::compiler;
  36. using CompiledVm<Allocator, softAes>::program;
  37. using CompiledVm<Allocator, softAes>::config;
  38. using CompiledVm<Allocator, softAes>::datasetOffset;
  39. };
  40. using CompiledLightVmDefault = CompiledLightVm<AlignedAllocator<CacheLineSize>, true>;
  41. using CompiledLightVmHardAes = CompiledLightVm<AlignedAllocator<CacheLineSize>, false>;
  42. using CompiledLightVmLargePage = CompiledLightVm<LargePageAllocator, true>;
  43. using CompiledLightVmLargePageHardAes = CompiledLightVm<LargePageAllocator, false>;
  44. }