|
|
|
@ -40,14 +40,12 @@ along with RandomX. If not, see<http://www.gnu.org/licenses/>.
|
|
|
|
|
#include "argon2.h"
|
|
|
|
|
#include "argon2_core.h"
|
|
|
|
|
|
|
|
|
|
randomx_dataset::~randomx_dataset() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static_assert(RANDOMX_ARGON_MEMORY % (RANDOMX_ARGON_LANES * ARGON2_SYNC_POINTS) == 0, "RANDOMX_ARGON_MEMORY - invalid value");
|
|
|
|
|
static_assert(ARGON2_BLOCK_SIZE == randomx::ArgonBlockSize, "Unpexpected value of ARGON2_BLOCK_SIZE");
|
|
|
|
|
|
|
|
|
|
void randomx_cache::initialize(const void *seed, size_t seedSize) {
|
|
|
|
|
namespace randomx {
|
|
|
|
|
|
|
|
|
|
void initCache(randomx_cache* cache, const void* seed, size_t seedSize) {
|
|
|
|
|
uint32_t memory_blocks, segment_length;
|
|
|
|
|
argon2_instance_t instance;
|
|
|
|
|
argon2_context context;
|
|
|
|
@ -86,7 +84,7 @@ void randomx_cache::initialize(const void *seed, size_t seedSize) {
|
|
|
|
|
instance.lanes = context.lanes;
|
|
|
|
|
instance.threads = context.threads;
|
|
|
|
|
instance.type = Argon2_d;
|
|
|
|
|
instance.memory = (block*)memory;
|
|
|
|
|
instance.memory = (block*)cache->memory;
|
|
|
|
|
|
|
|
|
|
if (instance.threads > instance.lanes) {
|
|
|
|
|
instance.threads = instance.lanes;
|
|
|
|
@ -99,67 +97,27 @@ void randomx_cache::initialize(const void *seed, size_t seedSize) {
|
|
|
|
|
|
|
|
|
|
fill_memory_blocks(&instance);
|
|
|
|
|
|
|
|
|
|
reciprocalCache.clear();
|
|
|
|
|
cache->reciprocalCache.clear();
|
|
|
|
|
randomx::Blake2Generator gen(seed, seedSize);
|
|
|
|
|
for (int i = 0; i < RANDOMX_CACHE_ACCESSES; ++i) {
|
|
|
|
|
randomx::generateSuperscalar(programs[i], gen);
|
|
|
|
|
for (unsigned j = 0; j < programs[i].getSize(); ++j) {
|
|
|
|
|
auto& instr = programs[i](j);
|
|
|
|
|
randomx::generateSuperscalar(cache->programs[i], gen);
|
|
|
|
|
for (unsigned j = 0; j < cache->programs[i].getSize(); ++j) {
|
|
|
|
|
auto& instr = cache->programs[i](j);
|
|
|
|
|
if (instr.opcode == randomx::SuperscalarInstructionType::IMUL_RCP) {
|
|
|
|
|
auto rcp = randomx_reciprocal(instr.getImm32());
|
|
|
|
|
instr.setImm32(reciprocalCache.size());
|
|
|
|
|
reciprocalCache.push_back(rcp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace randomx {
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
void Dataset<Allocator>::allocate() {
|
|
|
|
|
memory = (uint8_t*)Allocator::allocMemory(DatasetSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
Dataset<Allocator>::~Dataset() {
|
|
|
|
|
Allocator::freeMemory(memory, DatasetSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
void Cache<Allocator>::allocate() {
|
|
|
|
|
memory = (uint8_t*)Allocator::allocMemory(CacheSize);
|
|
|
|
|
instr.setImm32(cache->reciprocalCache.size());
|
|
|
|
|
cache->reciprocalCache.push_back(rcp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
Cache<Allocator>::~Cache() {
|
|
|
|
|
Allocator::freeMemory(memory, CacheSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
DatasetInitFunc Cache<Allocator>::getInitFunc() {
|
|
|
|
|
return &initDataset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
DatasetInitFunc CacheWithJit<Allocator>::getInitFunc() {
|
|
|
|
|
return jit.getDatasetInitFunc();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<class Allocator>
|
|
|
|
|
void CacheWithJit<Allocator>::initialize(const void *seed, size_t seedSize) {
|
|
|
|
|
randomx_cache::initialize(seed, seedSize);
|
|
|
|
|
jit.generateSuperscalarHash(programs, reciprocalCache);
|
|
|
|
|
jit.generateDatasetInitCode();
|
|
|
|
|
void initCacheCompile(randomx_cache* cache, const void* seed, size_t seedSize) {
|
|
|
|
|
initCache(cache, seed, seedSize);
|
|
|
|
|
cache->jit->generateSuperscalarHash(cache->programs, cache->reciprocalCache);
|
|
|
|
|
cache->jit->generateDatasetInitCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template class Dataset<AlignedAllocator<CacheLineSize>>;
|
|
|
|
|
template class Dataset<LargePageAllocator>;
|
|
|
|
|
template class Cache<AlignedAllocator<CacheLineSize>>;
|
|
|
|
|
template class Cache<LargePageAllocator>;
|
|
|
|
|
template class CacheWithJit<AlignedAllocator<CacheLineSize>>;
|
|
|
|
|
template class CacheWithJit<LargePageAllocator>;
|
|
|
|
|
|
|
|
|
|
constexpr uint64_t superscalarMul0 = 6364136223846793005ULL;
|
|
|
|
|
constexpr uint64_t superscalarAdd1 = 9298411001130361340ULL;
|
|
|
|
|
constexpr uint64_t superscalarAdd2 = 12065312585734608966ULL;
|
|
|
|
|