2018-12-11 20:00:30 +00:00
|
|
|
/*
|
|
|
|
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<http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2019-04-20 09:08:01 +00:00
|
|
|
#include <vector>
|
2018-12-11 20:00:30 +00:00
|
|
|
#include "intrinPortable.h"
|
|
|
|
#include "common.hpp"
|
2019-04-20 09:08:01 +00:00
|
|
|
#include "randomx.h"
|
|
|
|
#include "Program.hpp"
|
|
|
|
#include "superscalar_program.hpp"
|
|
|
|
#include "JitCompilerX86.hpp"
|
|
|
|
#include "allocator.hpp"
|
2018-12-11 20:00:30 +00:00
|
|
|
|
2019-04-20 09:08:01 +00:00
|
|
|
struct randomx_dataset {
|
|
|
|
virtual ~randomx_dataset() = 0;
|
|
|
|
virtual bool allocate() = 0;
|
|
|
|
uint8_t* memory = nullptr;
|
|
|
|
};
|
2018-12-11 20:00:30 +00:00
|
|
|
|
2019-04-20 09:08:01 +00:00
|
|
|
struct randomx_cache : public randomx_dataset {
|
|
|
|
virtual randomx::DatasetInitFunc getInitFunc() = 0;
|
|
|
|
virtual void initialize(const void *seed, size_t seedSize); //argon2
|
|
|
|
randomx::SuperscalarProgram programs[RANDOMX_CACHE_ACCESSES];
|
|
|
|
std::vector<uint64_t> reciprocalCache;
|
|
|
|
};
|
2018-12-11 20:00:30 +00:00
|
|
|
|
2018-12-19 20:54:44 +00:00
|
|
|
|
2018-12-11 20:00:30 +00:00
|
|
|
|
2019-04-20 09:08:01 +00:00
|
|
|
namespace randomx {
|
2018-12-11 20:00:30 +00:00
|
|
|
|
2019-04-20 09:08:01 +00:00
|
|
|
template<class Allocator>
|
|
|
|
struct Dataset : public randomx_dataset {
|
|
|
|
~Dataset() override;
|
|
|
|
bool allocate() override;
|
|
|
|
};
|
2018-12-11 20:00:30 +00:00
|
|
|
|
2019-04-20 09:08:01 +00:00
|
|
|
using DatasetDefault = Dataset<AlignedAllocator<CacheLineSize>>;
|
|
|
|
using DatasetLargePage = Dataset<LargePageAllocator>;
|
2019-01-14 23:01:11 +00:00
|
|
|
|
2019-04-20 09:08:01 +00:00
|
|
|
template<class Allocator>
|
|
|
|
struct Cache : public randomx_cache {
|
|
|
|
~Cache() override;
|
|
|
|
bool allocate() override;
|
|
|
|
DatasetInitFunc getInitFunc() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
struct CacheWithJit : public Cache<Allocator> {
|
|
|
|
using Cache<Allocator>::programs;
|
|
|
|
using Cache<Allocator>::reciprocalCache;
|
|
|
|
void initialize(const void *seed, size_t seedSize) override;
|
|
|
|
DatasetInitFunc getInitFunc() override;
|
|
|
|
JitCompilerX86 jit;
|
|
|
|
};
|
2018-12-11 20:00:30 +00:00
|
|
|
|
2019-04-20 09:08:01 +00:00
|
|
|
using CacheDefault = Cache<AlignedAllocator<CacheLineSize>>;
|
|
|
|
using CacheWithJitDefault = CacheWithJit<AlignedAllocator<CacheLineSize>>;
|
|
|
|
using CacheLargePage = Cache<LargePageAllocator>;
|
|
|
|
using CacheWithJitLargePage = CacheWithJit<LargePageAllocator>;
|
|
|
|
|
|
|
|
void initDatasetBlock(randomx_cache* cache, uint8_t* out, uint64_t blockNumber);
|
|
|
|
void initDataset(randomx_cache* cache, uint8_t* dataset, uint32_t startBlock, uint32_t endBlock);
|
|
|
|
}
|