This commit is contained in:
Jay D Dee
2017-03-31 11:59:04 -04:00
parent 2dcc4821b6
commit 9afa0d9820
63 changed files with 297 additions and 176 deletions

View File

@@ -41,8 +41,8 @@ cpuminer_SOURCES = \
algo/jh/sph_jh.c \
algo/keccak/sph_keccak.c \
algo/keccak/keccak.c\
algo/sha3/sph_sha2.c \
algo/sha3/sph_sha2big.c \
algo/sha/sph_sha2.c \
algo/sha/sph_sha2big.c \
algo/shabal/sph_shabal.c \
algo/whirlpool/sph_whirlpool.c\
crypto/blake2s.c \
@@ -118,8 +118,8 @@ cpuminer_SOURCES = \
algo/ripemd/sph_ripemd.c \
algo/scrypt.c \
algo/scryptjane/scrypt-jane.c \
algo/sha2/sha2.c \
algo/sha2/sha256t.c \
algo/sha/sha2.c \
algo/sha/sha256t.c \
algo/simd/sse2/nist.c \
algo/simd/sse2/vector.c \
algo/skein/skein.c \

View File

@@ -3,6 +3,12 @@ Compile instruction for Linux and Windows are at the bottom of this file.
Change Log
----------
v3.6.1
Fixed data alignment issue that broke lyra2rev2 AVX2 on Windows.
Added preliminary support for HW accelerated SHA.
Solo mining most algos should now work, cryptonight confirmed exception.
v3.6.0
Preliminary support for solo mining using getwork.

View File

@@ -239,7 +239,7 @@ bool register_json_rpc2( algo_gate_t *gate )
gate->nonce_index = JR2_NONCE_INDEX;
jsonrpc_2 = true; // still needed
opt_extranonce = false;
have_gbt = false;
// have_gbt = false;
return true;
}

View File

@@ -86,10 +86,11 @@
typedef uint32_t set_t;
#define EMPTY_SET 0
#define SSE2_OPT 1
#define AES_OPT 2
#define AVX_OPT 4
#define AVX2_OPT 8
#define SSE2_OPT 1
#define AES_OPT 2
#define AVX_OPT 4
#define AVX2_OPT 8
#define SHA_OPT 16
// return set containing all elements from sets a & b
inline set_t set_union ( set_t a, set_t b ) { return a | b; }

View File

@@ -93,10 +93,12 @@ int scanhash_blakecoin( int thr_id, struct work *work, uint32_t max_nonce,
return 0;
}
/*
void blakecoin_gen_merkle_root ( char* merkle_root, struct stratum_ctx* sctx )
{
SHA256( sctx->job.coinbase, (int)sctx->job.coinbase_size, merkle_root );
}
*/
// changed to get_max64_0x3fffffLL in cpuminer-multi-decred
int64_t blakecoin_get_max64 ()

View File

@@ -42,7 +42,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for BLAKE-224.

View File

@@ -31,7 +31,7 @@
#include <stdint.h>
#include <string.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#include "sph_blake2b.h"
// Cyclic right rotation.

View File

@@ -41,7 +41,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for BMW-224.

View File

@@ -42,7 +42,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for CubeHash-224.

View File

@@ -9,8 +9,7 @@
#include <immintrin.h>
#endif
#include "cubehash_sse2.h"
#include "algo/sha3/sha3-defs.h"
//#include "avxdefs.h"
#include "algo/sha/sha3-defs.h"
static void transform( cubehashParam *sp )
{

View File

@@ -3,7 +3,7 @@
#include "compat.h"
#include <stdint.h>
#include "algo/sha3/sha3-defs.h"
#include "algo/sha/sha3-defs.h"
#define OPTIMIZE_SSE2

View File

@@ -22,7 +22,7 @@
#endif
#include "algo/sha3/sha3_common.h"
#include "algo/sha/sha3_common.h"
#include <emmintrin.h>

View File

@@ -16,7 +16,7 @@
#ifndef VPERM_H
#define VPERM_H
#include "algo/sha3/sha3_common.h"
#include "algo/sha/sha3_common.h"
#include <tmmintrin.h>
/*

View File

@@ -71,7 +71,7 @@ extern "C"{
#endif
#define AES_BIG_ENDIAN 0
#include "algo/sha3/aes_helper.c"
#include "algo/sha/aes_helper.c"
#if SPH_ECHO_64

View File

@@ -41,7 +41,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for ECHO-224.

View File

@@ -41,7 +41,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for ECHO-224.

View File

@@ -2,7 +2,7 @@
#define SPH_FUGUE_H__
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#ifdef __cplusplus
extern "C"{

View File

@@ -41,7 +41,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for GOST-256.

View File

@@ -11,7 +11,12 @@
#else
#include "aes_ni/hash-groestl.h"
#endif
#include "algo/sha3/sph_sha2.h"
#if defined (SHA_NI)
#include <openssl/sha.h>
#else
#include "algo/sha/sph_sha2.h"
#endif
typedef struct {
#ifdef NO_AES_NI
@@ -19,7 +24,11 @@ typedef struct {
#else
hashState_groestl groestl;
#endif
sph_sha256_context sha;
#if defined (SHA_NI)
SHA256_CTX sha;
#else
sph_sha256_context sha;
#endif
} myrgr_ctx_holder;
myrgr_ctx_holder myrgr_ctx;
@@ -31,28 +40,35 @@ void init_myrgr_ctx()
#else
init_groestl (&myrgr_ctx.groestl, 64 );
#endif
sph_sha256_init(&myrgr_ctx.sha);
#if defined (SHA_NI)
SHA256_Init( &myrgr_ctx.sha );
#else
sph_sha256_init( &myrgr_ctx.sha );
#endif
}
void myriadhash( void *output, const void *input )
{
myrgr_ctx_holder ctx __attribute__ ((aligned (64)));
memcpy( &ctx, &myrgr_ctx, sizeof(myrgr_ctx) );
uint32_t hash[16] __attribute__ ((aligned (64)));
myrgr_ctx_holder ctx __attribute__ ((aligned (64)));
memcpy( &ctx, &myrgr_ctx, sizeof(myrgr_ctx) );
uint32_t hash[16] __attribute__ ((aligned (64)));
#ifdef NO_AES_NI
sph_groestl512(&ctx.groestl, input, 80);
sph_groestl512_close(&ctx.groestl, hash);
sph_groestl512(&ctx.groestl, input, 80);
sph_groestl512_close(&ctx.groestl, hash);
#else
update_and_final_groestl( &ctx.groestl, (char*)input,
(const char*)input, 640 );
update_and_final_groestl( &ctx.groestl, (char*)input,
(const char*)input, 640 );
#endif
sph_sha256(&ctx.sha, hash, 64);
sph_sha256_close(&ctx.sha, hash);
memcpy(output, hash, 32);
#if defined (SHA_NI)
SHA256_Update( &ctx.sha, hash, 64 );
SHA256_Final( (unsigned char*) hash, &ctx.sha );
#else
sph_sha256(&ctx.sha, hash, 64);
sph_sha256_close(&ctx.sha, hash);
#endif
memcpy(output, hash, 32);
}
int scanhash_myriad( int thr_id, struct work *work, uint32_t max_nonce,
@@ -92,7 +108,7 @@ int scanhash_myriad( int thr_id, struct work *work, uint32_t max_nonce,
bool register_myriad_algo( algo_gate_t* gate )
{
gate->optimizations = SSE2_OPT | AES_OPT;
gate->optimizations = SSE2_OPT | AES_OPT | SHA_OPT;
init_myrgr_ctx();
gate->scanhash = (void*)&scanhash_myriad;
gate->hash = (void*)&myriadhash;

View File

@@ -40,7 +40,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for Groestl-224.

View File

@@ -36,7 +36,7 @@
#define SPH_HAMSI_H__
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#ifdef __cplusplus
extern "C"{

View File

@@ -66,7 +66,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for HAVAL-128/3.

View File

@@ -20,7 +20,7 @@
#include "algo/fugue/sph_fugue.h"
#include "algo/shabal/sph_shabal.h"
#include "algo/whirlpool/sph_whirlpool.h"
#include "algo/sha2/sph-sha2.h"
#include "algo/sha/sph_sha2.h"
#include "algo/haval/sph-haval.h"
#ifndef NO_AES_NI
@@ -416,7 +416,7 @@ int scanhash_hmq1725( int thr_id, struct work *work, int32_t max_nonce,
bool register_hmq1725_algo( algo_gate_t* gate )
{
init_hmq1725_ctx();
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT;
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT | SHA_OPT;
gate->set_target = (void*)&scrypt_set_target;
gate->scanhash = (void*)&scanhash_hmq1725;
gate->hash = (void*)&hmq1725hash;

View File

@@ -41,7 +41,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for JH-224.

View File

@@ -41,7 +41,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for Keccak-224.

View File

@@ -41,7 +41,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#define QSTATIC static

View File

@@ -4,11 +4,12 @@
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "sha3/sph_sha2.h"
#include "ripemd/sph_ripemd.h"
//#define DEBUG_ALGO
#if defined (SHA_NI)
#include <openssl/sha.h>
#else
#include "sha/sph_sha2.h"
#endif
#define LBRY_NTIME_INDEX 25
#define LBRY_NBITS_INDEX 26
@@ -18,9 +19,13 @@
/* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */
typedef struct {
sph_sha256_context sha256;
sph_sha512_context sha512;
sph_ripemd160_context ripemd;
#if defined (SHA_NI)
SHA256_CTX sha256;
#else
sph_sha256_context sha256;
#endif
sph_sha512_context sha512;
sph_ripemd160_context ripemd;
} lbryhash_context_holder;
/* no need to copy, because close reinit the context */
@@ -28,50 +33,78 @@ static lbryhash_context_holder ctx __attribute__ ((aligned (64)));
void init_lbry_contexts(void *dummy)
{
sph_sha256_init(&ctx.sha256);
sph_sha512_init(&ctx.sha512);
sph_ripemd160_init(&ctx.ripemd);
#if defined (SHA_NI)
SHA256_Init( &ctx.sha256 );
#else
sph_sha256_init( &ctx.sha256 );
#endif
sph_sha512_init( &ctx.sha512 );
sph_ripemd160_init( &ctx.ripemd );
}
void lbry_hash(void* output, const void* input)
{
sph_sha256_context ctx_sha256 __attribute__ ((aligned (64)));
sph_sha512_context ctx_sha512 __attribute__ ((aligned (64)));
sph_ripemd160_context ctx_ripemd __attribute__ ((aligned (64)));
uint32_t _ALIGN(64) hashA[16];
uint32_t _ALIGN(64) hashB[16];
uint32_t _ALIGN(64) hashC[16];
#if defined (SHA_NI)
SHA256_CTX ctx_sha256 __attribute__ ((aligned (64)));
#else
sph_sha256_context ctx_sha256 __attribute__ ((aligned (64)));
#endif
sph_sha512_context ctx_sha512 __attribute__ ((aligned (64)));
sph_ripemd160_context ctx_ripemd __attribute__ ((aligned (64)));
uint32_t _ALIGN(64) hashA[16];
uint32_t _ALIGN(64) hashB[16];
uint32_t _ALIGN(64) hashC[16];
sph_sha256_init(&ctx_sha256);
sph_sha256 (&ctx_sha256, input, 112);
sph_sha256_close(&ctx_sha256, hashA);
#if defined (SHA_NI)
SHA256_Init( &ctx_sha256 );
SHA256_Update( &ctx_sha256, input, 112 );
SHA256_Final( (unsigned char*) hashA, &ctx_sha256 );
sph_sha256_init(&ctx_sha256);
sph_sha256 (&ctx_sha256, hashA, 32);
sph_sha256_close(&ctx_sha256, hashA);
SHA256_Init( &ctx_sha256 );
SHA256_Update( &ctx_sha256, hashA, 32 );
SHA256_Final( (unsigned char*) hashA, &ctx_sha256 );
#else
sph_sha256_init( &ctx_sha256 );
sph_sha256 ( &ctx_sha256, input, 112 );
sph_sha256_close( &ctx_sha256, hashA );
sph_sha512_init(&ctx_sha512);
sph_sha512 (&ctx_sha512, hashA, 32);
sph_sha512_close(&ctx_sha512, hashA);
sph_sha256_init( &ctx_sha256 );
sph_sha256 ( &ctx_sha256, hashA, 32 );
sph_sha256_close( &ctx_sha256, hashA );
#endif
sph_ripemd160_init(&ctx_ripemd);
sph_ripemd160 (&ctx_ripemd, hashA, 32);
sph_ripemd160_close(&ctx_ripemd, hashB);
sph_sha512_init( &ctx_sha512 );
sph_sha512 ( &ctx_sha512, hashA, 32 );
sph_sha512_close( &ctx_sha512, hashA );
sph_ripemd160_init(&ctx_ripemd);
sph_ripemd160 (&ctx_ripemd, hashA+8, 32);
sph_ripemd160_close(&ctx_ripemd, hashC);
sph_ripemd160_init( &ctx_ripemd );
sph_ripemd160 ( &ctx_ripemd, hashA, 32 );
sph_ripemd160_close( &ctx_ripemd, hashB );
sph_sha256_init(&ctx_sha256);
sph_sha256 (&ctx_sha256, hashB, 20);
sph_sha256 (&ctx_sha256, hashC, 20);
sph_sha256_close(&ctx_sha256, hashA);
sph_ripemd160_init( &ctx_ripemd );
sph_ripemd160 ( &ctx_ripemd, hashA+8, 32 );
sph_ripemd160_close( &ctx_ripemd, hashC );
sph_sha256_init(&ctx_sha256);
sph_sha256 (&ctx_sha256, hashA, 32);
sph_sha256_close(&ctx_sha256, hashA);
#if defined (SHA_NI)
SHA256_Init( &ctx_sha256 );
SHA256_Update( &ctx_sha256, hashB, 20 );
SHA256_Update( &ctx_sha256, hashC, 20 );
SHA256_Final( (unsigned char*) hashA, &ctx_sha256 );
memcpy(output, hashA, 32);
SHA256_Init( &ctx_sha256 );
SHA256_Update( &ctx_sha256, hashA, 32 );
SHA256_Final( (unsigned char*) hashA, &ctx_sha256 );
#else
sph_sha256_init( &ctx_sha256 );
sph_sha256 ( &ctx_sha256, hashB, 20 );
sph_sha256 ( &ctx_sha256, hashC, 20 );
sph_sha256_close( &ctx_sha256, hashA );
sph_sha256_init( &ctx_sha256 );
sph_sha256 ( &ctx_sha256, hashA, 32 );
sph_sha256_close( &ctx_sha256, hashA );
#endif
memcpy( output, hashA, 32 );
}
int scanhash_lbry( int thr_id, struct work *work, uint32_t max_nonce,
@@ -211,6 +244,7 @@ int64_t lbry_get_max64() { return 0x1ffffLL; }
bool register_lbry_algo( algo_gate_t* gate )
{
gate->optimizations = SSE2_OPT | SHA_OPT;
gate->scanhash = (void*)&scanhash_lbry;
gate->hash = (void*)&lbry_hash;
gate->calc_network_diff = (void*)&lbry_calc_network_diff;

View File

@@ -41,7 +41,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for Luffa-224.

View File

@@ -19,7 +19,7 @@
*/
#include <emmintrin.h>
#include "algo/sha3/sha3-defs.h"
#include "algo/sha/sha3-defs.h"
/* The length of digests*/
#define DIGEST_BIT_LEN_224 224
#define DIGEST_BIT_LEN_256 256

View File

@@ -50,8 +50,9 @@ void lyra2rev2_hash( void *state, const void *input )
{
lyra2v2_ctx_holder ctx __attribute__ ((aligned (64)));
memcpy( &ctx, &lyra2v2_ctx, sizeof(lyra2v2_ctx) );
uint32_t hashA[8], hashB[8] __attribute__ ((aligned (64)));
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
@@ -124,7 +125,6 @@ void lyra2rev2_set_target( struct work* work, double job_diff )
work_set_target( work, job_diff / (256.0 * opt_diff_factor) );
}
bool lyra2rev2_thread_init()
{
const int64_t ROW_LEN_INT64 = BLOCK_LEN_INT64 * 4; // nCols
@@ -138,7 +138,7 @@ bool lyra2rev2_thread_init()
#if defined (__AVX2__)
memset_zero_m256i( (__m256i*)l2v2_wholeMatrix, i/32 );
#elif defined(__AVX__)
#elif defined (__AVX__)
memset_zero_m128i( (__m128i*)l2v2_wholeMatrix, i/16 );
#else
memset( l2v2_wholeMatrix, 0, i );
@@ -151,9 +151,9 @@ bool register_lyra2rev2_algo( algo_gate_t* gate )
init_lyra2rev2_ctx();
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | AVX2_OPT;
gate->miner_thread_init = (void*)&lyra2rev2_thread_init;
gate->scanhash = (void*)&scanhash_lyra2rev2;
gate->hash = (void*)&lyra2rev2_hash;
gate->set_target = (void*)&lyra2rev2_set_target;
gate->scanhash = (void*)&scanhash_lyra2rev2;
gate->hash = (void*)&lyra2rev2_hash;
gate->set_target = (void*)&lyra2rev2_set_target;
return true;
};

View File

@@ -8,7 +8,7 @@
#include <string.h>
#include <float.h>
#include <math.h>
#include "algo/sha2/sph-sha2.h"
#include "algo/sha/sph_sha2.h"
#include "algo/keccak/sph_keccak.h"
#include "algo/haval/sph-haval.h"
#include "algo/tiger/sph_tiger.h"
@@ -540,7 +540,7 @@ void m7m_reverse_endian( struct work *work )
bool register_m7m_algo( algo_gate_t *gate )
{
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT;
gate->optimizations = SSE2_OPT | AES_OPT | AVX_OPT | SHA_OPT;
init_m7m_ctx();
gate->scanhash = (void*)scanhash_m7m_hash;
gate->build_stratum_request = (void*)&std_be_build_stratum_request;

View File

@@ -263,7 +263,7 @@ sph_ripemd_init(void *cc)
#define RFUN ripemd_round
#define HASH ripemd
#define LE32 1
#include "algo/sha3/md_helper.c"
#include "algo/sha/md_helper.c"
#undef RFUN
#undef HASH
#undef LE32
@@ -517,7 +517,7 @@ sph_ripemd128_init(void *cc)
#define RFUN ripemd128_round
#define HASH ripemd128
#define LE32 1
#include "algo/sha3/md_helper.c"
#include "algo/sha/md_helper.c"
#undef RFUN
#undef HASH
#undef LE32
@@ -810,7 +810,7 @@ sph_ripemd160_init(void *cc)
#define RFUN ripemd160_round
#define HASH ripemd160
#define LE32 1
#include "algo/sha3/md_helper.c"
#include "algo/sha/md_helper.c"
#undef RFUN
#undef HASH
#undef LE32

View File

@@ -57,7 +57,7 @@
#define SPH_RIPEMD_H__
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for RIPEMD.

View File

@@ -6,45 +6,62 @@
#include <string.h>
#include <stdio.h>
#include "sph-sha2.h"
//#define DEBUG_ALGO
#include "sph_sha2.h"
#if defined (SHA_NI)
#include <openssl/sha.h>
static SHA256_CTX sha256t_ctx __attribute__ ((aligned (64)));
static __thread SHA256_CTX sha256t_mid __attribute__ ((aligned (64)));
#else
static sph_sha256_context sha256t_ctx __attribute__ ((aligned (64)));
static __thread sph_sha256_context sha256t_mid __attribute__ ((aligned (64)));
#endif
void sha256t_midstate( const void* input )
{
memcpy( &sha256t_mid, &sha256t_ctx, sizeof sha256t_mid );
#if defined (SHA_NI)
SHA256_Update( &sha256t_mid, input, 64 );
#else
sph_sha256( &sha256t_mid, input, 64 );
#endif
}
void sha256t_hash(void* output, const void* input, uint32_t len)
{
sph_sha256_context ctx_sha256 __attribute__ ((aligned (64)));
uint32_t _ALIGN(64) hashA[16];
const int midlen = 64; // bytes
const int tail = 80 - midlen; // 16
#if defined (SHA_NI)
SHA256_CTX ctx_sha256 __attribute__ ((aligned (64)));
memcpy( &ctx_sha256, &sha256t_mid, sizeof sha256t_mid );
SHA256_Update( &ctx_sha256, input + midlen, tail );
SHA256_Final( hashA, &ctx_sha256 );
memcpy( &ctx_sha256, &sha256t_ctx, sizeof sha256t_ctx );
SHA256_Update( &ctx_sha256, hashA, 32 );
SHA256_Final( hashA, &ctx_sha256 );
memcpy( &ctx_sha256, &sha256t_ctx, sizeof sha256t_ctx );
SHA256_Update( &ctx_sha256, hashA, 32 );
SHA256_Final( hashA, &ctx_sha256 );
#else
sph_sha256_context ctx_sha256 __attribute__ ((aligned (64)));
memcpy( &ctx_sha256, &sha256t_mid, sizeof sha256t_mid );
sph_sha256( &ctx_sha256, input + midlen, tail );
// sph_sha256_init(&ctx_sha256);
// sph_sha256 (&ctx_sha256, input, 80);
sph_sha256_close( &ctx_sha256, hashA );
// sph_sha256_init(&ctx_sha256);
memcpy( &ctx_sha256, &sha256t_ctx, sizeof sha256t_ctx );
sph_sha256( &ctx_sha256, hashA, 32 );
sph_sha256_close( &ctx_sha256, hashA );
// sph_sha256_init(&ctx_sha256);
memcpy( &ctx_sha256, &sha256t_ctx, sizeof sha256t_ctx );
sph_sha256( &ctx_sha256, hashA, 32 );
sph_sha256_close( &ctx_sha256, hashA );
#endif
memcpy( output, hashA, 32 );
}
@@ -133,7 +150,12 @@ void sha256t_set_target( struct work* work, double job_diff )
bool register_sha256t_algo( algo_gate_t* gate )
{
#if defined (SHA_NI)
SHA256_Init( &sha256t_ctx );
#else
sph_sha256_init( &sha256t_ctx );
#endif
gate->optimizations = SSE2_OPT | SHA_OPT;
gate->scanhash = (void*)&scanhash_sha256t;
gate->hash = (void*)&sha256t_hash;
gate->set_target = (void*)&sha256t_set_target;

View File

@@ -649,7 +649,7 @@ sph_sha256_init(void *cc)
#define RFUN sha2_round
#define HASH sha224
#define BE32 1
#include "algo/sha3/md_helper.c"
#include "md_helper.c"
/* see sph_sha2.h */
void

View File

@@ -41,7 +41,7 @@
#define SPH_SHA2_H__
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "sph_types.h"
#ifdef __cplusplus
extern "C"{

View File

@@ -37,7 +37,7 @@
#define SPH_SHABAL_H__
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#ifdef __cplusplus
extern "C"{
#endif

View File

@@ -62,7 +62,7 @@ extern "C"{
*/
#define AES_BIG_ENDIAN 0
#include "algo/sha3/aes_helper.c"
#include "algo/sha/aes_helper.c"
static const sph_u32 IV224[] = {
C32(0x6774F31C), C32(0x990AE210), C32(0xC87D4274), C32(0xC9546371),

View File

@@ -39,7 +39,7 @@
#define SPH_SHAVITE_H__
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#ifdef __cplusplus
extern "C"{

View File

@@ -41,7 +41,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
/**
* Output size (in bits) for SIMD-224.

View File

@@ -9,7 +9,7 @@
#endif
#include "compat.h"
#include "algo/sha3/sha3-defs.h"
#include "algo/sha/sha3-defs.h"
/*
* NIST API Specific types.
*/

View File

@@ -4,21 +4,33 @@
#include <string.h>
#include <stdint.h>
#include <openssl/sha.h>
#include "sph_skein.h"
#if defined (SHA_NI)
#include <openssl/sha.h>
#else
#include "algo/sha/sph_sha2.h"
#endif
typedef struct {
sph_skein512_context skein;
SHA256_CTX sha256;
sph_skein512_context skein;
#if defined (SHA_NI)
SHA256_CTX sha256;
#else
sph_sha256_context sha256;
#endif
} skein_ctx_holder;
skein_ctx_holder skein_ctx;
void init_skein_ctx()
{
sph_skein512_init(&skein_ctx.skein);
SHA256_Init(&skein_ctx.sha256);
sph_skein512_init( &skein_ctx.skein );
#if defined (SHA_NI)
SHA256_Init( &skein_ctx.sha256 );
#else
sph_sha256_init( &skein_ctx.sha256 );
#endif
}
void skeinhash(void *state, const void *input)
@@ -27,11 +39,16 @@ void skeinhash(void *state, const void *input)
memcpy( &ctx, &skein_ctx, sizeof(skein_ctx) );
uint32_t hash[16] __attribute__ ((aligned (64)));
sph_skein512(&ctx.skein, input, 80);
sph_skein512_close(&ctx.skein, hash);
sph_skein512( &ctx.skein, input, 80 );
sph_skein512_close( &ctx.skein, hash );
SHA256_Update(&ctx.sha256, hash, 64);
SHA256_Final((unsigned char*) hash, &ctx.sha256);
#if defined (SHA_NI)
SHA256_Update( &ctx.sha256, hash, 64 );
SHA256_Final( (unsigned char*) hash, &ctx.sha256 );
#else
sph_sha256( &ctx.sha256, hash, 64 );
sph_sha256_close( &ctx.sha256, hash );
#endif
memcpy(state, hash, 32);
}
@@ -72,6 +89,7 @@ int64_t skein_get_max64() { return 0x7ffffLL; }
bool register_skein_algo( algo_gate_t* gate )
{
init_skein_ctx();
gate->optimizations = SSE2_OPT | SHA_OPT;
gate->scanhash = (void*)&scanhash_skein;
gate->hash = (void*)&skeinhash;
gate->get_max64 = (void*)&skein_get_max64;

View File

@@ -46,7 +46,7 @@ extern "C"{
#endif
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#if SPH_64

View File

@@ -661,7 +661,7 @@ sph_tiger_init(void *cc)
#define BLEN 64U
#define PW01 1
#define PLW1 1
#include "algo/sha3/md_helper.c"
#include "algo/sha/md_helper.c"
/* see sph_tiger.h */
void
@@ -684,7 +684,7 @@ sph_tiger_comp(const sph_u64 msg[8], sph_u64 val[3])
#define HASH tiger2
#undef PW01
#define CLOSE_ONLY 1
#include "algo/sha3/md_helper.c"
#include "algo/sha/md_helper.c"
/* see sph_tiger.h */
void

View File

@@ -45,7 +45,7 @@
#define SPH_TIGER_H__
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#if SPH_64

View File

@@ -3441,19 +3441,19 @@ ROUND_FUN(whirlpool1, old1)
#define RFUN whirlpool_round
#define HASH whirlpool
#include "algo/sha3/md_helper.c"
#include "algo/sha/md_helper.c"
#undef RFUN
#undef HASH
#define RFUN whirlpool0_round
#define HASH whirlpool0
#include "algo/sha3/md_helper.c"
#include "algo/sha/md_helper.c"
#undef RFUN
#undef HASH
#define RFUN whirlpool1_round
#define HASH whirlpool1
#include "algo/sha3/md_helper.c"
#include "algo/sha/md_helper.c"
#undef RFUN
#undef HASH

View File

@@ -49,7 +49,7 @@
#define SPH_WHIRLPOOL_H__
#include <stddef.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#if SPH_64

View File

@@ -21,7 +21,7 @@
#include "algo/fugue/sph_fugue.h"
#include "algo/shabal/sph_shabal.h"
#include "algo/whirlpool/sph_whirlpool.h"
#include "algo/sha3/sph_sha2.h"
#include "algo/sha/sph_sha2.h"
#include "algo/haval/sph-haval.h"
#include "algo/luffa/sse2/luffa_for_sse2.h"

View File

@@ -17,7 +17,7 @@
#include "algo/fugue/sph_fugue.h"
#include "algo/shabal/sph_shabal.h"
#include "algo/whirlpool/sph_whirlpool.h"
#include "algo/sha3/sph_sha2.h"
#include "algo/sha/sph_sha2.h"
#include "algo/haval/sph-haval.h"
#include "algo/simd/sse2/nist.h"
#include "algo/cubehash/sse2/cubehash_sse2.h"

View File

@@ -1,4 +1,4 @@
AC_INIT([cpuminer-opt], [3.6.0])
AC_INIT([cpuminer-opt], [3.6.1])
AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM

View File

@@ -225,7 +225,7 @@ static void affine_to_cpu_mask(int id, unsigned long mask) { }
#endif
// not very useful, just index the arrray directly.
// but declaring this fuinction in miner.h eliminates
// but declaring this function in miner.h eliminates
// an annoying compiler warning for not using a static.
const char* algo_name( enum algos a ) {return algo_names[a];}
@@ -2781,18 +2781,22 @@ bool check_cpu_capability ()
bool cpu_has_aes = has_aes_ni();
bool cpu_has_avx = has_avx1();
bool cpu_has_avx2 = has_avx2();
bool cpu_has_sha = has_sha();
bool sw_has_sse2 = false;
bool sw_has_aes = false;
bool sw_has_avx = false;
bool sw_has_avx2 = false;
bool sw_has_sha = false;
set_t algo_features = algo_gate.optimizations;
bool algo_has_aes = set_incl( AES_OPT, algo_features );
bool algo_has_avx = set_incl( AVX_OPT, algo_features );
bool algo_has_avx2 = set_incl( AVX2_OPT, algo_features );
bool algo_has_sha = set_incl( SHA_OPT, algo_features );
bool use_aes;
bool use_sse2;
bool use_avx;
bool use_avx2;
bool use_sha;
#ifdef __AES__
sw_has_aes = true;
@@ -2806,6 +2810,10 @@ bool check_cpu_capability ()
#ifdef __AVX2__
sw_has_avx2 = true;
#endif
#ifdef __SHA__
sw_has_sha = true;
#endif
#if !((__AES__) || (__SSE2__))
printf("Neither __AES__ nor __SSE2__ defined.\n");
@@ -2819,6 +2827,7 @@ bool check_cpu_capability ()
if ( cpu_has_aes ) printf( " AES" );
if ( cpu_has_avx ) printf( " AVX" );
if ( cpu_has_avx2 ) printf( " AVX2" );
if ( cpu_has_sha ) printf( " SHA" );
printf("\nSW built on " __DATE__
#ifdef _MSC_VER
@@ -2835,42 +2844,33 @@ bool check_cpu_capability ()
if ( sw_has_aes ) printf( " AES" );
if ( sw_has_avx ) printf( " AVX" );
if ( sw_has_avx2 ) printf( " AVX2" );
if ( sw_has_sha ) printf( " SHA" );
// SSE2 defaults to yes regardless
printf("\nAlgo features: SSE2");
if ( algo_has_aes ) printf( " AES" );
if ( algo_has_avx ) printf( " AVX" );
if ( algo_has_avx2 ) printf( " AVX2" );
if ( algo_has_sha ) printf( " SHA" );
printf("\n");
// printf("\nAlgo features: %s\n", algo_has_aes ? "SSE2 AES" : "SSE2" );
use_aes = cpu_has_aes && sw_has_aes && algo_has_aes;
// don't use AES algo on non-AES CPU if compiled with AES.
use_sse2 = cpu_has_sse2 && sw_has_sse2 && !( sw_has_aes && algo_has_aes );
use_avx = use_aes && cpu_has_avx && sw_has_avx && algo_has_avx;
use_avx2 = use_avx && cpu_has_avx2 && sw_has_avx2 && algo_has_avx2;
use_sse2 = cpu_has_sse2 && sw_has_sse2;
use_aes = cpu_has_aes && sw_has_aes && algo_has_aes;
use_avx = cpu_has_avx && sw_has_avx && algo_has_avx;
use_avx2 = cpu_has_avx2 && sw_has_avx2 && algo_has_avx2;
use_sha = cpu_has_sha && sw_has_sha && algo_has_sha;
if ( use_sse2 )
printf( "Start mining with SSE2\n\n" );
else if ( use_aes )
{
printf( "Start mining with SSE2 AES" );
if ( use_avx )
{
printf( " AVX" );
if ( use_avx2 )
printf( " AVX2");
}
printf( "Start mining with SSE2" );
if ( use_aes ) printf( " AES" );
if ( use_avx2 ) printf( " AVX2" );
else if ( use_avx ) printf( " AVX" );
if ( use_sha ) printf( " SHA" );
printf( "\n\n" );
}
// if ( use_aes )
// printf( "Start mining with AES-AVX optimizations...\n\n" );
// else if ( use_sse2 )
// printf( "AES not available, starting mining with SSE2 optimizations...\n\n" );
else
printf( CL_RED "Unsupported CPU or SW configuration, miner will likely crash!\n\n" CL_N );
printf( CL_RED "Unsupported CPU, miner will likely crash!\n\n" CL_N );
return true;
}

View File

@@ -15,7 +15,7 @@
#include <string.h>
#include <stdio.h>
#include "algo/sha3/sph_types.h"
#include "algo/sha/sph_types.h"
#include "crypto/blake2s.h"
static const uint32_t blake2s_IV[8] =

View File

@@ -12,6 +12,12 @@
#endif
//#endif
#ifdef __SHA__
#ifndef NO_SHA_NI
#define SHA_NI
#endif
#endif
#ifdef _MSC_VER
#undef USE_ASM /* to fix */
@@ -323,7 +329,8 @@ double hash_target_ratio( uint32_t* hash, uint32_t* target );
void work_set_target_ratio( struct work* work, uint32_t* hash );
void get_currentalgo( char* buf, int sz );
bool has_aes_ni( void );
bool has_sha();
bool has_aes_ni();
bool has_avx1();
bool has_avx2();
bool has_sse2();

View File

@@ -247,23 +247,39 @@ void cpu_getmodelid(char *outbuf, size_t maxsz)
#define ECX_Reg (2)
#define EDX_Reg (3)
#define XSAVE_Flag (1 << 26) // ECX
#define OSXSAVE_Flag (1 << 27)
#define AVX1_Flag (1 << 28)
#define XOP_Flag (1 << 11)
#define FMA3_Flag (1 << 12)
#define AES_Flag (1 << 25)
#define SSE42_Flag (1 << 20)
#define XSAVE_Flag (1<<26) // ECX
#define OSXSAVE_Flag (1<<27)
#define AVX1_Flag (1<<28)
#define XOP_Flag (1<<11)
#define FMA3_Flag (1<<12)
#define AES_Flag (1<<25)
#define SSE42_Flag (1<<20)
#define SSE_Flag (1 << 25) // EDX
#define SSE2_Flag (1 << 26)
#define SSE_Flag (1<<25) // EDX
#define SSE2_Flag (1<<26)
#define AVX2_Flag (1 << 5) // ADV EBX
#define AVX2_Flag (1<< 5) // ADV EBX
#define SHA_Flag (1<<29)
// Use this to detect presence of feature
#define AVX1_mask (AVX1_Flag|XSAVE_Flag|OSXSAVE_Flag)
#define FMA3_mask (FMA3_Flag|AVX1_mask)
static inline bool has_sha_()
{
#ifdef __arm__
return false;
#else
int cpu_info[4] = { 0 };
cpuid( EXTENDED_FEATURES, cpu_info );
return cpu_info[ EBX_Reg ] & SHA_Flag;
#endif
}
bool has_sha() { return has_sha_(); }
static inline bool has_sse2_()
{
#ifdef __arm__