Files
cpuminer-opt-gpu/algo/polytimos/polytimos.c.broke
Jay D Dee 6d1361c87f v3.7.3
2017-11-20 21:19:15 -05:00

126 lines
3.3 KiB
Plaintext

#include "polytimos-gate.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "algo/skein/sph_skein.h"
#include "algo/echo/sph_echo.h"
#include "algo/fugue/sph_fugue.h"
#include "algo/luffa/sph_luffa.h"
#include "algo/shabal/sph_shabal.h"
#include "algo/gost/sph_gost.h"
#include "algo/luffa/sse2/luffa_for_sse2.h"
#ifndef NO_AES_NI
#include "algo/echo/aes_ni/hash_api.h"
#endif
/* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */
typedef struct {
sph_skein512_context skein;
sph_luffa512_context luffa;
// hashState_luffa luffa;
//#ifdef NO_AES_NI
sph_echo512_context echo;
//#else
// hashState_echo echo;
//#endif
sph_shabal512_context shabal;
sph_fugue512_context fugue;
sph_gost512_context gost;
} poly_context_holder;
static __thread poly_context_holder poly_ctx __attribute__ ((aligned (64)));
void init_polytimos_context()
{
sph_skein512_init(&poly_ctx.skein);
sph_shabal512_init(&poly_ctx.shabal);
//#ifdef NO_AES_NI
sph_echo512_init(&poly_ctx.echo);
//#else
// init_echo( &poly_ctx.echo, 512 );
//#endif
// init_luffa( &poly_ctx.luffa, 512 );
sph_luffa512_init(&poly_ctx.luffa);
sph_fugue512_init(&poly_ctx.fugue);
sph_gost512_init(&poly_ctx.gost);
}
void polytimos_hash(void *output, const void *input)
{
poly_context_holder ctx __attribute__ ((aligned (64)));
uint32_t hashA[16]__attribute__ ((aligned (64)));
memcpy( &ctx, &poly_ctx, sizeof(poly_ctx) );
sph_skein512(&ctx.skein, input, 80);
sph_skein512_close(&ctx.skein, hashA);
sph_shabal512(&ctx.shabal, hashA, 64);
sph_shabal512_close(&ctx.shabal, hashA);
//#ifdef NO_AES_NI
sph_echo512(&ctx.echo, hashA, 64);
sph_echo512_close(&ctx.echo, hashA);
//#else
// update_final_echo ( &ctx.echo, (BitSequence *)hashA,
// (const BitSequence *)hashA, 512 );
//#endif
// update_and_final_luffa( &ctx.luffa, (BitSequence*)hashA,
// (const BitSequence*)hashA, 64 );
sph_luffa512(&ctx.luffa, hashA, 64);
sph_luffa512_close(&ctx.luffa, hashA);
sph_fugue512(&ctx.fugue, hashA, 64);
sph_fugue512_close(&ctx.fugue, hashA);
sph_gost512(&ctx.gost, hashA, 64);
sph_gost512_close(&ctx.gost, hashA);
memcpy(output, hashA, 32);
}
int scanhash_polytimos( int thr_id, struct work *work, uint32_t max_nonce,
uint64_t *hashes_done )
{
uint32_t _ALIGN(128) hash[8];
uint32_t _ALIGN(128) endiandata[20];
uint32_t *pdata = work->data;
uint32_t *ptarget = work->target;
const uint32_t Htarg = ptarget[7];
const uint32_t first_nonce = pdata[19];
uint32_t nonce = first_nonce;
volatile uint8_t *restart = &(work_restart[thr_id].restart);
if (opt_benchmark)
ptarget[7] = 0x0cff;
// we need bigendian data...
for (int i=0; i < 19; i++) {
be32enc(&endiandata[i], pdata[i]);
}
do {
be32enc(&endiandata[19], nonce);
polytimos_hash(hash, endiandata);
if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
work_set_target_ratio(work, hash);
pdata[19] = nonce;
*hashes_done = pdata[19] - first_nonce;
return 1;
}
nonce++;
} while (nonce < max_nonce && !(*restart));
pdata[19] = nonce;
*hashes_done = pdata[19] - first_nonce + 1;
return 0;
}