RandomWOW/src/dataset.hpp

77 lines
2.3 KiB
C++
Raw Normal View History

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>
#include <type_traits>
2018-12-11 20:00:30 +00:00
#include "common.hpp"
2019-04-20 09:08:01 +00:00
#include "superscalar_program.hpp"
#include "allocator.hpp"
2018-12-11 20:00:30 +00:00
2019-04-20 14:53:06 +00:00
/* Global scope for C binding */
2019-04-20 09:08:01 +00:00
struct randomx_dataset {
uint8_t* memory = nullptr;
2019-04-28 16:17:29 +00:00
randomx::DatasetDeallocFunc* dealloc;
2019-04-20 09:08:01 +00:00
};
2018-12-11 20:00:30 +00:00
2019-04-28 14:42:45 +00:00
namespace randomx {
class JitCompilerX86;
}
2019-04-20 14:53:06 +00:00
/* Global scope for C binding */
struct randomx_cache {
uint8_t* memory = nullptr;
2019-04-28 16:17:29 +00:00
randomx::CacheDeallocFunc* dealloc;
randomx::JitCompilerX86* jit;
2019-04-28 16:17:29 +00:00
randomx::CacheInitializeFunc* initialize;
randomx::DatasetInitFunc* datasetInit;
2019-04-20 09:08:01 +00:00
randomx::SuperscalarProgram programs[RANDOMX_CACHE_ACCESSES];
std::vector<uint64_t> reciprocalCache;
};
2018-12-11 20:00:30 +00:00
//A pointer to a standard-layout struct object points to its initial member
static_assert(std::is_standard_layout<randomx_dataset>(), "randomx_dataset must be a standard-layout struct");
static_assert(std::is_standard_layout<randomx_cache>(), "randomx_cache must be a standard-layout struct");
2018-12-11 20:00:30 +00:00
namespace randomx {
2018-12-11 20:00:30 +00:00
using DefaultAllocator = AlignedAllocator<CacheLineSize>;
2019-01-14 23:01:11 +00:00
2019-04-20 09:08:01 +00:00
template<class Allocator>
void deallocDataset(randomx_dataset* dataset) {
if (dataset->memory != nullptr)
Allocator::freeMemory(dataset->memory, DatasetSize);
}
2019-04-20 09:08:01 +00:00
template<class Allocator>
void deallocCache(randomx_cache* cache) {
if(cache->memory != nullptr)
Allocator::freeMemory(cache->memory, CacheSize);
if (cache->jit != nullptr)
delete cache->jit;
}
2019-04-20 09:08:01 +00:00
void initCache(randomx_cache*, const void*, size_t);
void initCacheCompile(randomx_cache*, const void*, size_t);
void initDatasetItem(randomx_cache* cache, uint8_t* out, uint64_t blockNumber);
2019-04-20 09:08:01 +00:00
void initDataset(randomx_cache* cache, uint8_t* dataset, uint32_t startBlock, uint32_t endBlock);
}