Files
cpuminer-opt-gpu/algo/lyra2/lyra2rev3.c
Jay D Dee e1aead3c76 v3.9.0
2019-05-19 13:39:45 -04:00

103 lines
2.9 KiB
C

#include "lyra2-gate.h"
#include <memory.h>
#include "algo/blake/sph_blake.h"
#include "algo/cubehash/sph_cubehash.h"
#include "algo/bmw/sph_bmw.h"
#include "algo/cubehash/cubehash_sse2.h"
//#include "lyra2.h"
typedef struct {
cubehashParam cube;
// cubehashParam cube2;
sph_blake256_context blake;
sph_bmw256_context bmw;
} lyra2v3_ctx_holder;
static lyra2v3_ctx_holder lyra2v3_ctx;
static __thread sph_blake256_context l2v3_blake_mid;
bool init_lyra2rev3_ctx()
{
cubehashInit( &lyra2v3_ctx.cube, 256, 16, 32 );
// cubehashInit( &lyra2v3_ctx.cube2, 256, 16, 32 );
sph_blake256_init( &lyra2v3_ctx.blake );
sph_bmw256_init( &lyra2v3_ctx.bmw );
return true;
}
void l2v3_blake256_midstate( const void* input )
{
memcpy( &l2v3_blake_mid, &lyra2v3_ctx.blake, sizeof l2v3_blake_mid );
sph_blake256( &l2v3_blake_mid, input, 64 );
}
void lyra2rev3_hash( void *state, const void *input )
{
lyra2v3_ctx_holder ctx __attribute__ ((aligned (64)));
memcpy( &ctx, &lyra2v3_ctx, sizeof(lyra2v3_ctx) );
uint8_t hash[128] __attribute__ ((aligned (64)));
#define hashA hash
#define hashB hash+64
const int midlen = 64; // bytes
const int tail = 80 - midlen; // 16
memcpy( &ctx.blake, &l2v3_blake_mid, sizeof l2v3_blake_mid );
sph_blake256( &ctx.blake, (uint8_t*)input + midlen, tail );
sph_blake256_close( &ctx.blake, hash );
LYRA2REV3( l2v3_wholeMatrix, hash, 32, hash, 32, hash, 32, 1, 4, 4 );
cubehashUpdateDigest( &ctx.cube, (byte*) hashA,
(const byte*) hash, 32 );
LYRA2REV3( l2v3_wholeMatrix, hash, 32, hash, 32, hash, 32, 1, 4, 4 );
sph_bmw256( &ctx.bmw, hash, 32 );
sph_bmw256_close( &ctx.bmw, hash );
memcpy( state, hash, 32 );
}
int scanhash_lyra2rev3(int thr_id, struct work *work,
uint32_t max_nonce, uint64_t *hashes_done)
{
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
uint32_t endiandata[20] __attribute__ ((aligned (64)));
uint32_t hash[8] __attribute__((aligned(64)));
const uint32_t first_nonce = pdata[19];
uint32_t nonce = first_nonce;
const uint32_t Htarg = ptarget[7];
if (opt_benchmark)
((uint32_t*)ptarget)[7] = 0x0000ff;
swab32_array( endiandata, pdata, 20 );
l2v3_blake256_midstate( endiandata );
do {
be32enc(&endiandata[19], nonce);
lyra2rev3_hash(hash, endiandata);
if (hash[7] <= Htarg )
{
if( fulltest(hash, ptarget) )
{
pdata[19] = nonce;
work_set_target_ratio( work, hash );
*hashes_done = pdata[19] - first_nonce;
return 1;
}
}
nonce++;
} while (nonce < max_nonce && !work_restart[thr_id].restart);
pdata[19] = nonce;
*hashes_done = pdata[19] - first_nonce + 1;
return 0;
}