Changes for the Monero v1 PoW

This commit is contained in:
Lee Clagett 2018-03-02 22:10:46 -05:00
parent 79345119c6
commit 48b1de0b59
6 changed files with 128 additions and 52 deletions

View file

@ -344,11 +344,14 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
}
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES>
inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, bool MONERO>
inline bool cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx, uint8_t version)
{
keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state0, 200);
VARIANT1_CHECK();
VARIANT1_INIT(0);
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
const uint8_t* l0 = ctx->memory;
@ -374,6 +377,7 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
}
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx));
VARIANT1_1(&l0[idx0 & MASK]);
idx0 = EXTRACT64(cx);
bx0 = cx;
@ -385,8 +389,10 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*)&l0[idx0 & MASK])[0] = al0;
((uint64_t*)&l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -397,15 +403,20 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *
keccakf(h0, 24);
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output));
return true;
}
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES>
inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx)
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES, bool MONERO>
inline bool cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx, uint8_t version)
{
keccak((const uint8_t *) input, (int) size, ctx->state0, 200);
keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200);
VARIANT1_CHECK();
VARIANT1_INIT(0);
VARIANT1_INIT(1);
const uint8_t* l0 = ctx->memory;
const uint8_t* l1 = ctx->memory + MEM;
uint64_t* h0 = reinterpret_cast<uint64_t*>(ctx->state0);
@ -443,6 +454,8 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
_mm_store_si128((__m128i *) &l0[idx0 & MASK], _mm_xor_si128(bx0, cx0));
_mm_store_si128((__m128i *) &l1[idx1 & MASK], _mm_xor_si128(bx1, cx1));
VARIANT1_1(&l0[idx0 & MASK]);
VARIANT1_1(&l1[idx1 & MASK]);
idx0 = EXTRACT64(cx0);
idx1 = EXTRACT64(cx1);
@ -458,8 +471,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
al0 += hi;
ah0 += lo;
VARIANT1_2(ah0, 0);
((uint64_t*) &l0[idx0 & MASK])[0] = al0;
((uint64_t*) &l0[idx0 & MASK])[1] = ah0;
VARIANT1_2(ah0, 0);
ah0 ^= ch;
al0 ^= cl;
@ -472,8 +487,10 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
al1 += hi;
ah1 += lo;
VARIANT1_2(ah1, 1);
((uint64_t*) &l1[idx1 & MASK])[0] = al1;
((uint64_t*) &l1[idx1 & MASK])[1] = ah1;
VARIANT1_2(ah1, 1);
ah1 ^= ch;
al1 ^= cl;
@ -488,6 +505,7 @@ inline void cryptonight_double_hash(const void *__restrict__ input, size_t size,
extra_hashes[ctx->state0[0] & 3](ctx->state0, 200, static_cast<char*>(output));
extra_hashes[ctx->state1[0] & 3](ctx->state1, 200, static_cast<char*>(output) + 32);
return true;
}
#endif /* __CRYPTONIGHT_ARM_H__ */