mirror of
https://github.com/JayDDee/cpuminer-opt.git
synced 2025-09-17 23:44:27 +00:00
v3.6.2
This commit is contained in:
262
algo/m7m.c
262
algo/m7m.c
@@ -14,6 +14,10 @@
|
||||
#include "algo/tiger/sph_tiger.h"
|
||||
#include "algo/whirlpool/sph_whirlpool.h"
|
||||
#include "algo/ripemd/sph_ripemd.h"
|
||||
#if defined (SHA_NI)
|
||||
#include <openssl/sha.h>
|
||||
#endif
|
||||
|
||||
|
||||
#define EPSa DBL_EPSILON
|
||||
#define EPS1 DBL_EPSILON
|
||||
@@ -64,9 +68,7 @@ double GaussianQuad_N2(const double x1, const double x2)
|
||||
double x[6], w[6];
|
||||
//gauleg(a2, b2, x, w);
|
||||
|
||||
// int m;
|
||||
double z1, z, xm, xl, pp, p3, p2, p1;
|
||||
// m=3;
|
||||
xm=0.5*(x2+x1);
|
||||
xl=0.5*(x2-x1);
|
||||
for(int i=1;i<=3;i++)
|
||||
@@ -117,9 +119,12 @@ uint32_t sw2_(int nnounce)
|
||||
return ((uint32_t)(GaussianQuad_N2(0., wmax)*(1.+EPSa)*1.e6));
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
#if defined __SHA__
|
||||
SHA256_CTX sha256;
|
||||
#else
|
||||
sph_sha256_context sha256;
|
||||
#endif
|
||||
sph_sha512_context sha512;
|
||||
sph_keccak512_context keccak;
|
||||
sph_whirlpool_context whirlpool;
|
||||
@@ -128,13 +133,22 @@ typedef struct {
|
||||
sph_ripemd160_context ripemd;
|
||||
} m7m_ctx_holder;
|
||||
|
||||
#if defined __SHA__
|
||||
SHA256_CTX m7m_ctx_final_sha256
|
||||
#else
|
||||
sph_sha256_context m7m_ctx_final_sha256;
|
||||
#endif
|
||||
m7m_ctx_holder m7m_ctx;
|
||||
|
||||
void init_m7m_ctx()
|
||||
{
|
||||
#if defined __SHA__
|
||||
SHA256_Init( &m7m_ctx_final_sha256 );
|
||||
SHA256_Init( &m7m_ctx.sha256 );
|
||||
#else
|
||||
sph_sha256_init( &m7m_ctx_final_sha256 );
|
||||
sph_sha256_init( &m7m_ctx.sha256 );
|
||||
#endif
|
||||
sph_sha512_init( &m7m_ctx.sha512 );
|
||||
sph_keccak512_init( &m7m_ctx.keccak );
|
||||
sph_whirlpool_init( &m7m_ctx.whirlpool );
|
||||
@@ -170,18 +184,26 @@ int scanhash_m7m_hash( int thr_id, struct work* work,
|
||||
|
||||
m7m_ctx_holder ctx1, ctx2 __attribute__ ((aligned (64)));
|
||||
memcpy( &ctx1, &m7m_ctx, sizeof(m7m_ctx) );
|
||||
#if defined __SHA__
|
||||
SHA256_CTX ctx_fsha256;
|
||||
#else
|
||||
sph_sha256_context ctxf_sha256;
|
||||
#endif
|
||||
memcpy( &ctxf_sha256, &m7m_ctx_final_sha256, sizeof(ctxf_sha256) );
|
||||
|
||||
memcpy(data, pdata, 80);
|
||||
|
||||
sph_sha256( &ctx1.sha256, data, M7_MIDSTATE_LEN );
|
||||
sph_sha512( &ctx1.sha512, data, M7_MIDSTATE_LEN );
|
||||
sph_keccak512( &ctx1.keccak, data, M7_MIDSTATE_LEN );
|
||||
sph_whirlpool( &ctx1.whirlpool, data, M7_MIDSTATE_LEN );
|
||||
sph_haval256_5( &ctx1.haval, data, M7_MIDSTATE_LEN );
|
||||
sph_tiger( &ctx1.tiger, data, M7_MIDSTATE_LEN );
|
||||
sph_ripemd160( &ctx1.ripemd, data, M7_MIDSTATE_LEN );
|
||||
#if defined __SHA__
|
||||
SHA256_Update( &ctx1.sha256, data, M7_MIDSTATE_LEN );
|
||||
#else
|
||||
sph_sha256( &ctx1.sha256, data, M7_MIDSTATE_LEN );
|
||||
#endif
|
||||
sph_sha512( &ctx1.sha512, data, M7_MIDSTATE_LEN );
|
||||
sph_keccak512( &ctx1.keccak, data, M7_MIDSTATE_LEN );
|
||||
sph_whirlpool( &ctx1.whirlpool, data, M7_MIDSTATE_LEN );
|
||||
sph_haval256_5( &ctx1.haval, data, M7_MIDSTATE_LEN );
|
||||
sph_tiger( &ctx1.tiger, data, M7_MIDSTATE_LEN );
|
||||
sph_ripemd160( &ctx1.ripemd, data, M7_MIDSTATE_LEN );
|
||||
|
||||
mpz_t magipi, magisw, product, bns0, bns1;
|
||||
mpf_t magifpi, magifpi0, mpt1, mpt2, mptmp, mpten;
|
||||
@@ -207,9 +229,13 @@ int scanhash_m7m_hash( int thr_id, struct work* work,
|
||||
|
||||
memcpy( &ctx2, &ctx1, sizeof(m7m_ctx) );
|
||||
|
||||
#if defined __SHA__
|
||||
SHA256_Update( &ctx2.sha256, data_p64, 80 - M7_MIDSTATE_LEN );
|
||||
SHA256_Final( (unsigned char*) (bhash[0]), &ctx2.sha256 );
|
||||
#else
|
||||
sph_sha256( &ctx2.sha256, data_p64, 80 - M7_MIDSTATE_LEN );
|
||||
sph_sha256_close( &ctx2.sha256, (void*)(bhash[0]) );
|
||||
|
||||
#endif
|
||||
sph_sha512( &ctx2.sha512, data_p64, 80 - M7_MIDSTATE_LEN );
|
||||
sph_sha512_close( &ctx2.sha512, (void*)(bhash[1]) );
|
||||
|
||||
@@ -243,8 +269,13 @@ int scanhash_m7m_hash( int thr_id, struct work* work,
|
||||
bytes = mpz_sizeinbase(product, 256);
|
||||
mpz_export((void *)bdata, NULL, -1, 1, 0, 0, product);
|
||||
|
||||
#if defined __SHA__
|
||||
SHA256_Update( &ctxf_sha256, bdata_p64, bytes );
|
||||
SHA256_Final( (unsigned char*) hash, &ctxf_sha256 );
|
||||
#else
|
||||
sph_sha256( &ctxf_sha256, bdata, bytes );
|
||||
sph_sha256_close( &ctxf_sha256, (void*)(hash) );
|
||||
#endif
|
||||
|
||||
digits=(int)((sqrt((double)(n/2))*(1.+EPS))/9000+75);
|
||||
mp_bitcnt_t prec = (long int)(digits*BITS_PER_DIGIT+16);
|
||||
@@ -278,8 +309,13 @@ int scanhash_m7m_hash( int thr_id, struct work* work,
|
||||
mpzscale=bytes;
|
||||
mpz_export(bdata, NULL, -1, 1, 0, 0, product);
|
||||
|
||||
#if defined __SHA__
|
||||
SHA256_Update( &ctxf_sha256, bdata, bytes );
|
||||
SHA256_Final( (unsigned char*) hash, &ctxf_sha256 );
|
||||
#else
|
||||
sph_sha256( &ctxf_sha256, bdata, bytes );
|
||||
sph_sha256_close( &ctxf_sha256, (void*)(hash) );
|
||||
#endif
|
||||
}
|
||||
|
||||
const unsigned char *hash_ = (const unsigned char *)hash;
|
||||
@@ -329,210 +365,6 @@ out:
|
||||
return rc;
|
||||
}
|
||||
|
||||
int scanhash_m7m_hash_t(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint64_t max_nonce, unsigned long *hashes_done, struct timespec cpu_dec_time)
|
||||
{
|
||||
uint32_t data[32] __attribute__((aligned(128)));
|
||||
uint32_t *data_p64 = data + (M7_MIDSTATE_LEN / sizeof(data[0]));
|
||||
uint32_t hash[8] __attribute__((aligned(32)));
|
||||
uint8_t bhash[7][64] __attribute__((aligned(32)));
|
||||
uint32_t n = pdata[19] - 1;
|
||||
uint32_t usw_, mpzscale;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
char data_str[161], hash_str[65], target_str[65];
|
||||
//uint8_t *bdata = 0;
|
||||
uint8_t bdata[8192];
|
||||
int rc = 0, i, digits;
|
||||
int bytes;
|
||||
size_t p = sizeof(unsigned long), a = 64/p, b = 32/p;
|
||||
|
||||
memcpy(data, pdata, 80);
|
||||
|
||||
sph_sha256_context ctx_final_sha256;
|
||||
|
||||
sph_sha256_context ctx_sha256;
|
||||
sph_sha512_context ctx_sha512;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_whirlpool_context ctx_whirlpool;
|
||||
sph_haval256_5_context ctx_haval;
|
||||
sph_tiger_context ctx_tiger;
|
||||
sph_ripemd160_context ctx_ripemd;
|
||||
|
||||
sph_sha256_init(&ctx_final_sha256);
|
||||
|
||||
sph_sha256_init(&ctx_sha256);
|
||||
sph_sha256 (&ctx_sha256, data, M7_MIDSTATE_LEN);
|
||||
|
||||
sph_sha512_init(&ctx_sha512);
|
||||
sph_sha512 (&ctx_sha512, data, M7_MIDSTATE_LEN);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, data, M7_MIDSTATE_LEN);
|
||||
|
||||
sph_whirlpool_init(&ctx_whirlpool);
|
||||
sph_whirlpool (&ctx_whirlpool, data, M7_MIDSTATE_LEN);
|
||||
|
||||
sph_haval256_5_init(&ctx_haval);
|
||||
sph_haval256_5 (&ctx_haval, data, M7_MIDSTATE_LEN);
|
||||
|
||||
sph_tiger_init(&ctx_tiger);
|
||||
sph_tiger (&ctx_tiger, data, M7_MIDSTATE_LEN);
|
||||
|
||||
sph_ripemd160_init(&ctx_ripemd);
|
||||
sph_ripemd160 (&ctx_ripemd, data, M7_MIDSTATE_LEN);
|
||||
|
||||
sph_sha256_context ctx2_sha256;
|
||||
sph_sha512_context ctx2_sha512;
|
||||
sph_keccak512_context ctx2_keccak;
|
||||
sph_whirlpool_context ctx2_whirlpool;
|
||||
sph_haval256_5_context ctx2_haval;
|
||||
sph_tiger_context ctx2_tiger;
|
||||
sph_ripemd160_context ctx2_ripemd;
|
||||
|
||||
mpz_t magipi, magisw, product, bns0, bns1;
|
||||
mpf_t magifpi, magifpi0, mpt1, mpt2, mptmp, mpten;
|
||||
|
||||
mpz_inits(magipi, magisw, bns0, bns1, NULL);
|
||||
mpz_init2(product, 512);
|
||||
|
||||
mp_bitcnt_t prec0 = (long int)((int)((sqrt((double)(INT_MAX))*(1.+EPS))/9000+75)*BITS_PER_DIGIT+16);
|
||||
mpf_set_default_prec(prec0);
|
||||
|
||||
mpf_init(magifpi);
|
||||
mpf_init(magifpi0);
|
||||
mpf_init(mpt1);
|
||||
mpf_init(mpt2);
|
||||
mpf_init(mptmp);
|
||||
mpf_init_set_ui(mpten, 10);
|
||||
mpf_set_str(mpt2, "0.8e3b1a9b359805c2e54c6415037f2e336893b6457f7754f6b4ae045eb6c5f2bedb26a114030846be7", 16);
|
||||
mpf_set_str(magifpi0, "0.b7bfc6837e20bdb22653f1fc419f6bc33ca80eb65b7b0246f7f3b65689560aea1a2f2fd95f254d68c", 16);
|
||||
|
||||
do {
|
||||
data[19] = ++n;
|
||||
memset(bhash, 0, 7 * 64);
|
||||
|
||||
ctx2_sha256 = ctx_sha256;
|
||||
sph_sha256 (&ctx2_sha256, data_p64, 80 - M7_MIDSTATE_LEN);
|
||||
sph_sha256_close(&ctx2_sha256, (void*)(bhash[0]));
|
||||
|
||||
ctx2_sha512 = ctx_sha512;
|
||||
sph_sha512 (&ctx2_sha512, data_p64, 80 - M7_MIDSTATE_LEN);
|
||||
sph_sha512_close(&ctx2_sha512, (void*)(bhash[1]));
|
||||
|
||||
ctx2_keccak = ctx_keccak;
|
||||
sph_keccak512 (&ctx2_keccak, data_p64, 80 - M7_MIDSTATE_LEN);
|
||||
sph_keccak512_close(&ctx2_keccak, (void*)(bhash[2]));
|
||||
|
||||
ctx2_whirlpool = ctx_whirlpool;
|
||||
sph_whirlpool (&ctx2_whirlpool, data_p64, 80 - M7_MIDSTATE_LEN);
|
||||
sph_whirlpool_close(&ctx2_whirlpool, (void*)(bhash[3]));
|
||||
|
||||
ctx2_haval = ctx_haval;
|
||||
sph_haval256_5 (&ctx2_haval, data_p64, 80 - M7_MIDSTATE_LEN);
|
||||
sph_haval256_5_close(&ctx2_haval, (void*)(bhash[4]));
|
||||
|
||||
ctx2_tiger = ctx_tiger;
|
||||
sph_tiger (&ctx2_tiger, data_p64, 80 - M7_MIDSTATE_LEN);
|
||||
sph_tiger_close(&ctx2_tiger, (void*)(bhash[5]));
|
||||
|
||||
ctx2_ripemd = ctx_ripemd;
|
||||
sph_ripemd160 (&ctx2_ripemd, data_p64, 80 - M7_MIDSTATE_LEN);
|
||||
sph_ripemd160_close(&ctx2_ripemd, (void*)(bhash[6]));
|
||||
|
||||
mpz_import(bns0, a, -1, p, -1, 0, bhash[0]);
|
||||
mpz_set(bns1, bns0);
|
||||
mpz_set(product, bns0);
|
||||
for(int i=1; i < 7; i++){
|
||||
mpz_import(bns0, a, -1, p, -1, 0, bhash[i]);
|
||||
mpz_add(bns1, bns1, bns0);
|
||||
mpz_mul(product, product, bns0);
|
||||
}
|
||||
mpz_mul(product, product, bns1);
|
||||
|
||||
mpz_mul(product, product, product);
|
||||
bytes = mpz_sizeinbase(product, 256);
|
||||
mpz_export((void *)bdata, NULL, -1, 1, 0, 0, product);
|
||||
|
||||
sph_sha256 (&ctx_final_sha256, bdata, bytes);
|
||||
sph_sha256_close(&ctx_final_sha256, (void*)(hash));
|
||||
|
||||
digits=(int)((sqrt((double)(n/2))*(1.+EPS))/9000+75);
|
||||
mp_bitcnt_t prec = (long int)(digits*BITS_PER_DIGIT+16);
|
||||
mpf_set_prec_raw(magifpi, prec);
|
||||
mpf_set_prec_raw(mptmp, prec);
|
||||
mpf_set_prec_raw(mpt1, prec);
|
||||
mpf_set_prec_raw(mpt2, prec);
|
||||
|
||||
usw_ = sw2_(n/2);
|
||||
mpzscale = 1;
|
||||
mpz_set_ui(magisw, usw_);
|
||||
|
||||
for(i = 0; i < 5; i++)
|
||||
{
|
||||
mpf_set_d(mpt1, 0.25*mpzscale);
|
||||
mpf_sub(mpt1, mpt1, mpt2);
|
||||
mpf_abs(mpt1, mpt1);
|
||||
mpf_div(magifpi, magifpi0, mpt1);
|
||||
mpf_pow_ui(mptmp, mpten, digits >> 1);
|
||||
mpf_mul(magifpi, magifpi, mptmp);
|
||||
mpz_set_f(magipi, magifpi);
|
||||
mpz_add(magipi,magipi,magisw);
|
||||
mpz_add(product,product,magipi);
|
||||
|
||||
mpz_import(bns0, b, -1, p, -1, 0, (void*)(hash));
|
||||
mpz_add(bns1, bns1, bns0);
|
||||
mpz_mul(product,product,bns1);
|
||||
mpz_cdiv_q (product, product, bns0);
|
||||
|
||||
bytes = mpz_sizeinbase(product, 256);
|
||||
mpzscale=bytes;
|
||||
mpz_export(bdata, NULL, -1, 1, 0, 0, product);
|
||||
|
||||
sph_sha256 (&ctx_final_sha256, bdata, bytes);
|
||||
sph_sha256_close(&ctx_final_sha256, (void*)(hash));
|
||||
}
|
||||
if (n%10 == 0) nanosleep(&cpu_dec_time, NULL);
|
||||
const unsigned char *hash_ = (const unsigned char *)hash;
|
||||
const unsigned char *target_ = (const unsigned char *)ptarget;
|
||||
for (i = 31; i >= 0; i--) {
|
||||
if (hash_[i] != target_[i]) {
|
||||
rc = hash_[i] < target_[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (unlikely(rc)) {
|
||||
if (opt_debug) {
|
||||
bin2hex(hash_str, (unsigned char *)hash, 32);
|
||||
bin2hex(target_str, (unsigned char *)ptarget, 32);
|
||||
bin2hex(data_str, (unsigned char *)data, 80);
|
||||
applog(LOG_DEBUG, "DEBUG: [%d thread] Found share!\ndata %s\nhash %s\ntarget %s", thr_id,
|
||||
data_str,
|
||||
hash_str,
|
||||
target_str);
|
||||
}
|
||||
pdata[19] = data[19];
|
||||
goto out;
|
||||
}
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
pdata[19] = n;
|
||||
out:
|
||||
mpf_set_prec_raw(magifpi, prec0);
|
||||
mpf_set_prec_raw(magifpi0, prec0);
|
||||
mpf_set_prec_raw(mptmp, prec0);
|
||||
mpf_set_prec_raw(mpt1, prec0);
|
||||
mpf_set_prec_raw(mpt2, prec0);
|
||||
mpf_clear(magifpi);
|
||||
mpf_clear(magifpi0);
|
||||
mpf_clear(mpten);
|
||||
mpf_clear(mptmp);
|
||||
mpf_clear(mpt1);
|
||||
mpf_clear(mpt2);
|
||||
mpz_clears(magipi, magisw, product, bns0, bns1, NULL);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
void m7m_reverse_endian( struct work *work )
|
||||
{
|
||||
swab32_array( work->data, work->data, 20 );
|
||||
|
||||
Reference in New Issue
Block a user