/* Copyright (c) 2018 tevador This file is part of RandomX. RandomX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. RandomX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with RandomX. If not, see. */ #pragma once #include #include #include "common.hpp" #include "superscalar_program.hpp" #include "jit_compiler_x86.hpp" #include "allocator.hpp" /* Global scope for C binding */ struct randomx_dataset { virtual ~randomx_dataset() = 0; virtual void allocate() = 0; uint8_t* memory = nullptr; }; /* Global scope for C binding */ struct randomx_cache : public randomx_dataset { virtual randomx::DatasetInitFunc getInitFunc() = 0; virtual void initialize(const void *seed, size_t seedSize); randomx::SuperscalarProgram programs[RANDOMX_CACHE_ACCESSES]; std::vector reciprocalCache; }; namespace randomx { template struct Dataset : public randomx_dataset { ~Dataset() override; void allocate() override; }; using DatasetDefault = Dataset>; using DatasetLargePage = Dataset; template struct Cache : public randomx_cache { ~Cache() override; void allocate() override; DatasetInitFunc getInitFunc() override; }; template struct CacheWithJit : public Cache { using Cache::programs; using Cache::reciprocalCache; void initialize(const void *seed, size_t seedSize) override; DatasetInitFunc getInitFunc() override; JitCompilerX86 jit; }; using CacheDefault = Cache>; using CacheWithJitDefault = CacheWithJit>; using CacheLargePage = Cache; using CacheWithJitLargePage = CacheWithJit; void initDatasetItem(randomx_cache* cache, uint8_t* out, uint64_t blockNumber); void initDataset(randomx_cache* cache, uint8_t* dataset, uint32_t startBlock, uint32_t endBlock); }