mirror of
https://github.com/JayDDee/cpuminer-opt.git
synced 2025-09-17 23:44:27 +00:00
Initial upload v3.4.7
This commit is contained in:
0
algo/x11/.dirstamp
Normal file
0
algo/x11/.dirstamp
Normal file
251
algo/x11/c11.c
Normal file
251
algo/x11/c11.c
Normal file
@@ -0,0 +1,251 @@
|
||||
#include "miner.h"
|
||||
#include "algo-gate-api.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "algo/blake/sph_blake.h"
|
||||
#include "algo/bmw/sph_bmw.h"
|
||||
#include "algo/groestl/sph_groestl.h"
|
||||
#include "algo/jh/sph_jh.h"
|
||||
#include "algo/keccak/sph_keccak.h"
|
||||
#include "algo/skein/sph_skein.h"
|
||||
#include "algo/luffa/sph_luffa.h"
|
||||
#include "algo/cubehash/sph_cubehash.h"
|
||||
#include "algo/shavite/sph_shavite.h"
|
||||
#include "algo/simd/sph_simd.h"
|
||||
#include "algo/echo/sph_echo.h"
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
// #include "algo/echo/sph_echo.h"
|
||||
// #include "algo/groestl/sph_groestl.h"
|
||||
#else
|
||||
#include "algo/groestl/aes_ni/hash-groestl.h"
|
||||
#include "algo/echo/aes_ni/hash_api.h"
|
||||
#endif
|
||||
|
||||
#include "algo/luffa/sse2/luffa_for_sse2.h"
|
||||
#include "algo/cubehash/sse2/cubehash_sse2.h"
|
||||
#include "algo/simd/sse2/nist.h"
|
||||
#include "algo/blake/sse2/blake.c"
|
||||
#include "algo/keccak/sse2/keccak.c"
|
||||
#include "algo/bmw/sse2/bmw.c"
|
||||
#include "algo/skein/sse2/skein.c"
|
||||
#include "algo/jh/sse2/jh_sse2_opt64.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
sph_shavite512_context shavite;
|
||||
sph_skein512_context skein;
|
||||
#ifdef NO_AES_NI
|
||||
sph_groestl512_context groestl;
|
||||
sph_echo512_context echo;
|
||||
#else
|
||||
hashState_echo echo;
|
||||
hashState_groestl groestl;
|
||||
#endif
|
||||
hashState_luffa luffa;
|
||||
cubehashParam cube;
|
||||
hashState_sd simd;
|
||||
} c11_ctx_holder;
|
||||
|
||||
c11_ctx_holder c11_ctx;
|
||||
|
||||
void init_c11_ctx()
|
||||
{
|
||||
init_luffa( &c11_ctx.luffa, 512 );
|
||||
cubehashInit( &c11_ctx.cube, 512, 16, 32 );
|
||||
sph_shavite512_init( &c11_ctx.shavite );
|
||||
init_sd( &c11_ctx.simd, 512 );
|
||||
#ifdef NO_AES_NI
|
||||
sph_groestl512_init( &c11_ctx.groestl );
|
||||
sph_echo512_init( &c11_ctx.echo );
|
||||
#else
|
||||
init_echo( &c11_ctx.echo, 512 );
|
||||
init_groestl( &c11_ctx.groestl );
|
||||
#endif
|
||||
}
|
||||
|
||||
void c11hash( void *output, const void *input )
|
||||
{
|
||||
unsigned char hash[128]; // uint32_t hashA[16], hashB[16];
|
||||
// uint32_t _ALIGN(64) hash[16];
|
||||
|
||||
c11_ctx_holder ctx;
|
||||
memcpy( &ctx, &c11_ctx, sizeof(c11_ctx) );
|
||||
|
||||
size_t hashptr;
|
||||
unsigned char hashbuf[128];
|
||||
sph_u64 hashctA;
|
||||
sph_u64 hashctB;
|
||||
|
||||
DECL_BLK;
|
||||
BLK_I;
|
||||
BLK_W;
|
||||
BLK_C;
|
||||
|
||||
DECL_BMW;
|
||||
BMW_I;
|
||||
BMW_U;
|
||||
#define M(x) sph_dec64le_aligned(data + 8 * (x))
|
||||
#define H(x) (h[x])
|
||||
#define dH(x) (dh[x])
|
||||
BMW_C;
|
||||
#undef M
|
||||
#undef H
|
||||
#undef dH
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
sph_groestl512 (&ctx.groestl, hash, 64);
|
||||
sph_groestl512_close(&ctx.groestl, hash);
|
||||
#else
|
||||
update_groestl( &ctx.groestl, (char*)hash,512);
|
||||
final_groestl( &ctx.groestl, (char*)hash);
|
||||
#endif
|
||||
|
||||
DECL_JH;
|
||||
JH_H;
|
||||
|
||||
DECL_KEC;
|
||||
KEC_I;
|
||||
KEC_U;
|
||||
KEC_C;
|
||||
|
||||
DECL_SKN;
|
||||
SKN_I;
|
||||
SKN_U;
|
||||
SKN_C;
|
||||
|
||||
update_luffa( &ctx.luffa, (const BitSequence*)hash,512);
|
||||
final_luffa( &ctx.luffa, (BitSequence*)hash+64);
|
||||
|
||||
cubehashUpdate( &ctx.cube, (const byte*) hash+64,64);
|
||||
cubehashDigest( &ctx.cube, (byte*)hash);
|
||||
|
||||
sph_shavite512( &ctx.shavite, hash, 64);
|
||||
sph_shavite512_close( &ctx.shavite, hash+64);
|
||||
|
||||
update_sd( &ctx.simd, (const BitSequence *)hash+64,512);
|
||||
final_sd( &ctx.simd, (BitSequence *)hash);
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
sph_echo512 (&ctx.echo, hash, 64);
|
||||
sph_echo512_close(&ctx.echo, hash+64);
|
||||
#else
|
||||
update_echo ( &ctx.echo, (const BitSequence *) hash, 512);
|
||||
final_echo( &ctx.echo, (BitSequence *) hash+64 );
|
||||
#endif
|
||||
|
||||
memcpy(output, hash+64, 32);
|
||||
}
|
||||
|
||||
void c11hash_alt( void *output, const void *input )
|
||||
{
|
||||
unsigned char hash[128];
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_skein512_context ctx_skein;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_luffa512_context ctx_luffa1;
|
||||
sph_cubehash512_context ctx_cubehash1;
|
||||
sph_shavite512_context ctx_shavite1;
|
||||
sph_simd512_context ctx_simd1;
|
||||
sph_echo512_context ctx_echo;
|
||||
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, 80);
|
||||
sph_blake512_close (&ctx_blake, hash);
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, hash, 64);
|
||||
sph_bmw512_close(&ctx_bmw, hash);
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, hash);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hash, 64);
|
||||
sph_jh512_close(&ctx_jh, hash);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, hash, 64);
|
||||
sph_keccak512_close(&ctx_keccak, hash);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hash, 64);
|
||||
sph_skein512_close (&ctx_skein, hash);
|
||||
|
||||
sph_luffa512_init (&ctx_luffa1);
|
||||
sph_luffa512 (&ctx_luffa1, hash, 64);
|
||||
sph_luffa512_close (&ctx_luffa1, hash);
|
||||
|
||||
sph_cubehash512_init (&ctx_cubehash1);
|
||||
sph_cubehash512 (&ctx_cubehash1, hash, 64);
|
||||
sph_cubehash512_close(&ctx_cubehash1, hash);
|
||||
|
||||
sph_shavite512_init (&ctx_shavite1);
|
||||
sph_shavite512 (&ctx_shavite1, hash, 64);
|
||||
sph_shavite512_close(&ctx_shavite1, hash);
|
||||
|
||||
sph_simd512_init (&ctx_simd1);
|
||||
sph_simd512 (&ctx_simd1, hash, 64);
|
||||
sph_simd512_close(&ctx_simd1, hash);
|
||||
|
||||
sph_echo512_init (&ctx_echo);
|
||||
sph_echo512 (&ctx_echo, hash, 64);
|
||||
sph_echo512_close(&ctx_echo, hash);
|
||||
|
||||
memcpy(output, hash+64, 32);
|
||||
}
|
||||
|
||||
int scanhash_c11( int thr_id, struct work *work, uint32_t max_nonce,
|
||||
uint64_t *hashes_done )
|
||||
{
|
||||
uint32_t endiandata[20] __attribute__((aligned(64)));
|
||||
uint32_t hash[8] __attribute__((aligned(32)));
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t nonce = first_nonce;
|
||||
volatile uint8_t *restart = &(work_restart[thr_id].restart);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0cff;
|
||||
|
||||
swab32_array( endiandata, pdata, 20 );
|
||||
|
||||
do
|
||||
{
|
||||
be32enc( &endiandata[19], nonce );
|
||||
c11hash( hash, endiandata );
|
||||
if ( hash[7] <= Htarg && fulltest(hash, ptarget) )
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
bool register_c11_algo( algo_gate_t* gate )
|
||||
{
|
||||
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT;
|
||||
init_c11_ctx();
|
||||
gate->scanhash = (void*)&scanhash_c11;
|
||||
gate->hash = (void*)&c11hash;
|
||||
gate->hash_alt = (void*)&c11hash_alt;
|
||||
gate->get_max64 = (void*)&get_max64_0x3ffff;
|
||||
return true;
|
||||
};
|
||||
|
||||
276
algo/x11/x11.c
Normal file
276
algo/x11/x11.c
Normal file
@@ -0,0 +1,276 @@
|
||||
#include "cpuminer-config.h"
|
||||
#include "miner.h"
|
||||
#include "algo-gate-api.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "algo/blake/sph_blake.h"
|
||||
#include "algo/bmw/sph_bmw.h"
|
||||
#include "algo/groestl/sph_groestl.h"
|
||||
#include "algo/jh/sph_jh.h"
|
||||
#include "algo/keccak/sph_keccak.h"
|
||||
#include "algo/skein/sph_skein.h"
|
||||
#include "algo/luffa/sph_luffa.h"
|
||||
#include "algo/cubehash/sph_cubehash.h"
|
||||
#include "algo/shavite/sph_shavite.h"
|
||||
#include "algo/simd/sph_simd.h"
|
||||
#include "algo/echo/sph_echo.h"
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
#include "algo/groestl/sse2/grso.h"
|
||||
#include "algo/groestl/sse2/grso-macro.c"
|
||||
#else
|
||||
#include "algo/groestl/aes_ni/hash-groestl.h"
|
||||
#include "algo/echo/aes_ni/hash_api.h"
|
||||
#endif
|
||||
|
||||
#include "algo/luffa/sse2/luffa_for_sse2.h"
|
||||
#include "algo/cubehash/sse2/cubehash_sse2.h"
|
||||
#include "algo/simd/sse2/nist.h"
|
||||
#include "algo/blake/sse2/blake.c"
|
||||
#include "algo/keccak/sse2/keccak.c"
|
||||
#include "algo/bmw/sse2/bmw.c"
|
||||
#include "algo/skein/sse2/skein.c"
|
||||
#include "algo/jh/sse2/jh_sse2_opt64.h"
|
||||
|
||||
typedef struct {
|
||||
hashState_luffa luffa;
|
||||
cubehashParam cube;
|
||||
hashState_sd simd;
|
||||
sph_shavite512_context shavite;
|
||||
#ifdef NO_AES_NI
|
||||
// sph_groestl512_context groestl;
|
||||
sph_echo512_context echo;
|
||||
#else
|
||||
hashState_echo echo;
|
||||
hashState_groestl groestl;
|
||||
#endif
|
||||
} x11_ctx_holder;
|
||||
|
||||
x11_ctx_holder x11_ctx;
|
||||
|
||||
void init_x11_ctx()
|
||||
{
|
||||
init_luffa( &x11_ctx.luffa, 512 );
|
||||
cubehashInit( &x11_ctx.cube, 512, 16, 32 );
|
||||
sph_shavite512_init( &x11_ctx.shavite );
|
||||
init_sd( &x11_ctx.simd, 512 );
|
||||
#ifdef NO_AES_NI
|
||||
// sph_groestl512_init( &x11_ctx.groestl );
|
||||
sph_echo512_init( &x11_ctx.echo );
|
||||
#else
|
||||
init_echo( &x11_ctx.echo, 512 );
|
||||
init_groestl( &x11_ctx.groestl );
|
||||
#endif
|
||||
}
|
||||
|
||||
static void x11_hash( void *state, const void *input )
|
||||
{
|
||||
unsigned char hash[128] __attribute__ ((aligned (16)));
|
||||
unsigned char hashbuf[128] __attribute__ ((aligned (16)));
|
||||
sph_u64 hashctA;
|
||||
sph_u64 hashctB;
|
||||
x11_ctx_holder ctx;
|
||||
memcpy( &ctx, &x11_ctx, sizeof(x11_ctx) );
|
||||
size_t hashptr;
|
||||
|
||||
DECL_BLK;
|
||||
BLK_I;
|
||||
BLK_W;
|
||||
BLK_C;
|
||||
|
||||
DECL_BMW;
|
||||
BMW_I;
|
||||
BMW_U;
|
||||
#define M(x) sph_dec64le_aligned(data + 8 * (x))
|
||||
#define H(x) (h[x])
|
||||
#define dH(x) (dh[x])
|
||||
BMW_C;
|
||||
#undef M
|
||||
#undef H
|
||||
#undef dH
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
grsoState sts_grs;
|
||||
GRS_I;
|
||||
GRS_U;
|
||||
GRS_C;
|
||||
|
||||
// sph_groestl512 (&ctx.groestl, hash, 64);
|
||||
// sph_groestl512_close(&ctx.groestl, hash);
|
||||
#else
|
||||
update_groestl( &ctx.groestl, (char*)hash, 512 );
|
||||
final_groestl( &ctx.groestl, (char*)hash );
|
||||
#endif
|
||||
|
||||
DECL_SKN;
|
||||
SKN_I;
|
||||
SKN_U;
|
||||
SKN_C;
|
||||
|
||||
DECL_JH;
|
||||
JH_H;
|
||||
|
||||
DECL_KEC;
|
||||
KEC_I;
|
||||
KEC_U;
|
||||
KEC_C;
|
||||
|
||||
// asm volatile ("emms");
|
||||
|
||||
update_luffa( &ctx.luffa, (const BitSequence*)hash, 512 );
|
||||
final_luffa( &ctx.luffa, (BitSequence*)hash+64 );
|
||||
|
||||
cubehashUpdate( &ctx.cube, (const byte*) hash+64, 64 );
|
||||
cubehashDigest( &ctx.cube, (byte*)hash );
|
||||
|
||||
sph_shavite512( &ctx.shavite, hash, 64 );
|
||||
sph_shavite512_close( &ctx.shavite, hash+64 );
|
||||
|
||||
update_sd( &ctx.simd, (const BitSequence *)hash+64, 512 );
|
||||
final_sd( &ctx.simd, (BitSequence *)hash );
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
sph_echo512 (&ctx.echo, hash, 64 );
|
||||
sph_echo512_close(&ctx.echo, hash+64 );
|
||||
#else
|
||||
update_echo ( &ctx.echo, (const BitSequence *) hash, 512 );
|
||||
final_echo( &ctx.echo, (BitSequence *) hash+64 );
|
||||
#endif
|
||||
|
||||
// asm volatile ("emms");
|
||||
memcpy( state, hash+64, 32 );
|
||||
}
|
||||
|
||||
|
||||
static void x11hash_alt( void *output, const void *input )
|
||||
{
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_skein512_context ctx_skein;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
|
||||
sph_luffa512_context ctx_luffa1;
|
||||
sph_cubehash512_context ctx_cubehash1;
|
||||
sph_shavite512_context ctx_shavite1;
|
||||
sph_simd512_context ctx_simd1;
|
||||
sph_echo512_context ctx_echo1;
|
||||
|
||||
uint32_t _ALIGN(64) hashA[16], hashB[16];
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, 80);
|
||||
sph_blake512_close (&ctx_blake, hashA);
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, hashA, 64);
|
||||
sph_bmw512_close(&ctx_bmw, hashB);
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, hashB, 64);
|
||||
sph_groestl512_close(&ctx_groestl, hashA);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, hashA, 64);
|
||||
sph_skein512_close (&ctx_skein, hashB);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, hashB, 64);
|
||||
sph_jh512_close(&ctx_jh, hashA);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, hashA, 64);
|
||||
sph_keccak512_close(&ctx_keccak, hashB);
|
||||
|
||||
sph_luffa512_init (&ctx_luffa1);
|
||||
sph_luffa512 (&ctx_luffa1, hashB, 64);
|
||||
sph_luffa512_close (&ctx_luffa1, hashA);
|
||||
|
||||
sph_cubehash512_init (&ctx_cubehash1);
|
||||
sph_cubehash512 (&ctx_cubehash1, hashA, 64);
|
||||
sph_cubehash512_close(&ctx_cubehash1, hashB);
|
||||
|
||||
sph_shavite512_init (&ctx_shavite1);
|
||||
sph_shavite512 (&ctx_shavite1, hashB, 64);
|
||||
sph_shavite512_close(&ctx_shavite1, hashA);
|
||||
|
||||
sph_simd512_init (&ctx_simd1);
|
||||
sph_simd512 (&ctx_simd1, hashA, 64);
|
||||
sph_simd512_close(&ctx_simd1, hashB);
|
||||
|
||||
sph_echo512_init (&ctx_echo1);
|
||||
sph_echo512 (&ctx_echo1, hashB, 64);
|
||||
sph_echo512_close(&ctx_echo1, hashA);
|
||||
|
||||
memcpy(output, hashA, 32);
|
||||
}
|
||||
|
||||
int scanhash_x11( int thr_id, struct work *work, uint32_t max_nonce,
|
||||
uint64_t *hashes_done )
|
||||
{
|
||||
uint32_t endiandata[20] __attribute__((aligned(64)));
|
||||
uint32_t hash64[8] __attribute__((aligned(64)));
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
uint32_t n = pdata[19] - 1;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint64_t htmax[] = {
|
||||
0,
|
||||
0xF,
|
||||
0xFF,
|
||||
0xFFF,
|
||||
0xFFFF,
|
||||
0x10000000
|
||||
};
|
||||
uint32_t masks[] = {
|
||||
0xFFFFFFFF,
|
||||
0xFFFFFFF0,
|
||||
0xFFFFFF00,
|
||||
0xFFFFF000,
|
||||
0xFFFF0000,
|
||||
0
|
||||
};
|
||||
|
||||
// big endian encode 0..18 uint32_t, 64 bits at a time
|
||||
swab32_array( endiandata, pdata, 20 );
|
||||
|
||||
for (int m=0; m < 6; m++)
|
||||
if (Htarg <= htmax[m])
|
||||
{
|
||||
uint32_t mask = masks[m];
|
||||
do
|
||||
{
|
||||
pdata[19] = ++n;
|
||||
be32enc( &endiandata[19], n );
|
||||
x11_hash( hash64, &endiandata );
|
||||
if ( ( hash64[7] & mask ) == 0 )
|
||||
{
|
||||
if ( fulltest( hash64, ptarget ) )
|
||||
{
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} while ( n < max_nonce && !work_restart[thr_id].restart );
|
||||
}
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool register_x11_algo( algo_gate_t* gate )
|
||||
{
|
||||
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT;
|
||||
init_x11_ctx();
|
||||
gate->scanhash = (void*)&scanhash_x11;
|
||||
gate->hash = (void*)&x11_hash;
|
||||
gate->get_max64 = (void*)&get_max64_0x3ffff;
|
||||
gate->hash_alt = (void*)&x11hash_alt;
|
||||
return true;
|
||||
};
|
||||
|
||||
288
algo/x11/x11evo.c
Normal file
288
algo/x11/x11evo.c
Normal file
@@ -0,0 +1,288 @@
|
||||
#include "cpuminer-config.h"
|
||||
#include "miner.h"
|
||||
#include "algo-gate-api.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <compat/portable_endian.h>
|
||||
|
||||
#include "algo/blake/sph_blake.h"
|
||||
#include "algo/bmw/sph_bmw.h"
|
||||
#include "algo/groestl/sph_groestl.h"
|
||||
#include "algo/jh/sph_jh.h"
|
||||
#include "algo/keccak/sph_keccak.h"
|
||||
#include "algo/skein/sph_skein.h"
|
||||
#include "algo/luffa/sph_luffa.h"
|
||||
#include "algo/cubehash/sph_cubehash.h"
|
||||
#include "algo/shavite/sph_shavite.h"
|
||||
#include "algo/simd/sph_simd.h"
|
||||
#include "algo/echo/sph_echo.h"
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
// #include "algo/groestl/sse2/grso.h"
|
||||
// #include "algo/groestl/sse2/grso-macro.c"
|
||||
#else
|
||||
#include "algo/groestl/aes_ni/hash-groestl.h"
|
||||
#include "algo/echo/aes_ni/hash_api.h"
|
||||
#endif
|
||||
|
||||
#include "algo/luffa/sse2/luffa_for_sse2.h"
|
||||
#include "algo/cubehash/sse2/cubehash_sse2.h"
|
||||
#include "algo/simd/sse2/nist.h"
|
||||
|
||||
#define INITIAL_DATE 1462060800
|
||||
#define HASH_FUNC_COUNT 11
|
||||
|
||||
typedef struct {
|
||||
#ifdef NO_AES_NI
|
||||
sph_groestl512_context groestl;
|
||||
sph_echo512_context echo;
|
||||
#else
|
||||
hashState_echo echo;
|
||||
hashState_groestl groestl;
|
||||
#endif
|
||||
hashState_luffa luffa;
|
||||
cubehashParam cube;
|
||||
hashState_sd simd;
|
||||
sph_blake512_context blake;
|
||||
sph_bmw512_context bmw;
|
||||
sph_skein512_context skein;
|
||||
sph_jh512_context jh;
|
||||
sph_keccak512_context keccak;
|
||||
sph_shavite512_context shavite;
|
||||
} x11evo_ctx_holder;
|
||||
|
||||
static x11evo_ctx_holder x11evo_ctx;
|
||||
|
||||
void init_x11evo_ctx()
|
||||
{
|
||||
#ifdef NO_AES_NI
|
||||
sph_groestl512_init( &x11evo_ctx.groestl );
|
||||
sph_echo512_init( &x11evo_ctx.echo );
|
||||
#else
|
||||
init_echo( &x11evo_ctx.echo, 512 );
|
||||
init_groestl( &x11evo_ctx.groestl );
|
||||
#endif
|
||||
init_luffa( &x11evo_ctx.luffa, 512 );
|
||||
cubehashInit( &x11evo_ctx.cube, 512, 16, 32 );
|
||||
init_sd( &x11evo_ctx.simd, 512 );
|
||||
sph_blake512_init( &x11evo_ctx.blake );
|
||||
sph_bmw512_init( &x11evo_ctx.bmw );
|
||||
sph_skein512_init( &x11evo_ctx.skein );
|
||||
sph_jh512_init( &x11evo_ctx.jh );
|
||||
sph_keccak512_init( &x11evo_ctx.keccak );
|
||||
sph_shavite512_init( &x11evo_ctx.shavite );
|
||||
}
|
||||
|
||||
uint32_t getCurrentAlgoSeq(uint32_t current_time, uint32_t base_time)
|
||||
{
|
||||
return (current_time - base_time) / (60 * 60 * 24);
|
||||
}
|
||||
|
||||
void swap( uint8_t *a, uint8_t *b )
|
||||
{
|
||||
uint8_t __tmp = *a;
|
||||
*a = *b;
|
||||
*b = __tmp;
|
||||
}
|
||||
|
||||
void initPerm( uint8_t n[], uint8_t count )
|
||||
{
|
||||
int i;
|
||||
for ( i = 0; i<count; i++ )
|
||||
n[i] = i;
|
||||
}
|
||||
|
||||
int nextPerm( uint8_t n[], uint32_t count )
|
||||
{
|
||||
uint32_t tail, i, j;
|
||||
|
||||
if (unlikely( count <= 1 ))
|
||||
return 0;
|
||||
|
||||
for ( i = count - 1; i>0 && n[i - 1] >= n[i]; i-- );
|
||||
tail = i;
|
||||
|
||||
if ( tail > 0 )
|
||||
for ( j = count - 1; j>tail && n[j] <= n[tail - 1]; j-- );
|
||||
swap( &n[tail - 1], &n[j] );
|
||||
|
||||
for ( i = tail, j = count - 1; i<j; i++, j-- )
|
||||
swap( &n[i], &n[j] );
|
||||
|
||||
return ( tail != 0 );
|
||||
}
|
||||
|
||||
void getAlgoString( char *str, uint32_t count )
|
||||
{
|
||||
uint8_t algoList[HASH_FUNC_COUNT];
|
||||
char *sptr;
|
||||
int j;
|
||||
int k;
|
||||
initPerm( algoList, HASH_FUNC_COUNT );
|
||||
|
||||
for ( k = 0; k < count; k++ )
|
||||
nextPerm( algoList, HASH_FUNC_COUNT );
|
||||
|
||||
sptr = str;
|
||||
for ( j = 0; j < HASH_FUNC_COUNT; j++ )
|
||||
{
|
||||
if ( algoList[j] >= 10 )
|
||||
sprintf( sptr, "%c", 'A' + (algoList[j] - 10) );
|
||||
else
|
||||
sprintf( sptr, "%u", algoList[j] );
|
||||
sptr++;
|
||||
}
|
||||
*sptr = 0;
|
||||
|
||||
//applog(LOG_DEBUG, "nextPerm %s", str);
|
||||
}
|
||||
|
||||
void evocoin_twisted_code( char *result, char *code )
|
||||
{
|
||||
uint32_t h32, *be32 = get_stratum_job_ntime();
|
||||
h32 = be32toh(*be32);
|
||||
|
||||
uint32_t count = getCurrentAlgoSeq(h32, INITIAL_DATE);
|
||||
getAlgoString(code, count);
|
||||
sprintf(result, "_%d_%s_", count, code);
|
||||
}
|
||||
|
||||
static inline void x11evo_hash( void *state, const void *input )
|
||||
{
|
||||
uint32_t hash[16];
|
||||
char completeCode[64];
|
||||
char resultCode[HASH_FUNC_COUNT + 1];
|
||||
x11evo_ctx_holder ctx;
|
||||
memcpy( &ctx, &x11evo_ctx, sizeof(x11evo_ctx) );
|
||||
evocoin_twisted_code( completeCode, resultCode );
|
||||
|
||||
int i;
|
||||
for ( i = 0; i < strlen(resultCode); i++ )
|
||||
{
|
||||
char elem = resultCode[i];
|
||||
uint8_t idx;
|
||||
if (elem >= 'A')
|
||||
idx = elem - 'A' + 10;
|
||||
else
|
||||
idx = elem - '0';
|
||||
|
||||
int size = 64;
|
||||
|
||||
switch (idx)
|
||||
{
|
||||
case 0:
|
||||
sph_blake512( &ctx.blake, (char*)input, 80 );
|
||||
sph_blake512_close( &ctx.blake, (char*)hash );
|
||||
break;
|
||||
case 1:
|
||||
sph_bmw512( &ctx.bmw, (char*)hash, size );
|
||||
sph_bmw512_close( &ctx.bmw, (char*)hash );
|
||||
break;
|
||||
case 2:
|
||||
#ifdef NO_AES_NI
|
||||
sph_groestl512( &ctx.groestl, (char*)hash, size );
|
||||
sph_groestl512_close( &ctx.groestl, (char*)hash );
|
||||
#else
|
||||
update_groestl( &ctx.groestl, (char*)hash, 512 );
|
||||
final_groestl( &ctx.groestl, (char*)hash );
|
||||
#endif
|
||||
break;
|
||||
case 3:
|
||||
sph_skein512( &ctx.skein, (char*)hash, size );
|
||||
sph_skein512_close( &ctx.skein, (char*)hash );
|
||||
break;
|
||||
case 4:
|
||||
sph_jh512( &ctx.jh, (char*)hash, size );
|
||||
sph_jh512_close( &ctx.jh, (char*)hash );
|
||||
break;
|
||||
case 5:
|
||||
sph_keccak512( &ctx.keccak, (char*)hash, size );
|
||||
sph_keccak512_close( &ctx.keccak, (char*)hash );
|
||||
break;
|
||||
case 6:
|
||||
update_luffa( &ctx.luffa, (char*)hash, 512 );
|
||||
final_luffa( &ctx.luffa, (char*)hash );
|
||||
break;
|
||||
case 7:
|
||||
cubehashUpdate( &ctx.cube, (char*)hash, 64 );
|
||||
cubehashDigest( &ctx.cube, (char*)hash );
|
||||
break;
|
||||
case 8:
|
||||
sph_shavite512( &ctx.shavite, (char*)hash, size );
|
||||
sph_shavite512_close( &ctx.shavite, (char*)hash );
|
||||
break;
|
||||
case 9:
|
||||
update_sd( &ctx.simd, (char*)hash, 512 );
|
||||
final_sd( &ctx.simd, (char*)hash );
|
||||
break;
|
||||
case 10:
|
||||
#ifdef NO_AES_NI
|
||||
sph_echo512( &ctx.echo, (char*)hash, size );
|
||||
sph_echo512_close( &ctx.echo, (char*)hash );
|
||||
#else
|
||||
update_echo( &ctx.echo, (char*)hash, 512 );
|
||||
final_echo( &ctx.echo, (char*)hash );
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
memcpy( state, hash, 32 );
|
||||
}
|
||||
|
||||
static const uint32_t diff1targ = 0x0000ffff;
|
||||
|
||||
int scanhash_x11evo( int thr_id, struct work* work, uint32_t max_nonce,
|
||||
unsigned long *hashes_done )
|
||||
{
|
||||
uint32_t endiandata[20] __attribute__((aligned(64)));
|
||||
uint32_t hash64[8] __attribute__((aligned(32)));
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
uint32_t n = pdata[19] - 1;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
|
||||
swab32_array( endiandata, pdata, 20 );
|
||||
|
||||
uint32_t hmask = 0xFFFFFFFF;
|
||||
if ( Htarg > 0 )
|
||||
if ( Htarg <= 0xF )
|
||||
hmask = 0xFFFFFFF0;
|
||||
else if ( Htarg <= 0xFF )
|
||||
hmask = 0xFFFFFF00;
|
||||
else if ( Htarg <= 0xFFF )
|
||||
hmask = 0xFFFF000;
|
||||
else if ( Htarg <= 0xFFFF )
|
||||
hmask = 0xFFFF000;
|
||||
|
||||
do
|
||||
{
|
||||
pdata[19] = ++n;
|
||||
be32enc( &endiandata[19], n );
|
||||
x11evo_hash( hash64, &endiandata );
|
||||
if ( ( hash64[7] & hmask ) == 0 )
|
||||
{
|
||||
if ( fulltest( hash64, ptarget ) )
|
||||
{
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} while ( n < max_nonce && !work_restart[thr_id].restart );
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool register_x11evo_algo( algo_gate_t* gate )
|
||||
{
|
||||
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT;
|
||||
gate->scanhash = (void*)&scanhash_x11evo;
|
||||
gate->hash = (void*)&x11evo_hash;
|
||||
gate->hash_alt = (void*)&x11evo_hash;
|
||||
init_x11evo_ctx();
|
||||
return true;
|
||||
};
|
||||
|
||||
190
algo/x11/x11gost.c
Normal file
190
algo/x11/x11gost.c
Normal file
@@ -0,0 +1,190 @@
|
||||
#include "miner.h"
|
||||
#include "algo-gate-api.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "algo/gost/sph_gost.h"
|
||||
#include "algo/shavite/sph_shavite.h"
|
||||
#include "algo/echo/sph_echo.h"
|
||||
|
||||
#include "algo/luffa/sse2/luffa_for_sse2.h"
|
||||
#include "algo/cubehash/sse2/cubehash_sse2.h"
|
||||
#include "algo/simd/sse2/nist.h"
|
||||
#include "algo/blake/sse2/blake.c"
|
||||
#include "algo/keccak/sse2/keccak.c"
|
||||
#include "algo/bmw/sse2/bmw.c"
|
||||
#include "algo/skein/sse2/skein.c"
|
||||
#include "algo/jh/sse2/jh_sse2_opt64.h"
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
#include "algo/groestl/sse2/grso.h"
|
||||
#include "algo/groestl/sse2/grso-macro.c"
|
||||
#else
|
||||
#include "algo/groestl/aes_ni/hash-groestl.h"
|
||||
#include "algo/echo/aes_ni/hash_api.h"
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
sph_gost512_context gost;
|
||||
sph_shavite512_context shavite;
|
||||
hashState_luffa luffa;
|
||||
cubehashParam cube;
|
||||
hashState_sd simd;
|
||||
#ifdef NO_AES_NI
|
||||
sph_echo512_context echo;
|
||||
#else
|
||||
hashState_echo echo;
|
||||
hashState_groestl groestl;
|
||||
#endif
|
||||
} sib_ctx_holder;
|
||||
|
||||
sib_ctx_holder sib_ctx;
|
||||
|
||||
void init_sib_ctx()
|
||||
{
|
||||
sph_gost512_init(&sib_ctx.gost);
|
||||
sph_shavite512_init(&sib_ctx.shavite);
|
||||
init_luffa( &sib_ctx.luffa, 512 );
|
||||
cubehashInit( &sib_ctx.cube, 512, 16, 32 );
|
||||
init_sd( &sib_ctx.simd, 512 );
|
||||
#ifdef NO_AES_NI
|
||||
sph_echo512_init( &sib_ctx.echo );
|
||||
#else
|
||||
init_echo( &sib_ctx.echo, 512 );
|
||||
init_groestl( &sib_ctx.groestl );
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
void sibhash(void *output, const void *input)
|
||||
{
|
||||
unsigned char hash[128]; // uint32_t hashA[16], hashB[16];
|
||||
#define hashA hash
|
||||
#define hashB hash+64
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
grsoState sts_grs;
|
||||
#endif
|
||||
|
||||
size_t hashptr;
|
||||
unsigned char hashbuf[128];
|
||||
sph_u64 hashctA;
|
||||
sph_u64 hashctB;
|
||||
|
||||
sib_ctx_holder ctx;
|
||||
memcpy( &ctx, &sib_ctx, sizeof(sib_ctx) );
|
||||
|
||||
DECL_BLK;
|
||||
BLK_I;
|
||||
BLK_W;
|
||||
BLK_C;
|
||||
|
||||
DECL_BMW;
|
||||
BMW_I;
|
||||
BMW_U;
|
||||
#define M(x) sph_dec64le_aligned(data + 8 * (x))
|
||||
#define H(x) (h[x])
|
||||
#define dH(x) (dh[x])
|
||||
BMW_C;
|
||||
#undef M
|
||||
#undef H
|
||||
#undef dH
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
GRS_I;
|
||||
GRS_U;
|
||||
GRS_C;
|
||||
#else
|
||||
update_groestl( &ctx.groestl, (char*)hash,512);
|
||||
final_groestl( &ctx.groestl, (char*)hash);
|
||||
#endif
|
||||
|
||||
DECL_SKN;
|
||||
SKN_I;
|
||||
SKN_U;
|
||||
SKN_C;
|
||||
|
||||
DECL_JH;
|
||||
JH_H;
|
||||
|
||||
DECL_KEC;
|
||||
KEC_I;
|
||||
KEC_U;
|
||||
KEC_C;
|
||||
|
||||
sph_gost512(&ctx.gost, hashA, 64);
|
||||
sph_gost512_close(&ctx.gost, hashB);
|
||||
|
||||
update_luffa( &ctx.luffa, (const BitSequence*)hashB,512);
|
||||
final_luffa( &ctx.luffa, (BitSequence*)hashA);
|
||||
|
||||
cubehashUpdate( &ctx.cube, (const byte*) hashA,64);
|
||||
cubehashDigest( &ctx.cube, (byte*)hashB);
|
||||
|
||||
sph_shavite512(&ctx.shavite, hashB, 64);
|
||||
sph_shavite512_close(&ctx.shavite, hashA);
|
||||
|
||||
update_sd( &ctx.simd, (const BitSequence *)hashA,512);
|
||||
final_sd( &ctx.simd, (BitSequence *)hashB);
|
||||
|
||||
#ifdef NO_AES_NI
|
||||
sph_echo512(&ctx.echo, hashB, 64);
|
||||
sph_echo512_close(&ctx.echo, hashA);
|
||||
#else
|
||||
update_echo ( &ctx.echo, (const BitSequence *) hashB, 512);
|
||||
final_echo( &ctx.echo, (BitSequence *) hashA );
|
||||
#endif
|
||||
|
||||
memcpy(output, hashA, 32);
|
||||
}
|
||||
|
||||
int scanhash_sib(int thr_id, struct work *work,
|
||||
uint32_t max_nonce, uint64_t *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t nonce = first_nonce;
|
||||
volatile uint8_t *restart = &(work_restart[thr_id].restart);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0cff;
|
||||
|
||||
for (int k = 0; k < 19; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
do {
|
||||
uint32_t hash[8];
|
||||
be32enc(&endiandata[19], nonce);
|
||||
sibhash(hash, endiandata);
|
||||
|
||||
if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
|
||||
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;
|
||||
}
|
||||
|
||||
bool register_sib_algo( algo_gate_t* gate )
|
||||
{
|
||||
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT;
|
||||
init_sib_ctx();
|
||||
gate->scanhash = (void*)&scanhash_sib;
|
||||
gate->hash = (void*)&sibhash;
|
||||
gate->hash_alt = (void*)&sibhash;
|
||||
gate->get_max64 = (void*)&get_max64_0x3ffff;
|
||||
}
|
||||
Reference in New Issue
Block a user