Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52788a5962 | ||
|
|
8fb92415fb | ||
|
|
2ee86e8f47 | ||
|
|
e1c4b3042c | ||
|
|
8ec5dd7d8e | ||
|
|
ec054db317 | ||
|
|
41707760f5 | ||
|
|
fade2b74b5 | ||
|
|
5308898d1c | ||
|
|
4babf37256 | ||
|
|
cd64f9b0e7 | ||
|
|
8f98bde4fb | ||
|
|
6e64383b32 | ||
|
|
ac1f6ad1bb | ||
|
|
4b40c16359 | ||
|
|
bcbb959a34 | ||
|
|
9a13624c2e | ||
|
|
629d987177 | ||
|
|
21f5435420 | ||
|
|
877f25aee5 | ||
|
|
5be0a5c586 | ||
|
|
64e997e9d6 | ||
|
|
01f3183c31 | ||
|
|
e4414752c4 | ||
|
|
e3548f46f3 | ||
|
|
736f916da3 | ||
|
|
c9ef0b6b39 | ||
|
|
b256ca47a0 | ||
|
|
6500e7401a | ||
|
|
da8a31c4e5 | ||
|
|
53cd591956 | ||
|
|
4b04ca8027 | ||
|
|
c9a66b696f | ||
|
|
d4e191610e | ||
|
|
3788fef9fd | ||
|
|
21630d5fbc | ||
|
|
e2f73614c0 | ||
|
|
40fc2bdcbc | ||
|
|
d923f0c1b2 | ||
|
|
6b69246c33 | ||
|
|
c5df142124 | ||
|
|
15293d063f | ||
|
|
aa271104c1 | ||
|
|
25a78c96b5 | ||
|
|
5abfac72d6 | ||
|
|
7c5087d01c | ||
|
|
b5b9b1f2db | ||
|
|
b9cfee0bb3 | ||
|
|
f73f5f6a2e | ||
|
|
cad3772122 | ||
|
|
7981e83db7 | ||
|
|
e21c75793a | ||
|
|
7661f73317 | ||
|
|
cb9d51c026 | ||
|
|
a12dfa5370 | ||
|
|
6b41234ff1 | ||
|
|
1187a6e7e3 | ||
|
|
9aac7ca713 |
No files matched your search
+21
-4
@@ -379,17 +379,18 @@ void blake256_cpu_setBlock_16(uint32_t *penddata, const uint32_t *midstate, cons
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_blake256(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done, int8_t blakerounds=14)
|
||||
extern "C" int scanhash_blake256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, int8_t blakerounds=14)
|
||||
{
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint64_t targetHigh = ((uint64_t*)ptarget)[3];
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
#if PRECALC64
|
||||
uint32_t _ALIGN(64) midstate[8];
|
||||
#else
|
||||
uint32_t crcsum;
|
||||
#endif
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint64_t targetHigh = ((uint64_t*)ptarget)[3];
|
||||
int intensity = (device_sm[device_map[thr_id]] > 500) ? 22 : 20;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity);
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
@@ -488,3 +489,19 @@ extern "C" int scanhash_blake256(int thr_id, uint32_t *pdata, const uint32_t *pt
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_blake256(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFreeHost(h_resNonce[thr_id]);
|
||||
cudaFree(d_resNonce[thr_id]);
|
||||
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* bmw-256 MDT
|
||||
* tpruvot - 2015
|
||||
*/
|
||||
extern "C" {
|
||||
#include "sph/sph_bmw.h"
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
|
||||
extern void bmw256_midstate_init(int thr_id, uint32_t threads);
|
||||
extern void bmw256_setBlock_80(int thr_id, void *pdata);
|
||||
extern void bmw256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_outputHash, int swap);
|
||||
|
||||
extern uint32_t cuda_check_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash);
|
||||
|
||||
// CPU Hash
|
||||
extern "C" void bmw_hash(void *state, const void *input)
|
||||
{
|
||||
uint32_t _ALIGN(64) hash[16];
|
||||
sph_bmw256_context ctx;
|
||||
|
||||
sph_bmw256_init(&ctx);
|
||||
sph_bmw256(&ctx, input, 80);
|
||||
sph_bmw256_close(&ctx, (void*) hash);
|
||||
|
||||
memcpy(state, hash, 32);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
static __inline uint32_t swab32_if(uint32_t val, bool iftrue) {
|
||||
return iftrue ? swab32(val) : val;
|
||||
}
|
||||
|
||||
extern "C" int scanhash_bmw(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
bool swapnonce = true;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 21);
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0005;
|
||||
|
||||
if (!init[thr_id]) {
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cuda_check_cpu_init(thr_id, throughput);
|
||||
bmw256_midstate_init(thr_id, throughput);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t)32 * throughput));
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int k=0; k < 20; k++) {
|
||||
be32enc(&endiandata[k], ((uint32_t*)pdata)[k]);
|
||||
}
|
||||
|
||||
bmw256_setBlock_80(thr_id, (void*)endiandata);
|
||||
|
||||
cuda_check_cpu_setTarget(ptarget);
|
||||
|
||||
do {
|
||||
bmw256_cpu_hash_80(thr_id, (int) throughput, pdata[19], d_hash[thr_id], (int) swapnonce);
|
||||
uint32_t foundNonce = cuda_check_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
uint32_t _ALIGN(64) vhash64[8];
|
||||
endiandata[19] = swab32_if(foundNonce, swapnonce);
|
||||
bmw_hash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
*hashes_done = foundNonce - first_nonce + 1;
|
||||
pdata[19] = swab32_if(foundNonce,!swapnonce);
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
applog(LOG_DEBUG, "GPU #%d: result for nounce %08x does not validate on CPU!", thr_id, foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
if ((uint64_t) throughput + pdata[19] > max_nonce) {
|
||||
pdata[19] = max_nonce;
|
||||
break;
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (!work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_bmw(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
/**
|
||||
* BMW-256 CUDA Implementation - tpruvot 2015
|
||||
*
|
||||
* Not optimal but close to the sph version and easier to adapt.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#define SPH_64 1
|
||||
#define USE_MIDSTATE
|
||||
|
||||
extern "C" {
|
||||
#include "sph/sph_bmw.h"
|
||||
}
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
__constant__ uint64_t c_PaddedMessage80[16]; // padded message (80 bytes + padding)
|
||||
|
||||
#ifndef USE_MIDSTATE
|
||||
__constant__ static sph_u32 IV256[16] = {
|
||||
0x40414243, 0x44454647, 0x48494A4B, 0x4C4D4E4F,
|
||||
0x50515253, 0x54555657, 0x58595A5B, 0x5C5D5E5F,
|
||||
0x60616263, 0x64656667, 0x68696A6B, 0x6C6D6E6F,
|
||||
0x70717273, 0x74757677, 0x78797A7B, 0x7C7D7E7F
|
||||
};
|
||||
#endif
|
||||
|
||||
__constant__ static sph_u32 final_s[16] = {
|
||||
0xaaaaaaa0, 0xaaaaaaa1, 0xaaaaaaa2, 0xaaaaaaa3,
|
||||
0xaaaaaaa4, 0xaaaaaaa5, 0xaaaaaaa6, 0xaaaaaaa7,
|
||||
0xaaaaaaa8, 0xaaaaaaa9, 0xaaaaaaaa, 0xaaaaaaab,
|
||||
0xaaaaaaac, 0xaaaaaaad, 0xaaaaaaae, 0xaaaaaaaf
|
||||
};
|
||||
|
||||
static sph_bmw_small_context* d_midstate[MAX_GPUS];
|
||||
|
||||
#define I16_16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
||||
#define I16_17 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
||||
#define I16_18 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17
|
||||
#define I16_19 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18
|
||||
#define I16_20 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
|
||||
#define I16_21 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
|
||||
#define I16_22 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21
|
||||
#define I16_23 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22
|
||||
#define I16_24 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
|
||||
#define I16_25 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24
|
||||
#define I16_26 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
|
||||
#define I16_27 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26
|
||||
#define I16_28 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27
|
||||
#define I16_29 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28
|
||||
#define I16_30 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
|
||||
#define I16_31 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
|
||||
|
||||
//#define M16_16 0, 1, 3, 4, 7, 10, 11
|
||||
//#define M16_17 1, 2, 4, 5, 8, 11, 12
|
||||
#define M16_18 2, 3, 5, 6, 9, 12, 13
|
||||
#define M16_19 3, 4, 6, 7, 10, 13, 14
|
||||
#define M16_20 4, 5, 7, 8, 11, 14, 15
|
||||
#define M16_21 5, 6, 8, 9, 12, 15, 16
|
||||
#define M16_22 6, 7, 9, 10, 13, 0, 1
|
||||
#define M16_23 7, 8, 10, 11, 14, 1, 2
|
||||
#define M16_24 8, 9, 11, 12, 15, 2, 3
|
||||
#define M16_25 9, 10, 12, 13, 0, 3, 4
|
||||
#define M16_26 10, 11, 13, 14, 1, 4, 5
|
||||
#define M16_27 11, 12, 14, 15, 2, 5, 6
|
||||
#define M16_28 12, 13, 15, 16, 3, 6, 7
|
||||
#define M16_29 13, 14, 0, 1, 4, 7, 8
|
||||
#define M16_30 14, 15, 1, 2, 5, 8, 9
|
||||
#define M16_31 15, 16, 2, 3, 6, 9, 10
|
||||
|
||||
#define ss0(x) (((x) >> 1) ^ ((x) << 3) ^ ROTL32(x, 4) ^ ROTL32(x, 19))
|
||||
#define ss1(x) (((x) >> 1) ^ ((x) << 2) ^ ROTL32(x, 8) ^ ROTL32(x, 23))
|
||||
#define ss2(x) (((x) >> 2) ^ ((x) << 1) ^ ROTL32(x, 12) ^ ROTL32(x, 25))
|
||||
#define ss3(x) (((x) >> 2) ^ ((x) << 2) ^ ROTL32(x, 15) ^ ROTL32(x, 29))
|
||||
#define ss4(x) (((x) >> 1) ^ (x))
|
||||
#define ss5(x) (((x) >> 2) ^ (x))
|
||||
|
||||
#define rs1(x) ROTL32(x, 3)
|
||||
#define rs2(x) ROTL32(x, 7)
|
||||
#define rs3(x) ROTL32(x, 13)
|
||||
#define rs4(x) ROTL32(x, 16)
|
||||
#define rs5(x) ROTL32(x, 19)
|
||||
#define rs6(x) ROTL32(x, 23)
|
||||
#define rs7(x) ROTL32(x, 27)
|
||||
|
||||
#define MAKE_W(tt, i0, op01, i1, op12, i2, op23, i3, op34, i4) \
|
||||
tt((data[i0] ^ h[i0]) op01 (data[i1] ^ h[i1]) op12 (data[i2] ^ h[i2]) op23 (data[i3] ^ h[i3]) op34 (data[i4] ^ h[i4]))
|
||||
//#define Ws0 MAKE_W(SPH_T32, 5, -, 7, +, 10, +, 13, +, 14)
|
||||
//#define Ws1 MAKE_W(SPH_T32, 6, -, 8, +, 11, +, 14, -, 15)
|
||||
//#define Ws2 MAKE_W(SPH_T32, 0, +, 7, +, 9, -, 12, +, 15)
|
||||
//#define Ws3 MAKE_W(SPH_T32, 0, -, 1, +, 8, -, 10, +, 13)
|
||||
//#define Ws4 MAKE_W(SPH_T32, 1, +, 2, +, 9, -, 11, -, 14)
|
||||
//#define Ws5 MAKE_W(SPH_T32, 3, -, 2, +, 10, -, 12, +, 15)
|
||||
//#define Ws6 MAKE_W(SPH_T32, 4, -, 0, -, 3, -, 11, +, 13)
|
||||
//#define Ws7 MAKE_W(SPH_T32, 1, -, 4, -, 5, -, 12, -, 14)
|
||||
//#define Ws8 MAKE_W(SPH_T32, 2, -, 5, -, 6, +, 13, -, 15)
|
||||
//#define Ws9 MAKE_W(SPH_T32, 0, -, 3, +, 6, -, 7, +, 14)
|
||||
//#define Ws10 MAKE_W(SPH_T32, 8, -, 1, -, 4, -, 7, +, 15)
|
||||
//#define Ws11 MAKE_W(SPH_T32, 8, -, 0, -, 2, -, 5, +, 9)
|
||||
//#define Ws12 MAKE_W(SPH_T32, 1, +, 3, -, 6, -, 9, +, 10)
|
||||
//#define Ws13 MAKE_W(SPH_T32, 2, +, 4, +, 7, +, 10, +, 11)
|
||||
//#define Ws14 MAKE_W(SPH_T32, 3, -, 5, +, 8, -, 11, -, 12)
|
||||
//#define Ws15 MAKE_W(SPH_T32, 12, -, 4, -, 6, -, 9, +, 13)
|
||||
|
||||
__device__
|
||||
static void gpu_compress_small(const sph_u32 *data, const sph_u32 h[16], sph_u32 dh[16])
|
||||
{
|
||||
// FOLD MAKE_Qas;
|
||||
|
||||
sph_u32 dx[16];
|
||||
for (int i=0; i<16; i++)
|
||||
dx[i] = data[i] ^ h[i];
|
||||
|
||||
sph_u32 qt[32];
|
||||
qt[ 0] = dx[ 5] - dx[7] + dx[10] + dx[13] + dx[14]; // Ws0
|
||||
qt[ 1] = dx[ 6] - dx[8] + dx[11] + dx[14] - dx[15]; // Ws1
|
||||
qt[ 2] = dx[ 0] + dx[7] + dx[ 9] - dx[12] + dx[15]; // Ws2
|
||||
qt[ 3] = dx[ 0] - dx[1] + dx[ 8] - dx[10] + dx[13]; // Ws3
|
||||
qt[ 4] = dx[ 1] + dx[2] + dx[ 9] - dx[11] - dx[14]; // Ws4;
|
||||
qt[ 5] = dx[ 3] - dx[2] + dx[10] - dx[12] + dx[15]; // Ws5;
|
||||
qt[ 6] = dx[ 4] - dx[0] - dx[ 3] - dx[11] + dx[13]; // Ws6;
|
||||
qt[ 7] = dx[ 1] - dx[4] - dx[ 5] - dx[12] - dx[14]; // Ws7;
|
||||
qt[ 8] = dx[ 2] - dx[5] - dx[ 6] + dx[13] - dx[15]; // Ws8;
|
||||
qt[ 9] = dx[ 0] - dx[3] + dx[ 6] - dx[ 7] + dx[14]; // Ws9;
|
||||
qt[10] = dx[ 8] - dx[1] - dx[ 4] - dx[ 7] + dx[15]; // Ws10;
|
||||
qt[11] = dx[ 8] - dx[0] - dx[ 2] - dx[ 5] + dx[ 9]; // Ws11;
|
||||
qt[12] = dx[ 1] + dx[3] - dx[ 6] - dx[ 9] + dx[10]; // Ws12;
|
||||
qt[13] = dx[ 2] + dx[4] + dx[ 7] + dx[10] + dx[11]; // Ws13;
|
||||
qt[14] = dx[ 3] - dx[5] + dx[ 8] - dx[11] - dx[12]; // Ws14;
|
||||
qt[15] = dx[12] - dx[4] - dx[ 6] - dx[ 9] + dx[13]; // Ws15;
|
||||
|
||||
qt[ 0] = ss0(qt[ 0]) + h[ 1];
|
||||
qt[ 1] = ss1(qt[ 1]) + h[ 2];
|
||||
qt[ 2] = ss2(qt[ 2]) + h[ 3];
|
||||
qt[ 3] = ss3(qt[ 3]) + h[ 4];
|
||||
qt[ 4] = ss4(qt[ 4]) + h[ 5];
|
||||
|
||||
qt[ 5] = ss0(qt[ 5]) + h[ 6];
|
||||
qt[ 6] = ss1(qt[ 6]) + h[ 7];
|
||||
qt[ 7] = ss2(qt[ 7]) + h[ 8];
|
||||
qt[ 8] = ss3(qt[ 8]) + h[ 9];
|
||||
qt[ 9] = ss4(qt[ 9]) + h[10];
|
||||
|
||||
qt[10] = ss0(qt[10]) + h[11];
|
||||
qt[11] = ss1(qt[11]) + h[12];
|
||||
qt[12] = ss2(qt[12]) + h[13];
|
||||
qt[13] = ss3(qt[13]) + h[14];
|
||||
qt[14] = ss4(qt[14]) + h[15];
|
||||
|
||||
qt[15] = ss0(qt[15]) + h[ 0];
|
||||
|
||||
//MAKE_Qbs;
|
||||
#define Ks(j) ((sph_u32)(0x05555555UL * j))
|
||||
#define Qs(j) (qt[j])
|
||||
|
||||
#define expand1s_in(i16, \
|
||||
i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, \
|
||||
i0m, i1m, i3m, i4m, i7m, i10m, i11m) \
|
||||
(ss1(qt[i0]) + ss2(qt[i1]) + ss3(qt[i2]) + ss0(qt[i3]) + ss1(qt[i4]) + ss2(qt[i5]) + ss3(qt[i6]) + ss0(qt[i7]) \
|
||||
+ ss1(qt[i8]) + ss2(qt[i9]) + ss3(qt[i10]) + ss0(qt[i11]) + ss1(qt[i12]) + ss2(qt[i13]) + ss3(qt[i14]) + ss0(qt[i15]) \
|
||||
+ ((ROTL32(data[i0m], i1m) + ROTL32(data[i3m], i4m) - ROTL32(data[i10m], i11m) + Ks(i16)) ^ h[i7m]))
|
||||
|
||||
qt[16] = expand1s_in(16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 3, 4, 7, 10, 11);
|
||||
qt[17] = expand1s_in(17, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 4, 5, 8, 11, 12);
|
||||
|
||||
#define expand2s_inner(qf, i16, \
|
||||
i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, \
|
||||
i0m, i1m, i3m, i4m, i7m, i10m, i11m) \
|
||||
(qf(i0) + rs1(qf(i1)) + qf(i2) + rs2(qf(i3)) \
|
||||
+ qf(i4) + rs3(qf(i5)) + qf(i6) + rs4(qf(i7)) + qf(i8) + rs5(qf(i9)) + qf(i10) + rs6(qf(i11)) \
|
||||
+ qf(i12) + rs7(qf(i13)) + ss4(qf(i14)) + ss5(qf(i15)) \
|
||||
+ ((ROTL32(data[i0m], i1m) + ROTL32(data[i3m], i4m) - ROTL32(data[i10m], i11m) + Ks(i16)) ^ h[i7m]))
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define LPAR (
|
||||
#define expand2s(i16) \
|
||||
expand2s_(Qs, i16, I16_ ## i16, M16_ ## i16)
|
||||
#define expand2s_(qf, i16, ix, iy) \
|
||||
expand2s_inner LPAR qf, i16, ix, iy)
|
||||
#else
|
||||
#define expand2s_(i16, ix, iy) \
|
||||
expand2s_inner(Qs, i16, ix, iy)
|
||||
#define expand2s(i16) \
|
||||
expand2s_(i16, I16_ ## i16, M16_ ## i16)
|
||||
#endif
|
||||
|
||||
qt[18] = expand2s(18);
|
||||
qt[19] = expand2s(19);
|
||||
qt[20] = expand2s(20);
|
||||
qt[21] = expand2s(21);
|
||||
qt[22] = expand2s(22);
|
||||
qt[23] = expand2s(23);
|
||||
qt[24] = expand2s(24);
|
||||
qt[25] = expand2s(25);
|
||||
qt[26] = expand2s(26);
|
||||
qt[27] = expand2s(27);
|
||||
qt[28] = expand2s(28);
|
||||
qt[29] = expand2s(29);
|
||||
qt[30] = expand2s(30);
|
||||
qt[31] = expand2s(31);
|
||||
|
||||
sph_u32 xl, xh;
|
||||
xl = Qs(16) ^ Qs(17) ^ Qs(18) ^ Qs(19) ^ Qs(20) ^ Qs(21) ^ Qs(22) ^ Qs(23);
|
||||
|
||||
xh = xl ^ Qs(24) ^ Qs(25) ^ Qs(26) ^ Qs(27) ^ Qs(28) ^ Qs(29) ^ Qs(30) ^ Qs(31);
|
||||
|
||||
dh[ 0] = ((xh << 5) ^ (Qs(16) >> 5) ^ data[ 0]) + (xl ^ Qs(24) ^ Qs(0));
|
||||
dh[ 1] = ((xh >> 7) ^ (Qs(17) << 8) ^ data[ 1]) + (xl ^ Qs(25) ^ Qs(1));
|
||||
dh[ 2] = ((xh >> 5) ^ (Qs(18) << 5) ^ data[ 2]) + (xl ^ Qs(26) ^ Qs(2));
|
||||
dh[ 3] = ((xh >> 1) ^ (Qs(19) << 5) ^ data[ 3]) + (xl ^ Qs(27) ^ Qs(3));
|
||||
dh[ 4] = ((xh >> 3) ^ (Qs(20) << 0) ^ data[ 4]) + (xl ^ Qs(28) ^ Qs(4));
|
||||
dh[ 5] = ((xh << 6) ^ (Qs(21) >> 6) ^ data[ 5]) + (xl ^ Qs(29) ^ Qs(5));
|
||||
dh[ 6] = ((xh >> 4) ^ (Qs(22) << 6) ^ data[ 6]) + (xl ^ Qs(30) ^ Qs(6));
|
||||
dh[ 7] = ((xh >> 11) ^ (Qs(23) << 2) ^ data[ 7]) + (xl ^ Qs(31) ^ Qs(7));
|
||||
|
||||
dh[ 8] = ROTL32(dh[4], 9) + (xh ^ Qs(24) ^ data[ 8]) + ((xl << 8) ^ Qs(23) ^ Qs( 8));
|
||||
dh[ 9] = ROTL32(dh[5], 10) + (xh ^ Qs(25) ^ data[ 9]) + ((xl >> 6) ^ Qs(16) ^ Qs( 9));
|
||||
dh[10] = ROTL32(dh[6], 11) + (xh ^ Qs(26) ^ data[10]) + ((xl << 6) ^ Qs(17) ^ Qs(10));
|
||||
dh[11] = ROTL32(dh[7], 12) + (xh ^ Qs(27) ^ data[11]) + ((xl << 4) ^ Qs(18) ^ Qs(11));
|
||||
dh[12] = ROTL32(dh[0], 13) + (xh ^ Qs(28) ^ data[12]) + ((xl >> 3) ^ Qs(19) ^ Qs(12));
|
||||
dh[13] = ROTL32(dh[1], 14) + (xh ^ Qs(29) ^ data[13]) + ((xl >> 4) ^ Qs(20) ^ Qs(13));
|
||||
dh[14] = ROTL32(dh[2], 15) + (xh ^ Qs(30) ^ data[14]) + ((xl >> 7) ^ Qs(21) ^ Qs(14));
|
||||
dh[15] = ROTL32(dh[3], 16) + (xh ^ Qs(31) ^ data[15]) + ((xl >> 2) ^ Qs(22) ^ Qs(15));
|
||||
}
|
||||
|
||||
#ifndef USE_MIDSTATE
|
||||
|
||||
__device__
|
||||
static void gpu_bmw256_init(sph_bmw_small_context *sc)
|
||||
{
|
||||
memcpy(sc->H, IV256, sizeof sc->H);
|
||||
sc->ptr = 0;
|
||||
sc->bit_count = 0;
|
||||
}
|
||||
|
||||
__device__
|
||||
static void gpu_bmw256(sph_bmw_small_context *sc, const void *data, size_t len)
|
||||
{
|
||||
sph_u32 htmp[16];
|
||||
sph_u32 *h1, *h2;
|
||||
unsigned char *buf = sc->buf;
|
||||
size_t ptr = sc->ptr;
|
||||
|
||||
sc->bit_count += (sph_u64)len << 3;
|
||||
|
||||
h1 = sc->H;
|
||||
h2 = htmp;
|
||||
while (len > 0) {
|
||||
size_t clen;
|
||||
|
||||
clen = (sizeof sc->buf) - ptr;
|
||||
if (clen > len)
|
||||
clen = len;
|
||||
memcpy(buf + ptr, data, clen);
|
||||
data = (const unsigned char *)data + clen;
|
||||
len -= clen;
|
||||
ptr += clen;
|
||||
if (ptr == sizeof sc->buf) {
|
||||
sph_u32 *ht;
|
||||
|
||||
gpu_compress_small((sph_u32 *) buf, h1, h2);
|
||||
ht = h1;
|
||||
h1 = h2;
|
||||
h2 = ht;
|
||||
ptr = 0;
|
||||
}
|
||||
}
|
||||
sc->ptr = ptr;
|
||||
if (h1 != sc->H)
|
||||
memcpy(sc->H, h1, sizeof sc->H);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define sph_enc64le(ptr, x) \
|
||||
*((uint64_t*)(ptr)) = x
|
||||
#define sph_enc64le_aligned sph_enc64le
|
||||
|
||||
__device__
|
||||
static void gpu_bmw256_close(sph_bmw_small_context *sc, uint2 *out)
|
||||
{
|
||||
unsigned char *buf = sc->buf;
|
||||
size_t ptr = sc->ptr;
|
||||
|
||||
buf[ptr ++] = 0x80;
|
||||
sph_u32 *h = sc->H;
|
||||
|
||||
sph_u32 h1[16];
|
||||
if (ptr > (sizeof sc->buf) - 8) {
|
||||
memset(buf + ptr, 0, (sizeof sc->buf) - ptr);
|
||||
gpu_compress_small((sph_u32 *) buf, h, h1);
|
||||
ptr = 0;
|
||||
h = h1;
|
||||
}
|
||||
memset(buf + ptr, 0, sizeof(sc->buf) - 8 - ptr);
|
||||
|
||||
sph_enc64le_aligned(buf + sizeof(sc->buf) - 8, SPH_T64(sc->bit_count));
|
||||
|
||||
sph_u32 h2[16];
|
||||
gpu_compress_small((sph_u32 *) buf, h, h2);
|
||||
gpu_compress_small(h2, final_s, h1);
|
||||
|
||||
uint64_t* h64 = (uint64_t*) (&h1[8]);
|
||||
#pragma unroll
|
||||
for (int i = 0; i < 4; i++) {
|
||||
out[i] = vectorize(h64[i]);
|
||||
}
|
||||
}
|
||||
|
||||
__global__ /* __launch_bounds__(256, 3) */
|
||||
void bmw256_gpu_hash_80(uint32_t threads, uint32_t startNonce, uint64_t *g_hash, sph_bmw256_context *d_midstate, int swap)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t nonce = startNonce + thread;
|
||||
nonce = swap ? cuda_swab32(nonce): nonce;
|
||||
|
||||
#ifndef USE_MIDSTATE
|
||||
uint2 hash[10];
|
||||
#pragma unroll
|
||||
for(int i=0;i<9;i++)
|
||||
hash[i] = vectorize(c_PaddedMessage80[i]);
|
||||
hash[9] = make_uint2(c_PaddedMessage80[9], nonce);
|
||||
|
||||
sph_bmw256_context ctx;
|
||||
gpu_bmw256_init(&ctx);
|
||||
gpu_bmw256(&ctx, (void*) hash, 80);
|
||||
#else
|
||||
sph_bmw256_context ctx;
|
||||
ctx.ptr = 16; ctx.bit_count = 640;
|
||||
uint2 *buf = (uint2 *) ctx.buf;
|
||||
buf[0] = vectorize(c_PaddedMessage80[8]);
|
||||
buf[1] = make_uint2(c_PaddedMessage80[9], nonce);
|
||||
#pragma unroll
|
||||
for(int i=0;i<16;i++)
|
||||
ctx.H[i] = d_midstate->H[i];
|
||||
#endif
|
||||
gpu_bmw256_close(&ctx, (uint2*) &g_hash[thread << 2]);
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void bmw256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_outputHash, int swap)
|
||||
{
|
||||
const uint32_t threadsperblock = 256;
|
||||
|
||||
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
bmw256_gpu_hash_80<<<grid, block>>>(threads, startNonce, (uint64_t*)d_outputHash, d_midstate[thr_id], swap);
|
||||
}
|
||||
|
||||
__host__
|
||||
void bmw256_setBlock_80(int thr_id, void *pdata)
|
||||
{
|
||||
uint64_t PaddedMessage[16];
|
||||
memcpy(PaddedMessage, pdata, 80);
|
||||
memset(&PaddedMessage[10], 0, 48);
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_PaddedMessage80, PaddedMessage, sizeof(PaddedMessage), 0, cudaMemcpyHostToDevice));
|
||||
|
||||
sph_bmw256_context ctx;
|
||||
sph_bmw256_init(&ctx);
|
||||
sph_bmw256(&ctx, (void*) PaddedMessage, 80);
|
||||
CUDA_SAFE_CALL(cudaMemcpy(d_midstate[thr_id], &ctx, sizeof(sph_bmw256_context), cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
void bmw256_midstate_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
cudaMalloc(&d_midstate[thr_id], sizeof(sph_bmw256_context));
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#undef SPH_ROTL32
|
||||
#define SPH_ROTL32 ROTL32
|
||||
|
||||
static uint32_t *d_gnounce[MAX_GPUS];
|
||||
static uint32_t *d_GNonce[MAX_GPUS];
|
||||
|
||||
__constant__ uint64_t pTarget[4];
|
||||
|
||||
#define shl(x, n) ((x) << (n))
|
||||
#define shr(x, n) ((x) >> (n))
|
||||
|
||||
#define ss0(x) (shr((x), 1) ^ shl((x), 3) ^ SPH_ROTL32((x), 4) ^ SPH_ROTL32((x), 19))
|
||||
#define ss1(x) (shr((x), 1) ^ shl((x), 2) ^ SPH_ROTL32((x), 8) ^ SPH_ROTL32((x), 23))
|
||||
#define ss2(x) (shr((x), 2) ^ shl((x), 1) ^ SPH_ROTL32((x), 12) ^ SPH_ROTL32((x), 25))
|
||||
#define ss3(x) (shr((x), 2) ^ shl((x), 2) ^ SPH_ROTL32((x), 15) ^ SPH_ROTL32((x), 29))
|
||||
#define ss4(x) (shr((x), 1) ^ (x))
|
||||
#define ss5(x) (shr((x), 2) ^ (x))
|
||||
|
||||
#define rs1(x) SPH_ROTL32((x), 3)
|
||||
#define rs2(x) SPH_ROTL32((x), 7)
|
||||
#define rs3(x) SPH_ROTL32((x), 13)
|
||||
#define rs4(x) SPH_ROTL32((x), 16)
|
||||
#define rs5(x) SPH_ROTL32((x), 19)
|
||||
#define rs6(x) SPH_ROTL32((x), 23)
|
||||
#define rs7(x) SPH_ROTL32((x), 27)
|
||||
|
||||
/* Message expansion function 1 */
|
||||
__forceinline__ __device__
|
||||
uint32_t expand32_1(int i, uint32_t *M32, const uint32_t *H, uint32_t *Q)
|
||||
{
|
||||
return (ss1(Q[i - 16]) + ss2(Q[i - 15]) + ss3(Q[i - 14]) + ss0(Q[i - 13])
|
||||
+ ss1(Q[i - 12]) + ss2(Q[i - 11]) + ss3(Q[i - 10]) + ss0(Q[i - 9])
|
||||
+ ss1(Q[i - 8]) + ss2(Q[i - 7]) + ss3(Q[i - 6]) + ss0(Q[i - 5])
|
||||
+ ss1(Q[i - 4]) + ss2(Q[i - 3]) + ss3(Q[i - 2]) + ss0(Q[i - 1])
|
||||
+ ((i*(0x05555555ul) + SPH_ROTL32(M32[(i - 16) % 16], ((i - 16) % 16) + 1)
|
||||
+ SPH_ROTL32(M32[(i - 13) % 16], ((i - 13) % 16) + 1)
|
||||
- SPH_ROTL32(M32[(i - 6) % 16], ((i - 6) % 16) + 1)) ^ H[(i - 16 + 7) % 16]));
|
||||
}
|
||||
|
||||
/* Message expansion function 2 */
|
||||
__forceinline__ __device__
|
||||
uint32_t expand32_2(int i, uint32_t *M32, const uint32_t *H, uint32_t *Q)
|
||||
{
|
||||
return (Q[i - 16] + rs1(Q[i - 15]) + Q[i - 14] + rs2(Q[i - 13])
|
||||
+ Q[i - 12] + rs3(Q[i - 11]) + Q[i - 10] + rs4(Q[i - 9])
|
||||
+ Q[i - 8] + rs5(Q[i - 7]) + Q[i - 6] + rs6(Q[i - 5])
|
||||
+ Q[i - 4] + rs7(Q[i - 3]) + ss4(Q[i - 2]) + ss5(Q[i - 1])
|
||||
+ ((i*(0x05555555ul) + SPH_ROTL32(M32[(i - 16) % 16], ((i - 16) % 16) + 1)
|
||||
+ SPH_ROTL32(M32[(i - 13) % 16], ((i - 13) % 16) + 1)
|
||||
- SPH_ROTL32(M32[(i - 6) % 16], ((i - 6) % 16) + 1)) ^ H[(i - 16 + 7) % 16]));
|
||||
}
|
||||
|
||||
__forceinline__ __device__
|
||||
void Compression256(uint32_t * M32)
|
||||
{
|
||||
uint32_t Q[32], XL32, XH32;
|
||||
|
||||
const uint32_t H[16] = {
|
||||
0x40414243, 0x44454647, 0x48494A4B, 0x4C4D4E4F,
|
||||
0x50515253, 0x54555657, 0x58595A5B, 0x5C5D5E5F,
|
||||
0x60616263, 0x64656667, 0x68696A6B, 0x6C6D6E6F,
|
||||
0x70717273, 0x74757677, 0x78797A7B, 0x7C7D7E7F
|
||||
};
|
||||
|
||||
Q[0] = (M32[5] ^ H[5]) - (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[13] ^ H[13]) + (M32[14] ^ H[14]);
|
||||
Q[1] = (M32[6] ^ H[6]) - (M32[8] ^ H[8]) + (M32[11] ^ H[11]) + (M32[14] ^ H[14]) - (M32[15] ^ H[15]);
|
||||
Q[2] = (M32[0] ^ H[0]) + (M32[7] ^ H[7]) + (M32[9] ^ H[9]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
|
||||
Q[3] = (M32[0] ^ H[0]) - (M32[1] ^ H[1]) + (M32[8] ^ H[8]) - (M32[10] ^ H[10]) + (M32[13] ^ H[13]);
|
||||
Q[4] = (M32[1] ^ H[1]) + (M32[2] ^ H[2]) + (M32[9] ^ H[9]) - (M32[11] ^ H[11]) - (M32[14] ^ H[14]);
|
||||
Q[5] = (M32[3] ^ H[3]) - (M32[2] ^ H[2]) + (M32[10] ^ H[10]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
|
||||
Q[6] = (M32[4] ^ H[4]) - (M32[0] ^ H[0]) - (M32[3] ^ H[3]) - (M32[11] ^ H[11]) + (M32[13] ^ H[13]);
|
||||
Q[7] = (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[5] ^ H[5]) - (M32[12] ^ H[12]) - (M32[14] ^ H[14]);
|
||||
Q[8] = (M32[2] ^ H[2]) - (M32[5] ^ H[5]) - (M32[6] ^ H[6]) + (M32[13] ^ H[13]) - (M32[15] ^ H[15]);
|
||||
Q[9] = (M32[0] ^ H[0]) - (M32[3] ^ H[3]) + (M32[6] ^ H[6]) - (M32[7] ^ H[7]) + (M32[14] ^ H[14]);
|
||||
Q[10] = (M32[8] ^ H[8]) - (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[7] ^ H[7]) + (M32[15] ^ H[15]);
|
||||
Q[11] = (M32[8] ^ H[8]) - (M32[0] ^ H[0]) - (M32[2] ^ H[2]) - (M32[5] ^ H[5]) + (M32[9] ^ H[9]);
|
||||
Q[12] = (M32[1] ^ H[1]) + (M32[3] ^ H[3]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[10] ^ H[10]);
|
||||
Q[13] = (M32[2] ^ H[2]) + (M32[4] ^ H[4]) + (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[11] ^ H[11]);
|
||||
Q[14] = (M32[3] ^ H[3]) - (M32[5] ^ H[5]) + (M32[8] ^ H[8]) - (M32[11] ^ H[11]) - (M32[12] ^ H[12]);
|
||||
Q[15] = (M32[12] ^ H[12]) - (M32[4] ^ H[4]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[13] ^ H[13]);
|
||||
|
||||
/* Diffuse the differences in every word in a bijective manner with ssi, and then add the values of the previous double pipe. */
|
||||
Q[0] = ss0(Q[0]) + H[1];
|
||||
Q[1] = ss1(Q[1]) + H[2];
|
||||
Q[2] = ss2(Q[2]) + H[3];
|
||||
Q[3] = ss3(Q[3]) + H[4];
|
||||
Q[4] = ss4(Q[4]) + H[5];
|
||||
Q[5] = ss0(Q[5]) + H[6];
|
||||
Q[6] = ss1(Q[6]) + H[7];
|
||||
Q[7] = ss2(Q[7]) + H[8];
|
||||
Q[8] = ss3(Q[8]) + H[9];
|
||||
Q[9] = ss4(Q[9]) + H[10];
|
||||
Q[10] = ss0(Q[10]) + H[11];
|
||||
Q[11] = ss1(Q[11]) + H[12];
|
||||
Q[12] = ss2(Q[12]) + H[13];
|
||||
Q[13] = ss3(Q[13]) + H[14];
|
||||
Q[14] = ss4(Q[14]) + H[15];
|
||||
Q[15] = ss0(Q[15]) + H[0];
|
||||
|
||||
/* This is the Message expansion or f_1 in the documentation. */
|
||||
/* It has 16 rounds. */
|
||||
/* Blue Midnight Wish has two tunable security parameters. */
|
||||
/* The parameters are named EXPAND_1_ROUNDS and EXPAND_2_ROUNDS. */
|
||||
/* The following relation for these parameters should is satisfied: */
|
||||
/* EXPAND_1_ROUNDS + EXPAND_2_ROUNDS = 16 */
|
||||
|
||||
#pragma unroll
|
||||
for (int i=16; i<18; i++)
|
||||
Q[i] = expand32_1(i, M32, H, Q);
|
||||
|
||||
#pragma nounroll
|
||||
for (int i=18; i<32; i++)
|
||||
Q[i] = expand32_2(i, M32, H, Q);
|
||||
|
||||
/* Blue Midnight Wish has two temporary cummulative variables that accumulate via XORing */
|
||||
/* 16 new variables that are prooduced in the Message Expansion part. */
|
||||
XL32 = Q[16] ^ Q[17] ^ Q[18] ^ Q[19] ^ Q[20] ^ Q[21] ^ Q[22] ^ Q[23];
|
||||
XH32 = XL32^Q[24] ^ Q[25] ^ Q[26] ^ Q[27] ^ Q[28] ^ Q[29] ^ Q[30] ^ Q[31];
|
||||
|
||||
|
||||
/* This part is the function f_2 - in the documentation */
|
||||
|
||||
/* Compute the double chaining pipe for the next message block. */
|
||||
M32[0] = (shl(XH32, 5) ^ shr(Q[16], 5) ^ M32[0]) + (XL32 ^ Q[24] ^ Q[0]);
|
||||
M32[1] = (shr(XH32, 7) ^ shl(Q[17], 8) ^ M32[1]) + (XL32 ^ Q[25] ^ Q[1]);
|
||||
M32[2] = (shr(XH32, 5) ^ shl(Q[18], 5) ^ M32[2]) + (XL32 ^ Q[26] ^ Q[2]);
|
||||
M32[3] = (shr(XH32, 1) ^ shl(Q[19], 5) ^ M32[3]) + (XL32 ^ Q[27] ^ Q[3]);
|
||||
M32[4] = (shr(XH32, 3) ^ Q[20] ^ M32[4]) + (XL32 ^ Q[28] ^ Q[4]);
|
||||
M32[5] = (shl(XH32, 6) ^ shr(Q[21], 6) ^ M32[5]) + (XL32 ^ Q[29] ^ Q[5]);
|
||||
M32[6] = (shr(XH32, 4) ^ shl(Q[22], 6) ^ M32[6]) + (XL32 ^ Q[30] ^ Q[6]);
|
||||
M32[7] = (shr(XH32, 11) ^ shl(Q[23], 2) ^ M32[7]) + (XL32 ^ Q[31] ^ Q[7]);
|
||||
|
||||
M32[8] = SPH_ROTL32(M32[4], 9) + (XH32 ^ Q[24] ^ M32[8]) + (shl(XL32, 8) ^ Q[23] ^ Q[8]);
|
||||
M32[9] = SPH_ROTL32(M32[5], 10) + (XH32 ^ Q[25] ^ M32[9]) + (shr(XL32, 6) ^ Q[16] ^ Q[9]);
|
||||
M32[10] = SPH_ROTL32(M32[6], 11) + (XH32 ^ Q[26] ^ M32[10]) + (shl(XL32, 6) ^ Q[17] ^ Q[10]);
|
||||
M32[11] = SPH_ROTL32(M32[7], 12) + (XH32 ^ Q[27] ^ M32[11]) + (shl(XL32, 4) ^ Q[18] ^ Q[11]);
|
||||
M32[12] = SPH_ROTL32(M32[0], 13) + (XH32 ^ Q[28] ^ M32[12]) + (shr(XL32, 3) ^ Q[19] ^ Q[12]);
|
||||
M32[13] = SPH_ROTL32(M32[1], 14) + (XH32 ^ Q[29] ^ M32[13]) + (shr(XL32, 4) ^ Q[20] ^ Q[13]);
|
||||
M32[14] = SPH_ROTL32(M32[2], 15) + (XH32 ^ Q[30] ^ M32[14]) + (shr(XL32, 7) ^ Q[21] ^ Q[14]);
|
||||
M32[15] = SPH_ROTL32(M32[3], 16) + (XH32 ^ Q[31] ^ M32[15]) + (shr(XL32, 2) ^ Q[22] ^ Q[15]);
|
||||
}
|
||||
|
||||
__forceinline__ __device__
|
||||
void Compression256_2(uint32_t * M32)
|
||||
{
|
||||
uint32_t XL32, XH32, Q[32];
|
||||
|
||||
const uint32_t H[16] = {
|
||||
0xaaaaaaa0, 0xaaaaaaa1, 0xaaaaaaa2, 0xaaaaaaa3,
|
||||
0xaaaaaaa4, 0xaaaaaaa5, 0xaaaaaaa6, 0xaaaaaaa7,
|
||||
0xaaaaaaa8, 0xaaaaaaa9, 0xaaaaaaaa, 0xaaaaaaab,
|
||||
0xaaaaaaac, 0xaaaaaaad, 0xaaaaaaae, 0xaaaaaaaf
|
||||
};
|
||||
|
||||
Q[0] = (M32[5] ^ H[5]) - (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[13] ^ H[13]) + (M32[14] ^ H[14]);
|
||||
Q[1] = (M32[6] ^ H[6]) - (M32[8] ^ H[8]) + (M32[11] ^ H[11]) + (M32[14] ^ H[14]) - (M32[15] ^ H[15]);
|
||||
Q[2] = (M32[0] ^ H[0]) + (M32[7] ^ H[7]) + (M32[9] ^ H[9]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
|
||||
Q[3] = (M32[0] ^ H[0]) - (M32[1] ^ H[1]) + (M32[8] ^ H[8]) - (M32[10] ^ H[10]) + (M32[13] ^ H[13]);
|
||||
Q[4] = (M32[1] ^ H[1]) + (M32[2] ^ H[2]) + (M32[9] ^ H[9]) - (M32[11] ^ H[11]) - (M32[14] ^ H[14]);
|
||||
Q[5] = (M32[3] ^ H[3]) - (M32[2] ^ H[2]) + (M32[10] ^ H[10]) - (M32[12] ^ H[12]) + (M32[15] ^ H[15]);
|
||||
Q[6] = (M32[4] ^ H[4]) - (M32[0] ^ H[0]) - (M32[3] ^ H[3]) - (M32[11] ^ H[11]) + (M32[13] ^ H[13]);
|
||||
Q[7] = (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[5] ^ H[5]) - (M32[12] ^ H[12]) - (M32[14] ^ H[14]);
|
||||
Q[8] = (M32[2] ^ H[2]) - (M32[5] ^ H[5]) - (M32[6] ^ H[6]) + (M32[13] ^ H[13]) - (M32[15] ^ H[15]);
|
||||
Q[9] = (M32[0] ^ H[0]) - (M32[3] ^ H[3]) + (M32[6] ^ H[6]) - (M32[7] ^ H[7]) + (M32[14] ^ H[14]);
|
||||
Q[10] = (M32[8] ^ H[8]) - (M32[1] ^ H[1]) - (M32[4] ^ H[4]) - (M32[7] ^ H[7]) + (M32[15] ^ H[15]);
|
||||
Q[11] = (M32[8] ^ H[8]) - (M32[0] ^ H[0]) - (M32[2] ^ H[2]) - (M32[5] ^ H[5]) + (M32[9] ^ H[9]);
|
||||
Q[12] = (M32[1] ^ H[1]) + (M32[3] ^ H[3]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[10] ^ H[10]);
|
||||
Q[13] = (M32[2] ^ H[2]) + (M32[4] ^ H[4]) + (M32[7] ^ H[7]) + (M32[10] ^ H[10]) + (M32[11] ^ H[11]);
|
||||
Q[14] = (M32[3] ^ H[3]) - (M32[5] ^ H[5]) + (M32[8] ^ H[8]) - (M32[11] ^ H[11]) - (M32[12] ^ H[12]);
|
||||
Q[15] = (M32[12] ^ H[12]) - (M32[4] ^ H[4]) - (M32[6] ^ H[6]) - (M32[9] ^ H[9]) + (M32[13] ^ H[13]);
|
||||
|
||||
/* Diffuse the differences in every word in a bijective manner with ssi, and then add the values of the previous double pipe.*/
|
||||
Q[0] = ss0(Q[0]) + H[1];
|
||||
Q[1] = ss1(Q[1]) + H[2];
|
||||
Q[2] = ss2(Q[2]) + H[3];
|
||||
Q[3] = ss3(Q[3]) + H[4];
|
||||
Q[4] = ss4(Q[4]) + H[5];
|
||||
Q[5] = ss0(Q[5]) + H[6];
|
||||
Q[6] = ss1(Q[6]) + H[7];
|
||||
Q[7] = ss2(Q[7]) + H[8];
|
||||
Q[8] = ss3(Q[8]) + H[9];
|
||||
Q[9] = ss4(Q[9]) + H[10];
|
||||
Q[10] = ss0(Q[10]) + H[11];
|
||||
Q[11] = ss1(Q[11]) + H[12];
|
||||
Q[12] = ss2(Q[12]) + H[13];
|
||||
Q[13] = ss3(Q[13]) + H[14];
|
||||
Q[14] = ss4(Q[14]) + H[15];
|
||||
Q[15] = ss0(Q[15]) + H[0];
|
||||
|
||||
/* This is the Message expansion or f_1 in the documentation. */
|
||||
/* It has 16 rounds. */
|
||||
/* Blue Midnight Wish has two tunable security parameters. */
|
||||
/* The parameters are named EXPAND_1_ROUNDS and EXPAND_2_ROUNDS. */
|
||||
/* The following relation for these parameters should is satisfied: */
|
||||
/* EXPAND_1_ROUNDS + EXPAND_2_ROUNDS = 16 */
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 16; i<18; i++)
|
||||
Q[i] = expand32_1(i, M32, H, Q);
|
||||
|
||||
#pragma nounroll
|
||||
for (int i = 18; i<32; i++)
|
||||
Q[i] = expand32_2(i, M32, H, Q);
|
||||
|
||||
/* Blue Midnight Wish has two temporary cummulative variables that accumulate via XORing */
|
||||
/* 16 new variables that are prooduced in the Message Expansion part. */
|
||||
XL32 = Q[16] ^ Q[17] ^ Q[18] ^ Q[19] ^ Q[20] ^ Q[21] ^ Q[22] ^ Q[23];
|
||||
XH32 = XL32 ^ Q[24] ^ Q[25] ^ Q[26] ^ Q[27] ^ Q[28] ^ Q[29] ^ Q[30] ^ Q[31];
|
||||
|
||||
M32[2] = (shr(XH32, 5) ^ shl(Q[18], 5) ^ M32[2]) + (XL32 ^ Q[26] ^ Q[2]);
|
||||
M32[3] = (shr(XH32, 1) ^ shl(Q[19], 5) ^ M32[3]) + (XL32 ^ Q[27] ^ Q[3]);
|
||||
M32[14] = SPH_ROTL32(M32[2], 15) + (XH32 ^ Q[30] ^ M32[14]) + (shr(XL32, 7) ^ Q[21] ^ Q[14]);
|
||||
M32[15] = SPH_ROTL32(M32[3], 16) + (XH32 ^ Q[31] ^ M32[15]) + (shr(XL32, 2) ^ Q[22] ^ Q[15]);
|
||||
}
|
||||
|
||||
#define TPB 512
|
||||
__global__ __launch_bounds__(TPB, 2)
|
||||
void bmw256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *g_hash, uint32_t *const __restrict__ nonceVector)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t message[16] = { 0 };
|
||||
|
||||
LOHI(message[0], message[1], __ldg(&g_hash[thread]));
|
||||
LOHI(message[2], message[3], __ldg(&g_hash[thread + 1 * threads]));
|
||||
LOHI(message[4], message[5], __ldg(&g_hash[thread + 2 * threads]));
|
||||
LOHI(message[6], message[7], __ldg(&g_hash[thread + 3 * threads]));
|
||||
|
||||
message[8]=0x80;
|
||||
message[14]=0x100;
|
||||
Compression256(message);
|
||||
Compression256_2(message);
|
||||
|
||||
if (((uint64_t*)message)[7] <= pTarget[3])
|
||||
{
|
||||
uint32_t tmp = atomicExch(&nonceVector[0], startNounce + thread);
|
||||
if (tmp != 0)
|
||||
nonceVector[1] = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void bmw256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *g_hash, uint32_t *resultnonces)
|
||||
{
|
||||
const uint32_t threadsperblock = TPB;
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
cudaMemset(d_GNonce[thr_id], 0, 2 * sizeof(uint32_t));
|
||||
|
||||
bmw256_gpu_hash_32 << <grid, block >> >(threads, startNounce, g_hash, d_GNonce[thr_id]);
|
||||
cudaMemcpy(d_gnounce[thr_id], d_GNonce[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
resultnonces[0] = *(d_gnounce[thr_id]);
|
||||
resultnonces[1] = *(d_gnounce[thr_id] + 1);
|
||||
}
|
||||
|
||||
|
||||
__host__
|
||||
void bmw256_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
cudaMalloc(&d_GNonce[thr_id], 2 * sizeof(uint32_t));
|
||||
cudaMallocHost(&d_gnounce[thr_id], 2 * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__host__
|
||||
void bmw256_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_GNonce[thr_id]);
|
||||
cudaFreeHost(d_gnounce[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
void bmw256_setTarget(const void *pTargetIn)
|
||||
{
|
||||
cudaMemcpyToSymbol(pTarget, pTargetIn, 32, 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#define CUBEHASH_ROUNDS 16 /* this is r for CubeHashr/b */
|
||||
#define CUBEHASH_BLOCKBYTES 32 /* this is b for CubeHashr/b */
|
||||
|
||||
#if __CUDA_ARCH__ < 350
|
||||
#define LROT(x,bits) ((x << bits) | (x >> (32 - bits)))
|
||||
#else
|
||||
#define LROT(x, bits) __funnelshift_l(x, x, bits)
|
||||
#endif
|
||||
|
||||
#if __CUDA_ARCH__ < 500
|
||||
#define TPB 576
|
||||
#else
|
||||
#define TPB 1024
|
||||
#endif
|
||||
|
||||
#define ROTATEUPWARDS7(a) LROT(a,7)
|
||||
#define ROTATEUPWARDS11(a) LROT(a,11)
|
||||
|
||||
//#define SWAP(a,b) { uint32_t u = a; a = b; b = u; }
|
||||
#define SWAP(a,b) { a ^= b; b ^= a; a ^= b; }
|
||||
|
||||
__device__ __forceinline__ void rrounds(uint32_t x[2][2][2][2][2])
|
||||
{
|
||||
int r;
|
||||
int j;
|
||||
int k;
|
||||
int l;
|
||||
int m;
|
||||
|
||||
#pragma unroll 2
|
||||
for (r = 0; r < CUBEHASH_ROUNDS; ++r) {
|
||||
|
||||
/* "add x_0jklm into x_1jklmn modulo 2^32" */
|
||||
#pragma unroll 2
|
||||
for (j = 0; j < 2; ++j)
|
||||
#pragma unroll 2
|
||||
for (k = 0; k < 2; ++k)
|
||||
#pragma unroll 2
|
||||
for (l = 0; l < 2; ++l)
|
||||
#pragma unroll 2
|
||||
for (m = 0; m < 2; ++m)
|
||||
x[1][j][k][l][m] += x[0][j][k][l][m];
|
||||
|
||||
/* "rotate x_0jklm upwards by 7 bits" */
|
||||
#pragma unroll 2
|
||||
for (j = 0; j < 2; ++j)
|
||||
#pragma unroll 2
|
||||
for (k = 0; k < 2; ++k)
|
||||
#pragma unroll 2
|
||||
for (l = 0; l < 2; ++l)
|
||||
#pragma unroll 2
|
||||
for (m = 0; m < 2; ++m)
|
||||
x[0][j][k][l][m] = ROTATEUPWARDS7(x[0][j][k][l][m]);
|
||||
|
||||
/* "swap x_00klm with x_01klm" */
|
||||
#pragma unroll 2
|
||||
for (k = 0; k < 2; ++k)
|
||||
#pragma unroll 2
|
||||
for (l = 0; l < 2; ++l)
|
||||
#pragma unroll 2
|
||||
for (m = 0; m < 2; ++m)
|
||||
SWAP(x[0][0][k][l][m], x[0][1][k][l][m])
|
||||
|
||||
/* "xor x_1jklm into x_0jklm" */
|
||||
#pragma unroll 2
|
||||
for (j = 0; j < 2; ++j)
|
||||
#pragma unroll 2
|
||||
for (k = 0; k < 2; ++k)
|
||||
#pragma unroll 2
|
||||
for (l = 0; l < 2; ++l)
|
||||
#pragma unroll 2
|
||||
for (m = 0; m < 2; ++m)
|
||||
x[0][j][k][l][m] ^= x[1][j][k][l][m];
|
||||
|
||||
/* "swap x_1jk0m with x_1jk1m" */
|
||||
#pragma unroll 2
|
||||
for (j = 0; j < 2; ++j)
|
||||
#pragma unroll 2
|
||||
for (k = 0; k < 2; ++k)
|
||||
#pragma unroll 2
|
||||
for (m = 0; m < 2; ++m)
|
||||
SWAP(x[1][j][k][0][m], x[1][j][k][1][m])
|
||||
|
||||
/* "add x_0jklm into x_1jklm modulo 2^32" */
|
||||
#pragma unroll 2
|
||||
for (j = 0; j < 2; ++j)
|
||||
#pragma unroll 2
|
||||
for (k = 0; k < 2; ++k)
|
||||
#pragma unroll 2
|
||||
for (l = 0; l < 2; ++l)
|
||||
#pragma unroll 2
|
||||
for (m = 0; m < 2; ++m)
|
||||
x[1][j][k][l][m] += x[0][j][k][l][m];
|
||||
|
||||
/* "rotate x_0jklm upwards by 11 bits" */
|
||||
#pragma unroll 2
|
||||
for (j = 0; j < 2; ++j)
|
||||
#pragma unroll 2
|
||||
for (k = 0; k < 2; ++k)
|
||||
#pragma unroll 2
|
||||
for (l = 0; l < 2; ++l)
|
||||
#pragma unroll 2
|
||||
for (m = 0; m < 2; ++m)
|
||||
x[0][j][k][l][m] = ROTATEUPWARDS11(x[0][j][k][l][m]);
|
||||
|
||||
/* "swap x_0j0lm with x_0j1lm" */
|
||||
#pragma unroll 2
|
||||
for (j = 0; j < 2; ++j)
|
||||
#pragma unroll 2
|
||||
for (l = 0; l < 2; ++l)
|
||||
#pragma unroll 2
|
||||
for (m = 0; m < 2; ++m)
|
||||
SWAP(x[0][j][0][l][m], x[0][j][1][l][m])
|
||||
|
||||
/* "xor x_1jklm into x_0jklm" */
|
||||
#pragma unroll 2
|
||||
for (j = 0; j < 2; ++j)
|
||||
#pragma unroll 2
|
||||
for (k = 0; k < 2; ++k)
|
||||
#pragma unroll 2
|
||||
for (l = 0; l < 2; ++l)
|
||||
#pragma unroll 2
|
||||
for (m = 0; m < 2; ++m)
|
||||
x[0][j][k][l][m] ^= x[1][j][k][l][m];
|
||||
|
||||
/* "swap x_1jkl0 with x_1jkl1" */
|
||||
#pragma unroll 2
|
||||
for (j = 0; j < 2; ++j)
|
||||
#pragma unroll 2
|
||||
for (k = 0; k < 2; ++k)
|
||||
#pragma unroll 2
|
||||
for (l = 0; l < 2; ++l)
|
||||
SWAP(x[1][j][k][l][0], x[1][j][k][l][1])
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
__device__ __forceinline__ void block_tox(const uint32_t *in, uint32_t x[2][2][2][2][2])
|
||||
{
|
||||
x[0][0][0][0][0] ^= in[0];
|
||||
x[0][0][0][0][1] ^= in[1];
|
||||
x[0][0][0][1][0] ^= in[2];
|
||||
x[0][0][0][1][1] ^= in[3];
|
||||
x[0][0][1][0][0] ^= in[4];
|
||||
x[0][0][1][0][1] ^= in[5];
|
||||
x[0][0][1][1][0] ^= in[6];
|
||||
x[0][0][1][1][1] ^= in[7];
|
||||
}
|
||||
|
||||
__device__ __forceinline__ void hash_fromx(uint32_t *out, uint32_t x[2][2][2][2][2])
|
||||
{
|
||||
out[0] = x[0][0][0][0][0];
|
||||
out[1] = x[0][0][0][0][1];
|
||||
out[2] = x[0][0][0][1][0];
|
||||
out[3] = x[0][0][0][1][1];
|
||||
out[4] = x[0][0][1][0][0];
|
||||
out[5] = x[0][0][1][0][1];
|
||||
out[6] = x[0][0][1][1][0];
|
||||
out[7] = x[0][0][1][1][1];
|
||||
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void Update32(uint32_t x[2][2][2][2][2], const uint32_t *data)
|
||||
{
|
||||
/* "xor the block into the first b bytes of the state" */
|
||||
/* "and then transform the state invertibly through r identical rounds" */
|
||||
block_tox(data, x);
|
||||
rrounds(x);
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void Update32_const(uint32_t x[2][2][2][2][2])
|
||||
{
|
||||
x[0][0][0][0][0] ^= 0x80;
|
||||
rrounds(x);
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
void Final(uint32_t x[2][2][2][2][2], uint32_t *hashval)
|
||||
{
|
||||
/* "the integer 1 is xored into the last state word x_11111" */
|
||||
x[1][1][1][1][1] ^= 1U;
|
||||
|
||||
/* "the state is then transformed invertibly through 10r identical rounds" */
|
||||
#pragma unroll 2
|
||||
for (int i = 0; i < 10; ++i) rrounds(x);
|
||||
|
||||
/* "output the first h/8 bytes of the state" */
|
||||
hash_fromx(hashval, x);
|
||||
}
|
||||
|
||||
#if __CUDA_ARCH__ >= 500
|
||||
|
||||
__global__ __launch_bounds__(TPB, 1)
|
||||
void cubehash256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint2 *g_hash)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint2 Hash[4];
|
||||
|
||||
Hash[0] = __ldg(&g_hash[thread]);
|
||||
Hash[1] = __ldg(&g_hash[thread + 1 * threads]);
|
||||
Hash[2] = __ldg(&g_hash[thread + 2 * threads]);
|
||||
Hash[3] = __ldg(&g_hash[thread + 3 * threads]);
|
||||
|
||||
uint32_t x[2][2][2][2][2] =
|
||||
{
|
||||
0xEA2BD4B4, 0xCCD6F29F, 0x63117E71, 0x35481EAE,
|
||||
0x22512D5B, 0xE5D94E63, 0x7E624131, 0xF4CC12BE,
|
||||
0xC2D0B696, 0x42AF2070, 0xD0720C35, 0x3361DA8C,
|
||||
0x28CCECA4, 0x8EF8AD83, 0x4680AC00, 0x40E5FBAB,
|
||||
0xD89041C3, 0x6107FBD5, 0x6C859D41, 0xF0B26679,
|
||||
0x09392549, 0x5FA25603, 0x65C892FD, 0x93CB6285,
|
||||
0x2AF2B5AE, 0x9E4B4E60, 0x774ABFDD, 0x85254725,
|
||||
0x15815AEB, 0x4AB6AAD6, 0x9CDAF8AF, 0xD6032C0A
|
||||
};
|
||||
|
||||
x[0][0][0][0][0] ^= Hash[0].x;
|
||||
x[0][0][0][0][1] ^= Hash[0].y;
|
||||
x[0][0][0][1][0] ^= Hash[1].x;
|
||||
x[0][0][0][1][1] ^= Hash[1].y;
|
||||
x[0][0][1][0][0] ^= Hash[2].x;
|
||||
x[0][0][1][0][1] ^= Hash[2].y;
|
||||
x[0][0][1][1][0] ^= Hash[3].x;
|
||||
x[0][0][1][1][1] ^= Hash[3].y;
|
||||
|
||||
rrounds(x);
|
||||
x[0][0][0][0][0] ^= 0x80U;
|
||||
rrounds(x);
|
||||
|
||||
Final(x, (uint32_t*) Hash);
|
||||
|
||||
g_hash[thread] = Hash[0];
|
||||
g_hash[1 * threads + thread] = Hash[1];
|
||||
g_hash[2 * threads + thread] = Hash[2];
|
||||
g_hash[3 * threads + thread] = Hash[3];
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
__global__ __launch_bounds__(TPB, 1)
|
||||
void cubehash256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint2 *d_hash)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t Hash[8];
|
||||
uint64_t* g_hash = (uint64_t*) d_hash;
|
||||
|
||||
LOHI(Hash[0], Hash[1], __ldg(&g_hash[thread]));
|
||||
LOHI(Hash[2], Hash[3], __ldg(&g_hash[thread + 1 * threads]));
|
||||
LOHI(Hash[4], Hash[5], __ldg(&g_hash[thread + 2 * threads]));
|
||||
LOHI(Hash[6], Hash[7], __ldg(&g_hash[thread + 3 * threads]));
|
||||
|
||||
uint32_t x[2][2][2][2][2] =
|
||||
{
|
||||
0xEA2BD4B4, 0xCCD6F29F, 0x63117E71, 0x35481EAE,
|
||||
0x22512D5B, 0xE5D94E63, 0x7E624131, 0xF4CC12BE,
|
||||
0xC2D0B696, 0x42AF2070, 0xD0720C35, 0x3361DA8C,
|
||||
0x28CCECA4, 0x8EF8AD83, 0x4680AC00, 0x40E5FBAB,
|
||||
0xD89041C3, 0x6107FBD5, 0x6C859D41, 0xF0B26679,
|
||||
0x09392549, 0x5FA25603, 0x65C892FD, 0x93CB6285,
|
||||
0x2AF2B5AE, 0x9E4B4E60, 0x774ABFDD, 0x85254725,
|
||||
0x15815AEB, 0x4AB6AAD6, 0x9CDAF8AF, 0xD6032C0A
|
||||
};
|
||||
|
||||
x[0][0][0][0][0] ^= Hash[0];
|
||||
x[0][0][0][0][1] ^= Hash[1];
|
||||
x[0][0][0][1][0] ^= Hash[2];
|
||||
x[0][0][0][1][1] ^= Hash[3];
|
||||
x[0][0][1][0][0] ^= Hash[4];
|
||||
x[0][0][1][0][1] ^= Hash[5];
|
||||
x[0][0][1][1][0] ^= Hash[6];
|
||||
x[0][0][1][1][1] ^= Hash[7];
|
||||
|
||||
rrounds(x);
|
||||
x[0][0][0][0][0] ^= 0x80U;
|
||||
rrounds(x);
|
||||
|
||||
Final(x, Hash);
|
||||
|
||||
g_hash[thread] = ((uint64_t*)Hash)[0];
|
||||
g_hash[1 * threads + thread] = ((uint64_t*)Hash)[1];
|
||||
g_hash[2 * threads + thread] = ((uint64_t*)Hash)[2];
|
||||
g_hash[3 * threads + thread] = ((uint64_t*)Hash)[3];
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
__host__
|
||||
void cubehash256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_hash, int order)
|
||||
{
|
||||
uint32_t tpb = TPB;
|
||||
|
||||
dim3 grid((threads + tpb-1)/tpb);
|
||||
dim3 block(tpb);
|
||||
|
||||
cubehash256_gpu_hash_32 <<<grid, block>>> (threads, startNounce, (uint2*) d_hash);
|
||||
}
|
||||
@@ -732,6 +732,13 @@ void fugue256_cpu_init(int thr_id, uint32_t threads)
|
||||
cudaMalloc(&d_resultNonce[thr_id], sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__host__
|
||||
void fugue256_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_fugue256_hashoutput[thr_id]);
|
||||
cudaFree(d_resultNonce[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
void fugue256_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
|
||||
{
|
||||
|
||||
@@ -262,7 +262,6 @@ void groestl256_gpu_hash32(uint32_t threads, uint32_t startNounce, uint64_t *out
|
||||
__host__
|
||||
void groestl256_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
|
||||
// Texturen mit obigem Makro initialisieren
|
||||
texDef(t0up2, d_T0up, T0up_cpu, sizeof(uint32_t) * 256);
|
||||
texDef(t0dn2, d_T0dn, T0dn_cpu, sizeof(uint32_t) * 256);
|
||||
@@ -277,6 +276,13 @@ void groestl256_cpu_init(int thr_id, uint32_t threads)
|
||||
cudaMallocHost(&h_GNonces[thr_id], 2*sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__host__
|
||||
void groestl256_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_GNonces[thr_id]);
|
||||
cudaFreeHost(h_GNonces[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t groestl256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order)
|
||||
{
|
||||
|
||||
@@ -300,3 +300,10 @@ void keccak256_cpu_init(int thr_id, uint32_t threads)
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_KNonce[thr_id], sizeof(uint32_t)));
|
||||
CUDA_SAFE_CALL(cudaMallocHost(&d_nounce[thr_id], 1*sizeof(uint32_t)));
|
||||
}
|
||||
|
||||
__host__
|
||||
void keccak256_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_KNonce[thr_id]);
|
||||
cudaFreeHost(d_nounce[thr_id]);
|
||||
}
|
||||
+134
-133
@@ -2,79 +2,40 @@
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static __constant__ uint64_t SKEIN_IV512_256[8] = {
|
||||
0xCCD044A12FDB3E13, 0xE83590301A79A9EB,
|
||||
0x55AEA0614F816E6F, 0x2A2767A4AE9B94DB,
|
||||
0xEC06025E74DD7683, 0xE7A436CDC4746251,
|
||||
0xC36FBAF9393AD185, 0x3EEDBA1833EDFC13
|
||||
};
|
||||
|
||||
static __constant__ uint2 vSKEIN_IV512_256[8] = {
|
||||
{ 0x2FDB3E13, 0xCCD044A1 },
|
||||
{ 0x1A79A9EB, 0xE8359030 },
|
||||
{ 0x4F816E6F, 0x55AEA061 },
|
||||
{ 0xAE9B94DB, 0x2A2767A4 },
|
||||
{ 0x74DD7683, 0xEC06025E },
|
||||
{ 0xC4746251, 0xE7A436CD },
|
||||
{ 0x393AD185, 0xC36FBAF9 },
|
||||
{ 0x33EDFC13, 0x3EEDBA18 }
|
||||
};
|
||||
|
||||
static __constant__ int8_t ROT256[8][4] = {
|
||||
46, 36, 19, 37,
|
||||
33, 27, 14, 42,
|
||||
17, 49, 36, 39,
|
||||
44, 9, 54, 56,
|
||||
39, 30, 34, 24,
|
||||
13, 50, 10, 17,
|
||||
25, 29, 39, 43,
|
||||
8, 35, 56, 22,
|
||||
};
|
||||
|
||||
static __constant__ uint2 t12[6] = {
|
||||
{ 0x20, 0 },
|
||||
{ 0, 0xf0000000 },
|
||||
{ 0x20, 0xf0000000 },
|
||||
{ 0x08, 0 },
|
||||
{ 0, 0xff000000 },
|
||||
{ 0x08, 0xff000000 }
|
||||
};
|
||||
|
||||
static __constant__ uint2 skein_ks_parity = { 0xA9FC1A22, 0x1BD11BDA };
|
||||
static __constant__ uint64_t skein_ks_parity64 = 0x1BD11BDAA9FC1A22ull;
|
||||
|
||||
|
||||
static __forceinline__ __device__
|
||||
void Round512v35(uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7, int ROT)
|
||||
void Round512v35(uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7,
|
||||
const int ROT0, const int ROT1, const int ROT2, const int ROT3)
|
||||
{
|
||||
p0 += p1; p1 = ROL2(p1, ROT256[ROT][0]) ^ p0;
|
||||
p2 += p3; p3 = ROL2(p3, ROT256[ROT][1]) ^ p2;
|
||||
p4 += p5; p5 = ROL2(p5, ROT256[ROT][2]) ^ p4;
|
||||
p6 += p7; p7 = ROL2(p7, ROT256[ROT][3]) ^ p6;
|
||||
p0 += p1; p1 = ROL2(p1, ROT0) ^ p0;
|
||||
p2 += p3; p3 = ROL2(p3, ROT1) ^ p2;
|
||||
p4 += p5; p5 = ROL2(p5, ROT2) ^ p4;
|
||||
p6 += p7; p7 = ROL2(p7, ROT3) ^ p6;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__
|
||||
void Round_8_512v35(uint2 *ks, uint2 *ts,
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3,
|
||||
uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7, int R)
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35(const uint2 *const __restrict__ ks, const uint2 *const __restrict__ ts,
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7, int R)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 0);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 1);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 2);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 3);
|
||||
p0 += ks[(R+0) % 9]; /* inject the key schedule value */
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[(R+0) % 9];
|
||||
p1 += ks[(R+1) % 9];
|
||||
p2 += ks[(R+2) % 9];
|
||||
p3 += ks[(R+3) % 9];
|
||||
p4 += ks[(R+4) % 9];
|
||||
p5 += ks[(R+5) % 9] + ts[(R+0) % 3];
|
||||
p6 += ks[(R+6) % 9] + ts[(R+1) % 3];
|
||||
p7 += ks[(R+7) % 9] + make_uint2((R),0);
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 4);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 5);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 6);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 7);
|
||||
p0 += ks[(R+1) % 9]; /* inject the key schedule value */
|
||||
p7 += ks[(R+7) % 9] + make_uint2(R, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[(R+1) % 9];
|
||||
p1 += ks[(R+2) % 9];
|
||||
p2 += ks[(R+3) % 9];
|
||||
p3 += ks[(R+4) % 9];
|
||||
@@ -84,38 +45,83 @@ void Round_8_512v35(uint2 *ks, uint2 *ts,
|
||||
p7 += ks[(R+8) % 9] + make_uint2(R+1, 0);
|
||||
}
|
||||
|
||||
__forceinline__ __device__
|
||||
void Round_8_512v35_final(const uint2 *const __restrict__ ks, const uint2 *const __restrict__ ts,
|
||||
uint2 &p0, uint2 &p1, uint2 &p2, uint2 &p3, uint2 &p4, uint2 &p5, uint2 &p6, uint2 &p7)
|
||||
{
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[8];
|
||||
p1 += ks[0];
|
||||
p2 += ks[1];
|
||||
p3 += ks[2];
|
||||
p4 += ks[3];
|
||||
p5 += ks[4] + ts[2];
|
||||
p6 += ks[5] + ts[0];
|
||||
p7 += ks[6] + make_uint2(17, 0);
|
||||
|
||||
Round512v35(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v35(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v35(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v35(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[0];
|
||||
p1 += ks[1];
|
||||
p2 += ks[2];
|
||||
p3 += ks[3];
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(256,3)
|
||||
void skein256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outputHash)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
|
||||
if (thread < threads)
|
||||
{
|
||||
uint2 h[9], t[3] = { t12[0], t12[1], t12[2] };
|
||||
const uint2 skein_ks_parity = { 0xA9FC1A22, 0x1BD11BDA };
|
||||
const uint2 t12[6] = {
|
||||
{ 0x20, 0 },
|
||||
{ 0, 0xf0000000 },
|
||||
{ 0x20, 0xf0000000 },
|
||||
{ 0x08, 0 },
|
||||
{ 0, 0xff000000 },
|
||||
{ 0x08, 0xff000000 }
|
||||
};
|
||||
|
||||
h[8] = skein_ks_parity;
|
||||
for (int i = 0; i<8; i++) {
|
||||
h[i] = vSKEIN_IV512_256[i];
|
||||
h[8] ^= h[i];
|
||||
}
|
||||
uint2 h[9] = {
|
||||
{ 0x2FDB3E13, 0xCCD044A1 },
|
||||
{ 0x1A79A9EB, 0xE8359030 },
|
||||
{ 0x4F816E6F, 0x55AEA061 },
|
||||
{ 0xAE9B94DB, 0x2A2767A4 },
|
||||
{ 0x74DD7683, 0xEC06025E },
|
||||
{ 0xC4746251, 0xE7A436CD },
|
||||
{ 0x393AD185, 0xC36FBAF9 },
|
||||
{ 0x33EDFC13, 0x3EEDBA18 },
|
||||
{ 0xC73A4E2A, 0xB69D3CFC }
|
||||
};
|
||||
uint2 dt0,dt1,dt2,dt3;
|
||||
uint2 p0, p1, p2, p3, p4, p5, p6, p7;
|
||||
|
||||
uint2 dt0 = vectorize(outputHash[thread]);
|
||||
uint2 dt1 = vectorize(outputHash[threads + thread]);
|
||||
uint2 dt2 = vectorize(outputHash[threads*2 + thread]);
|
||||
uint2 dt3 = vectorize(outputHash[threads*3 + thread]);
|
||||
LOHI(dt0.x,dt0.y,outputHash[thread]);
|
||||
LOHI(dt1.x,dt1.y,outputHash[threads+thread]);
|
||||
LOHI(dt2.x,dt2.y,outputHash[2*threads+thread]);
|
||||
LOHI(dt3.x,dt3.y,outputHash[3*threads+thread]);
|
||||
|
||||
uint2 p0 = h[0] + dt0;
|
||||
uint2 p1 = h[1] + dt1;
|
||||
uint2 p2 = h[2] + dt2;
|
||||
uint2 p3 = h[3] + dt3;
|
||||
uint2 p4 = h[4];
|
||||
uint2 p5 = h[5] + t[0];
|
||||
uint2 p6 = h[6] + t[1];
|
||||
uint2 p7 = h[7];
|
||||
p0 = h[0] + dt0;
|
||||
p1 = h[1] + dt1;
|
||||
p2 = h[2] + dt2;
|
||||
p3 = h[3] + dt3;
|
||||
p4 = h[4];
|
||||
p5 = h[5] + t12[0];
|
||||
p6 = h[6] + t12[1];
|
||||
p7 = h[7];
|
||||
|
||||
#pragma unroll 9
|
||||
#pragma unroll
|
||||
for (int i = 1; i<19; i+=2) {
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, i);
|
||||
Round_8_512v35(h,t12,p0,p1,p2,p3,p4,p5,p6,p7,i);
|
||||
}
|
||||
|
||||
p0 ^= dt0;
|
||||
@@ -131,51 +137,46 @@ void skein256_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint64_t *outp
|
||||
h[5] = p5;
|
||||
h[6] = p6;
|
||||
h[7] = p7;
|
||||
h[8] = skein_ks_parity;
|
||||
h[8] = skein_ks_parity ^ h[0] ^ h[1] ^ h[2] ^ h[3] ^ h[4] ^ h[5] ^ h[6] ^ h[7];
|
||||
|
||||
#pragma unroll 8
|
||||
for (int i = 0; i<8; i++) {
|
||||
h[8] ^= h[i];
|
||||
}
|
||||
const uint2 *t = t12+3;
|
||||
p5 += t12[3]; //p5 already equal h[5]
|
||||
p6 += t12[4];
|
||||
|
||||
t[0] = t12[3];
|
||||
t[1] = t12[4];
|
||||
t[2] = t12[5];
|
||||
|
||||
p5 += t[0];
|
||||
p6 += t[1];
|
||||
|
||||
#pragma unroll 9
|
||||
for (int i = 1; i<19; i+=2) {
|
||||
#pragma unroll
|
||||
for (int i = 1; i<17; i+=2) {
|
||||
Round_8_512v35(h, t, p0, p1, p2, p3, p4, p5, p6, p7, i);
|
||||
}
|
||||
|
||||
outputHash[thread] = devectorize(p0);
|
||||
outputHash[threads + thread] = devectorize(p1);
|
||||
outputHash[threads*2 + thread] = devectorize(p2);
|
||||
outputHash[threads*3 + thread] = devectorize(p3);
|
||||
Round_8_512v35_final(h, t, p0, p1, p2, p3, p4, p5, p6, p7);
|
||||
outputHash[thread] = devectorize(p0);
|
||||
outputHash[threads+thread] = devectorize(p1);
|
||||
outputHash[2*threads+thread] = devectorize(p2);
|
||||
outputHash[3*threads+thread] = devectorize(p3);
|
||||
}
|
||||
}
|
||||
|
||||
static __forceinline__ __device__
|
||||
void Round512v30(uint64_t &p0, uint64_t &p1, uint64_t &p2, uint64_t &p3,
|
||||
uint64_t &p4, uint64_t &p5, uint64_t &p6, uint64_t &p7, int ROT)
|
||||
uint64_t &p4, uint64_t &p5, uint64_t &p6, uint64_t &p7,
|
||||
const int ROT0, const int ROT1, const int ROT2, const int ROT3)
|
||||
{
|
||||
p0 += p1; p1 = ROTL64(p1, ROT256[ROT][0]) ^ p0;
|
||||
p2 += p3; p3 = ROTL64(p3, ROT256[ROT][1]) ^ p2;
|
||||
p4 += p5; p5 = ROTL64(p5, ROT256[ROT][2]) ^ p4;
|
||||
p6 += p7; p7 = ROTL64(p7, ROT256[ROT][3]) ^ p6;
|
||||
p0 += p1; p1 = ROTL64(p1, ROT0) ^ p0;
|
||||
p2 += p3; p3 = ROTL64(p3, ROT1) ^ p2;
|
||||
p4 += p5; p5 = ROTL64(p5, ROT2) ^ p4;
|
||||
p6 += p7; p7 = ROTL64(p7, ROT3) ^ p6;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__
|
||||
void Round_8_512v30(uint64_t *ks, uint64_t *ts, uint64_t &p0, uint64_t &p1, uint64_t &p2, uint64_t &p3,
|
||||
void Round_8_512v30(uint64_t *ks, uint64_t *ts,
|
||||
uint64_t &p0, uint64_t &p1, uint64_t &p2, uint64_t &p3,
|
||||
uint64_t &p4, uint64_t &p5, uint64_t &p6, uint64_t &p7, int R)
|
||||
{
|
||||
Round512v30(p0, p1, p2, p3, p4, p5, p6, p7, 0);
|
||||
Round512v30(p2, p1, p4, p7, p6, p5, p0, p3, 1);
|
||||
Round512v30(p4, p1, p6, p3, p0, p5, p2, p7, 2);
|
||||
Round512v30(p6, p1, p0, p7, p2, p5, p4, p3, 3);
|
||||
p0 += ks[(R+0) % 9]; /* inject the key schedule value */
|
||||
Round512v30(p0, p1, p2, p3, p4, p5, p6, p7, 46, 36, 19, 37);
|
||||
Round512v30(p2, p1, p4, p7, p6, p5, p0, p3, 33, 27, 14, 42);
|
||||
Round512v30(p4, p1, p6, p3, p0, p5, p2, p7, 17, 49, 36, 39);
|
||||
Round512v30(p6, p1, p0, p7, p2, p5, p4, p3, 44, 9, 54, 56);
|
||||
|
||||
p0 += ks[(R+0) % 9];
|
||||
p1 += ks[(R+1) % 9];
|
||||
p2 += ks[(R+2) % 9];
|
||||
p3 += ks[(R+3) % 9];
|
||||
@@ -183,11 +184,13 @@ void Round_8_512v30(uint64_t *ks, uint64_t *ts, uint64_t &p0, uint64_t &p1, uint
|
||||
p5 += ks[(R+5) % 9] + ts[(R+0) % 3];
|
||||
p6 += ks[(R+6) % 9] + ts[(R+1) % 3];
|
||||
p7 += ks[(R+7) % 9] + R;
|
||||
Round512v30(p0, p1, p2, p3, p4, p5, p6, p7, 4);
|
||||
Round512v30(p2, p1, p4, p7, p6, p5, p0, p3, 5);
|
||||
Round512v30(p4, p1, p6, p3, p0, p5, p2, p7, 6);
|
||||
Round512v30(p6, p1, p0, p7, p2, p5, p4, p3, 7);
|
||||
p0 += ks[(R+1) % 9]; /* inject the key schedule value */
|
||||
|
||||
Round512v30(p0, p1, p2, p3, p4, p5, p6, p7, 39, 30, 34, 24);
|
||||
Round512v30(p2, p1, p4, p7, p6, p5, p0, p3, 13, 50, 10, 17);
|
||||
Round512v30(p4, p1, p6, p3, p0, p5, p2, p7, 25, 29, 39, 43);
|
||||
Round512v30(p6, p1, p0, p7, p2, p5, p4, p3, 8, 35, 56, 22);
|
||||
|
||||
p0 += ks[(R+1) % 9];
|
||||
p1 += ks[(R+2) % 9];
|
||||
p2 += ks[(R+3) % 9];
|
||||
p3 += ks[(R+4) % 9];
|
||||
@@ -197,29 +200,28 @@ void Round_8_512v30(uint64_t *ks, uint64_t *ts, uint64_t &p0, uint64_t &p1, uint
|
||||
p7 += ks[(R+8) % 9] + R+1;
|
||||
}
|
||||
|
||||
#define skein_ks_parity64 0x1BD11BDAA9FC1A22ull
|
||||
#include <stdio.h>
|
||||
__global__ __launch_bounds__(256, 3)
|
||||
void skein256_gpu_hash_32_v30(uint32_t threads, uint32_t startNounce, uint64_t *outputHash)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint64_t h[9], t[3];
|
||||
|
||||
h[8] = skein_ks_parity64;
|
||||
for (int i = 0; i<8; i++) {
|
||||
h[i] = SKEIN_IV512_256[i];
|
||||
h[8] ^= h[i];
|
||||
}
|
||||
|
||||
t[0] = devectorize(t12[0]);
|
||||
t[1] = devectorize(t12[1]);
|
||||
t[2] = devectorize(t12[2]);
|
||||
|
||||
uint64_t h[12] = { // SKEIN_IV512_256
|
||||
0xCCD044A12FDB3E13, 0xE83590301A79A9EB,
|
||||
0x55AEA0614F816E6F, 0x2A2767A4AE9B94DB,
|
||||
0xEC06025E74DD7683, 0xE7A436CDC4746251,
|
||||
0xC36FBAF9393AD185, 0x3EEDBA1833EDFC13,
|
||||
0xb69d3cfcc73a4e2a, // skein_ks_parity64 ^ h[0..7]
|
||||
0x20, 0xf000000000000000, 0xf000000000000020 // t0..2
|
||||
};
|
||||
uint64_t dt0 = outputHash[thread];
|
||||
uint64_t dt1 = outputHash[threads + thread];
|
||||
uint64_t dt2 = outputHash[threads*2 + thread];
|
||||
uint64_t dt3 = outputHash[threads*3 + thread];
|
||||
|
||||
uint64_t *t = &h[9];
|
||||
uint64_t p0 = h[0] + dt0;
|
||||
uint64_t p1 = h[1] + dt1;
|
||||
uint64_t p2 = h[2] + dt2;
|
||||
@@ -254,9 +256,9 @@ void skein256_gpu_hash_32_v30(uint32_t threads, uint32_t startNounce, uint64_t *
|
||||
h[8] ^= h[i];
|
||||
}
|
||||
|
||||
t[0] = devectorize(t12[3]);
|
||||
t[1] = devectorize(t12[4]);
|
||||
t[2] = devectorize(t12[5]);
|
||||
t[0] = 0x08;
|
||||
t[1] = 0xff00000000000000;
|
||||
t[2] = 0xff00000000000008;
|
||||
|
||||
p5 += t[0]; //p5 already equal h[5]
|
||||
p6 += t[1];
|
||||
@@ -270,7 +272,6 @@ void skein256_gpu_hash_32_v30(uint32_t threads, uint32_t startNounce, uint64_t *
|
||||
outputHash[threads + thread] = p1;
|
||||
outputHash[threads*2 + thread] = p2;
|
||||
outputHash[threads*3 + thread] = p3;
|
||||
|
||||
} //thread
|
||||
}
|
||||
|
||||
|
||||
+22
-4
@@ -17,6 +17,7 @@ extern "C"
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
|
||||
extern void keccak256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void keccak256_cpu_free(int thr_id);
|
||||
extern void keccak256_setBlock_80(void *pdata,const void *ptarget);
|
||||
extern uint32_t keccak256_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash, int order);
|
||||
|
||||
@@ -35,10 +36,11 @@ extern "C" void keccak256_hash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_keccak256(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_keccak256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 21); // 256*256*8*4
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
@@ -55,7 +57,6 @@ extern "C" int scanhash_keccak256(int thr_id, uint32_t *pdata,
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t endiandata[20];
|
||||
for (int k=0; k < 20; k++) {
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
}
|
||||
@@ -74,6 +75,7 @@ extern "C" int scanhash_keccak256(int thr_id, uint32_t *pdata,
|
||||
keccak256_hash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[19] = foundNonce;
|
||||
return 1;
|
||||
}
|
||||
@@ -92,3 +94,19 @@ extern "C" int scanhash_keccak256(int thr_id, uint32_t *pdata,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_keccak256(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
keccak256_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -13,7 +13,7 @@ but some distros may have a different default location)
|
||||
|
||||
# Step 1: gcc and dependencies
|
||||
dnf install gcc gcc-c++ automake
|
||||
dnf install jansson-devel openssl-devel libcurl-devel
|
||||
dnf install jansson-devel openssl-devel libcurl-devel zlib-devel pciutils-devel
|
||||
|
||||
# Step 2: nvidia drivers (Download common linux drivers from nvidia site)
|
||||
dnf install kernel-devel
|
||||
|
||||
+31
-4
@@ -87,10 +87,11 @@ extern "C" unsigned int jackpothash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_jackpot(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_jackpot(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[22];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 20);
|
||||
@@ -123,7 +124,6 @@ extern "C" int scanhash_jackpot(int thr_id, uint32_t *pdata,
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t endiandata[22];
|
||||
for (int k=0; k < 22; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
|
||||
@@ -221,7 +221,12 @@ extern "C" int scanhash_jackpot(int thr_id, uint32_t *pdata,
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
nist5hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -245,3 +250,25 @@ extern "C" int scanhash_jackpot(int thr_id, uint32_t *pdata,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_jackpot(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cudaFree(d_branch1Nonces[thr_id]);
|
||||
cudaFree(d_branch2Nonces[thr_id]);
|
||||
cudaFree(d_branch3Nonces[thr_id]);
|
||||
|
||||
cudaFree(d_jackpotNonces[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+14
-10
@@ -33,31 +33,32 @@ ccminer_SOURCES = elist.h miner.h compat.h \
|
||||
myriadgroestl.cpp cuda_myriadgroestl.cu \
|
||||
lyra2/Lyra2.c lyra2/Sponge.c \
|
||||
lyra2/lyra2RE.cu lyra2/cuda_lyra2.cu \
|
||||
lyra2/lyra2REv2.cu lyra2/cuda_lyra2v2.cu \
|
||||
Algo256/cuda_bmw256.cu Algo256/cuda_cubehash256.cu \
|
||||
Algo256/cuda_blake256.cu Algo256/cuda_groestl256.cu Algo256/cuda_keccak256.cu Algo256/cuda_skein256.cu \
|
||||
Algo256/blake256.cu Algo256/keccak256.cu \
|
||||
Algo256/bmw.cu Algo256/cuda_bmw.cu \
|
||||
JHA/jackpotcoin.cu JHA/cuda_jha_keccak512.cu \
|
||||
JHA/cuda_jha_compactionTest.cu cuda_checkhash.cu \
|
||||
quark/cuda_jh512.cu quark/cuda_quark_blake512.cu quark/cuda_quark_groestl512.cu quark/cuda_skein512.cu \
|
||||
quark/cuda_bmw512.cu quark/cuda_quark_keccak512.cu \
|
||||
quark/quarkcoin.cu quark/animecoin.cu \
|
||||
quark/cuda_quark_compactionTest.cu \
|
||||
quark/quarkcoin.cu quark/cuda_quark_compactionTest.cu \
|
||||
neoscrypt/neoscrypt.cpp neoscrypt/neoscrypt-cpu.c neoscrypt/cuda_neoscrypt.cu \
|
||||
cuda_nist5.cu pentablake.cu skein.cu cuda_skeincoin.cu skein2.cpp zr5.cu \
|
||||
sph/bmw.c sph/blake.c sph/groestl.c sph/jh.c sph/keccak.c sph/skein.c \
|
||||
sph/cubehash.c sph/echo.c sph/luffa.c sph/sha2.c sph/sha256d.c sph/shavite.c sph/simd.c \
|
||||
sph/cubehash.c sph/echo.c sph/luffa.c sph/sha2.c sph/shavite.c sph/simd.c \
|
||||
sph/hamsi.c sph/hamsi_helper.c sph/sph_hamsi.h \
|
||||
sph/shabal.c sph/whirlpool.c sph/sha2big.c sph/haval.c \
|
||||
sha256/bitcoin.cu sha256/cuda_bitcoin.cu \
|
||||
sha256/credits.cu sha256/cuda_credits.cu \
|
||||
pluck/pluck.cu pluck/cuda_pluck.cu \
|
||||
qubit/qubit.cu qubit/qubit_luffa512.cu qubit/deep.cu qubit/luffa.cu \
|
||||
x11/x11.cu x11/fresh.cu x11/cuda_x11_luffa512.cu x11/cuda_x11_cubehash512.cu \
|
||||
x11/cuda_x11_shavite512.cu x11/cuda_x11_simd512.cu x11/cuda_x11_echo.cu \
|
||||
x11/cuda_x11_luffa512_Cubehash.cu \
|
||||
x13/x13.cu x13/cuda_x13_hamsi512.cu x13/cuda_x13_fugue512.cu \
|
||||
x15/x14.cu x15/x15.cu x15/cuda_x14_shabal512.cu x15/cuda_x15_whirlpool.cu \
|
||||
x15/whirlpoolx.cu x15/cuda_whirlpoolx.cu \
|
||||
x17/x17.cu x17/cuda_x17_haval512.cu x17/cuda_x17_sha512.cu \
|
||||
x11/s3.cu
|
||||
x11/c11.cu x11/s3.cu \
|
||||
spreadx11/spreadx11.cu spreadx11/cuda_blake.cu spreadx11/cuda_spreadx11_sign.cu spreadx11/cuda_sha256.cu
|
||||
|
||||
# scrypt
|
||||
ccminer_SOURCES += scrypt.cpp scrypt-jane.cpp \
|
||||
@@ -76,12 +77,12 @@ ccminer_SOURCES += compat/winansi.c
|
||||
endif
|
||||
|
||||
ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@
|
||||
ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @OPENMP_CFLAGS@ @LIBS@ $(nvml_libs)
|
||||
ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(DEF_INCLUDES) $(nvml_defs) -DSCRYPT_KECCAK512 -DSCRYPT_CHACHA -DSCRYPT_CHOOSE_COMPILETIME
|
||||
ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @PCILIB@ @OPENMP_CFLAGS@ @LIBS@ $(nvml_libs)
|
||||
ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @PCIFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(DEF_INCLUDES) $(nvml_defs)
|
||||
|
||||
nvcc_ARCH = -gencode=arch=compute_50,code=\"sm_50,compute_50\"
|
||||
|
||||
nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_35,code=\"sm_35,compute_35\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_30,code=\"sm_30,compute_30\"
|
||||
#nvcc_ARCH += -gencode=arch=compute_20,code=\"sm_21,compute_20\"
|
||||
@@ -96,6 +97,9 @@ nvcc_FLAGS += $(JANSSON_INCLUDES) --ptxas-options="-v"
|
||||
Algo256/blake256.o: Algo256/blake256.cu
|
||||
$(NVCC) $(nvcc_FLAGS) --maxrregcount=64 -o $@ -c $<
|
||||
|
||||
Algo256/cuda_bmw.o: Algo256/cuda_bmw.cu
|
||||
$(NVCC) $(nvcc_FLAGS) --maxrregcount=76 -o $@ -c $<
|
||||
|
||||
heavy/cuda_hefty1.o: heavy/cuda_hefty1.cu
|
||||
$(NVCC) $(nvcc_FLAGS) --maxrregcount=80 -o $@ -c $<
|
||||
|
||||
|
||||
+35
-11
@@ -1,5 +1,5 @@
|
||||
|
||||
ccMiner release 1.6.x-tpruvot (Jun 2015) - "SHA and ..."
|
||||
ccMiner release 1.6.6 (Aug 2015) "Lyra2REv2, BMW And Vanilla"
|
||||
---------------------------------------------------------------
|
||||
|
||||
***************************************************************
|
||||
@@ -24,7 +24,6 @@ cbuchner v1.2:
|
||||
|
||||
This is a CUDA accelerated mining application which handle :
|
||||
|
||||
Credits
|
||||
HeavyCoin & MjollnirCoin
|
||||
FugueCoin
|
||||
GroestlCoin & Myriad-Groestl
|
||||
@@ -32,8 +31,10 @@ JackpotCoin
|
||||
QuarkCoin family & AnimeCoin
|
||||
TalkCoin
|
||||
DarkCoin and other X11 coins
|
||||
Chaincoin and Flaxscript (C11)
|
||||
Saffroncoin blake (256 14-rounds)
|
||||
BlakeCoin (256 8-rounds)
|
||||
Midnight (BMW 256)
|
||||
Qubit (Digibyte, ...)
|
||||
Luffa (Joincoin)
|
||||
Keccak (Maxcoin)
|
||||
@@ -64,11 +65,10 @@ This code is based on the pooler cpuminer and inherits
|
||||
its command line interface and options.
|
||||
|
||||
-a, --algo=ALGO specify the algorithm to use
|
||||
anime use to mine Animecoin
|
||||
bitcoin use to mine SHA-256d coins
|
||||
blake use to mine Saffroncoin (Blake 256)
|
||||
blakecoin use to mine Old Blake 256
|
||||
credits use to mine Credits [CRE]
|
||||
bmw use to mine Midnight
|
||||
c11/flax use to mine Chaincoin and Flax
|
||||
deep use to mine Deepcoin
|
||||
dmd-gr use to mine Diamond-Groestl
|
||||
fresh use to mine Freshcoin
|
||||
@@ -84,7 +84,6 @@ its command line interface and options.
|
||||
neoscrypt use to mine FeatherCoin
|
||||
nist5 use to mine TalkCoin
|
||||
penta use to mine Joincoin / Pentablake
|
||||
pluck use to mine Supcoin
|
||||
quark use to mine Quarkcoin
|
||||
qubit use to mine Qubit
|
||||
scrypt use to mine Scrypt coins
|
||||
@@ -97,6 +96,7 @@ its command line interface and options.
|
||||
x14 use to mine X14Coin
|
||||
x15 use to mine Halcyon
|
||||
x17 use to mine X17
|
||||
whirlpoolx use to mine Vanilla
|
||||
zr5 use to mine ZiftrCoin
|
||||
|
||||
-d, --devices gives a comma separated list of CUDA device IDs
|
||||
@@ -106,6 +106,7 @@ its command line interface and options.
|
||||
|
||||
-i, --intensity=N[,N] GPU threads per call 8-25 (2^N + F, default: 0=auto)
|
||||
Decimals and multiple values are allowed for fine tuning
|
||||
--cuda-schedule Set device threads scheduling mode (default: auto)
|
||||
-f, --diff-factor Divide difficulty by this factor (default 1.0)
|
||||
-m, --diff-multiplier Multiply difficulty by this value (default 1.0)
|
||||
--vote=VOTE block reward vote (for HeavyCoin)
|
||||
@@ -121,7 +122,7 @@ its command line interface and options.
|
||||
(default: retry indefinitely)
|
||||
-R, --retry-pause=N time to pause between retries, in seconds (default: 15)
|
||||
--time-limit maximum time [s] to mine before exiting the program.
|
||||
-T, --timeout=N network timeout, in seconds (default: 270)
|
||||
-T, --timeout=N network timeout, in seconds (default: 300)
|
||||
-s, --scantime=N upper bound on time spent scanning current work when
|
||||
long polling is unavailable, in seconds (default: 5)
|
||||
-n, --ndevs list cuda devices
|
||||
@@ -138,12 +139,17 @@ its command line interface and options.
|
||||
--max-temp=N Only mine if gpu temp is less than specified value
|
||||
--max-rate=N[KMG] Only mine if net hashrate is less than specified value
|
||||
--max-diff=N Only mine if net difficulty is less than specified value
|
||||
--pstate=0 will force the Geforce 9xx to run in P0 P-State
|
||||
--plimit=150W set the gpu power limit, allow multiple values for N cards
|
||||
--keep-clocks prevent reset clocks and/or power limit on exit
|
||||
--show-diff display submitted block and net difficulty
|
||||
-B, --background run the miner in the background
|
||||
--benchmark run in offline benchmark mode
|
||||
--cputest debug hashes from cpu algorithms
|
||||
--cpu-affinity set process affinity to specific cpu core(s) mask
|
||||
--cpu-priority set process priority (default: 0 idle, 2 normal to 5 highest)
|
||||
-c, --config=FILE load a JSON-format configuration file
|
||||
can be from an url with the http:// prefix
|
||||
-V, --version display version information and exit
|
||||
-h, --help display this help text and exit
|
||||
|
||||
@@ -221,14 +227,32 @@ features.
|
||||
|
||||
>>> RELEASE HISTORY <<<
|
||||
|
||||
June 2015 v1.6.5
|
||||
Under Dev... v1.7
|
||||
Add --cuda-schedule parameter
|
||||
Add --show-diff parameter, which display shares diff,
|
||||
and is able to detect real solved blocks on pools.
|
||||
|
||||
Aug. 28th 2015 v1.6.6
|
||||
Allow to load remote config with curl (-c http://...)
|
||||
Add Lyra2REv2 algo (Vertcoin/Zoom)
|
||||
Restore WhirlpoolX algo (VNL)
|
||||
Drop Animecoin support
|
||||
Add bmw (Midnight) algo
|
||||
|
||||
July 06th 2015 v1.6.5-C11
|
||||
Nvml api power limits
|
||||
Add chaincoin c11 algo (used by Flaxscript too)
|
||||
Remove pluck algo
|
||||
|
||||
June 23th 2015 v1.6.5
|
||||
Handle Ziftrcoin PoK solo mining
|
||||
Basic compatibility with CUDA 7.0 (generally slower hashrate)
|
||||
Show gpus vendor names on linux (windows test branch is pciutils)
|
||||
Remove -v and -m short params specific to heavycoin
|
||||
Add --diff-multiplier (-m) and rename --diff to --diff-factor (-f)
|
||||
First steps to handle nvml application clocks and P0 on the GTX9xx
|
||||
Optimize qubit, deep and luffa algos
|
||||
Compatibility with CUDA 7.0 (but slower hashrate)
|
||||
Various improvements on multipool and cmdline parameters
|
||||
Import Credits (djm34) and Bitcoin (klaus) "SHA256" algos
|
||||
Optimize a bit qubit, deep, luffa, x11 and quark algos
|
||||
|
||||
May 26th 2015 v1.6.4
|
||||
Implement multi-pool support (failover and time rotate)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version. See COPYING for more details.
|
||||
*/
|
||||
#define APIVERSION "1.5"
|
||||
#define APIVERSION "1.6"
|
||||
|
||||
#ifdef WIN32
|
||||
# define _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
@@ -124,6 +124,7 @@ static void gpustatus(int thr_id)
|
||||
cgpu->gpu_temp = gpu_temp(cgpu);
|
||||
cgpu->gpu_fan = (uint16_t) gpu_fanpercent(cgpu);
|
||||
cgpu->gpu_fan_rpm = (uint16_t) gpu_fanrpm(cgpu);
|
||||
cgpu->gpu_power = gpu_power(cgpu);
|
||||
#endif
|
||||
cuda_gpu_clocks(cgpu);
|
||||
|
||||
@@ -135,10 +136,11 @@ static void gpustatus(int thr_id)
|
||||
|
||||
card = device_name[gpuid];
|
||||
|
||||
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;"
|
||||
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%d;KHS=%.2f;HWF=%d;I=%.1f;THR=%u|",
|
||||
gpuid, cgpu->gpu_bus, card, cgpu->gpu_temp, cgpu->gpu_fan,
|
||||
cgpu->gpu_fan_rpm, cgpu->gpu_clock, cgpu->khashes,
|
||||
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;TEMP=%.1f;"
|
||||
"POWER=%u;FAN=%hu;RPM=%hu;FREQ=%d;KHS=%.2f;HWF=%d;I=%.1f;THR=%u|",
|
||||
gpuid, cgpu->gpu_bus, card, cgpu->gpu_temp,
|
||||
cgpu->gpu_power, cgpu->gpu_fan, cgpu->gpu_fan_rpm,
|
||||
cgpu->gpu_clock, cgpu->khashes,
|
||||
cgpu->hw_errors, cgpu->intensity, cgpu->throughput);
|
||||
|
||||
// append to buffer for multi gpus
|
||||
@@ -248,6 +250,7 @@ static void gpuhwinfos(int gpu_id)
|
||||
cgpu->gpu_fan = (uint16_t) gpu_fanpercent(cgpu);
|
||||
cgpu->gpu_fan_rpm = (uint16_t) gpu_fanrpm(cgpu);
|
||||
cgpu->gpu_pstate = (int16_t) gpu_pstate(cgpu);
|
||||
cgpu->gpu_power = gpu_power(cgpu);
|
||||
gpu_info(cgpu);
|
||||
#endif
|
||||
|
||||
@@ -260,12 +263,13 @@ static void gpuhwinfos(int gpu_id)
|
||||
card = device_name[gpu_id];
|
||||
|
||||
snprintf(buf, sizeof(buf), "GPU=%d;BUS=%hd;CARD=%s;SM=%u;MEM=%lu;"
|
||||
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%d;MEMFREQ=%d;PST=%s;"
|
||||
"TEMP=%.1f;FAN=%hu;RPM=%hu;FREQ=%d;MEMFREQ=%d;PST=%s;POWER=%u;"
|
||||
"VID=%hx;PID=%hx;NVML=%d;NVAPI=%d;SN=%s;BIOS=%s|",
|
||||
gpu_id, cgpu->gpu_bus, card, cgpu->gpu_arch, cgpu->gpu_mem,
|
||||
cgpu->gpu_temp, cgpu->gpu_fan, cgpu->gpu_fan_rpm,
|
||||
cgpu->gpu_clock, cgpu->gpu_memclock,
|
||||
pstate, cgpu->gpu_vid, cgpu->gpu_pid, cgpu->nvml_id, cgpu->nvapi_id,
|
||||
pstate, cgpu->gpu_power,
|
||||
cgpu->gpu_vid, cgpu->gpu_pid, cgpu->nvml_id, cgpu->nvapi_id,
|
||||
cgpu->gpu_sn, cgpu->gpu_desc);
|
||||
|
||||
strcat(buffer, buf);
|
||||
@@ -874,7 +878,7 @@ static void api()
|
||||
buffer = (char *) calloc(1, MYBUFSIZ + 1);
|
||||
|
||||
counter = 0;
|
||||
while (bye == 0) {
|
||||
while (bye == 0 && !abort_flag) {
|
||||
counter++;
|
||||
|
||||
clisiz = sizeof(cli);
|
||||
|
||||
@@ -62,6 +62,7 @@ function translateField($key)
|
||||
$intl['TEMP'] = 'T°c';
|
||||
$intl['FAN'] = 'Fan %';
|
||||
$intl['FREQ'] = 'Freq.';
|
||||
$intl['POWER'] = 'Power';
|
||||
$intl['PST'] = 'P-State';
|
||||
|
||||
// pool infos
|
||||
@@ -96,6 +97,9 @@ function translateValue($key,$val,$data=array())
|
||||
case 'FREQ':
|
||||
$val = sprintf("%d MHz", round(floatval($val)/1000.0));
|
||||
break;
|
||||
case 'POWER':
|
||||
$val = sprintf("%d W", round(floatval($val)/1000.0));
|
||||
break;
|
||||
case 'TS':
|
||||
$val = strftime("%H:%M:%S", (int) $val);
|
||||
break;
|
||||
|
||||
+54
@@ -24,3 +24,57 @@ extern "C" void bn_nbits_to_uchar(const uint32_t nBits, unsigned char *target)
|
||||
snprintf(buff, 65, "%s\n", bn.ToString().c_str()); buff[64] = '\0';
|
||||
hex2bin(target, buff, 32);
|
||||
}
|
||||
|
||||
// unused, but should allow more than 256bits targets
|
||||
#if 0
|
||||
extern "C" double bn_hash_target_ratio(uint32_t* hash, uint32_t* target)
|
||||
{
|
||||
double dhash;
|
||||
|
||||
if (!opt_showdiff)
|
||||
return 0.0;
|
||||
|
||||
CBigNum h(0), t(0);
|
||||
std::vector<unsigned char> vch(32);
|
||||
|
||||
memcpy(&vch[0], (void*) target, 32);
|
||||
t.setvch(vch);
|
||||
memcpy(&vch[0], (void*) hash, 32);
|
||||
h.setvch(vch);
|
||||
|
||||
dhash = h.getuint256().getdouble();
|
||||
if (dhash > 0.)
|
||||
return t.getuint256().getdouble() / dhash;
|
||||
else
|
||||
return dhash;
|
||||
}
|
||||
#endif
|
||||
|
||||
// compute the diff ratio between a found hash and the target
|
||||
extern "C" double bn_hash_target_ratio(uint32_t* hash, uint32_t* target)
|
||||
{
|
||||
uint256 h, t;
|
||||
double dhash;
|
||||
|
||||
if (!opt_showdiff)
|
||||
return 0.0;
|
||||
|
||||
memcpy(&t, (void*) target, 32);
|
||||
memcpy(&h, (void*) hash, 32);
|
||||
|
||||
dhash = h.getdouble();
|
||||
if (dhash > 0.)
|
||||
return t.getdouble() / dhash;
|
||||
else
|
||||
return dhash;
|
||||
}
|
||||
|
||||
// store ratio in work struct
|
||||
extern "C" void bn_store_hash_target_ratio(uint32_t* hash, uint32_t* target, struct work* work)
|
||||
{
|
||||
// only if the option is enabled (to reduce cpu usage)
|
||||
if (opt_showdiff) {
|
||||
work->shareratio = bn_hash_target_ratio(hash, target);
|
||||
work->sharediff = work->targetdiff * work->shareratio;
|
||||
}
|
||||
}
|
||||
+489
-367
File diff suppressed because it is too large.
Load diff
+26
-19
@@ -135,6 +135,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;USE_WRAPNVML;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>.;compat;compat\curl-for-windows\curl\include;compat\jansson;compat\getopt;compat\pthreads;compat\curl-for-windows\openssl\openssl\include;compat\curl-for-windows\zlib;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
@@ -157,7 +158,7 @@
|
||||
<MaxRegCount>80</MaxRegCount>
|
||||
<PtxAsOptionV>true</PtxAsOptionV>
|
||||
<Keep>true</Keep>
|
||||
<CodeGeneration>compute_35,sm_35;compute_50,sm_50;compute_52,sm_52</CodeGeneration>
|
||||
<CodeGeneration>compute_50,sm_50;compute_52,sm_52;compute_30,sm_30;compute_35,sm_35</CodeGeneration>
|
||||
<AdditionalOptions>--ptxas-options="-O2" %(AdditionalOptions)</AdditionalOptions>
|
||||
<Optimization>O2</Optimization>
|
||||
</CudaCompile>
|
||||
@@ -180,6 +181,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;USE_WRAPNVML;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>.;compat;compat\curl-for-windows\curl\include;compat\jansson;compat\getopt;compat\pthreads;compat\curl-for-windows\openssl\openssl\include;compat\curl-for-windows\zlib;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
@@ -247,6 +249,10 @@
|
||||
<ClCompile Include="neoscrypt\neoscrypt.cpp" />
|
||||
<ClCompile Include="neoscrypt\neoscrypt-cpu.c" />
|
||||
<ClInclude Include="neoscrypt\cuda_vectors.h" />
|
||||
<CudaCompile Include="Algo256\bmw.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_bmw.cu">
|
||||
<MaxRegCount>76</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="neoscrypt\cuda_neoscrypt.cu" />
|
||||
<ClCompile Include="scrypt-jane.cpp" />
|
||||
<ClCompile Include="scrypt.cpp" />
|
||||
@@ -269,7 +275,6 @@
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sha2.c" />
|
||||
<ClCompile Include="sph\sha256d.c" />
|
||||
<ClCompile Include="sph\sha2big.c" />
|
||||
<ClCompile Include="sph\shabal.c" />
|
||||
<ClCompile Include="sph\shavite.c" />
|
||||
@@ -331,16 +336,15 @@
|
||||
<ClInclude Include="lyra2\Sponge.h" />
|
||||
<ClInclude Include="quark\groestl_transf_quad.h" />
|
||||
<ClInclude Include="quark\groestl_functions_quad.h" />
|
||||
<ClInclude Include="spreadx11\bignum_fp.h" />
|
||||
<ClInclude Include="spreadx11\spreadx11.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CudaCompile Include="cuda.cpp" />
|
||||
<CudaCompile Include="cuda_groestlcoin.cu" />
|
||||
<CudaCompile Include="cuda_myriadgroestl.cu" />
|
||||
<CudaCompile Include="cuda_nist5.cu" />
|
||||
<CudaCompile Include="sha256\bitcoin.cu" />
|
||||
<CudaCompile Include="sha256\cuda_bitcoin.cu" />
|
||||
<CudaCompile Include="sha256\credits.cu" />
|
||||
<CudaCompile Include="sha256\cuda_credits.cu" />
|
||||
<CudaCompile Include="cuda_nist5.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="scrypt\blake.cu" />
|
||||
<CudaCompile Include="scrypt\keccak.cu" />
|
||||
<CudaCompile Include="scrypt\sha256.cu" />
|
||||
@@ -396,6 +400,8 @@
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\keccak256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_blake256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_bmw256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_cubehash256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_fugue256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_groestl256.cu" />
|
||||
<CudaCompile Include="Algo256\cuda_keccak256.cu">
|
||||
@@ -407,8 +413,6 @@
|
||||
<AdditionalOptions Condition="'$(Configuration)'=='Release'">--ptxas-options="-dlcm=cg" %(AdditionalOptions)</AdditionalOptions>
|
||||
<FastMath>true</FastMath>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\animecoin.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\cuda_bmw512.cu">
|
||||
<MaxRegCount>128</MaxRegCount>
|
||||
</CudaCompile>
|
||||
@@ -425,8 +429,6 @@
|
||||
<AdditionalOptions Condition="'$(Configuration)'=='Release'">-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions Condition="'$(Configuration)'=='Debug'">-Xptxas "-abi=yes" %(AdditionalOptions)</AdditionalOptions>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="pluck\pluck.cu" />
|
||||
<CudaCompile Include="pluck\cuda_pluck.cu" />
|
||||
<CudaCompile Include="quark\cuda_quark_groestl512.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\cuda_quark_keccak512.cu">
|
||||
@@ -446,12 +448,18 @@
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lyra2\lyra2RE.cu" />
|
||||
<CudaCompile Include="lyra2\cuda_lyra2.cu" />
|
||||
<CudaCompile Include="lyra2\lyra2REv2.cu" />
|
||||
<CudaCompile Include="lyra2\cuda_lyra2v2.cu" />
|
||||
<CudaCompile Include="skein.cu">
|
||||
<MaxRegCount>64</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="cuda_skeincoin.cu">
|
||||
<MaxRegCount>48</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="spreadx11\spreadx11.cu" />
|
||||
<CudaCompile Include="spreadx11\cuda_blake.cu" />
|
||||
<CudaCompile Include="spreadx11\cuda_spreadx11_sign.cu" />
|
||||
<CudaCompile Include="spreadx11\cuda_sha256.cu" />
|
||||
<CudaCompile Include="x11\cuda_x11_aes.cu">
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
</CudaCompile>
|
||||
@@ -468,8 +476,8 @@
|
||||
<CudaCompile Include="x11\cuda_x11_simd512.cu">
|
||||
<MaxRegCount>64</MaxRegCount>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\fresh.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\c11.cu" />
|
||||
<CudaCompile Include="x11\fresh.cu" />
|
||||
<CudaCompile Include="x11\s3.cu" />
|
||||
<CudaCompile Include="x11\simd_functions.cu">
|
||||
<ExcludedFromBuild>true</ExcludedFromBuild>
|
||||
@@ -485,12 +493,11 @@
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\x14.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\cuda_x14_shabal512.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\x15.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\cuda_x15_whirlpool.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\cuda_x14_shabal512.cu" />
|
||||
<CudaCompile Include="x15\cuda_x15_whirlpool.cu" />
|
||||
<CudaCompile Include="x15\x15.cu" />
|
||||
<CudaCompile Include="x15\cuda_whirlpoolx.cu" />
|
||||
<CudaCompile Include="x15\whirlpoolx.cu" />
|
||||
<CudaCompile Include="x17\x17.cu">
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\cuda_x17_haval512.cu">
|
||||
|
||||
+26
-26
@@ -79,9 +79,6 @@
|
||||
<Filter Include="Source Files\neoscrypt">
|
||||
<UniqueIdentifier>{2037fd0d-e7a2-4da8-956c-150aec726a99}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\CUDA\sha256">
|
||||
<UniqueIdentifier>{6def248f-bf21-43b0-8fd7-f2c749b73e9e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="compat\jansson\dump.c">
|
||||
@@ -183,9 +180,6 @@
|
||||
<ClCompile Include="sph\haval_helper.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sha256d.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sph\sha2big.c">
|
||||
<Filter>Source Files\sph</Filter>
|
||||
</ClCompile>
|
||||
@@ -439,12 +433,6 @@
|
||||
<CudaCompile Include="JHA\cuda_jha_compactionTest.cu">
|
||||
<Filter>Source Files\CUDA\JHA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="pluck\pluck.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="pluck\cuda_pluck.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\cuda_jh512.cu">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</CudaCompile>
|
||||
@@ -478,9 +466,6 @@
|
||||
<CudaCompile Include="heavy\heavy.cu">
|
||||
<Filter>Source Files\CUDA\heavy</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\animecoin.cu">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="quark\cuda_bmw512.cu">
|
||||
<Filter>Source Files\CUDA\quark</Filter>
|
||||
</CudaCompile>
|
||||
@@ -529,6 +514,9 @@
|
||||
<CudaCompile Include="x11\cuda_x11_simd512.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\c11.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x11\fresh.cu">
|
||||
<Filter>Source Files\CUDA\x11</Filter>
|
||||
</CudaCompile>
|
||||
@@ -562,6 +550,12 @@
|
||||
<CudaCompile Include="x15\cuda_x15_whirlpool.cu">
|
||||
<Filter>Source Files\CUDA\x15</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\cuda_whirlpoolx.cu">
|
||||
<Filter>Source Files\CUDA\x15</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x15\whirlpoolx.cu">
|
||||
<Filter>Source Files\CUDA\x15</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="x17\cuda_x17_haval512.cu">
|
||||
<Filter>Source Files\CUDA\x17</Filter>
|
||||
</CudaCompile>
|
||||
@@ -586,6 +580,12 @@
|
||||
<CudaCompile Include="Algo256\cuda_blake256.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\cuda_bmw256.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\cuda_cubehash256.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="Algo256\cuda_fugue256.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
@@ -604,6 +604,12 @@
|
||||
<CudaCompile Include="lyra2\lyra2RE.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lyra2\cuda_lyra2v2.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="lyra2\lyra2REv2.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="zr5.cu">
|
||||
<Filter>Source Files\CUDA</Filter>
|
||||
</CudaCompile>
|
||||
@@ -646,17 +652,11 @@
|
||||
<CudaCompile Include="neoscrypt\cuda_neoscrypt.cu">
|
||||
<Filter>Source Files\neoscrypt</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\bitcoin.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
<CudaCompile Include="Algo256\bmw.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\cuda_bitcoin.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\credits.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
</CudaCompile>
|
||||
<CudaCompile Include="sha256\cuda_credits.cu">
|
||||
<Filter>Source Files\CUDA\sha256</Filter>
|
||||
<CudaCompile Include="Algo256\cuda_bmw.cu">
|
||||
<Filter>Source Files\CUDA\Algo256</Filter>
|
||||
</CudaCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -674,4 +674,4 @@
|
||||
<Filter>Ressources</Filter>
|
||||
</Text>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -4,8 +4,9 @@
|
||||
#ifdef WIN32
|
||||
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
|
||||
extern int opt_priority;
|
||||
#define localtime_r(src, dst) localtime_s(dst, src)
|
||||
|
||||
static __inline void sleep(int secs)
|
||||
{
|
||||
@@ -16,6 +17,8 @@ enum {
|
||||
PRIO_PROCESS = 0,
|
||||
};
|
||||
|
||||
extern int opt_priority;
|
||||
|
||||
static __inline int setpriority(int which, int who, int prio)
|
||||
{
|
||||
switch (opt_priority) {
|
||||
|
||||
+28
-31
@@ -54,42 +54,39 @@ static const char rcsid[]="$Id: getopt_long.c,v 1.1 2009/10/16 19:50:28 rodney E
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include <err.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Windows needs warnx(). We change the definition though:
|
||||
* 1. (another) global is defined, opterrmsg, which holds the error message
|
||||
* 2. errors are always printed out on stderr w/o the program name
|
||||
* Note that opterrmsg always gets set no matter what opterr is set to. The
|
||||
* error message will not be printed if opterr is 0 as usual.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
char opterrmsg[128]; /* last error message is stored here */
|
||||
|
||||
static void warnx(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL)
|
||||
_vsnprintf(opterrmsg, 128, fmt, ap);
|
||||
else
|
||||
opterrmsg[0]='\0';
|
||||
va_end(ap);
|
||||
fprintf(stderr, opterrmsg);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Windows needs warnx(). We change the definition though:
|
||||
* 1. (another) global is defined, opterrmsg, which holds the error message
|
||||
* 2. errors are always printed out on stderr w/o the program name
|
||||
* Note that opterrmsg always gets set no matter what opterr is set to. The
|
||||
* error message will not be printed if opterr is 0 as usual.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
char opterrmsg[128]; /* last error message is stored here */
|
||||
|
||||
static void warnx(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
if (fmt != NULL)
|
||||
_vsnprintf(opterrmsg, 128, fmt, ap);
|
||||
else
|
||||
opterrmsg[0]='\0';
|
||||
va_end(ap);
|
||||
fprintf(stderr, opterrmsg);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
#endif /*_WIN32*/
|
||||
|
||||
#define REPLACE_GETOPT /* use this getopt as the system getopt(3) */
|
||||
|
||||
@@ -1,310 +1,347 @@
|
||||
#! /bin/sh
|
||||
# Wrapper for compilers which do not understand '-c -o'.
|
||||
|
||||
scriptversion=2012-01-04.17; # UTC
|
||||
|
||||
# Copyright (C) 1999, 2000, 2003, 2004, 2005, 2009, 2010, 2012 Free
|
||||
# Software Foundation, Inc.
|
||||
# Written by Tom Tromey <tromey@cygnus.com>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# This file is maintained in Automake, please report
|
||||
# bugs to <bug-automake@gnu.org> or send patches to
|
||||
# <automake-patches@gnu.org>.
|
||||
|
||||
nl='
|
||||
'
|
||||
|
||||
# We need space, tab and new line, in precisely that order. Quoting is
|
||||
# there to prevent tools from complaining about whitespace usage.
|
||||
IFS=" "" $nl"
|
||||
|
||||
file_conv=
|
||||
|
||||
# func_file_conv build_file lazy
|
||||
# Convert a $build file to $host form and store it in $file
|
||||
# Currently only supports Windows hosts. If the determined conversion
|
||||
# type is listed in (the comma separated) LAZY, no conversion will
|
||||
# take place.
|
||||
func_file_conv ()
|
||||
{
|
||||
file=$1
|
||||
case $file in
|
||||
/ | /[!/]*) # absolute file, and not a UNC file
|
||||
if test -z "$file_conv"; then
|
||||
# lazily determine how to convert abs files
|
||||
case `uname -s` in
|
||||
MINGW*)
|
||||
file_conv=mingw
|
||||
;;
|
||||
CYGWIN*)
|
||||
file_conv=cygwin
|
||||
;;
|
||||
*)
|
||||
file_conv=wine
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
case $file_conv/,$2, in
|
||||
*,$file_conv,*)
|
||||
;;
|
||||
mingw/*)
|
||||
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
|
||||
;;
|
||||
cygwin/*)
|
||||
file=`cygpath -m "$file" || echo "$file"`
|
||||
;;
|
||||
wine/*)
|
||||
file=`winepath -w "$file" || echo "$file"`
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# func_cl_wrapper cl arg...
|
||||
# Adjust compile command to suit cl
|
||||
func_cl_wrapper ()
|
||||
{
|
||||
# Assume a capable shell
|
||||
lib_path=
|
||||
shared=:
|
||||
linker_opts=
|
||||
for arg
|
||||
do
|
||||
if test -n "$eat"; then
|
||||
eat=
|
||||
else
|
||||
case $1 in
|
||||
-o)
|
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||
eat=1
|
||||
case $2 in
|
||||
*.o | *.[oO][bB][jJ])
|
||||
func_file_conv "$2"
|
||||
set x "$@" -Fo"$file"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
func_file_conv "$2"
|
||||
set x "$@" -Fe"$file"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
-I*)
|
||||
func_file_conv "${1#-I}" mingw
|
||||
set x "$@" -I"$file"
|
||||
shift
|
||||
;;
|
||||
-l*)
|
||||
lib=${1#-l}
|
||||
found=no
|
||||
save_IFS=$IFS
|
||||
IFS=';'
|
||||
for dir in $lib_path $LIB
|
||||
do
|
||||
IFS=$save_IFS
|
||||
if $shared && test -f "$dir/$lib.dll.lib"; then
|
||||
found=yes
|
||||
set x "$@" "$dir/$lib.dll.lib"
|
||||
break
|
||||
fi
|
||||
if test -f "$dir/$lib.lib"; then
|
||||
found=yes
|
||||
set x "$@" "$dir/$lib.lib"
|
||||
break
|
||||
fi
|
||||
done
|
||||
IFS=$save_IFS
|
||||
|
||||
test "$found" != yes && set x "$@" "$lib.lib"
|
||||
shift
|
||||
;;
|
||||
-L*)
|
||||
func_file_conv "${1#-L}"
|
||||
if test -z "$lib_path"; then
|
||||
lib_path=$file
|
||||
else
|
||||
lib_path="$lib_path;$file"
|
||||
fi
|
||||
linker_opts="$linker_opts -LIBPATH:$file"
|
||||
;;
|
||||
-static)
|
||||
shared=false
|
||||
;;
|
||||
-Wl,*)
|
||||
arg=${1#-Wl,}
|
||||
save_ifs="$IFS"; IFS=','
|
||||
for flag in $arg; do
|
||||
IFS="$save_ifs"
|
||||
linker_opts="$linker_opts $flag"
|
||||
done
|
||||
IFS="$save_ifs"
|
||||
;;
|
||||
-Xlinker)
|
||||
eat=1
|
||||
linker_opts="$linker_opts $2"
|
||||
;;
|
||||
-*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
|
||||
func_file_conv "$1"
|
||||
set x "$@" -Tp"$file"
|
||||
shift
|
||||
;;
|
||||
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
|
||||
func_file_conv "$1" mingw
|
||||
set x "$@" "$file"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
shift
|
||||
done
|
||||
if test -n "$linker_opts"; then
|
||||
linker_opts="-link$linker_opts"
|
||||
fi
|
||||
exec "$@" $linker_opts
|
||||
exit 1
|
||||
}
|
||||
|
||||
eat=
|
||||
|
||||
case $1 in
|
||||
'')
|
||||
echo "$0: No command. Try '$0 --help' for more information." 1>&2
|
||||
exit 1;
|
||||
;;
|
||||
-h | --h*)
|
||||
cat <<\EOF
|
||||
Usage: compile [--help] [--version] PROGRAM [ARGS]
|
||||
|
||||
Wrapper for compilers which do not understand '-c -o'.
|
||||
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
|
||||
arguments, and rename the output as expected.
|
||||
|
||||
If you are trying to build a whole package this is not the
|
||||
right script to run: please start by reading the file 'INSTALL'.
|
||||
|
||||
Report bugs to <bug-automake@gnu.org>.
|
||||
EOF
|
||||
exit $?
|
||||
;;
|
||||
-v | --v*)
|
||||
echo "compile $scriptversion"
|
||||
exit $?
|
||||
;;
|
||||
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
|
||||
func_cl_wrapper "$@" # Doesn't return...
|
||||
;;
|
||||
esac
|
||||
|
||||
ofile=
|
||||
cfile=
|
||||
|
||||
for arg
|
||||
do
|
||||
if test -n "$eat"; then
|
||||
eat=
|
||||
else
|
||||
case $1 in
|
||||
-o)
|
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||
# So we strip '-o arg' only if arg is an object.
|
||||
eat=1
|
||||
case $2 in
|
||||
*.o | *.obj)
|
||||
ofile=$2
|
||||
;;
|
||||
*)
|
||||
set x "$@" -o "$2"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*.c)
|
||||
cfile=$1
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
if test -z "$ofile" || test -z "$cfile"; then
|
||||
# If no '-o' option was seen then we might have been invoked from a
|
||||
# pattern rule where we don't need one. That is ok -- this is a
|
||||
# normal compilation that the losing compiler can handle. If no
|
||||
# '.c' file was seen then we are probably linking. That is also
|
||||
# ok.
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
# Name of file we expect compiler to create.
|
||||
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
|
||||
|
||||
# Create the lock directory.
|
||||
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
|
||||
# that we are using for the .o file. Also, base the name on the expected
|
||||
# object file name, since that is what matters with a parallel build.
|
||||
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
|
||||
while true; do
|
||||
if mkdir "$lockdir" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
# FIXME: race condition here if user kills between mkdir and trap.
|
||||
trap "rmdir '$lockdir'; exit 1" 1 2 15
|
||||
|
||||
# Run the compile.
|
||||
"$@"
|
||||
ret=$?
|
||||
|
||||
if test -f "$cofile"; then
|
||||
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
|
||||
elif test -f "${cofile}bj"; then
|
||||
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
|
||||
fi
|
||||
|
||||
rmdir "$lockdir"
|
||||
exit $ret
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
#! /bin/sh
|
||||
# Wrapper for compilers which do not understand '-c -o'.
|
||||
|
||||
scriptversion=2012-10-14.11; # UTC
|
||||
|
||||
# Copyright (C) 1999-2013 Free Software Foundation, Inc.
|
||||
# Written by Tom Tromey <tromey@cygnus.com>.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
# This file is maintained in Automake, please report
|
||||
# bugs to <bug-automake@gnu.org> or send patches to
|
||||
# <automake-patches@gnu.org>.
|
||||
|
||||
nl='
|
||||
'
|
||||
|
||||
# We need space, tab and new line, in precisely that order. Quoting is
|
||||
# there to prevent tools from complaining about whitespace usage.
|
||||
IFS=" "" $nl"
|
||||
|
||||
file_conv=
|
||||
|
||||
# func_file_conv build_file lazy
|
||||
# Convert a $build file to $host form and store it in $file
|
||||
# Currently only supports Windows hosts. If the determined conversion
|
||||
# type is listed in (the comma separated) LAZY, no conversion will
|
||||
# take place.
|
||||
func_file_conv ()
|
||||
{
|
||||
file=$1
|
||||
case $file in
|
||||
/ | /[!/]*) # absolute file, and not a UNC file
|
||||
if test -z "$file_conv"; then
|
||||
# lazily determine how to convert abs files
|
||||
case `uname -s` in
|
||||
MINGW*)
|
||||
file_conv=mingw
|
||||
;;
|
||||
CYGWIN*)
|
||||
file_conv=cygwin
|
||||
;;
|
||||
*)
|
||||
file_conv=wine
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
case $file_conv/,$2, in
|
||||
*,$file_conv,*)
|
||||
;;
|
||||
mingw/*)
|
||||
file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
|
||||
;;
|
||||
cygwin/*)
|
||||
file=`cygpath -m "$file" || echo "$file"`
|
||||
;;
|
||||
wine/*)
|
||||
file=`winepath -w "$file" || echo "$file"`
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# func_cl_dashL linkdir
|
||||
# Make cl look for libraries in LINKDIR
|
||||
func_cl_dashL ()
|
||||
{
|
||||
func_file_conv "$1"
|
||||
if test -z "$lib_path"; then
|
||||
lib_path=$file
|
||||
else
|
||||
lib_path="$lib_path;$file"
|
||||
fi
|
||||
linker_opts="$linker_opts -LIBPATH:$file"
|
||||
}
|
||||
|
||||
# func_cl_dashl library
|
||||
# Do a library search-path lookup for cl
|
||||
func_cl_dashl ()
|
||||
{
|
||||
lib=$1
|
||||
found=no
|
||||
save_IFS=$IFS
|
||||
IFS=';'
|
||||
for dir in $lib_path $LIB
|
||||
do
|
||||
IFS=$save_IFS
|
||||
if $shared && test -f "$dir/$lib.dll.lib"; then
|
||||
found=yes
|
||||
lib=$dir/$lib.dll.lib
|
||||
break
|
||||
fi
|
||||
if test -f "$dir/$lib.lib"; then
|
||||
found=yes
|
||||
lib=$dir/$lib.lib
|
||||
break
|
||||
fi
|
||||
if test -f "$dir/lib$lib.a"; then
|
||||
found=yes
|
||||
lib=$dir/lib$lib.a
|
||||
break
|
||||
fi
|
||||
done
|
||||
IFS=$save_IFS
|
||||
|
||||
if test "$found" != yes; then
|
||||
lib=$lib.lib
|
||||
fi
|
||||
}
|
||||
|
||||
# func_cl_wrapper cl arg...
|
||||
# Adjust compile command to suit cl
|
||||
func_cl_wrapper ()
|
||||
{
|
||||
# Assume a capable shell
|
||||
lib_path=
|
||||
shared=:
|
||||
linker_opts=
|
||||
for arg
|
||||
do
|
||||
if test -n "$eat"; then
|
||||
eat=
|
||||
else
|
||||
case $1 in
|
||||
-o)
|
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||
eat=1
|
||||
case $2 in
|
||||
*.o | *.[oO][bB][jJ])
|
||||
func_file_conv "$2"
|
||||
set x "$@" -Fo"$file"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
func_file_conv "$2"
|
||||
set x "$@" -Fe"$file"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
-I)
|
||||
eat=1
|
||||
func_file_conv "$2" mingw
|
||||
set x "$@" -I"$file"
|
||||
shift
|
||||
;;
|
||||
-I*)
|
||||
func_file_conv "${1#-I}" mingw
|
||||
set x "$@" -I"$file"
|
||||
shift
|
||||
;;
|
||||
-l)
|
||||
eat=1
|
||||
func_cl_dashl "$2"
|
||||
set x "$@" "$lib"
|
||||
shift
|
||||
;;
|
||||
-l*)
|
||||
func_cl_dashl "${1#-l}"
|
||||
set x "$@" "$lib"
|
||||
shift
|
||||
;;
|
||||
-L)
|
||||
eat=1
|
||||
func_cl_dashL "$2"
|
||||
;;
|
||||
-L*)
|
||||
func_cl_dashL "${1#-L}"
|
||||
;;
|
||||
-static)
|
||||
shared=false
|
||||
;;
|
||||
-Wl,*)
|
||||
arg=${1#-Wl,}
|
||||
save_ifs="$IFS"; IFS=','
|
||||
for flag in $arg; do
|
||||
IFS="$save_ifs"
|
||||
linker_opts="$linker_opts $flag"
|
||||
done
|
||||
IFS="$save_ifs"
|
||||
;;
|
||||
-Xlinker)
|
||||
eat=1
|
||||
linker_opts="$linker_opts $2"
|
||||
;;
|
||||
-*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)
|
||||
func_file_conv "$1"
|
||||
set x "$@" -Tp"$file"
|
||||
shift
|
||||
;;
|
||||
*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])
|
||||
func_file_conv "$1" mingw
|
||||
set x "$@" "$file"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
shift
|
||||
done
|
||||
if test -n "$linker_opts"; then
|
||||
linker_opts="-link$linker_opts"
|
||||
fi
|
||||
exec "$@" $linker_opts
|
||||
exit 1
|
||||
}
|
||||
|
||||
eat=
|
||||
|
||||
case $1 in
|
||||
'')
|
||||
echo "$0: No command. Try '$0 --help' for more information." 1>&2
|
||||
exit 1;
|
||||
;;
|
||||
-h | --h*)
|
||||
cat <<\EOF
|
||||
Usage: compile [--help] [--version] PROGRAM [ARGS]
|
||||
|
||||
Wrapper for compilers which do not understand '-c -o'.
|
||||
Remove '-o dest.o' from ARGS, run PROGRAM with the remaining
|
||||
arguments, and rename the output as expected.
|
||||
|
||||
If you are trying to build a whole package this is not the
|
||||
right script to run: please start by reading the file 'INSTALL'.
|
||||
|
||||
Report bugs to <bug-automake@gnu.org>.
|
||||
EOF
|
||||
exit $?
|
||||
;;
|
||||
-v | --v*)
|
||||
echo "compile $scriptversion"
|
||||
exit $?
|
||||
;;
|
||||
cl | *[/\\]cl | cl.exe | *[/\\]cl.exe )
|
||||
func_cl_wrapper "$@" # Doesn't return...
|
||||
;;
|
||||
esac
|
||||
|
||||
ofile=
|
||||
cfile=
|
||||
|
||||
for arg
|
||||
do
|
||||
if test -n "$eat"; then
|
||||
eat=
|
||||
else
|
||||
case $1 in
|
||||
-o)
|
||||
# configure might choose to run compile as 'compile cc -o foo foo.c'.
|
||||
# So we strip '-o arg' only if arg is an object.
|
||||
eat=1
|
||||
case $2 in
|
||||
*.o | *.obj)
|
||||
ofile=$2
|
||||
;;
|
||||
*)
|
||||
set x "$@" -o "$2"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*.c)
|
||||
cfile=$1
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set x "$@" "$1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
if test -z "$ofile" || test -z "$cfile"; then
|
||||
# If no '-o' option was seen then we might have been invoked from a
|
||||
# pattern rule where we don't need one. That is ok -- this is a
|
||||
# normal compilation that the losing compiler can handle. If no
|
||||
# '.c' file was seen then we are probably linking. That is also
|
||||
# ok.
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
# Name of file we expect compiler to create.
|
||||
cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'`
|
||||
|
||||
# Create the lock directory.
|
||||
# Note: use '[/\\:.-]' here to ensure that we don't use the same name
|
||||
# that we are using for the .o file. Also, base the name on the expected
|
||||
# object file name, since that is what matters with a parallel build.
|
||||
lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d
|
||||
while true; do
|
||||
if mkdir "$lockdir" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
# FIXME: race condition here if user kills between mkdir and trap.
|
||||
trap "rmdir '$lockdir'; exit 1" 1 2 15
|
||||
|
||||
# Run the compile.
|
||||
"$@"
|
||||
ret=$?
|
||||
|
||||
if test -f "$cofile"; then
|
||||
test "$cofile" = "$ofile" || mv "$cofile" "$ofile"
|
||||
elif test -f "${cofile}bj"; then
|
||||
test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile"
|
||||
fi
|
||||
|
||||
rmdir "$lockdir"
|
||||
exit $ret
|
||||
|
||||
# Local Variables:
|
||||
# mode: shell-script
|
||||
# sh-indentation: 2
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
+332
-300
@@ -1,14 +1,12 @@
|
||||
#! /bin/sh
|
||||
# Attempt to guess a canonical system name.
|
||||
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
|
||||
# 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
|
||||
# Free Software Foundation, Inc.
|
||||
# Copyright 1992-2013 Free Software Foundation, Inc.
|
||||
|
||||
timestamp='2008-01-23'
|
||||
timestamp='2013-06-10'
|
||||
|
||||
# This file is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
@@ -17,26 +15,22 @@ timestamp='2008-01-23'
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
|
||||
# 02110-1301, USA.
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# As a special exception to the GNU General Public License, if you
|
||||
# distribute this file as part of a program that contains a
|
||||
# configuration script generated by Autoconf, you may include it under
|
||||
# the same distribution terms that you use for the rest of that program.
|
||||
|
||||
|
||||
# Originally written by Per Bothner <per@bothner.com>.
|
||||
# Please send patches to <config-patches@gnu.org>. Submit a context
|
||||
# diff and a properly formatted ChangeLog entry.
|
||||
# the same distribution terms that you use for the rest of that
|
||||
# program. This Exception is an additional permission under section 7
|
||||
# of the GNU General Public License, version 3 ("GPLv3").
|
||||
#
|
||||
# This script attempts to guess a canonical system name similar to
|
||||
# config.sub. If it succeeds, it prints the system name on stdout, and
|
||||
# exits with 0. Otherwise, it exits with 1.
|
||||
# Originally written by Per Bothner.
|
||||
#
|
||||
# The plan is that this can be called by configure scripts if you
|
||||
# don't specify an explicit build system type.
|
||||
# You can get the latest version of this script from:
|
||||
# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
|
||||
#
|
||||
# Please send patches with a ChangeLog entry to config-patches@gnu.org.
|
||||
|
||||
|
||||
me=`echo "$0" | sed -e 's,.*/,,'`
|
||||
|
||||
@@ -56,8 +50,7 @@ version="\
|
||||
GNU config.guess ($timestamp)
|
||||
|
||||
Originally written by Per Bothner.
|
||||
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
|
||||
2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
Copyright 1992-2013 Free Software Foundation, Inc.
|
||||
|
||||
This is free software; see the source for copying conditions. There is NO
|
||||
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
|
||||
@@ -139,12 +132,33 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
|
||||
UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
|
||||
UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
|
||||
|
||||
case "${UNAME_SYSTEM}" in
|
||||
Linux|GNU|GNU/*)
|
||||
# If the system lacks a compiler, then just pick glibc.
|
||||
# We could probably try harder.
|
||||
LIBC=gnu
|
||||
|
||||
eval $set_cc_for_build
|
||||
cat <<-EOF > $dummy.c
|
||||
#include <features.h>
|
||||
#if defined(__UCLIBC__)
|
||||
LIBC=uclibc
|
||||
#elif defined(__dietlibc__)
|
||||
LIBC=dietlibc
|
||||
#else
|
||||
LIBC=gnu
|
||||
#endif
|
||||
EOF
|
||||
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
|
||||
;;
|
||||
esac
|
||||
|
||||
# Note: order is significant - the case branches are not exclusive.
|
||||
|
||||
case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
*:NetBSD:*:*)
|
||||
# NetBSD (nbsd) targets should (where applicable) match one or
|
||||
# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
|
||||
# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
|
||||
# *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
|
||||
# switched to ELF, *-*-netbsd* would select the old
|
||||
# object file format. This provides both forward
|
||||
@@ -170,7 +184,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
arm*|i386|m68k|ns32k|sh3*|sparc|vax)
|
||||
eval $set_cc_for_build
|
||||
if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
|
||||
| grep __ELF__ >/dev/null
|
||||
| grep -q __ELF__
|
||||
then
|
||||
# Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
|
||||
# Return netbsd for either. FIX?
|
||||
@@ -180,7 +194,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
os=netbsd
|
||||
os=netbsd
|
||||
;;
|
||||
esac
|
||||
# The OS release
|
||||
@@ -201,6 +215,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
|
||||
echo "${machine}-${os}${release}"
|
||||
exit ;;
|
||||
*:Bitrig:*:*)
|
||||
UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
|
||||
echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}
|
||||
exit ;;
|
||||
*:OpenBSD:*:*)
|
||||
UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
|
||||
echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
|
||||
@@ -223,7 +241,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
|
||||
;;
|
||||
*5.*)
|
||||
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
|
||||
UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
|
||||
;;
|
||||
esac
|
||||
# According to Compaq, /usr/sbin/psrinfo has been available on
|
||||
@@ -269,7 +287,10 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
# A Xn.n version is an unreleased experimental baselevel.
|
||||
# 1.2 uses "1.2" for uname -r.
|
||||
echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
|
||||
exit ;;
|
||||
# Reset EXIT trap before exiting to avoid spurious non-zero exit code.
|
||||
exitcode=$?
|
||||
trap '' 0
|
||||
exit $exitcode ;;
|
||||
Alpha\ *:Windows_NT*:*)
|
||||
# How do we know it's Interix rather than the generic POSIX subsystem?
|
||||
# Should we change UNAME_MACHINE based on the output of uname instead
|
||||
@@ -295,12 +316,12 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
echo s390-ibm-zvmoe
|
||||
exit ;;
|
||||
*:OS400:*:*)
|
||||
echo powerpc-ibm-os400
|
||||
echo powerpc-ibm-os400
|
||||
exit ;;
|
||||
arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
|
||||
echo arm-acorn-riscix${UNAME_RELEASE}
|
||||
exit ;;
|
||||
arm:riscos:*:*|arm:RISCOS:*:*)
|
||||
arm*:riscos:*:*|arm*:RISCOS:*:*)
|
||||
echo arm-unknown-riscos
|
||||
exit ;;
|
||||
SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
|
||||
@@ -324,14 +345,33 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
case `/usr/bin/uname -p` in
|
||||
sparc) echo sparc-icl-nx7; exit ;;
|
||||
esac ;;
|
||||
s390x:SunOS:*:*)
|
||||
echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit ;;
|
||||
sun4H:SunOS:5.*:*)
|
||||
echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit ;;
|
||||
sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
|
||||
echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit ;;
|
||||
i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
|
||||
echo i386-pc-auroraux${UNAME_RELEASE}
|
||||
exit ;;
|
||||
i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
|
||||
echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
eval $set_cc_for_build
|
||||
SUN_ARCH="i386"
|
||||
# If there is a compiler, see if it is configured for 64-bit objects.
|
||||
# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
|
||||
# This test works for both compilers.
|
||||
if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
|
||||
if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
|
||||
(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
|
||||
grep IS_64BIT_ARCH >/dev/null
|
||||
then
|
||||
SUN_ARCH="x86_64"
|
||||
fi
|
||||
fi
|
||||
echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
|
||||
exit ;;
|
||||
sun4*:SunOS:6*:*)
|
||||
# According to config.sub, this is the proper way to canonicalize
|
||||
@@ -375,23 +415,23 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
|
||||
# MiNT. But MiNT is downward compatible to TOS, so this should
|
||||
# be no problem.
|
||||
atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
|
||||
echo m68k-atari-mint${UNAME_RELEASE}
|
||||
echo m68k-atari-mint${UNAME_RELEASE}
|
||||
exit ;;
|
||||
atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
|
||||
echo m68k-atari-mint${UNAME_RELEASE}
|
||||
exit ;;
|
||||
exit ;;
|
||||
*falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
|
||||
echo m68k-atari-mint${UNAME_RELEASE}
|
||||
echo m68k-atari-mint${UNAME_RELEASE}
|
||||
exit ;;
|
||||
milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
|
||||
echo m68k-milan-mint${UNAME_RELEASE}
|
||||
exit ;;
|
||||
echo m68k-milan-mint${UNAME_RELEASE}
|
||||
exit ;;
|
||||
hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
|
||||
echo m68k-hades-mint${UNAME_RELEASE}
|
||||
exit ;;
|
||||
echo m68k-hades-mint${UNAME_RELEASE}
|
||||
exit ;;
|
||||
*:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
|
||||
echo m68k-unknown-mint${UNAME_RELEASE}
|
||||
exit ;;
|
||||
echo m68k-unknown-mint${UNAME_RELEASE}
|
||||
exit ;;
|
||||
m68k:machten:*:*)
|
||||
echo m68k-apple-machten${UNAME_RELEASE}
|
||||
exit ;;
|
||||
@@ -461,8 +501,8 @@ EOF
|
||||
echo m88k-motorola-sysv3
|
||||
exit ;;
|
||||
AViiON:dgux:*:*)
|
||||
# DG/UX returns AViiON for all architectures
|
||||
UNAME_PROCESSOR=`/usr/bin/uname -p`
|
||||
# DG/UX returns AViiON for all architectures
|
||||
UNAME_PROCESSOR=`/usr/bin/uname -p`
|
||||
if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
|
||||
then
|
||||
if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
|
||||
@@ -475,7 +515,7 @@ EOF
|
||||
else
|
||||
echo i586-dg-dgux${UNAME_RELEASE}
|
||||
fi
|
||||
exit ;;
|
||||
exit ;;
|
||||
M88*:DolphinOS:*:*) # DolphinOS (SVR3)
|
||||
echo m88k-dolphin-sysv3
|
||||
exit ;;
|
||||
@@ -532,7 +572,7 @@ EOF
|
||||
echo rs6000-ibm-aix3.2
|
||||
fi
|
||||
exit ;;
|
||||
*:AIX:*:[456])
|
||||
*:AIX:*:[4567])
|
||||
IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
|
||||
if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
|
||||
IBM_ARCH=rs6000
|
||||
@@ -575,52 +615,52 @@ EOF
|
||||
9000/[678][0-9][0-9])
|
||||
if [ -x /usr/bin/getconf ]; then
|
||||
sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
|
||||
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
|
||||
case "${sc_cpu_version}" in
|
||||
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
|
||||
528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
|
||||
532) # CPU_PA_RISC2_0
|
||||
case "${sc_kernel_bits}" in
|
||||
32) HP_ARCH="hppa2.0n" ;;
|
||||
64) HP_ARCH="hppa2.0w" ;;
|
||||
sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
|
||||
case "${sc_cpu_version}" in
|
||||
523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
|
||||
528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
|
||||
532) # CPU_PA_RISC2_0
|
||||
case "${sc_kernel_bits}" in
|
||||
32) HP_ARCH="hppa2.0n" ;;
|
||||
64) HP_ARCH="hppa2.0w" ;;
|
||||
'') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
|
||||
esac ;;
|
||||
esac
|
||||
esac ;;
|
||||
esac
|
||||
fi
|
||||
if [ "${HP_ARCH}" = "" ]; then
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
|
||||
#define _HPUX_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#define _HPUX_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
#if defined(_SC_KERNEL_BITS)
|
||||
long bits = sysconf(_SC_KERNEL_BITS);
|
||||
#endif
|
||||
long cpu = sysconf (_SC_CPU_VERSION);
|
||||
int main ()
|
||||
{
|
||||
#if defined(_SC_KERNEL_BITS)
|
||||
long bits = sysconf(_SC_KERNEL_BITS);
|
||||
#endif
|
||||
long cpu = sysconf (_SC_CPU_VERSION);
|
||||
|
||||
switch (cpu)
|
||||
{
|
||||
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
|
||||
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
|
||||
case CPU_PA_RISC2_0:
|
||||
#if defined(_SC_KERNEL_BITS)
|
||||
switch (bits)
|
||||
{
|
||||
case 64: puts ("hppa2.0w"); break;
|
||||
case 32: puts ("hppa2.0n"); break;
|
||||
default: puts ("hppa2.0"); break;
|
||||
} break;
|
||||
#else /* !defined(_SC_KERNEL_BITS) */
|
||||
puts ("hppa2.0"); break;
|
||||
#endif
|
||||
default: puts ("hppa1.0"); break;
|
||||
}
|
||||
exit (0);
|
||||
}
|
||||
switch (cpu)
|
||||
{
|
||||
case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
|
||||
case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
|
||||
case CPU_PA_RISC2_0:
|
||||
#if defined(_SC_KERNEL_BITS)
|
||||
switch (bits)
|
||||
{
|
||||
case 64: puts ("hppa2.0w"); break;
|
||||
case 32: puts ("hppa2.0n"); break;
|
||||
default: puts ("hppa2.0"); break;
|
||||
} break;
|
||||
#else /* !defined(_SC_KERNEL_BITS) */
|
||||
puts ("hppa2.0"); break;
|
||||
#endif
|
||||
default: puts ("hppa1.0"); break;
|
||||
}
|
||||
exit (0);
|
||||
}
|
||||
EOF
|
||||
(CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
|
||||
test -z "$HP_ARCH" && HP_ARCH=hppa
|
||||
@@ -640,7 +680,7 @@ EOF
|
||||
# => hppa64-hp-hpux11.23
|
||||
|
||||
if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
|
||||
grep __LP64__ >/dev/null
|
||||
grep -q __LP64__
|
||||
then
|
||||
HP_ARCH="hppa2.0w"
|
||||
else
|
||||
@@ -711,22 +751,22 @@ EOF
|
||||
exit ;;
|
||||
C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
|
||||
echo c1-convex-bsd
|
||||
exit ;;
|
||||
exit ;;
|
||||
C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
|
||||
if getsysinfo -f scalar_acc
|
||||
then echo c32-convex-bsd
|
||||
else echo c2-convex-bsd
|
||||
fi
|
||||
exit ;;
|
||||
exit ;;
|
||||
C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
|
||||
echo c34-convex-bsd
|
||||
exit ;;
|
||||
exit ;;
|
||||
C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
|
||||
echo c38-convex-bsd
|
||||
exit ;;
|
||||
exit ;;
|
||||
C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
|
||||
echo c4-convex-bsd
|
||||
exit ;;
|
||||
exit ;;
|
||||
CRAY*Y-MP:*:*:*)
|
||||
echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
|
||||
exit ;;
|
||||
@@ -750,14 +790,14 @@ EOF
|
||||
exit ;;
|
||||
F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
|
||||
FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
|
||||
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
|
||||
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
|
||||
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
|
||||
exit ;;
|
||||
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
|
||||
FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
|
||||
echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
|
||||
exit ;;
|
||||
5000:UNIX_System_V:4.*:*)
|
||||
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
|
||||
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
|
||||
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
|
||||
FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
|
||||
FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
|
||||
echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
|
||||
exit ;;
|
||||
i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
|
||||
@@ -769,34 +809,39 @@ EOF
|
||||
echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
|
||||
exit ;;
|
||||
*:FreeBSD:*:*)
|
||||
case ${UNAME_MACHINE} in
|
||||
pc98)
|
||||
echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
|
||||
UNAME_PROCESSOR=`/usr/bin/uname -p`
|
||||
case ${UNAME_PROCESSOR} in
|
||||
amd64)
|
||||
echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
|
||||
*)
|
||||
echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
|
||||
echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
|
||||
esac
|
||||
exit ;;
|
||||
i*:CYGWIN*:*)
|
||||
echo ${UNAME_MACHINE}-pc-cygwin
|
||||
exit ;;
|
||||
*:MINGW64*:*)
|
||||
echo ${UNAME_MACHINE}-pc-mingw64
|
||||
exit ;;
|
||||
*:MINGW*:*)
|
||||
echo ${UNAME_MACHINE}-pc-mingw32
|
||||
exit ;;
|
||||
i*:MSYS*:*)
|
||||
echo ${UNAME_MACHINE}-pc-msys
|
||||
exit ;;
|
||||
i*:windows32*:*)
|
||||
# uname -m includes "-pc" on this system.
|
||||
echo ${UNAME_MACHINE}-mingw32
|
||||
# uname -m includes "-pc" on this system.
|
||||
echo ${UNAME_MACHINE}-mingw32
|
||||
exit ;;
|
||||
i*:PW*:*)
|
||||
echo ${UNAME_MACHINE}-pc-pw32
|
||||
exit ;;
|
||||
*:Interix*:[3456]*)
|
||||
case ${UNAME_MACHINE} in
|
||||
*:Interix*:*)
|
||||
case ${UNAME_MACHINE} in
|
||||
x86)
|
||||
echo i586-pc-interix${UNAME_RELEASE}
|
||||
exit ;;
|
||||
EM64T | authenticamd)
|
||||
authenticamd | genuineintel | EM64T)
|
||||
echo x86_64-unknown-interix${UNAME_RELEASE}
|
||||
exit ;;
|
||||
IA64)
|
||||
@@ -806,6 +851,9 @@ EOF
|
||||
[345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
|
||||
echo i${UNAME_MACHINE}-pc-mks
|
||||
exit ;;
|
||||
8664:Windows_NT:*)
|
||||
echo x86_64-pc-mks
|
||||
exit ;;
|
||||
i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
|
||||
# How do we know it's Interix rather than the generic POSIX subsystem?
|
||||
# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
|
||||
@@ -826,100 +874,21 @@ EOF
|
||||
exit ;;
|
||||
*:GNU:*:*)
|
||||
# the GNU system
|
||||
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
|
||||
echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
|
||||
exit ;;
|
||||
*:GNU/*:*:*)
|
||||
# other systems with GNU libc and userland
|
||||
echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
|
||||
echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
|
||||
exit ;;
|
||||
i*86:Minix:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-minix
|
||||
exit ;;
|
||||
arm*:Linux:*:*)
|
||||
eval $set_cc_for_build
|
||||
if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
|
||||
| grep -q __ARM_EABI__
|
||||
then
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
else
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnueabi
|
||||
fi
|
||||
aarch64:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
avr32*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit ;;
|
||||
cris:Linux:*:*)
|
||||
echo cris-axis-linux-gnu
|
||||
exit ;;
|
||||
crisv32:Linux:*:*)
|
||||
echo crisv32-axis-linux-gnu
|
||||
exit ;;
|
||||
frv:Linux:*:*)
|
||||
echo frv-unknown-linux-gnu
|
||||
exit ;;
|
||||
ia64:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit ;;
|
||||
m32r*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit ;;
|
||||
m68*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
exit ;;
|
||||
mips:Linux:*:*)
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
#undef CPU
|
||||
#undef mips
|
||||
#undef mipsel
|
||||
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
|
||||
CPU=mipsel
|
||||
#else
|
||||
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
|
||||
CPU=mips
|
||||
#else
|
||||
CPU=
|
||||
#endif
|
||||
#endif
|
||||
EOF
|
||||
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
|
||||
/^CPU/{
|
||||
s: ::g
|
||||
p
|
||||
}'`"
|
||||
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
|
||||
;;
|
||||
mips64:Linux:*:*)
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
#undef CPU
|
||||
#undef mips64
|
||||
#undef mips64el
|
||||
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
|
||||
CPU=mips64el
|
||||
#else
|
||||
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
|
||||
CPU=mips64
|
||||
#else
|
||||
CPU=
|
||||
#endif
|
||||
#endif
|
||||
EOF
|
||||
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
|
||||
/^CPU/{
|
||||
s: ::g
|
||||
p
|
||||
}'`"
|
||||
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
|
||||
;;
|
||||
or32:Linux:*:*)
|
||||
echo or32-unknown-linux-gnu
|
||||
exit ;;
|
||||
ppc:Linux:*:*)
|
||||
echo powerpc-unknown-linux-gnu
|
||||
exit ;;
|
||||
ppc64:Linux:*:*)
|
||||
echo powerpc64-unknown-linux-gnu
|
||||
aarch64_be:Linux:*:*)
|
||||
UNAME_MACHINE=aarch64_be
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
alpha:Linux:*:*)
|
||||
case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
|
||||
@@ -930,106 +899,132 @@ EOF
|
||||
EV6) UNAME_MACHINE=alphaev6 ;;
|
||||
EV67) UNAME_MACHINE=alphaev67 ;;
|
||||
EV68*) UNAME_MACHINE=alphaev68 ;;
|
||||
esac
|
||||
objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null
|
||||
if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
|
||||
esac
|
||||
objdump --private-headers /bin/sh | grep -q ld.so.1
|
||||
if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
arc:Linux:*:* | arceb:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
arm*:Linux:*:*)
|
||||
eval $set_cc_for_build
|
||||
if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
|
||||
| grep -q __ARM_EABI__
|
||||
then
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
else
|
||||
if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
|
||||
| grep -q __ARM_PCS_VFP
|
||||
then
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
|
||||
else
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
|
||||
fi
|
||||
fi
|
||||
exit ;;
|
||||
avr32*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
cris:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-axis-linux-${LIBC}
|
||||
exit ;;
|
||||
crisv32:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-axis-linux-${LIBC}
|
||||
exit ;;
|
||||
frv:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
hexagon:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
i*86:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-linux-${LIBC}
|
||||
exit ;;
|
||||
ia64:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
m32r*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
m68*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
mips:Linux:*:* | mips64:Linux:*:*)
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
#undef CPU
|
||||
#undef ${UNAME_MACHINE}
|
||||
#undef ${UNAME_MACHINE}el
|
||||
#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
|
||||
CPU=${UNAME_MACHINE}el
|
||||
#else
|
||||
#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
|
||||
CPU=${UNAME_MACHINE}
|
||||
#else
|
||||
CPU=
|
||||
#endif
|
||||
#endif
|
||||
EOF
|
||||
eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
|
||||
test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
|
||||
;;
|
||||
or1k:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
or32:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
padre:Linux:*:*)
|
||||
echo sparc-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
parisc64:Linux:*:* | hppa64:Linux:*:*)
|
||||
echo hppa64-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
parisc:Linux:*:* | hppa:Linux:*:*)
|
||||
# Look for CPU level
|
||||
case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
|
||||
PA7*) echo hppa1.1-unknown-linux-gnu ;;
|
||||
PA8*) echo hppa2.0-unknown-linux-gnu ;;
|
||||
*) echo hppa-unknown-linux-gnu ;;
|
||||
PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
|
||||
PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
|
||||
*) echo hppa-unknown-linux-${LIBC} ;;
|
||||
esac
|
||||
exit ;;
|
||||
parisc64:Linux:*:* | hppa64:Linux:*:*)
|
||||
echo hppa64-unknown-linux-gnu
|
||||
ppc64:Linux:*:*)
|
||||
echo powerpc64-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
ppc:Linux:*:*)
|
||||
echo powerpc-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
ppc64le:Linux:*:*)
|
||||
echo powerpc64le-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
ppcle:Linux:*:*)
|
||||
echo powerpcle-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
s390:Linux:*:* | s390x:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-ibm-linux
|
||||
echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
|
||||
exit ;;
|
||||
sh64*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
sh*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
sparc:Linux:*:* | sparc64:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
tile*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
vax:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-dec-linux-gnu
|
||||
echo ${UNAME_MACHINE}-dec-linux-${LIBC}
|
||||
exit ;;
|
||||
x86_64:Linux:*:*)
|
||||
echo x86_64-unknown-linux-gnu
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
xtensa*:Linux:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-linux-gnu
|
||||
echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
|
||||
exit ;;
|
||||
i*86:Linux:*:*)
|
||||
# The BFD linker knows what the default object file format is, so
|
||||
# first see if it will tell us. cd to the root directory to prevent
|
||||
# problems with other programs or directories called `ld' in the path.
|
||||
# Set LC_ALL=C to ensure ld outputs messages in English.
|
||||
ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \
|
||||
| sed -ne '/supported targets:/!d
|
||||
s/[ ][ ]*/ /g
|
||||
s/.*supported targets: *//
|
||||
s/ .*//
|
||||
p'`
|
||||
case "$ld_supported_targets" in
|
||||
elf32-i386)
|
||||
TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu"
|
||||
;;
|
||||
a.out-i386-linux)
|
||||
echo "${UNAME_MACHINE}-pc-linux-gnuaout"
|
||||
exit ;;
|
||||
coff-i386)
|
||||
echo "${UNAME_MACHINE}-pc-linux-gnucoff"
|
||||
exit ;;
|
||||
"")
|
||||
# Either a pre-BFD a.out linker (linux-gnuoldld) or
|
||||
# one that does not give us useful --help.
|
||||
echo "${UNAME_MACHINE}-pc-linux-gnuoldld"
|
||||
exit ;;
|
||||
esac
|
||||
# Determine whether the default compiler is a.out or elf
|
||||
eval $set_cc_for_build
|
||||
sed 's/^ //' << EOF >$dummy.c
|
||||
#include <features.h>
|
||||
#ifdef __ELF__
|
||||
# ifdef __GLIBC__
|
||||
# if __GLIBC__ >= 2
|
||||
LIBC=gnu
|
||||
# else
|
||||
LIBC=gnulibc1
|
||||
# endif
|
||||
# else
|
||||
LIBC=gnulibc1
|
||||
# endif
|
||||
#else
|
||||
#if defined(__INTEL_COMPILER) || defined(__PGI) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
|
||||
LIBC=gnu
|
||||
#else
|
||||
LIBC=gnuaout
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __dietlibc__
|
||||
LIBC=dietlibc
|
||||
#endif
|
||||
EOF
|
||||
eval "`$CC_FOR_BUILD -E $dummy.c 2>/dev/null | sed -n '
|
||||
/^LIBC/{
|
||||
s: ::g
|
||||
p
|
||||
}'`"
|
||||
test x"${LIBC}" != x && {
|
||||
echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
|
||||
exit
|
||||
}
|
||||
test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; }
|
||||
;;
|
||||
i*86:DYNIX/ptx:4*:*)
|
||||
# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
|
||||
# earlier versions are messed up and put the nodename in both
|
||||
@@ -1037,11 +1032,11 @@ EOF
|
||||
echo i386-sequent-sysv4
|
||||
exit ;;
|
||||
i*86:UNIX_SV:4.2MP:2.*)
|
||||
# Unixware is an offshoot of SVR4, but it has its own version
|
||||
# number series starting with 2...
|
||||
# I am not positive that other SVR4 systems won't match this,
|
||||
# Unixware is an offshoot of SVR4, but it has its own version
|
||||
# number series starting with 2...
|
||||
# I am not positive that other SVR4 systems won't match this,
|
||||
# I just have to hope. -- rms.
|
||||
# Use sysv4.2uw... so that sysv4* matches it.
|
||||
# Use sysv4.2uw... so that sysv4* matches it.
|
||||
echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
|
||||
exit ;;
|
||||
i*86:OS/2:*:*)
|
||||
@@ -1058,7 +1053,7 @@ EOF
|
||||
i*86:syllable:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-syllable
|
||||
exit ;;
|
||||
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*)
|
||||
i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
|
||||
echo i386-unknown-lynxos${UNAME_RELEASE}
|
||||
exit ;;
|
||||
i*86:*DOS:*:*)
|
||||
@@ -1073,7 +1068,7 @@ EOF
|
||||
fi
|
||||
exit ;;
|
||||
i*86:*:5:[678]*)
|
||||
# UnixWare 7.x, OpenUNIX and OpenServer 6.
|
||||
# UnixWare 7.x, OpenUNIX and OpenServer 6.
|
||||
case `/bin/uname -X | grep "^Machine"` in
|
||||
*486*) UNAME_MACHINE=i486 ;;
|
||||
*Pentium) UNAME_MACHINE=i586 ;;
|
||||
@@ -1101,10 +1096,13 @@ EOF
|
||||
exit ;;
|
||||
pc:*:*:*)
|
||||
# Left here for compatibility:
|
||||
# uname -m prints for DJGPP always 'pc', but it prints nothing about
|
||||
# the processor, so we play safe by assuming i386.
|
||||
echo i386-pc-msdosdjgpp
|
||||
exit ;;
|
||||
# uname -m prints for DJGPP always 'pc', but it prints nothing about
|
||||
# the processor, so we play safe by assuming i586.
|
||||
# Note: whatever this is, it MUST be the same as what config.sub
|
||||
# prints for the "djgpp" host, or else GDB configury will decide that
|
||||
# this is a cross-build.
|
||||
echo i586-pc-msdosdjgpp
|
||||
exit ;;
|
||||
Intel:Mach:3*:*)
|
||||
echo i386-pc-mach3
|
||||
exit ;;
|
||||
@@ -1139,8 +1137,18 @@ EOF
|
||||
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
|
||||
&& { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
|
||||
3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
|
||||
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
|
||||
&& { echo i486-ncr-sysv4; exit; } ;;
|
||||
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
|
||||
&& { echo i486-ncr-sysv4; exit; } ;;
|
||||
NCR*:*:4.2:* | MPRAS*:*:4.2:*)
|
||||
OS_REL='.3'
|
||||
test -r /etc/.relid \
|
||||
&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
|
||||
/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
|
||||
&& { echo i486-ncr-sysv4.3${OS_REL}; exit; }
|
||||
/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
|
||||
&& { echo i586-ncr-sysv4.3${OS_REL}; exit; }
|
||||
/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
|
||||
&& { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
|
||||
m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
|
||||
echo m68k-unknown-lynxos${UNAME_RELEASE}
|
||||
exit ;;
|
||||
@@ -1153,7 +1161,7 @@ EOF
|
||||
rs6000:LynxOS:2.*:*)
|
||||
echo rs6000-unknown-lynxos${UNAME_RELEASE}
|
||||
exit ;;
|
||||
PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*)
|
||||
PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
|
||||
echo powerpc-unknown-lynxos${UNAME_RELEASE}
|
||||
exit ;;
|
||||
SM[BE]S:UNIX_SV:*:*)
|
||||
@@ -1173,10 +1181,10 @@ EOF
|
||||
echo ns32k-sni-sysv
|
||||
fi
|
||||
exit ;;
|
||||
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
|
||||
# says <Richard.M.Bartel@ccMail.Census.GOV>
|
||||
echo i586-unisys-sysv4
|
||||
exit ;;
|
||||
PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
|
||||
# says <Richard.M.Bartel@ccMail.Census.GOV>
|
||||
echo i586-unisys-sysv4
|
||||
exit ;;
|
||||
*:UNIX_System_V:4*:FTX*)
|
||||
# From Gerald Hewes <hewes@openmarket.com>.
|
||||
# How about differentiating between stratus architectures? -djm
|
||||
@@ -1202,11 +1210,11 @@ EOF
|
||||
exit ;;
|
||||
R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
|
||||
if [ -d /usr/nec ]; then
|
||||
echo mips-nec-sysv${UNAME_RELEASE}
|
||||
echo mips-nec-sysv${UNAME_RELEASE}
|
||||
else
|
||||
echo mips-unknown-sysv${UNAME_RELEASE}
|
||||
echo mips-unknown-sysv${UNAME_RELEASE}
|
||||
fi
|
||||
exit ;;
|
||||
exit ;;
|
||||
BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
|
||||
echo powerpc-be-beos
|
||||
exit ;;
|
||||
@@ -1216,6 +1224,12 @@ EOF
|
||||
BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
|
||||
echo i586-pc-beos
|
||||
exit ;;
|
||||
BePC:Haiku:*:*) # Haiku running on Intel PC compatible.
|
||||
echo i586-pc-haiku
|
||||
exit ;;
|
||||
x86_64:Haiku:*:*)
|
||||
echo x86_64-unknown-haiku
|
||||
exit ;;
|
||||
SX-4:SUPER-UX:*:*)
|
||||
echo sx4-nec-superux${UNAME_RELEASE}
|
||||
exit ;;
|
||||
@@ -1242,9 +1256,21 @@ EOF
|
||||
exit ;;
|
||||
*:Darwin:*:*)
|
||||
UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
|
||||
case $UNAME_PROCESSOR in
|
||||
unknown) UNAME_PROCESSOR=powerpc ;;
|
||||
esac
|
||||
eval $set_cc_for_build
|
||||
if test "$UNAME_PROCESSOR" = unknown ; then
|
||||
UNAME_PROCESSOR=powerpc
|
||||
fi
|
||||
if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
|
||||
if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
|
||||
(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
|
||||
grep IS_64BIT_ARCH >/dev/null
|
||||
then
|
||||
case $UNAME_PROCESSOR in
|
||||
i386) UNAME_PROCESSOR=x86_64 ;;
|
||||
powerpc) UNAME_PROCESSOR=powerpc64 ;;
|
||||
esac
|
||||
fi
|
||||
fi
|
||||
echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
|
||||
exit ;;
|
||||
*:procnto*:*:* | *:QNX:[0123456789]*:*)
|
||||
@@ -1258,7 +1284,10 @@ EOF
|
||||
*:QNX:*:4*)
|
||||
echo i386-pc-qnx
|
||||
exit ;;
|
||||
NSE-?:NONSTOP_KERNEL:*:*)
|
||||
NEO-?:NONSTOP_KERNEL:*:*)
|
||||
echo neo-tandem-nsk${UNAME_RELEASE}
|
||||
exit ;;
|
||||
NSE-*:NONSTOP_KERNEL:*:*)
|
||||
echo nse-tandem-nsk${UNAME_RELEASE}
|
||||
exit ;;
|
||||
NSR-?:NONSTOP_KERNEL:*:*)
|
||||
@@ -1303,13 +1332,13 @@ EOF
|
||||
echo pdp10-unknown-its
|
||||
exit ;;
|
||||
SEI:*:*:SEIUX)
|
||||
echo mips-sei-seiux${UNAME_RELEASE}
|
||||
echo mips-sei-seiux${UNAME_RELEASE}
|
||||
exit ;;
|
||||
*:DragonFly:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
|
||||
exit ;;
|
||||
*:*VMS:*:*)
|
||||
UNAME_MACHINE=`(uname -p) 2>/dev/null`
|
||||
UNAME_MACHINE=`(uname -p) 2>/dev/null`
|
||||
case "${UNAME_MACHINE}" in
|
||||
A*) echo alpha-dec-vms ; exit ;;
|
||||
I*) echo ia64-dec-vms ; exit ;;
|
||||
@@ -1324,11 +1353,14 @@ EOF
|
||||
i*86:rdos:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-rdos
|
||||
exit ;;
|
||||
i*86:AROS:*:*)
|
||||
echo ${UNAME_MACHINE}-pc-aros
|
||||
exit ;;
|
||||
x86_64:VMkernel:*:*)
|
||||
echo ${UNAME_MACHINE}-unknown-esx
|
||||
exit ;;
|
||||
esac
|
||||
|
||||
#echo '(No uname command or uname output not recognized.)' 1>&2
|
||||
#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
|
||||
|
||||
eval $set_cc_for_build
|
||||
cat >$dummy.c <<EOF
|
||||
#ifdef _SEQUENT_
|
||||
@@ -1346,11 +1378,11 @@ main ()
|
||||
#include <sys/param.h>
|
||||
printf ("m68k-sony-newsos%s\n",
|
||||
#ifdef NEWSOS4
|
||||
"4"
|
||||
"4"
|
||||
#else
|
||||
""
|
||||
""
|
||||
#endif
|
||||
); exit (0);
|
||||
); exit (0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
+8
-1
@@ -1,4 +1,4 @@
|
||||
AC_INIT([ccminer], [1.6.5-git])
|
||||
AC_INIT([ccminer], [1.7-dev])
|
||||
|
||||
AC_PREREQ([2.59c])
|
||||
AC_CANONICAL_SYSTEM
|
||||
@@ -72,9 +72,16 @@ AC_CHECK_LIB([pthread], [pthread_create], PTHREAD_LIBS="-lpthread",
|
||||
AC_CHECK_LIB([pthreadGC], [pthread_create], PTHREAD_LIBS="-lpthreadGC"
|
||||
))))
|
||||
|
||||
AC_CHECK_LIB([z],[gzopen], [], [])
|
||||
AC_CHECK_LIB([ssl],[SSL_library_init], [], [AC_MSG_ERROR([OpenSSL library required])])
|
||||
AC_CHECK_LIB([crypto],[EVP_DigestFinal_ex], [], [AC_MSG_ERROR([OpenSSL library required])])
|
||||
|
||||
# libpci-dev (to get vendor name)
|
||||
PCILIB=""; PCIFLAGS=""
|
||||
AC_CHECK_LIB([pci],[pci_alloc], PCILIB="-lpci"; PCIFLAGS="-DHAVE_PCIDEV", [])
|
||||
AC_SUBST(PCILIB)
|
||||
AC_SUBST(PCIFLAGS)
|
||||
|
||||
AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue])
|
||||
AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue])
|
||||
AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue])
|
||||
|
||||
+6
-3
@@ -47,6 +47,9 @@
|
||||
/* Define to 1 if you have the `ssl' library (-lssl). */
|
||||
#define HAVE_LIBSSL 1
|
||||
|
||||
/* Define to 1 if you have the `z' library (-lz). */
|
||||
#define HAVE_LIBZ 1
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
@@ -159,7 +162,7 @@
|
||||
#define PACKAGE_NAME "ccminer"
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING "ccminer 1.6.5-git"
|
||||
#define PACKAGE_STRING "ccminer 1.7-dev"
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME "ccminer"
|
||||
@@ -168,7 +171,7 @@
|
||||
#define PACKAGE_URL "http://github.com/tpruvot/ccminer"
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION "1.6.5-git"
|
||||
#define PACKAGE_VERSION "1.7-dev"
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
@@ -182,7 +185,7 @@
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "1.6.5-git"
|
||||
#define VERSION "1.7-dev"
|
||||
|
||||
/* Define curl_free() as free() if our version of curl lacks curl_free. */
|
||||
/* #undef curl_free */
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#endif
|
||||
|
||||
#include "miner.h"
|
||||
#include "nvml.h"
|
||||
|
||||
#include "cuda_runtime.h"
|
||||
|
||||
@@ -64,23 +65,40 @@ void cuda_devicenames()
|
||||
GPU_N = min(MAX_GPUS, GPU_N);
|
||||
for (int i=0; i < GPU_N; i++)
|
||||
{
|
||||
char vendorname[32] = { 0 };
|
||||
cudaDeviceProp props;
|
||||
cudaGetDeviceProperties(&props, device_map[i]);
|
||||
|
||||
device_name[i] = strdup(props.name);
|
||||
device_sm[i] = (props.major * 100 + props.minor * 10);
|
||||
|
||||
if (device_name[i]) {
|
||||
free(device_name[i]);
|
||||
device_name[i] = NULL;
|
||||
}
|
||||
#ifdef USE_WRAPNVML
|
||||
if (gpu_vendor((uint8_t)props.pciBusID, vendorname) > 0 && strlen(vendorname)) {
|
||||
device_name[i] = (char*) calloc(1, strlen(vendorname) + strlen(props.name) + 2);
|
||||
if (!strncmp(props.name, "GeForce ", 8))
|
||||
sprintf(device_name[i], "%s %s", vendorname, &props.name[8]);
|
||||
else
|
||||
sprintf(device_name[i], "%s %s", vendorname, props.name);
|
||||
} else
|
||||
#endif
|
||||
device_name[i] = strdup(props.name);
|
||||
}
|
||||
}
|
||||
|
||||
void cuda_print_devices()
|
||||
{
|
||||
int ngpus = cuda_num_devices();
|
||||
cuda_devicenames();
|
||||
for (int n=0; n < ngpus; n++) {
|
||||
int m = device_map[n];
|
||||
cudaDeviceProp props;
|
||||
cudaGetDeviceProperties(&props, m);
|
||||
if (!opt_n_threads || n < opt_n_threads)
|
||||
fprintf(stderr, "GPU #%d: SM %d.%d %s\n", m, props.major, props.minor, props.name);
|
||||
if (!opt_n_threads || n < opt_n_threads) {
|
||||
fprintf(stderr, "GPU #%d: SM %d.%d %s\n", m, props.major, props.minor, device_name[n]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,6 +212,8 @@ void cuda_reset_device(int thr_id, bool *init)
|
||||
usleep(1000);
|
||||
}
|
||||
cudaDeviceReset();
|
||||
if (opt_cudaschedule >= 0)
|
||||
cudaSetDeviceFlags((unsigned)(opt_cudaschedule & cudaDeviceScheduleMask));
|
||||
}
|
||||
|
||||
void cudaReportHardwareFailure(int thr_id, cudaError_t err, const char* func)
|
||||
|
||||
@@ -23,6 +23,13 @@ void cuda_check_cpu_init(int thr_id, uint32_t threads)
|
||||
init_done = true;
|
||||
}
|
||||
|
||||
__host__
|
||||
void cuda_check_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_resNonces[thr_id]);
|
||||
cudaFreeHost(h_resNonces[thr_id]);
|
||||
}
|
||||
|
||||
// Target Difficulty
|
||||
__host__
|
||||
void cuda_check_cpu_setTarget(const void *ptarget)
|
||||
@@ -89,6 +96,21 @@ void cuda_checkhash_64(uint32_t threads, uint32_t startNounce, uint32_t *hash, u
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(512, 4)
|
||||
void cuda_checkhash_32(uint32_t threads, uint32_t startNounce, uint32_t *hash, uint32_t *resNonces)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t *inpHash = &hash[thread << 3];
|
||||
|
||||
if (resNonces[0] == UINT32_MAX) {
|
||||
if (hashbelowtarget(inpHash, pTarget))
|
||||
resNonces[0] = (startNounce + thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t cuda_check_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash)
|
||||
{
|
||||
@@ -111,6 +133,28 @@ uint32_t cuda_check_hash(int thr_id, uint32_t threads, uint32_t startNounce, uin
|
||||
return h_resNonces[thr_id][0];
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t cuda_check_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash)
|
||||
{
|
||||
cudaMemset(d_resNonces[thr_id], 0xff, sizeof(uint32_t));
|
||||
|
||||
const uint32_t threadsperblock = 512;
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
if (!init_done) {
|
||||
applog(LOG_ERR, "missing call to cuda_check_cpu_init");
|
||||
return UINT32_MAX;
|
||||
}
|
||||
|
||||
cuda_checkhash_32 <<<grid, block>>> (threads, startNounce, d_inputHash, d_resNonces[thr_id]);
|
||||
cudaThreadSynchronize();
|
||||
|
||||
cudaMemcpy(h_resNonces[thr_id], d_resNonces[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
return h_resNonces[thr_id][0];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
__global__ __launch_bounds__(512, 4)
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
void fugue256_cpu_hash(int thr_id, uint32_t threads, int startNounce, void *outputHashes, uint32_t *nounce);
|
||||
void fugue256_cpu_setBlock(int thr_id, void *data, void *pTargetIn);
|
||||
void fugue256_cpu_init(int thr_id, uint32_t threads);
|
||||
void fugue256_cpu_free(int thr_id);
|
||||
|
||||
#endif
|
||||
@@ -102,6 +102,12 @@ void groestlcoin_cpu_init(int thr_id, uint32_t threads)
|
||||
cudaMalloc(&d_resultNonce[thr_id], sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__host__
|
||||
void groestlcoin_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_resultNonce[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
void groestlcoin_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define _CUDA_GROESTLCOIN_H
|
||||
|
||||
void groestlcoin_cpu_init(int thr_id, uint32_t threads);
|
||||
void groestlcoin_cpu_free(int thr_id);
|
||||
void groestlcoin_cpu_setBlock(int thr_id, void *data, void *pTargetIn);
|
||||
void groestlcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce);
|
||||
|
||||
|
||||
+32
-35
@@ -31,6 +31,7 @@ extern int cuda_arch[MAX_GPUS];
|
||||
extern int cuda_get_arch(int thr_id);
|
||||
extern void cuda_reset_device(int thr_id, bool *init);
|
||||
extern void cuda_check_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void cuda_check_cpu_free(int thr_id);
|
||||
extern void cuda_check_cpu_setTarget(const void *ptarget);
|
||||
extern uint32_t cuda_check_hash(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash);
|
||||
extern uint32_t cuda_check_hash_suppl(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_inputHash, uint8_t numNonce);
|
||||
@@ -309,7 +310,6 @@ uint64_t shr_t64(uint64_t x, uint32_t n)
|
||||
#endif
|
||||
}
|
||||
|
||||
// device asm for ?
|
||||
__device__ __forceinline__
|
||||
uint64_t shl_t64(uint64_t x, uint32_t n)
|
||||
{
|
||||
@@ -324,40 +324,6 @@ uint64_t shl_t64(uint64_t x, uint32_t n)
|
||||
#endif
|
||||
}
|
||||
|
||||
// device asm 32 for pluck
|
||||
__device__ __forceinline__
|
||||
uint32_t andor32(uint32_t a, uint32_t b, uint32_t c) {
|
||||
#ifdef __CUDA_ARCH__
|
||||
uint32_t result;
|
||||
asm("{ .reg .u32 m,n,o;\n\t"
|
||||
"and.b32 m, %1, %2;\n\t"
|
||||
" or.b32 n, %1, %2;\n\t"
|
||||
"and.b32 o, n, %3;\n\t"
|
||||
" or.b32 %0, m, o ;\n\t"
|
||||
"}\n\t"
|
||||
: "=r"(result) : "r"(a), "r"(b), "r"(c));
|
||||
return result;
|
||||
#else
|
||||
// unused on host...
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
uint32_t xor3b(uint32_t a, uint32_t b, uint32_t c) {
|
||||
#ifdef __CUDA_ARCH__
|
||||
uint32_t result;
|
||||
asm("{ .reg .u32 t1;\n\t"
|
||||
"xor.b32 t1, %2, %3;\n\t"
|
||||
"xor.b32 %0, %1, t1;\n\t"
|
||||
"}"
|
||||
: "=r"(result) : "r"(a) ,"r"(b),"r"(c));
|
||||
return result;
|
||||
#else
|
||||
return a^b^c;
|
||||
#endif
|
||||
}
|
||||
|
||||
__device__ __forceinline__
|
||||
uint32_t shr_t32(uint32_t x,uint32_t n) {
|
||||
#ifdef __CUDA_ARCH__
|
||||
@@ -641,6 +607,37 @@ uint2 SWAPUINT2(uint2 value)
|
||||
return make_uint2(value.y, value.x);
|
||||
}
|
||||
|
||||
/* Byte aligned Rotations (lyra2) */
|
||||
#ifdef __CUDA_ARCH__
|
||||
__device__ __inline__ uint2 ROL8(const uint2 a)
|
||||
{
|
||||
uint2 result;
|
||||
result.x = __byte_perm(a.y, a.x, 0x6543);
|
||||
result.y = __byte_perm(a.y, a.x, 0x2107);
|
||||
return result;
|
||||
}
|
||||
|
||||
__device__ __inline__ uint2 ROR16(const uint2 a)
|
||||
{
|
||||
uint2 result;
|
||||
result.x = __byte_perm(a.y, a.x, 0x1076);
|
||||
result.y = __byte_perm(a.y, a.x, 0x5432);
|
||||
return result;
|
||||
}
|
||||
|
||||
__device__ __inline__ uint2 ROR24(const uint2 a)
|
||||
{
|
||||
uint2 result;
|
||||
result.x = __byte_perm(a.y, a.x, 0x2107);
|
||||
result.y = __byte_perm(a.y, a.x, 0x6543);
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
#define ROL8(u) ((u) << 8)
|
||||
#define ROR16(u) ((u) >> 16)
|
||||
#define ROR24(u) ((u) >> 24)
|
||||
#endif
|
||||
|
||||
/* uint2 for bmw512 - to double check later */
|
||||
|
||||
__device__ __forceinline__
|
||||
|
||||
@@ -327,6 +327,13 @@ void myriadgroestl_cpu_init(int thr_id, uint32_t threads)
|
||||
cudaMalloc(&d_outputHashes[thr_id], 16*sizeof(uint32_t)*threads);
|
||||
}
|
||||
|
||||
__host__
|
||||
void myriadgroestl_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_resultNonce[thr_id]);
|
||||
cudaFree(d_outputHashes[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
void myriadgroestl_cpu_setBlock(int thr_id, void *data, void *pTargetIn)
|
||||
{
|
||||
|
||||
+46
-11
@@ -66,11 +66,13 @@ extern "C" void nist5hash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_nist5(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int res = 0;
|
||||
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1 << 20); // 256*256*16
|
||||
throughput = min(throughput, (max_nonce - first_nonce));
|
||||
@@ -82,20 +84,26 @@ extern "C" int scanhash_nist5(int thr_id, uint32_t *pdata,
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
// Konstanten kopieren, Speicher belegen
|
||||
// Constants copy/init (no device alloc in these algos)
|
||||
quark_blake512_cpu_init(thr_id, throughput);
|
||||
quark_groestl512_cpu_init(thr_id, throughput);
|
||||
quark_jh512_cpu_init(thr_id, throughput);
|
||||
quark_keccak512_cpu_init(thr_id, throughput);
|
||||
quark_skein512_cpu_init(thr_id, throughput);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], 16 * sizeof(uint32_t) * throughput));
|
||||
// char[64] work space for hashes results
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t)64 * throughput));
|
||||
|
||||
cuda_check_cpu_init(thr_id, throughput);
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t endiandata[20];
|
||||
#ifdef USE_STREAMS
|
||||
cudaStream_t stream[5];
|
||||
for (int i = 0; i < 5; i++)
|
||||
cudaStreamCreate(&stream[i]);
|
||||
#endif
|
||||
|
||||
for (int k=0; k < 20; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
|
||||
@@ -112,6 +120,8 @@ extern "C" int scanhash_nist5(int thr_id, uint32_t *pdata,
|
||||
quark_keccak512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
quark_skein512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
uint32_t foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
@@ -121,15 +131,19 @@ extern "C" int scanhash_nist5(int thr_id, uint32_t *pdata,
|
||||
nist5hash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
nist5hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
pdata[19] = foundNonce;
|
||||
return res;
|
||||
goto out;
|
||||
}
|
||||
else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
@@ -140,6 +154,27 @@ extern "C" int scanhash_nist5(int thr_id, uint32_t *pdata,
|
||||
|
||||
} while (pdata[19] < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
out:
|
||||
#ifdef USE_STREAMS
|
||||
for (int i = 0; i < 5; i++)
|
||||
cudaStreamDestroy(stream[i]);
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// ressources cleanup
|
||||
extern "C" void free_nist5(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+32
-16
@@ -20,11 +20,22 @@ extern "C" void my_fugue256_addbits_and_close(void *cc, unsigned ub, unsigned n,
|
||||
((((x) << 24) & 0xff000000u) | (((x) << 8) & 0x00ff0000u) | \
|
||||
(((x) >> 8) & 0x0000ff00u) | (((x) >> 24) & 0x000000ffu))
|
||||
|
||||
void fugue256_hash(unsigned char* output, const unsigned char* input, int len)
|
||||
{
|
||||
sph_fugue256_context ctx;
|
||||
|
||||
sph_fugue256_init(&ctx);
|
||||
sph_fugue256(&ctx, input, len);
|
||||
sph_fugue256_close(&ctx, (void *)output);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
int scanhash_fugue256(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
int scanhash_fugue256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
uint32_t start_nonce = pdata[19]++;
|
||||
int intensity = (device_sm[device_map[thr_id]] > 500) ? 22 : 19;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1 << intensity); // 256*256*8
|
||||
@@ -42,8 +53,7 @@ int scanhash_fugue256(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
// Endian Drehung ist notwendig
|
||||
uint32_t endiandata[20];
|
||||
// Endian
|
||||
for (int kk=0; kk < 20; kk++)
|
||||
be32enc(&endiandata[kk], pdata[kk]);
|
||||
|
||||
@@ -57,17 +67,17 @@ int scanhash_fugue256(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
|
||||
if (foundNounce < UINT32_MAX)
|
||||
{
|
||||
uint32_t hash[8];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
|
||||
endiandata[19] = SWAP32(foundNounce);
|
||||
uint32_t vhash[8];
|
||||
sph_fugue256_context ctx_fugue;
|
||||
endiandata[19] = SWAP32(foundNounce);
|
||||
|
||||
sph_fugue256_init(&ctx_fugue);
|
||||
sph_fugue256 (&ctx_fugue, endiandata, 80);
|
||||
sph_fugue256_close(&ctx_fugue, &hash);
|
||||
sph_fugue256_close(&ctx_fugue, &vhash);
|
||||
|
||||
if (hash[7] <= Htarg && fulltest(hash, ptarget))
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget))
|
||||
{
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
pdata[19] = foundNounce;
|
||||
*hashes_done = foundNounce - start_nonce + 1;
|
||||
return 1;
|
||||
@@ -90,11 +100,17 @@ int scanhash_fugue256(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fugue256_hash(unsigned char* output, const unsigned char* input, int len)
|
||||
// cleanup
|
||||
void free_fugue256(int thr_id)
|
||||
{
|
||||
sph_fugue256_context ctx;
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
sph_fugue256_init(&ctx);
|
||||
sph_fugue256(&ctx, input, len);
|
||||
sph_fugue256_close(&ctx, (void *)output);
|
||||
}
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
fugue256_cpu_free(thr_id);
|
||||
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+21
-6
@@ -27,10 +27,11 @@ void groestlhash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
int scanhash_groestlcoin(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
int scanhash_groestlcoin(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t _ALIGN(64) endiandata[32];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
uint32_t start_nonce = pdata[19];
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1 << 19); // 256*256*8
|
||||
throughput = min(throughput, max_nonce - start_nonce);
|
||||
@@ -62,11 +63,12 @@ int scanhash_groestlcoin(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
|
||||
if (foundNounce < UINT32_MAX)
|
||||
{
|
||||
uint32_t _ALIGN(64) tmpHash[8];
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
endiandata[19] = swab32(foundNounce);
|
||||
groestlhash(tmpHash, endiandata);
|
||||
groestlhash(vhash, endiandata);
|
||||
|
||||
if (tmpHash[7] <= ptarget[7] && fulltest(tmpHash, ptarget)) {
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
pdata[19] = foundNounce;
|
||||
free(outputHash);
|
||||
return true;
|
||||
@@ -89,3 +91,16 @@ int scanhash_groestlcoin(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
void free_groestlcoin(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
groestlcoin_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+30
-15
@@ -130,10 +130,10 @@ struct check_nonce_for_remove
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
__host__
|
||||
int scanhash_heavy(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done, uint32_t maxvote, int blocklen)
|
||||
int scanhash_heavy(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done, uint32_t maxvote, int blocklen)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
// CUDA will process thousands of threads.
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, (1U << 19) - 256);
|
||||
@@ -271,18 +271,17 @@ int scanhash_heavy(int thr_id, uint32_t *pdata,
|
||||
{
|
||||
uint32_t nonce = cpu_nonceVector[i];
|
||||
uint32_t *foundhash = &hash[8*i];
|
||||
if (foundhash[7] <= ptarget[7]) {
|
||||
if (fulltest(foundhash, ptarget)) {
|
||||
uint32_t verification[8];
|
||||
pdata[19] += nonce - pdata[19];
|
||||
heavycoin_hash((uchar*)verification, (uchar*)pdata, blocklen);
|
||||
if (memcmp(verification, foundhash, 8*sizeof(uint32_t))) {
|
||||
applog(LOG_ERR, "hash for nonce=$%08X does not validate on CPU!\n", nonce);
|
||||
} else {
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
rc = 1;
|
||||
goto exit;
|
||||
}
|
||||
if (foundhash[7] <= ptarget[7] && fulltest(foundhash, ptarget)) {
|
||||
uint32_t vhash[8];
|
||||
pdata[19] += nonce - pdata[19];
|
||||
heavycoin_hash((uchar*)vhash, (uchar*)pdata, blocklen);
|
||||
if (memcmp(vhash, foundhash, 8*sizeof(uint32_t))) {
|
||||
applog(LOG_ERR, "hash for nonce %08x does not validate on CPU!\n", nonce);
|
||||
} else {
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
rc = 1;
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,6 +300,22 @@ exit:
|
||||
return rc;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_heavy(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(heavy_nonceVector[thr_id]);
|
||||
|
||||
// todo: free sub algos vectors
|
||||
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
__host__
|
||||
void heavycoin_hash(uchar* output, const uchar* input, int len)
|
||||
{
|
||||
|
||||
Regular → Executable
+7
-7
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# install - install a program, script, or datafile
|
||||
|
||||
scriptversion=2011-01-19.21; # UTC
|
||||
scriptversion=2011-11-20.07; # UTC
|
||||
|
||||
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||
@@ -35,7 +35,7 @@ scriptversion=2011-01-19.21; # UTC
|
||||
# FSF changes to this file are in the public domain.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# 'make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
@@ -156,7 +156,7 @@ while test $# -ne 0; do
|
||||
-s) stripcmd=$stripprog;;
|
||||
|
||||
-t) dst_arg=$2
|
||||
# Protect names problematic for `test' and other utilities.
|
||||
# Protect names problematic for 'test' and other utilities.
|
||||
case $dst_arg in
|
||||
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
||||
esac
|
||||
@@ -190,7 +190,7 @@ if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
|
||||
fi
|
||||
shift # arg
|
||||
dst_arg=$arg
|
||||
# Protect names problematic for `test' and other utilities.
|
||||
# Protect names problematic for 'test' and other utilities.
|
||||
case $dst_arg in
|
||||
-* | [=\(\)!]) dst_arg=./$dst_arg;;
|
||||
esac
|
||||
@@ -202,7 +202,7 @@ if test $# -eq 0; then
|
||||
echo "$0: no input file specified." >&2
|
||||
exit 1
|
||||
fi
|
||||
# It's OK to call `install-sh -d' without argument.
|
||||
# It's OK to call 'install-sh -d' without argument.
|
||||
# This can happen when creating conditional directories.
|
||||
exit 0
|
||||
fi
|
||||
@@ -240,7 +240,7 @@ fi
|
||||
|
||||
for src
|
||||
do
|
||||
# Protect names problematic for `test' and other utilities.
|
||||
# Protect names problematic for 'test' and other utilities.
|
||||
case $src in
|
||||
-* | [=\(\)!]) src=./$src;;
|
||||
esac
|
||||
@@ -354,7 +354,7 @@ do
|
||||
if test -z "$dir_arg" || {
|
||||
# Check for POSIX incompatibilities with -m.
|
||||
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||
# other-writeable bit of parent directory when it shouldn't.
|
||||
# other-writable bit of parent directory when it shouldn't.
|
||||
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||
ls_ld_tmpdir=`ls -ld "$tmpdir"`
|
||||
case $ls_ld_tmpdir in
|
||||
|
||||
+49
-46
@@ -44,7 +44,7 @@
|
||||
*
|
||||
* @return 0 if the key is generated correctly; -1 if there is an error (usually due to lack of memory for allocation)
|
||||
*/
|
||||
int LYRA2(void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *salt, uint64_t saltlen, uint64_t timeCost, uint64_t nRows, uint64_t nCols)
|
||||
int LYRA2(void *K, int64_t kLen, const void *pwd, int32_t pwdlen, const void *salt, int32_t saltlen, int64_t timeCost, const int16_t nRows, const int16_t nCols)
|
||||
{
|
||||
//============================= Basic variables ============================//
|
||||
int64_t row = 2; //index of row to be processed
|
||||
@@ -55,25 +55,32 @@ int LYRA2(void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *
|
||||
int64_t window = 2; //Visitation window (used to define which rows can be revisited during Setup)
|
||||
int64_t gap = 1; //Modifier to the step, assuming the values 1 or -1
|
||||
int64_t i; //auxiliary iteration counter
|
||||
int64_t v64; // 64bit var for memcpy
|
||||
//==========================================================================/
|
||||
|
||||
//========== Initializing the Memory Matrix and pointers to it =============//
|
||||
//Tries to allocate enough space for the whole memory matrix
|
||||
i = (int64_t) ((int64_t) nRows * (int64_t) ROW_LEN_BYTES);
|
||||
uint64_t *wholeMatrix = (uint64_t*) malloc((size_t) i);
|
||||
|
||||
const int64_t ROW_LEN_INT64 = BLOCK_LEN_INT64 * nCols;
|
||||
const int64_t ROW_LEN_BYTES = ROW_LEN_INT64 * 8;
|
||||
// for Lyra2REv2, nCols = 4, v1 was using 8
|
||||
const int64_t BLOCK_LEN = (nCols == 4) ? BLOCK_LEN_BLAKE2_SAFE_INT64 : BLOCK_LEN_BLAKE2_SAFE_BYTES;
|
||||
|
||||
size_t sz = (size_t)ROW_LEN_BYTES * nRows;
|
||||
uint64_t *wholeMatrix = malloc(sz);
|
||||
if (wholeMatrix == NULL) {
|
||||
return -1;
|
||||
}
|
||||
memset(wholeMatrix, 0, (size_t) i);
|
||||
memset(wholeMatrix, 0, sz);
|
||||
|
||||
//Allocates pointers to each row of the matrix
|
||||
uint64_t **memMatrix = malloc((size_t) nRows * sizeof(uint64_t*));
|
||||
uint64_t **memMatrix = malloc(sizeof(uint64_t*) * nRows);
|
||||
if (memMatrix == NULL) {
|
||||
return -1;
|
||||
}
|
||||
//Places the pointers in the correct positions
|
||||
uint64_t *ptrWord = wholeMatrix;
|
||||
for (i = 0; i < (int64_t) nRows; i++) {
|
||||
for (i = 0; i < nRows; i++) {
|
||||
memMatrix[i] = ptrWord;
|
||||
ptrWord += ROW_LEN_INT64;
|
||||
}
|
||||
@@ -84,32 +91,38 @@ int LYRA2(void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *
|
||||
//but this ensures that the password copied locally will be overwritten as soon as possible
|
||||
|
||||
//First, we clean enough blocks for the password, salt, basil and padding
|
||||
uint64_t nBlocksInput = ((saltlen + pwdlen + 6 * sizeof (uint64_t)) / BLOCK_LEN_BLAKE2_SAFE_BYTES) + 1;
|
||||
int64_t nBlocksInput = ((saltlen + pwdlen + 6 * sizeof(uint64_t)) / BLOCK_LEN_BLAKE2_SAFE_BYTES) + 1;
|
||||
|
||||
byte *ptrByte = (byte*) wholeMatrix;
|
||||
memset(ptrByte, 0, (size_t) nBlocksInput * BLOCK_LEN_BLAKE2_SAFE_BYTES);
|
||||
|
||||
//Prepends the password
|
||||
memcpy(ptrByte, pwd, (size_t) pwdlen);
|
||||
memcpy(ptrByte, pwd, pwdlen);
|
||||
ptrByte += pwdlen;
|
||||
|
||||
//Concatenates the salt
|
||||
memcpy(ptrByte, salt, (size_t) saltlen);
|
||||
memcpy(ptrByte, salt, saltlen);
|
||||
ptrByte += saltlen;
|
||||
|
||||
memset(ptrByte, 0, (size_t) (nBlocksInput * BLOCK_LEN_BLAKE2_SAFE_BYTES - (saltlen + pwdlen)));
|
||||
|
||||
//Concatenates the basil: every integer passed as parameter, in the order they are provided by the interface
|
||||
memcpy(ptrByte, &kLen, sizeof (uint64_t));
|
||||
ptrByte += sizeof (uint64_t);
|
||||
memcpy(ptrByte, &pwdlen, sizeof (uint64_t));
|
||||
ptrByte += sizeof (uint64_t);
|
||||
memcpy(ptrByte, &saltlen, sizeof (uint64_t));
|
||||
ptrByte += sizeof (uint64_t);
|
||||
memcpy(ptrByte, &timeCost, sizeof (uint64_t));
|
||||
ptrByte += sizeof (uint64_t);
|
||||
memcpy(ptrByte, &nRows, sizeof (uint64_t));
|
||||
ptrByte += sizeof (uint64_t);
|
||||
memcpy(ptrByte, &nCols, sizeof (uint64_t));
|
||||
ptrByte += sizeof (uint64_t);
|
||||
memcpy(ptrByte, &kLen, sizeof(int64_t));
|
||||
ptrByte += sizeof(uint64_t);
|
||||
v64 = pwdlen;
|
||||
memcpy(ptrByte, &v64, sizeof(int64_t));
|
||||
ptrByte += sizeof(uint64_t);
|
||||
v64 = saltlen;
|
||||
memcpy(ptrByte, &v64, sizeof(int64_t));
|
||||
ptrByte += sizeof(uint64_t);
|
||||
v64 = timeCost;
|
||||
memcpy(ptrByte, &v64, sizeof(int64_t));
|
||||
ptrByte += sizeof(uint64_t);
|
||||
v64 = nRows;
|
||||
memcpy(ptrByte, &v64, sizeof(int64_t));
|
||||
ptrByte += sizeof(uint64_t);
|
||||
v64 = nCols;
|
||||
memcpy(ptrByte, &v64, sizeof(int64_t));
|
||||
ptrByte += sizeof(uint64_t);
|
||||
|
||||
//Now comes the padding
|
||||
*ptrByte = 0x80; //first byte of padding: right after the password
|
||||
@@ -120,30 +133,27 @@ int LYRA2(void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *
|
||||
|
||||
//======================= Initializing the Sponge State ====================//
|
||||
//Sponge state: 16 uint64_t, BLOCK_LEN_INT64 words of them for the bitrate (b) and the remainder for the capacity (c)
|
||||
uint64_t *state = malloc(16 * sizeof (uint64_t));
|
||||
if (state == NULL) {
|
||||
return -1;
|
||||
}
|
||||
uint64_t state[16];
|
||||
initState(state);
|
||||
//==========================================================================/
|
||||
|
||||
//================================ Setup Phase =============================//
|
||||
//Absorbing salt, password and basil: this is the only place in which the block length is hard-coded to 512 bits
|
||||
ptrWord = wholeMatrix;
|
||||
for (i = 0; i < (int64_t) nBlocksInput; i++) {
|
||||
for (i = 0; i < nBlocksInput; i++) {
|
||||
absorbBlockBlake2Safe(state, ptrWord); //absorbs each block of pad(pwd || salt || basil)
|
||||
ptrWord += BLOCK_LEN_BLAKE2_SAFE_BYTES; //goes to next block of pad(pwd || salt || basil)
|
||||
ptrWord += BLOCK_LEN; //goes to next block of pad(pwd || salt || basil)
|
||||
}
|
||||
|
||||
//Initializes M[0] and M[1]
|
||||
reducedSqueezeRow0(state, memMatrix[0]); //The locally copied password is most likely overwritten here
|
||||
reducedSqueezeRow0(state, memMatrix[0], nCols); //The locally copied password is most likely overwritten here
|
||||
|
||||
reducedDuplexRow1(state, memMatrix[0], memMatrix[1]);
|
||||
reducedDuplexRow1(state, memMatrix[0], memMatrix[1], nCols);
|
||||
|
||||
do {
|
||||
//M[row] = rand; //M[row*] = M[row*] XOR rotW(rand)
|
||||
|
||||
reducedDuplexRowSetup(state, memMatrix[prev], memMatrix[rowa], memMatrix[row]);
|
||||
reducedDuplexRowSetup(state, memMatrix[prev], memMatrix[rowa], memMatrix[row], nCols);
|
||||
|
||||
//updates the value of row* (deterministically picked during Setup))
|
||||
rowa = (rowa + step) & (window - 1);
|
||||
@@ -159,53 +169,46 @@ int LYRA2(void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *
|
||||
gap = -gap; //inverts the modifier to the step
|
||||
}
|
||||
|
||||
} while (row < (int64_t) nRows);
|
||||
} while (row < nRows);
|
||||
//==========================================================================/
|
||||
|
||||
//============================ Wandering Phase =============================//
|
||||
row = 0; //Resets the visitation to the first row of the memory matrix
|
||||
for (tau = 1; tau <= (int64_t) timeCost; tau++) {
|
||||
for (tau = 1; tau <= timeCost; tau++) {
|
||||
//Step is approximately half the number of all rows of the memory matrix for an odd tau; otherwise, it is -1
|
||||
step = (tau % 2 == 0) ? -1 : nRows / 2 - 1;
|
||||
do {
|
||||
//Selects a pseudorandom index row*
|
||||
//------------------------------------------------------------------------------------------
|
||||
//rowa = ((unsigned int)state[0]) & (nRows-1); //(USE THIS IF nRows IS A POWER OF 2)
|
||||
rowa = ((uint64_t) (state[0])) % nRows; //(USE THIS FOR THE "GENERIC" CASE)
|
||||
rowa = state[0] & (unsigned int)(nRows-1); //(USE THIS IF nRows IS A POWER OF 2)
|
||||
//rowa = state[0] % nRows; //(USE THIS FOR THE "GENERIC" CASE)
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
||||
//Performs a reduced-round duplexing operation over M[row*] XOR M[prev], updating both M[row*] and M[row]
|
||||
reducedDuplexRow(state, memMatrix[prev], memMatrix[rowa], memMatrix[row]);
|
||||
reducedDuplexRow(state, memMatrix[prev], memMatrix[rowa], memMatrix[row], nCols);
|
||||
|
||||
//update prev: it now points to the last row ever computed
|
||||
prev = row;
|
||||
|
||||
//updates row: goes to the next row to be computed
|
||||
//------------------------------------------------------------------------------------------
|
||||
//row = (row + step) & (nRows-1); //(USE THIS IF nRows IS A POWER OF 2)
|
||||
row = (row + step) % nRows; //(USE THIS FOR THE "GENERIC" CASE)
|
||||
row = (row + step) & (unsigned int)(nRows-1); //(USE THIS IF nRows IS A POWER OF 2)
|
||||
//row = (row + step) % nRows; //(USE THIS FOR THE "GENERIC" CASE)
|
||||
//------------------------------------------------------------------------------------------
|
||||
|
||||
} while (row != 0);
|
||||
}
|
||||
//==========================================================================/
|
||||
|
||||
//============================ Wrap-up Phase ===============================//
|
||||
//Absorbs the last block of the memory matrix
|
||||
absorbBlock(state, memMatrix[rowa]);
|
||||
|
||||
//Squeezes the key
|
||||
squeeze(state, K, (size_t) kLen);
|
||||
//==========================================================================/
|
||||
squeeze(state, K, (unsigned int) kLen);
|
||||
|
||||
//========================= Freeing the memory =============================//
|
||||
free(memMatrix);
|
||||
free(wholeMatrix);
|
||||
|
||||
//Wiping out the sponge's internal state before freeing it
|
||||
memset(state, 0, 16 * sizeof (uint64_t));
|
||||
free(state);
|
||||
//==========================================================================/
|
||||
|
||||
return 0;
|
||||
}
|
||||
+1
-9
@@ -37,14 +37,6 @@ typedef unsigned char byte;
|
||||
#define BLOCK_LEN_BYTES (BLOCK_LEN_INT64 * 8) //Block length, in bytes
|
||||
#endif
|
||||
|
||||
#ifndef N_COLS
|
||||
#define N_COLS 8 //Number of columns in the memory matrix: fixed to 64 by default
|
||||
#endif
|
||||
|
||||
#define ROW_LEN_INT64 (BLOCK_LEN_INT64 * N_COLS) //Total length of a row: N_COLS blocks
|
||||
#define ROW_LEN_BYTES (ROW_LEN_INT64 * 8) //Number of bytes per row
|
||||
|
||||
|
||||
int LYRA2(void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *salt, uint64_t saltlen, uint64_t timeCost, uint64_t nRows, uint64_t nCols);
|
||||
int LYRA2(void *K, int64_t kLen, const void *pwd, int32_t pwdlen, const void *salt, int32_t saltlen, int64_t timeCost, const int16_t nRows, const int16_t nCols);
|
||||
|
||||
#endif /* LYRA2_H_ */
|
||||
+243
-588
@@ -25,7 +25,6 @@
|
||||
#include "Lyra2.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the Sponge State. The first 512 bits are set to zeros and the remainder
|
||||
* receive Blake2b's IV as per Blake2b's specification. <b>Note:</b> Even though sponges
|
||||
@@ -37,20 +36,18 @@
|
||||
*
|
||||
* @param state The 1024-bit array to be initialized
|
||||
*/
|
||||
void initState(uint64_t state[/*16*/]) {
|
||||
//First 512 bis are zeros
|
||||
memset(state, 0, 64);
|
||||
//Remainder BLOCK_LEN_BLAKE2_SAFE_BYTES are reserved to the IV
|
||||
|
||||
state[8] = blake2b_IV[0];
|
||||
state[9] = blake2b_IV[1];
|
||||
state[10] = blake2b_IV[2];
|
||||
state[11] = blake2b_IV[3];
|
||||
state[12] = blake2b_IV[4];
|
||||
state[13] = blake2b_IV[5];
|
||||
state[14] = blake2b_IV[6];
|
||||
state[15] = blake2b_IV[7];
|
||||
|
||||
void initState(uint64_t state[/*16*/]) {
|
||||
//First 512 bis are zeros
|
||||
memset(state, 0, 64);
|
||||
//Remainder BLOCK_LEN_BLAKE2_SAFE_BYTES are reserved to the IV
|
||||
state[8] = blake2b_IV[0];
|
||||
state[9] = blake2b_IV[1];
|
||||
state[10] = blake2b_IV[2];
|
||||
state[11] = blake2b_IV[3];
|
||||
state[12] = blake2b_IV[4];
|
||||
state[13] = blake2b_IV[5];
|
||||
state[14] = blake2b_IV[6];
|
||||
state[15] = blake2b_IV[7];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,18 +56,18 @@
|
||||
* @param v A 1024-bit (16 uint64_t) array to be processed by Blake2b's G function
|
||||
*/
|
||||
__inline static void blake2bLyra(uint64_t *v) {
|
||||
ROUND_LYRA(0);
|
||||
ROUND_LYRA(1);
|
||||
ROUND_LYRA(2);
|
||||
ROUND_LYRA(3);
|
||||
ROUND_LYRA(4);
|
||||
ROUND_LYRA(5);
|
||||
ROUND_LYRA(6);
|
||||
ROUND_LYRA(7);
|
||||
ROUND_LYRA(8);
|
||||
ROUND_LYRA(9);
|
||||
ROUND_LYRA(10);
|
||||
ROUND_LYRA(11);
|
||||
ROUND_LYRA(0);
|
||||
ROUND_LYRA(1);
|
||||
ROUND_LYRA(2);
|
||||
ROUND_LYRA(3);
|
||||
ROUND_LYRA(4);
|
||||
ROUND_LYRA(5);
|
||||
ROUND_LYRA(6);
|
||||
ROUND_LYRA(7);
|
||||
ROUND_LYRA(8);
|
||||
ROUND_LYRA(9);
|
||||
ROUND_LYRA(10);
|
||||
ROUND_LYRA(11);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +75,7 @@ __inline static void blake2bLyra(uint64_t *v) {
|
||||
* @param v A 1024-bit (16 uint64_t) array to be processed by Blake2b's G function
|
||||
*/
|
||||
__inline static void reducedBlake2bLyra(uint64_t *v) {
|
||||
ROUND_LYRA(0);
|
||||
ROUND_LYRA(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,19 +86,20 @@ __inline static void reducedBlake2bLyra(uint64_t *v) {
|
||||
* @param out Array that will receive the data squeezed
|
||||
* @param len The number of bytes to be squeezed into the "out" array
|
||||
*/
|
||||
void squeeze(uint64_t *state, byte *out, unsigned int len) {
|
||||
int fullBlocks = len / BLOCK_LEN_BYTES;
|
||||
byte *ptr = out;
|
||||
int i;
|
||||
//Squeezes full blocks
|
||||
for (i = 0; i < fullBlocks; i++) {
|
||||
memcpy(ptr, state, BLOCK_LEN_BYTES);
|
||||
blake2bLyra(state);
|
||||
ptr += BLOCK_LEN_BYTES;
|
||||
}
|
||||
void squeeze(uint64_t *state, byte *out, unsigned int len)
|
||||
{
|
||||
int fullBlocks = len / BLOCK_LEN_BYTES;
|
||||
byte *ptr = out;
|
||||
int i;
|
||||
//Squeezes full blocks
|
||||
for (i = 0; i < fullBlocks; i++) {
|
||||
memcpy(ptr, state, BLOCK_LEN_BYTES);
|
||||
blake2bLyra(state);
|
||||
ptr += BLOCK_LEN_BYTES;
|
||||
}
|
||||
|
||||
//Squeezes remaining bytes
|
||||
memcpy(ptr, state, (len % BLOCK_LEN_BYTES));
|
||||
//Squeezes remaining bytes
|
||||
memcpy(ptr, state, (len % BLOCK_LEN_BYTES));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,23 +109,24 @@ __inline static void reducedBlake2bLyra(uint64_t *v) {
|
||||
* @param state The current state of the sponge
|
||||
* @param in The block to be absorbed (BLOCK_LEN_INT64 words)
|
||||
*/
|
||||
void absorbBlock(uint64_t *state, const uint64_t *in) {
|
||||
//XORs the first BLOCK_LEN_INT64 words of "in" with the current state
|
||||
state[0] ^= in[0];
|
||||
state[1] ^= in[1];
|
||||
state[2] ^= in[2];
|
||||
state[3] ^= in[3];
|
||||
state[4] ^= in[4];
|
||||
state[5] ^= in[5];
|
||||
state[6] ^= in[6];
|
||||
state[7] ^= in[7];
|
||||
state[8] ^= in[8];
|
||||
state[9] ^= in[9];
|
||||
state[10] ^= in[10];
|
||||
state[11] ^= in[11];
|
||||
void absorbBlock(uint64_t *state, const uint64_t *in)
|
||||
{
|
||||
//XORs the first BLOCK_LEN_INT64 words of "in" with the current state
|
||||
state[0] ^= in[0];
|
||||
state[1] ^= in[1];
|
||||
state[2] ^= in[2];
|
||||
state[3] ^= in[3];
|
||||
state[4] ^= in[4];
|
||||
state[5] ^= in[5];
|
||||
state[6] ^= in[6];
|
||||
state[7] ^= in[7];
|
||||
state[8] ^= in[8];
|
||||
state[9] ^= in[9];
|
||||
state[10] ^= in[10];
|
||||
state[11] ^= in[11];
|
||||
|
||||
//Applies the transformation f to the sponge's state
|
||||
blake2bLyra(state);
|
||||
//Applies the transformation f to the sponge's state
|
||||
blake2bLyra(state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,25 +136,21 @@ void absorbBlock(uint64_t *state, const uint64_t *in) {
|
||||
* @param state The current state of the sponge
|
||||
* @param in The block to be absorbed (BLOCK_LEN_BLAKE2_SAFE_INT64 words)
|
||||
*/
|
||||
void absorbBlockBlake2Safe(uint64_t *state, const uint64_t *in) {
|
||||
//XORs the first BLOCK_LEN_BLAKE2_SAFE_INT64 words of "in" with the current state
|
||||
state[0] ^= in[0];
|
||||
state[1] ^= in[1];
|
||||
state[2] ^= in[2];
|
||||
state[3] ^= in[3];
|
||||
state[4] ^= in[4];
|
||||
state[5] ^= in[5];
|
||||
state[6] ^= in[6];
|
||||
state[7] ^= in[7];
|
||||
void absorbBlockBlake2Safe(uint64_t *state, const uint64_t *in)
|
||||
{
|
||||
//XORs the first BLOCK_LEN_BLAKE2_SAFE_INT64 words of "in" with the current state
|
||||
|
||||
//Applies the transformation f to the sponge's state
|
||||
blake2bLyra(state);
|
||||
/*
|
||||
for(int i = 0; i<16; i++) {
|
||||
printf(" final state %d %08x %08x in %08x %08x\n", i, (uint32_t)(state[i] & 0xFFFFFFFFULL), (uint32_t)(state[i] >> 32),
|
||||
(uint32_t)(in[i] & 0xFFFFFFFFULL), (uint32_t)(in[i] >> 32));
|
||||
}
|
||||
*/
|
||||
state[0] ^= in[0];
|
||||
state[1] ^= in[1];
|
||||
state[2] ^= in[2];
|
||||
state[3] ^= in[3];
|
||||
state[4] ^= in[4];
|
||||
state[5] ^= in[5];
|
||||
state[6] ^= in[6];
|
||||
state[7] ^= in[7];
|
||||
|
||||
//Applies the transformation f to the sponge's state
|
||||
blake2bLyra(state);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,36 +161,31 @@ void absorbBlockBlake2Safe(uint64_t *state, const uint64_t *in) {
|
||||
* @param state The current state of the sponge
|
||||
* @param rowOut Row to receive the data squeezed
|
||||
*/
|
||||
void reducedSqueezeRow0(uint64_t* state, uint64_t* rowOut) {
|
||||
uint64_t* ptrWord = rowOut + (N_COLS-1)*BLOCK_LEN_INT64; //In Lyra2: pointer to M[0][C-1]
|
||||
int i;
|
||||
//M[row][C-1-col] = H.reduced_squeeze()
|
||||
for (i = 0; i < N_COLS; i++) {
|
||||
void reducedSqueezeRow0(uint64_t* state, uint64_t* rowOut, const uint32_t nCols)
|
||||
{
|
||||
uint64_t* ptrWord = rowOut + (nCols-1)*BLOCK_LEN_INT64; //In Lyra2: pointer to M[0][C-1]
|
||||
unsigned int i;
|
||||
//M[row][C-1-col] = H.reduced_squeeze()
|
||||
for (i = 0; i < nCols; i++) {
|
||||
ptrWord[0] = state[0];
|
||||
ptrWord[1] = state[1];
|
||||
ptrWord[2] = state[2];
|
||||
ptrWord[3] = state[3];
|
||||
ptrWord[4] = state[4];
|
||||
ptrWord[5] = state[5];
|
||||
ptrWord[6] = state[6];
|
||||
ptrWord[7] = state[7];
|
||||
ptrWord[8] = state[8];
|
||||
ptrWord[9] = state[9];
|
||||
ptrWord[10] = state[10];
|
||||
ptrWord[11] = state[11];
|
||||
|
||||
ptrWord[0] = state[0];
|
||||
ptrWord[1] = state[1];
|
||||
ptrWord[2] = state[2];
|
||||
ptrWord[3] = state[3];
|
||||
ptrWord[4] = state[4];
|
||||
ptrWord[5] = state[5];
|
||||
ptrWord[6] = state[6];
|
||||
ptrWord[7] = state[7];
|
||||
ptrWord[8] = state[8];
|
||||
ptrWord[9] = state[9];
|
||||
ptrWord[10] = state[10];
|
||||
ptrWord[11] = state[11];
|
||||
/*
|
||||
for (int i = 0; i<12; i++) {
|
||||
printf(" after reducedSqueezeRow0 %d %08x %08x in %08x %08x\n", i, (uint32_t)(ptrWord[i] & 0xFFFFFFFFULL), (uint32_t)(ptrWord[i] >> 32),
|
||||
(uint32_t)(state[i] & 0xFFFFFFFFULL), (uint32_t)(state[i] >> 32));
|
||||
//Goes to next block (column) that will receive the squeezed data
|
||||
ptrWord -= BLOCK_LEN_INT64;
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
}
|
||||
*/
|
||||
//Goes to next block (column) that will receive the squeezed data
|
||||
ptrWord -= BLOCK_LEN_INT64;
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,50 +197,50 @@ for (int i = 0; i<12; i++) {
|
||||
* @param rowIn Row to feed the sponge
|
||||
* @param rowOut Row to receive the sponge's output
|
||||
*/
|
||||
void reducedDuplexRow1(uint64_t *state, uint64_t *rowIn, uint64_t *rowOut) {
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordOut = rowOut + (N_COLS-1)*BLOCK_LEN_INT64; //In Lyra2: pointer to row
|
||||
int i;
|
||||
void reducedDuplexRow1(uint64_t *state, uint64_t *rowIn, uint64_t *rowOut, const uint32_t nCols)
|
||||
{
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordOut = rowOut + (nCols-1)*BLOCK_LEN_INT64; //In Lyra2: pointer to row
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < N_COLS; i++) {
|
||||
for (i = 0; i < nCols; i++) {
|
||||
|
||||
//Absorbing "M[prev][col]"
|
||||
state[0] ^= (ptrWordIn[0]);
|
||||
state[1] ^= (ptrWordIn[1]);
|
||||
state[2] ^= (ptrWordIn[2]);
|
||||
state[3] ^= (ptrWordIn[3]);
|
||||
state[4] ^= (ptrWordIn[4]);
|
||||
state[5] ^= (ptrWordIn[5]);
|
||||
state[6] ^= (ptrWordIn[6]);
|
||||
state[7] ^= (ptrWordIn[7]);
|
||||
state[8] ^= (ptrWordIn[8]);
|
||||
state[9] ^= (ptrWordIn[9]);
|
||||
state[10] ^= (ptrWordIn[10]);
|
||||
state[11] ^= (ptrWordIn[11]);
|
||||
//Absorbing "M[prev][col]"
|
||||
state[0] ^= (ptrWordIn[0]);
|
||||
state[1] ^= (ptrWordIn[1]);
|
||||
state[2] ^= (ptrWordIn[2]);
|
||||
state[3] ^= (ptrWordIn[3]);
|
||||
state[4] ^= (ptrWordIn[4]);
|
||||
state[5] ^= (ptrWordIn[5]);
|
||||
state[6] ^= (ptrWordIn[6]);
|
||||
state[7] ^= (ptrWordIn[7]);
|
||||
state[8] ^= (ptrWordIn[8]);
|
||||
state[9] ^= (ptrWordIn[9]);
|
||||
state[10] ^= (ptrWordIn[10]);
|
||||
state[11] ^= (ptrWordIn[11]);
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
|
||||
//M[row][C-1-col] = M[prev][col] XOR rand
|
||||
ptrWordOut[0] = ptrWordIn[0] ^ state[0];
|
||||
ptrWordOut[1] = ptrWordIn[1] ^ state[1];
|
||||
ptrWordOut[2] = ptrWordIn[2] ^ state[2];
|
||||
ptrWordOut[3] = ptrWordIn[3] ^ state[3];
|
||||
ptrWordOut[4] = ptrWordIn[4] ^ state[4];
|
||||
ptrWordOut[5] = ptrWordIn[5] ^ state[5];
|
||||
ptrWordOut[6] = ptrWordIn[6] ^ state[6];
|
||||
ptrWordOut[7] = ptrWordIn[7] ^ state[7];
|
||||
ptrWordOut[8] = ptrWordIn[8] ^ state[8];
|
||||
ptrWordOut[9] = ptrWordIn[9] ^ state[9];
|
||||
ptrWordOut[10] = ptrWordIn[10] ^ state[10];
|
||||
ptrWordOut[11] = ptrWordIn[11] ^ state[11];
|
||||
//M[row][C-1-col] = M[prev][col] XOR rand
|
||||
ptrWordOut[0] = ptrWordIn[0] ^ state[0];
|
||||
ptrWordOut[1] = ptrWordIn[1] ^ state[1];
|
||||
ptrWordOut[2] = ptrWordIn[2] ^ state[2];
|
||||
ptrWordOut[3] = ptrWordIn[3] ^ state[3];
|
||||
ptrWordOut[4] = ptrWordIn[4] ^ state[4];
|
||||
ptrWordOut[5] = ptrWordIn[5] ^ state[5];
|
||||
ptrWordOut[6] = ptrWordIn[6] ^ state[6];
|
||||
ptrWordOut[7] = ptrWordIn[7] ^ state[7];
|
||||
ptrWordOut[8] = ptrWordIn[8] ^ state[8];
|
||||
ptrWordOut[9] = ptrWordIn[9] ^ state[9];
|
||||
ptrWordOut[10] = ptrWordIn[10] ^ state[10];
|
||||
ptrWordOut[11] = ptrWordIn[11] ^ state[11];
|
||||
|
||||
|
||||
//Input: next column (i.e., next block in sequence)
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
//Output: goes to previous column
|
||||
ptrWordOut -= BLOCK_LEN_INT64;
|
||||
}
|
||||
//Input: next column (i.e., next block in sequence)
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
//Output: goes to previous column
|
||||
ptrWordOut -= BLOCK_LEN_INT64;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -267,63 +257,66 @@ for (int i = 0; i<12; i++) {
|
||||
* @param rowOut Row receiving the output
|
||||
*
|
||||
*/
|
||||
void reducedDuplexRowSetup(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut) {
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
|
||||
uint64_t* ptrWordOut = rowOut + (N_COLS-1)*BLOCK_LEN_INT64; //In Lyra2: pointer to row
|
||||
int i;
|
||||
for (i = 0; i < N_COLS; i++) {
|
||||
//Absorbing "M[prev] [+] M[row*]"
|
||||
state[0] ^= (ptrWordIn[0] + ptrWordInOut[0]);
|
||||
state[1] ^= (ptrWordIn[1] + ptrWordInOut[1]);
|
||||
state[2] ^= (ptrWordIn[2] + ptrWordInOut[2]);
|
||||
state[3] ^= (ptrWordIn[3] + ptrWordInOut[3]);
|
||||
state[4] ^= (ptrWordIn[4] + ptrWordInOut[4]);
|
||||
state[5] ^= (ptrWordIn[5] + ptrWordInOut[5]);
|
||||
state[6] ^= (ptrWordIn[6] + ptrWordInOut[6]);
|
||||
state[7] ^= (ptrWordIn[7] + ptrWordInOut[7]);
|
||||
state[8] ^= (ptrWordIn[8] + ptrWordInOut[8]);
|
||||
state[9] ^= (ptrWordIn[9] + ptrWordInOut[9]);
|
||||
state[10] ^= (ptrWordIn[10] + ptrWordInOut[10]);
|
||||
state[11] ^= (ptrWordIn[11] + ptrWordInOut[11]);
|
||||
void reducedDuplexRowSetup(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, const uint32_t nCols)
|
||||
{
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
|
||||
uint64_t* ptrWordOut = rowOut + (nCols-1)*BLOCK_LEN_INT64; //In Lyra2: pointer to row
|
||||
unsigned int i;
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
for (i = 0; i < nCols; i++) {
|
||||
|
||||
//M[row][col] = M[prev][col] XOR rand
|
||||
ptrWordOut[0] = ptrWordIn[0] ^ state[0];
|
||||
ptrWordOut[1] = ptrWordIn[1] ^ state[1];
|
||||
ptrWordOut[2] = ptrWordIn[2] ^ state[2];
|
||||
ptrWordOut[3] = ptrWordIn[3] ^ state[3];
|
||||
ptrWordOut[4] = ptrWordIn[4] ^ state[4];
|
||||
ptrWordOut[5] = ptrWordIn[5] ^ state[5];
|
||||
ptrWordOut[6] = ptrWordIn[6] ^ state[6];
|
||||
ptrWordOut[7] = ptrWordIn[7] ^ state[7];
|
||||
ptrWordOut[8] = ptrWordIn[8] ^ state[8];
|
||||
ptrWordOut[9] = ptrWordIn[9] ^ state[9];
|
||||
ptrWordOut[10] = ptrWordIn[10] ^ state[10];
|
||||
ptrWordOut[11] = ptrWordIn[11] ^ state[11];
|
||||
//Absorbing "M[prev] [+] M[row*]"
|
||||
state[0] ^= (ptrWordIn[0] + ptrWordInOut[0]);
|
||||
state[1] ^= (ptrWordIn[1] + ptrWordInOut[1]);
|
||||
state[2] ^= (ptrWordIn[2] + ptrWordInOut[2]);
|
||||
state[3] ^= (ptrWordIn[3] + ptrWordInOut[3]);
|
||||
state[4] ^= (ptrWordIn[4] + ptrWordInOut[4]);
|
||||
state[5] ^= (ptrWordIn[5] + ptrWordInOut[5]);
|
||||
state[6] ^= (ptrWordIn[6] + ptrWordInOut[6]);
|
||||
state[7] ^= (ptrWordIn[7] + ptrWordInOut[7]);
|
||||
state[8] ^= (ptrWordIn[8] + ptrWordInOut[8]);
|
||||
state[9] ^= (ptrWordIn[9] + ptrWordInOut[9]);
|
||||
state[10] ^= (ptrWordIn[10] + ptrWordInOut[10]);
|
||||
state[11] ^= (ptrWordIn[11] + ptrWordInOut[11]);
|
||||
|
||||
//M[row*][col] = M[row*][col] XOR rotW(rand)
|
||||
ptrWordInOut[0] ^= state[11];
|
||||
ptrWordInOut[1] ^= state[0];
|
||||
ptrWordInOut[2] ^= state[1];
|
||||
ptrWordInOut[3] ^= state[2];
|
||||
ptrWordInOut[4] ^= state[3];
|
||||
ptrWordInOut[5] ^= state[4];
|
||||
ptrWordInOut[6] ^= state[5];
|
||||
ptrWordInOut[7] ^= state[6];
|
||||
ptrWordInOut[8] ^= state[7];
|
||||
ptrWordInOut[9] ^= state[8];
|
||||
ptrWordInOut[10] ^= state[9];
|
||||
ptrWordInOut[11] ^= state[10];
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
|
||||
//Inputs: next column (i.e., next block in sequence)
|
||||
ptrWordInOut += BLOCK_LEN_INT64;
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
//Output: goes to previous column
|
||||
ptrWordOut -= BLOCK_LEN_INT64;
|
||||
}
|
||||
//M[row][col] = M[prev][col] XOR rand
|
||||
ptrWordOut[0] = ptrWordIn[0] ^ state[0];
|
||||
ptrWordOut[1] = ptrWordIn[1] ^ state[1];
|
||||
ptrWordOut[2] = ptrWordIn[2] ^ state[2];
|
||||
ptrWordOut[3] = ptrWordIn[3] ^ state[3];
|
||||
ptrWordOut[4] = ptrWordIn[4] ^ state[4];
|
||||
ptrWordOut[5] = ptrWordIn[5] ^ state[5];
|
||||
ptrWordOut[6] = ptrWordIn[6] ^ state[6];
|
||||
ptrWordOut[7] = ptrWordIn[7] ^ state[7];
|
||||
ptrWordOut[8] = ptrWordIn[8] ^ state[8];
|
||||
ptrWordOut[9] = ptrWordIn[9] ^ state[9];
|
||||
ptrWordOut[10] = ptrWordIn[10] ^ state[10];
|
||||
ptrWordOut[11] = ptrWordIn[11] ^ state[11];
|
||||
|
||||
//M[row*][col] = M[row*][col] XOR rotW(rand)
|
||||
ptrWordInOut[0] ^= state[11];
|
||||
ptrWordInOut[1] ^= state[0];
|
||||
ptrWordInOut[2] ^= state[1];
|
||||
ptrWordInOut[3] ^= state[2];
|
||||
ptrWordInOut[4] ^= state[3];
|
||||
ptrWordInOut[5] ^= state[4];
|
||||
ptrWordInOut[6] ^= state[5];
|
||||
ptrWordInOut[7] ^= state[6];
|
||||
ptrWordInOut[8] ^= state[7];
|
||||
ptrWordInOut[9] ^= state[8];
|
||||
ptrWordInOut[10] ^= state[9];
|
||||
ptrWordInOut[11] ^= state[10];
|
||||
|
||||
//Inputs: next column (i.e., next block in sequence)
|
||||
ptrWordInOut += BLOCK_LEN_INT64;
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
//Output: goes to previous column
|
||||
ptrWordOut -= BLOCK_LEN_INT64;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -340,410 +333,72 @@ for (int i = 0; i<12; i++) {
|
||||
* @param rowOut Row receiving the output
|
||||
*
|
||||
*/
|
||||
void reducedDuplexRow(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut) {
|
||||
uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordOut = rowOut; //In Lyra2: pointer to row
|
||||
int i;
|
||||
void reducedDuplexRow(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, const uint32_t nCols)
|
||||
{
|
||||
uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordOut = rowOut; //In Lyra2: pointer to row
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < N_COLS; i++) {
|
||||
for (i = 0; i < nCols; i++) {
|
||||
|
||||
//Absorbing "M[prev] [+] M[row*]"
|
||||
state[0] ^= (ptrWordIn[0] + ptrWordInOut[0]);
|
||||
state[1] ^= (ptrWordIn[1] + ptrWordInOut[1]);
|
||||
state[2] ^= (ptrWordIn[2] + ptrWordInOut[2]);
|
||||
state[3] ^= (ptrWordIn[3] + ptrWordInOut[3]);
|
||||
state[4] ^= (ptrWordIn[4] + ptrWordInOut[4]);
|
||||
state[5] ^= (ptrWordIn[5] + ptrWordInOut[5]);
|
||||
state[6] ^= (ptrWordIn[6] + ptrWordInOut[6]);
|
||||
state[7] ^= (ptrWordIn[7] + ptrWordInOut[7]);
|
||||
state[8] ^= (ptrWordIn[8] + ptrWordInOut[8]);
|
||||
state[9] ^= (ptrWordIn[9] + ptrWordInOut[9]);
|
||||
state[10] ^= (ptrWordIn[10] + ptrWordInOut[10]);
|
||||
state[11] ^= (ptrWordIn[11] + ptrWordInOut[11]);
|
||||
//Absorbing "M[prev] [+] M[row*]"
|
||||
state[0] ^= (ptrWordIn[0] + ptrWordInOut[0]);
|
||||
state[1] ^= (ptrWordIn[1] + ptrWordInOut[1]);
|
||||
state[2] ^= (ptrWordIn[2] + ptrWordInOut[2]);
|
||||
state[3] ^= (ptrWordIn[3] + ptrWordInOut[3]);
|
||||
state[4] ^= (ptrWordIn[4] + ptrWordInOut[4]);
|
||||
state[5] ^= (ptrWordIn[5] + ptrWordInOut[5]);
|
||||
state[6] ^= (ptrWordIn[6] + ptrWordInOut[6]);
|
||||
state[7] ^= (ptrWordIn[7] + ptrWordInOut[7]);
|
||||
state[8] ^= (ptrWordIn[8] + ptrWordInOut[8]);
|
||||
state[9] ^= (ptrWordIn[9] + ptrWordInOut[9]);
|
||||
state[10] ^= (ptrWordIn[10] + ptrWordInOut[10]);
|
||||
state[11] ^= (ptrWordIn[11] + ptrWordInOut[11]);
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
|
||||
//M[rowOut][col] = M[rowOut][col] XOR rand
|
||||
ptrWordOut[0] ^= state[0];
|
||||
ptrWordOut[1] ^= state[1];
|
||||
ptrWordOut[2] ^= state[2];
|
||||
ptrWordOut[3] ^= state[3];
|
||||
ptrWordOut[4] ^= state[4];
|
||||
ptrWordOut[5] ^= state[5];
|
||||
ptrWordOut[6] ^= state[6];
|
||||
ptrWordOut[7] ^= state[7];
|
||||
ptrWordOut[8] ^= state[8];
|
||||
ptrWordOut[9] ^= state[9];
|
||||
ptrWordOut[10] ^= state[10];
|
||||
ptrWordOut[11] ^= state[11];
|
||||
//M[rowOut][col] = M[rowOut][col] XOR rand
|
||||
ptrWordOut[0] ^= state[0];
|
||||
ptrWordOut[1] ^= state[1];
|
||||
ptrWordOut[2] ^= state[2];
|
||||
ptrWordOut[3] ^= state[3];
|
||||
ptrWordOut[4] ^= state[4];
|
||||
ptrWordOut[5] ^= state[5];
|
||||
ptrWordOut[6] ^= state[6];
|
||||
ptrWordOut[7] ^= state[7];
|
||||
ptrWordOut[8] ^= state[8];
|
||||
ptrWordOut[9] ^= state[9];
|
||||
ptrWordOut[10] ^= state[10];
|
||||
ptrWordOut[11] ^= state[11];
|
||||
|
||||
//M[rowInOut][col] = M[rowInOut][col] XOR rotW(rand)
|
||||
ptrWordInOut[0] ^= state[11];
|
||||
ptrWordInOut[1] ^= state[0];
|
||||
ptrWordInOut[2] ^= state[1];
|
||||
ptrWordInOut[3] ^= state[2];
|
||||
ptrWordInOut[4] ^= state[3];
|
||||
ptrWordInOut[5] ^= state[4];
|
||||
ptrWordInOut[6] ^= state[5];
|
||||
ptrWordInOut[7] ^= state[6];
|
||||
ptrWordInOut[8] ^= state[7];
|
||||
ptrWordInOut[9] ^= state[8];
|
||||
ptrWordInOut[10] ^= state[9];
|
||||
ptrWordInOut[11] ^= state[10];
|
||||
//M[rowInOut][col] = M[rowInOut][col] XOR rotW(rand)
|
||||
ptrWordInOut[0] ^= state[11];
|
||||
ptrWordInOut[1] ^= state[0];
|
||||
ptrWordInOut[2] ^= state[1];
|
||||
ptrWordInOut[3] ^= state[2];
|
||||
ptrWordInOut[4] ^= state[3];
|
||||
ptrWordInOut[5] ^= state[4];
|
||||
ptrWordInOut[6] ^= state[5];
|
||||
ptrWordInOut[7] ^= state[6];
|
||||
ptrWordInOut[8] ^= state[7];
|
||||
ptrWordInOut[9] ^= state[8];
|
||||
ptrWordInOut[10] ^= state[9];
|
||||
ptrWordInOut[11] ^= state[10];
|
||||
|
||||
//Goes to next block
|
||||
ptrWordOut += BLOCK_LEN_INT64;
|
||||
ptrWordInOut += BLOCK_LEN_INT64;
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
}
|
||||
//Goes to next block
|
||||
ptrWordOut += BLOCK_LEN_INT64;
|
||||
ptrWordInOut += BLOCK_LEN_INT64;
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Performs a duplex operation over "M[rowInOut] [+] M[rowIn]", writing the output "rand"
|
||||
* on M[rowOut] and making "M[rowInOut] = M[rowInOut] XOR rotW(rand)", where rotW is a 64-bit
|
||||
* rotation to the left.
|
||||
*
|
||||
* @param state The current state of the sponge
|
||||
* @param rowIn Row used only as input
|
||||
* @param rowInOut Row used as input and to receive output after rotation
|
||||
* @param rowOut Row receiving the output
|
||||
*
|
||||
* Prints an array of unsigned chars
|
||||
*/
|
||||
/*
|
||||
inline void reducedDuplexRowSetupOLD(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut) {
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
|
||||
uint64_t* ptrWordOut = rowOut; //In Lyra2: pointer to row
|
||||
int i;
|
||||
for (i = 0; i < N_COLS; i++) {
|
||||
|
||||
//Absorbing "M[rowInOut] XOR M[rowIn]"
|
||||
state[0] ^= ptrWordInOut[0] ^ ptrWordIn[0];
|
||||
state[1] ^= ptrWordInOut[1] ^ ptrWordIn[1];
|
||||
state[2] ^= ptrWordInOut[2] ^ ptrWordIn[2];
|
||||
state[3] ^= ptrWordInOut[3] ^ ptrWordIn[3];
|
||||
state[4] ^= ptrWordInOut[4] ^ ptrWordIn[4];
|
||||
state[5] ^= ptrWordInOut[5] ^ ptrWordIn[5];
|
||||
state[6] ^= ptrWordInOut[6] ^ ptrWordIn[6];
|
||||
state[7] ^= ptrWordInOut[7] ^ ptrWordIn[7];
|
||||
state[8] ^= ptrWordInOut[8] ^ ptrWordIn[8];
|
||||
state[9] ^= ptrWordInOut[9] ^ ptrWordIn[9];
|
||||
state[10] ^= ptrWordInOut[10] ^ ptrWordIn[10];
|
||||
state[11] ^= ptrWordInOut[11] ^ ptrWordIn[11];
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
|
||||
//M[row][col] = rand
|
||||
ptrWordOut[0] = state[0];
|
||||
ptrWordOut[1] = state[1];
|
||||
ptrWordOut[2] = state[2];
|
||||
ptrWordOut[3] = state[3];
|
||||
ptrWordOut[4] = state[4];
|
||||
ptrWordOut[5] = state[5];
|
||||
ptrWordOut[6] = state[6];
|
||||
ptrWordOut[7] = state[7];
|
||||
ptrWordOut[8] = state[8];
|
||||
ptrWordOut[9] = state[9];
|
||||
ptrWordOut[10] = state[10];
|
||||
ptrWordOut[11] = state[11];
|
||||
|
||||
|
||||
//M[row*][col] = M[row*][col] XOR rotW(rand)
|
||||
ptrWordInOut[0] ^= state[10];
|
||||
ptrWordInOut[1] ^= state[11];
|
||||
ptrWordInOut[2] ^= state[0];
|
||||
ptrWordInOut[3] ^= state[1];
|
||||
ptrWordInOut[4] ^= state[2];
|
||||
ptrWordInOut[5] ^= state[3];
|
||||
ptrWordInOut[6] ^= state[4];
|
||||
ptrWordInOut[7] ^= state[5];
|
||||
ptrWordInOut[8] ^= state[6];
|
||||
ptrWordInOut[9] ^= state[7];
|
||||
ptrWordInOut[10] ^= state[8];
|
||||
ptrWordInOut[11] ^= state[9];
|
||||
|
||||
//Goes to next column (i.e., next block in sequence)
|
||||
ptrWordInOut += BLOCK_LEN_INT64;
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
ptrWordOut += BLOCK_LEN_INT64;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Performs a duplex operation over "M[rowInOut] XOR M[rowIn]", writing the output "rand"
|
||||
* on M[rowOut] and making "M[rowInOut] = M[rowInOut] XOR rotW(rand)", where rotW is a 64-bit
|
||||
* rotation to the left.
|
||||
*
|
||||
* @param state The current state of the sponge
|
||||
* @param rowIn Row used only as input
|
||||
* @param rowInOut Row used as input and to receive output after rotation
|
||||
* @param rowOut Row receiving the output
|
||||
*
|
||||
*/
|
||||
/*
|
||||
inline void reducedDuplexRowSetupv5(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut) {
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
|
||||
uint64_t* ptrWordOut = rowOut; //In Lyra2: pointer to row
|
||||
int i;
|
||||
for (i = 0; i < N_COLS; i++) {
|
||||
|
||||
//Absorbing "M[rowInOut] XOR M[rowIn]"
|
||||
state[0] ^= ptrWordInOut[0] + ptrWordIn[0];
|
||||
state[1] ^= ptrWordInOut[1] + ptrWordIn[1];
|
||||
state[2] ^= ptrWordInOut[2] + ptrWordIn[2];
|
||||
state[3] ^= ptrWordInOut[3] + ptrWordIn[3];
|
||||
state[4] ^= ptrWordInOut[4] + ptrWordIn[4];
|
||||
state[5] ^= ptrWordInOut[5] + ptrWordIn[5];
|
||||
state[6] ^= ptrWordInOut[6] + ptrWordIn[6];
|
||||
state[7] ^= ptrWordInOut[7] + ptrWordIn[7];
|
||||
state[8] ^= ptrWordInOut[8] + ptrWordIn[8];
|
||||
state[9] ^= ptrWordInOut[9] + ptrWordIn[9];
|
||||
state[10] ^= ptrWordInOut[10] + ptrWordIn[10];
|
||||
state[11] ^= ptrWordInOut[11] + ptrWordIn[11];
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
|
||||
|
||||
//M[row*][col] = M[row*][col] XOR rotW(rand)
|
||||
ptrWordInOut[0] ^= state[10];
|
||||
ptrWordInOut[1] ^= state[11];
|
||||
ptrWordInOut[2] ^= state[0];
|
||||
ptrWordInOut[3] ^= state[1];
|
||||
ptrWordInOut[4] ^= state[2];
|
||||
ptrWordInOut[5] ^= state[3];
|
||||
ptrWordInOut[6] ^= state[4];
|
||||
ptrWordInOut[7] ^= state[5];
|
||||
ptrWordInOut[8] ^= state[6];
|
||||
ptrWordInOut[9] ^= state[7];
|
||||
ptrWordInOut[10] ^= state[8];
|
||||
ptrWordInOut[11] ^= state[9];
|
||||
|
||||
|
||||
//M[row][col] = rand
|
||||
ptrWordOut[0] = state[0] ^ ptrWordIn[0];
|
||||
ptrWordOut[1] = state[1] ^ ptrWordIn[1];
|
||||
ptrWordOut[2] = state[2] ^ ptrWordIn[2];
|
||||
ptrWordOut[3] = state[3] ^ ptrWordIn[3];
|
||||
ptrWordOut[4] = state[4] ^ ptrWordIn[4];
|
||||
ptrWordOut[5] = state[5] ^ ptrWordIn[5];
|
||||
ptrWordOut[6] = state[6] ^ ptrWordIn[6];
|
||||
ptrWordOut[7] = state[7] ^ ptrWordIn[7];
|
||||
ptrWordOut[8] = state[8] ^ ptrWordIn[8];
|
||||
ptrWordOut[9] = state[9] ^ ptrWordIn[9];
|
||||
ptrWordOut[10] = state[10] ^ ptrWordIn[10];
|
||||
ptrWordOut[11] = state[11] ^ ptrWordIn[11];
|
||||
|
||||
//Goes to next column (i.e., next block in sequence)
|
||||
ptrWordInOut += BLOCK_LEN_INT64;
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
ptrWordOut += BLOCK_LEN_INT64;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Performs a duplex operation over "M[rowInOut] XOR M[rowIn]", writing the output "rand"
|
||||
* on M[rowOut] and making "M[rowInOut] = M[rowInOut] XOR rotW(rand)", where rotW is a 64-bit
|
||||
* rotation to the left.
|
||||
*
|
||||
* @param state The current state of the sponge
|
||||
* @param rowIn Row used only as input
|
||||
* @param rowInOut Row used as input and to receive output after rotation
|
||||
* @param rowOut Row receiving the output
|
||||
*
|
||||
*/
|
||||
/*
|
||||
inline void reducedDuplexRowSetupv5c(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut) {
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
|
||||
uint64_t* ptrWordOut = rowOut;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < N_COLS / 2; i++) {
|
||||
//Absorbing "M[rowInOut] XOR M[rowIn]"
|
||||
state[0] ^= ptrWordInOut[0] + ptrWordIn[0];
|
||||
state[1] ^= ptrWordInOut[1] + ptrWordIn[1];
|
||||
state[2] ^= ptrWordInOut[2] + ptrWordIn[2];
|
||||
state[3] ^= ptrWordInOut[3] + ptrWordIn[3];
|
||||
state[4] ^= ptrWordInOut[4] + ptrWordIn[4];
|
||||
state[5] ^= ptrWordInOut[5] + ptrWordIn[5];
|
||||
state[6] ^= ptrWordInOut[6] + ptrWordIn[6];
|
||||
state[7] ^= ptrWordInOut[7] + ptrWordIn[7];
|
||||
state[8] ^= ptrWordInOut[8] + ptrWordIn[8];
|
||||
state[9] ^= ptrWordInOut[9] + ptrWordIn[9];
|
||||
state[10] ^= ptrWordInOut[10] + ptrWordIn[10];
|
||||
state[11] ^= ptrWordInOut[11] + ptrWordIn[11];
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
|
||||
|
||||
//M[row*][col] = M[row*][col] XOR rotW(rand)
|
||||
ptrWordInOut[0] ^= state[10];
|
||||
ptrWordInOut[1] ^= state[11];
|
||||
ptrWordInOut[2] ^= state[0];
|
||||
ptrWordInOut[3] ^= state[1];
|
||||
ptrWordInOut[4] ^= state[2];
|
||||
ptrWordInOut[5] ^= state[3];
|
||||
ptrWordInOut[6] ^= state[4];
|
||||
ptrWordInOut[7] ^= state[5];
|
||||
ptrWordInOut[8] ^= state[6];
|
||||
ptrWordInOut[9] ^= state[7];
|
||||
ptrWordInOut[10] ^= state[8];
|
||||
ptrWordInOut[11] ^= state[9];
|
||||
|
||||
|
||||
//M[row][col] = rand
|
||||
ptrWordOut[0] = state[0] ^ ptrWordIn[0];
|
||||
ptrWordOut[1] = state[1] ^ ptrWordIn[1];
|
||||
ptrWordOut[2] = state[2] ^ ptrWordIn[2];
|
||||
ptrWordOut[3] = state[3] ^ ptrWordIn[3];
|
||||
ptrWordOut[4] = state[4] ^ ptrWordIn[4];
|
||||
ptrWordOut[5] = state[5] ^ ptrWordIn[5];
|
||||
ptrWordOut[6] = state[6] ^ ptrWordIn[6];
|
||||
ptrWordOut[7] = state[7] ^ ptrWordIn[7];
|
||||
ptrWordOut[8] = state[8] ^ ptrWordIn[8];
|
||||
ptrWordOut[9] = state[9] ^ ptrWordIn[9];
|
||||
ptrWordOut[10] = state[10] ^ ptrWordIn[10];
|
||||
ptrWordOut[11] = state[11] ^ ptrWordIn[11];
|
||||
|
||||
//Goes to next column (i.e., next block in sequence)
|
||||
ptrWordInOut += BLOCK_LEN_INT64;
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
ptrWordOut += 2 * BLOCK_LEN_INT64;
|
||||
}
|
||||
|
||||
ptrWordOut = rowOut + BLOCK_LEN_INT64;
|
||||
for (i = 0; i < N_COLS / 2; i++) {
|
||||
//Absorbing "M[rowInOut] XOR M[rowIn]"
|
||||
state[0] ^= ptrWordInOut[0] + ptrWordIn[0];
|
||||
state[1] ^= ptrWordInOut[1] + ptrWordIn[1];
|
||||
state[2] ^= ptrWordInOut[2] + ptrWordIn[2];
|
||||
state[3] ^= ptrWordInOut[3] + ptrWordIn[3];
|
||||
state[4] ^= ptrWordInOut[4] + ptrWordIn[4];
|
||||
state[5] ^= ptrWordInOut[5] + ptrWordIn[5];
|
||||
state[6] ^= ptrWordInOut[6] + ptrWordIn[6];
|
||||
state[7] ^= ptrWordInOut[7] + ptrWordIn[7];
|
||||
state[8] ^= ptrWordInOut[8] + ptrWordIn[8];
|
||||
state[9] ^= ptrWordInOut[9] + ptrWordIn[9];
|
||||
state[10] ^= ptrWordInOut[10] + ptrWordIn[10];
|
||||
state[11] ^= ptrWordInOut[11] + ptrWordIn[11];
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
|
||||
|
||||
//M[row*][col] = M[row*][col] XOR rotW(rand)
|
||||
ptrWordInOut[0] ^= state[10];
|
||||
ptrWordInOut[1] ^= state[11];
|
||||
ptrWordInOut[2] ^= state[0];
|
||||
ptrWordInOut[3] ^= state[1];
|
||||
ptrWordInOut[4] ^= state[2];
|
||||
ptrWordInOut[5] ^= state[3];
|
||||
ptrWordInOut[6] ^= state[4];
|
||||
ptrWordInOut[7] ^= state[5];
|
||||
ptrWordInOut[8] ^= state[6];
|
||||
ptrWordInOut[9] ^= state[7];
|
||||
ptrWordInOut[10] ^= state[8];
|
||||
ptrWordInOut[11] ^= state[9];
|
||||
|
||||
|
||||
//M[row][col] = rand
|
||||
ptrWordOut[0] = state[0] ^ ptrWordIn[0];
|
||||
ptrWordOut[1] = state[1] ^ ptrWordIn[1];
|
||||
ptrWordOut[2] = state[2] ^ ptrWordIn[2];
|
||||
ptrWordOut[3] = state[3] ^ ptrWordIn[3];
|
||||
ptrWordOut[4] = state[4] ^ ptrWordIn[4];
|
||||
ptrWordOut[5] = state[5] ^ ptrWordIn[5];
|
||||
ptrWordOut[6] = state[6] ^ ptrWordIn[6];
|
||||
ptrWordOut[7] = state[7] ^ ptrWordIn[7];
|
||||
ptrWordOut[8] = state[8] ^ ptrWordIn[8];
|
||||
ptrWordOut[9] = state[9] ^ ptrWordIn[9];
|
||||
ptrWordOut[10] = state[10] ^ ptrWordIn[10];
|
||||
ptrWordOut[11] = state[11] ^ ptrWordIn[11];
|
||||
|
||||
//Goes to next column (i.e., next block in sequence)
|
||||
ptrWordInOut += BLOCK_LEN_INT64;
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
ptrWordOut += 2 * BLOCK_LEN_INT64;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Performs a duplex operation over "M[rowInOut] XOR M[rowIn]", using the output "rand"
|
||||
* to make "M[rowOut][col] = M[rowOut][col] XOR rand" and "M[rowInOut] = M[rowInOut] XOR rotW(rand)",
|
||||
* where rotW is a 64-bit rotation to the left.
|
||||
*
|
||||
* @param state The current state of the sponge
|
||||
* @param rowIn Row used only as input
|
||||
* @param rowInOut Row used as input and to receive output after rotation
|
||||
* @param rowOut Row receiving the output
|
||||
*
|
||||
*/
|
||||
/*
|
||||
inline void reducedDuplexRowd(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut) {
|
||||
uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
|
||||
uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
|
||||
uint64_t* ptrWordOut = rowOut; //In Lyra2: pointer to row
|
||||
int i;
|
||||
for (i = 0; i < N_COLS; i++) {
|
||||
|
||||
//Absorbing "M[rowInOut] XOR M[rowIn]"
|
||||
state[0] ^= ptrWordInOut[0] + ptrWordIn[0];
|
||||
state[1] ^= ptrWordInOut[1] + ptrWordIn[1];
|
||||
state[2] ^= ptrWordInOut[2] + ptrWordIn[2];
|
||||
state[3] ^= ptrWordInOut[3] + ptrWordIn[3];
|
||||
state[4] ^= ptrWordInOut[4] + ptrWordIn[4];
|
||||
state[5] ^= ptrWordInOut[5] + ptrWordIn[5];
|
||||
state[6] ^= ptrWordInOut[6] + ptrWordIn[6];
|
||||
state[7] ^= ptrWordInOut[7] + ptrWordIn[7];
|
||||
state[8] ^= ptrWordInOut[8] + ptrWordIn[8];
|
||||
state[9] ^= ptrWordInOut[9] + ptrWordIn[9];
|
||||
state[10] ^= ptrWordInOut[10] + ptrWordIn[10];
|
||||
state[11] ^= ptrWordInOut[11] + ptrWordIn[11];
|
||||
|
||||
//Applies the reduced-round transformation f to the sponge's state
|
||||
reducedBlake2bLyra(state);
|
||||
|
||||
//M[rowOut][col] = M[rowOut][col] XOR rand
|
||||
ptrWordOut[0] ^= state[0];
|
||||
ptrWordOut[1] ^= state[1];
|
||||
ptrWordOut[2] ^= state[2];
|
||||
ptrWordOut[3] ^= state[3];
|
||||
ptrWordOut[4] ^= state[4];
|
||||
ptrWordOut[5] ^= state[5];
|
||||
ptrWordOut[6] ^= state[6];
|
||||
ptrWordOut[7] ^= state[7];
|
||||
ptrWordOut[8] ^= state[8];
|
||||
ptrWordOut[9] ^= state[9];
|
||||
ptrWordOut[10] ^= state[10];
|
||||
ptrWordOut[11] ^= state[11];
|
||||
|
||||
//M[rowInOut][col] = M[rowInOut][col] XOR rotW(rand)
|
||||
|
||||
|
||||
//Goes to next block
|
||||
ptrWordOut += BLOCK_LEN_INT64;
|
||||
ptrWordInOut += BLOCK_LEN_INT64;
|
||||
ptrWordIn += BLOCK_LEN_INT64;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
Prints an array of unsigned chars
|
||||
*/
|
||||
void printArray(unsigned char *array, unsigned int size, char *name) {
|
||||
void printArray(unsigned char *array, unsigned int size, char *name)
|
||||
{
|
||||
unsigned int i;
|
||||
printf("%s: ", name);
|
||||
for (i = 0; i < size; i++) {
|
||||
|
||||
+35
-55
@@ -24,85 +24,65 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define ALIGN __attribute__ ((aligned(32)))
|
||||
#elif defined(_MSC_VER)
|
||||
#define ALIGN __declspec(align(32))
|
||||
#else
|
||||
#define ALIGN
|
||||
#endif
|
||||
|
||||
|
||||
/*Blake2b IV Array*/
|
||||
/* Blake2b IV Array */
|
||||
static const uint64_t blake2b_IV[8] =
|
||||
{
|
||||
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
|
||||
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
|
||||
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
|
||||
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
|
||||
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
|
||||
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
|
||||
};
|
||||
|
||||
/*Blake2b's rotation*/
|
||||
static __inline uint64_t rotr64( const uint64_t w, const unsigned c ){
|
||||
return ( w >> c ) | ( w << ( 64 - c ) );
|
||||
/* Blake2b's rotation */
|
||||
static __inline uint64_t rotr64(const uint64_t w, const unsigned c) {
|
||||
#ifdef _MSC_VER
|
||||
return _rotr64(w, c);
|
||||
#else
|
||||
return ( w >> c ) | ( w << ( 64 - c ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
/*Blake2b's G function*/
|
||||
#define G(r,i,a,b,c,d) \
|
||||
do { \
|
||||
a = a + b; \
|
||||
d = rotr64(d ^ a, 32); \
|
||||
c = c + d; \
|
||||
b = rotr64(b ^ c, 24); \
|
||||
a = a + b; \
|
||||
d = rotr64(d ^ a, 16); \
|
||||
c = c + d; \
|
||||
b = rotr64(b ^ c, 63); \
|
||||
/* Blake2b's G function */
|
||||
#define G(r,i,a,b,c,d) do { \
|
||||
a = a + b; \
|
||||
d = rotr64(d ^ a, 32); \
|
||||
c = c + d; \
|
||||
b = rotr64(b ^ c, 24); \
|
||||
a = a + b; \
|
||||
d = rotr64(d ^ a, 16); \
|
||||
c = c + d; \
|
||||
b = rotr64(b ^ c, 63); \
|
||||
} while(0)
|
||||
|
||||
|
||||
/*One Round of the Blake2b's compression function*/
|
||||
#define ROUND_LYRA(r) \
|
||||
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
|
||||
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
|
||||
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
|
||||
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
|
||||
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
|
||||
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
|
||||
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
|
||||
G(r,7,v[ 3],v[ 4],v[ 9],v[14]);
|
||||
|
||||
#define ROUND_LYRA(r) \
|
||||
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
|
||||
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
|
||||
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
|
||||
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
|
||||
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
|
||||
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
|
||||
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
|
||||
G(r,7,v[ 3],v[ 4],v[ 9],v[14]);
|
||||
|
||||
//---- Housekeeping
|
||||
void initState(uint64_t state[/*16*/]);
|
||||
|
||||
//---- Squeezes
|
||||
void squeeze(uint64_t *state, unsigned char *out, unsigned int len);
|
||||
void reducedSqueezeRow0(uint64_t* state, uint64_t* row);
|
||||
void reducedSqueezeRow0(uint64_t* state, uint64_t* row, const uint32_t nCols);
|
||||
|
||||
//---- Absorbs
|
||||
void absorbBlock(uint64_t *state, const uint64_t *in);
|
||||
void absorbBlockBlake2Safe(uint64_t *state, const uint64_t *in);
|
||||
|
||||
//---- Duplexes
|
||||
void reducedDuplexRow1(uint64_t *state, uint64_t *rowIn, uint64_t *rowOut);
|
||||
void reducedDuplexRowSetup(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
|
||||
void reducedDuplexRow(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
|
||||
void reducedDuplexRow1(uint64_t *state, uint64_t *rowIn, uint64_t *rowOut, const uint32_t nCols);
|
||||
void reducedDuplexRowSetup(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, const uint32_t nCols);
|
||||
void reducedDuplexRow(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, const uint32_t nCols);
|
||||
|
||||
//---- Misc
|
||||
void printArray(unsigned char *array, unsigned int size, char *name);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////TESTS////
|
||||
//void reducedDuplexRowc(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
|
||||
//void reducedDuplexRowd(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
|
||||
//void reducedDuplexRowSetupv4(uint64_t *state, uint64_t *rowIn1, uint64_t *rowIn2, uint64_t *rowOut1, uint64_t *rowOut2);
|
||||
//void reducedDuplexRowSetupv5(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
|
||||
//void reducedDuplexRowSetupv5c(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
|
||||
//void reducedDuplexRowSetupv5d(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
|
||||
/////////////
|
||||
|
||||
|
||||
#endif /* SPONGE_H_ */
|
||||
@@ -0,0 +1,582 @@
|
||||
/* DJM CRAP to strip (again) made for SM 3.2+ */
|
||||
|
||||
#ifndef CUDA_LYRA_VECTOR_H
|
||||
#define CUDA_LYRA_VECTOR_H
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
#if (defined(_MSC_VER) && defined(_WIN64)) || defined(__LP64__)
|
||||
#define __LDG_PTR "l"
|
||||
#else
|
||||
#define __LDG_PTR "r"
|
||||
#endif
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#if __CUDA_ARCH__ < 320 && !defined(__ldg4)
|
||||
#define __ldg4(x) (*(x))
|
||||
#endif
|
||||
|
||||
typedef struct __align__(32) uint8 {
|
||||
unsigned int s0, s1, s2, s3, s4, s5, s6, s7;
|
||||
} uint8;
|
||||
|
||||
typedef struct __align__(64) uint2_8 {
|
||||
uint2 s0, s1, s2, s3, s4, s5, s6, s7;
|
||||
} uint2_8;
|
||||
|
||||
typedef struct __align__(64) ulonglong2to8 {
|
||||
ulonglong2 l0,l1,l2,l3;
|
||||
} ulonglong2to8;
|
||||
|
||||
typedef struct __align__(128) ulonglong8to16 {
|
||||
ulonglong2to8 lo, hi;
|
||||
} ulonglong8to16;
|
||||
|
||||
typedef struct __align__(256) ulonglong16to32 {
|
||||
ulonglong8to16 lo, hi;
|
||||
} ulonglong16to32;
|
||||
|
||||
typedef struct __align__(512) ulonglong32to64 {
|
||||
ulonglong16to32 lo, hi;
|
||||
} ulonglong32to64;
|
||||
|
||||
typedef struct __align__(128) ulonglonglong {
|
||||
ulonglong2 s0,s1,s2,s3,s4,s5,s6,s7;
|
||||
} ulonglonglong;
|
||||
|
||||
typedef struct __align__(64) uint16 {
|
||||
union {
|
||||
struct {unsigned int s0, s1, s2, s3, s4, s5, s6, s7;};
|
||||
uint8 lo;
|
||||
};
|
||||
union {
|
||||
struct {unsigned int s8, s9, sa, sb, sc, sd, se, sf;};
|
||||
uint8 hi;
|
||||
};
|
||||
} uint16;
|
||||
|
||||
typedef struct __align__(128) uint2_16 {
|
||||
union {
|
||||
struct { uint2 s0, s1, s2, s3, s4, s5, s6, s7; };
|
||||
uint2_8 lo;
|
||||
};
|
||||
union {
|
||||
struct { uint2 s8, s9, sa, sb, sc, sd, se, sf; };
|
||||
uint2_8 hi;
|
||||
};
|
||||
} uint2_16;
|
||||
|
||||
typedef struct __align__(128) uint32 {
|
||||
uint16 lo,hi;
|
||||
} uint32;
|
||||
|
||||
struct __align__(128) ulong8 {
|
||||
ulonglong4 s0, s1, s2, s3;
|
||||
};
|
||||
typedef __device_builtin__ struct ulong8 ulong8;
|
||||
|
||||
typedef struct __align__(256) ulonglong16 {
|
||||
ulonglong4 s0, s1, s2, s3, s4, s5, s6, s7;
|
||||
} ulonglong16;
|
||||
|
||||
typedef struct __align__(16) uint28 {
|
||||
uint2 x, y, z, w;
|
||||
} uint28;
|
||||
|
||||
typedef struct __builtin_align__(32) uint48 {
|
||||
uint4 s0,s1;
|
||||
} uint48;
|
||||
|
||||
typedef struct __align__(256) uint4x16 {
|
||||
uint4 s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15;
|
||||
} uint4x16;
|
||||
|
||||
static __inline__ __device__ ulonglong2to8 make_ulonglong2to8(ulonglong2 s0, ulonglong2 s1, ulonglong2 s2, ulonglong2 s3)
|
||||
{
|
||||
ulonglong2to8 t; t.l0=s0; t.l1=s1; t.l2=s2; t.l3=s3;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __device__ ulonglong8to16 make_ulonglong8to16(const ulonglong2to8 &s0, const ulonglong2to8 &s1)
|
||||
{
|
||||
ulonglong8to16 t; t.lo = s0; t.hi = s1;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __device__ ulonglong16to32 make_ulonglong16to32(const ulonglong8to16 &s0, const ulonglong8to16 &s1)
|
||||
{
|
||||
ulonglong16to32 t; t.lo = s0; t.hi = s1;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __device__ ulonglong32to64 make_ulonglong32to64(const ulonglong16to32 &s0, const ulonglong16to32 &s1)
|
||||
{
|
||||
ulonglong32to64 t; t.lo = s0; t.hi = s1;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __host__ __device__ ulonglonglong make_ulonglonglong(
|
||||
const ulonglong2 &s0, const ulonglong2 &s1, const ulonglong2 &s2, const ulonglong2 &s3,
|
||||
const ulonglong2 &s4, const ulonglong2 &s5)
|
||||
{
|
||||
ulonglonglong t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3; t.s4 = s4; t.s5 = s5;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __device__ uint48 make_uint48(uint4 s0, uint4 s1)
|
||||
{
|
||||
uint48 t; t.s0 = s0; t.s1 = s1;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __device__ uint28 make_uint28(uint2 s0, uint2 s1, uint2 s2, uint2 s3)
|
||||
{
|
||||
uint28 t; t.x = s0; t.y = s1; t.z = s2; t.w = s3;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __host__ __device__ uint4x16 make_uint4x16(
|
||||
uint4 s0, uint4 s1, uint4 s2, uint4 s3, uint4 s4, uint4 s5, uint4 s6, uint4 s7,
|
||||
uint4 s8, uint4 s9, uint4 sa, uint4 sb, uint4 sc, uint4 sd, uint4 se, uint4 sf)
|
||||
{
|
||||
uint4x16 t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3; t.s4 = s4; t.s5 = s5; t.s6 = s6; t.s7 = s7;
|
||||
t.s8 = s8; t.s9 = s9; t.s10 = sa; t.s11 = sb; t.s12 = sc; t.s13 = sd; t.s14 = se; t.s15 = sf;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __device__ uint2_16 make_uint2_16(
|
||||
uint2 s0, uint2 s1, uint2 s2, uint2 s3, uint2 s4, uint2 s5, uint2 s6, uint2 s7,
|
||||
uint2 s8, uint2 s9, uint2 sa, uint2 sb, uint2 sc, uint2 sd, uint2 se, uint2 sf)
|
||||
{
|
||||
uint2_16 t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3; t.s4 = s4; t.s5 = s5; t.s6 = s6; t.s7 = s7;
|
||||
t.s8 = s8; t.s9 = s9; t.sa = sa; t.sb = sb; t.sc = sc; t.sd = sd; t.se = se; t.sf = sf;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __host__ __device__ uint16 make_uint16(
|
||||
unsigned int s0, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4, unsigned int s5, unsigned int s6, unsigned int s7,
|
||||
unsigned int s8, unsigned int s9, unsigned int sa, unsigned int sb, unsigned int sc, unsigned int sd, unsigned int se, unsigned int sf)
|
||||
{
|
||||
uint16 t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3; t.s4 = s4; t.s5 = s5; t.s6 = s6; t.s7 = s7;
|
||||
t.s8 = s8; t.s9 = s9; t.sa = sa; t.sb = sb; t.sc = sc; t.sd = sd; t.se = se; t.sf = sf;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __host__ __device__ uint16 make_uint16(const uint8 &a, const uint8 &b)
|
||||
{
|
||||
uint16 t; t.lo=a; t.hi=b; return t;
|
||||
}
|
||||
|
||||
static __inline__ __host__ __device__ uint32 make_uint32(const uint16 &a, const uint16 &b)
|
||||
{
|
||||
uint32 t; t.lo = a; t.hi = b; return t;
|
||||
}
|
||||
|
||||
|
||||
static __inline__ __host__ __device__ uint8 make_uint8(
|
||||
unsigned int s0, unsigned int s1, unsigned int s2, unsigned int s3, unsigned int s4, unsigned int s5, unsigned int s6, unsigned int s7)
|
||||
{
|
||||
uint8 t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3; t.s4 = s4; t.s5 = s5; t.s6 = s6; t.s7 = s7;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __host__ __device__ uint2_8 make_uint2_8(
|
||||
uint2 s0, uint2 s1, uint2 s2, uint2 s3, uint2 s4, uint2 s5, uint2 s6, uint2 s7)
|
||||
{
|
||||
uint2_8 t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3; t.s4 = s4; t.s5 = s5; t.s6 = s6; t.s7 = s7;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __host__ __device__ ulonglong16 make_ulonglong16(const ulonglong4 &s0, const ulonglong4 &s1,
|
||||
const ulonglong4 &s2, const ulonglong4 &s3, const ulonglong4 &s4, const ulonglong4 &s5, const ulonglong4 &s6, const ulonglong4 &s7)
|
||||
{
|
||||
ulonglong16 t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3; t.s4 = s4; t.s5 = s5; t.s6 = s6; t.s7 = s7;
|
||||
return t;
|
||||
}
|
||||
|
||||
static __inline__ __host__ __device__ ulong8 make_ulong8(
|
||||
ulonglong4 s0, ulonglong4 s1, ulonglong4 s2, ulonglong4 s3)
|
||||
{
|
||||
ulong8 t; t.s0 = s0; t.s1 = s1; t.s2 = s2; t.s3 = s3;// t.s4 = s4; t.s5 = s5; t.s6 = s6; t.s7 = s7;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
static __forceinline__ __device__ uchar4 operator^ (uchar4 a, uchar4 b) { return make_uchar4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w); }
|
||||
static __forceinline__ __device__ uchar4 operator+ (uchar4 a, uchar4 b) { return make_uchar4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); }
|
||||
|
||||
static __forceinline__ __device__ uint4 operator+ (uint4 a, uint4 b) { return make_uint4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); }
|
||||
|
||||
static __forceinline__ __device__ ulonglong4 operator^ (ulonglong4 a, ulonglong4 b) { return make_ulonglong4(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w); }
|
||||
static __forceinline__ __device__ ulonglong4 operator+ (ulonglong4 a, ulonglong4 b) { return make_ulonglong4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w); }
|
||||
static __forceinline__ __device__ ulonglong2 operator^ (ulonglong2 a, ulonglong2 b) { return make_ulonglong2(a.x ^ b.x, a.y ^ b.y); }
|
||||
static __forceinline__ __device__ ulonglong2 operator+ (ulonglong2 a, ulonglong2 b) { return make_ulonglong2(a.x + b.x, a.y + b.y); }
|
||||
|
||||
static __forceinline__ __device__ ulong8 operator^ (const ulong8 &a, const ulong8 &b) {
|
||||
return make_ulong8(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ ulong8 operator+ (const ulong8 &a, const ulong8 &b) {
|
||||
return make_ulong8(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ __host__ uint8 operator^ (const uint8 &a, const uint8 &b) { return make_uint8(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, a.s4 ^ b.s4, a.s5 ^ b.s5, a.s6 ^ b.s6, a.s7 ^ b.s7); }
|
||||
|
||||
static __forceinline__ __device__ __host__ uint8 operator+ (const uint8 &a, const uint8 &b) { return make_uint8(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, a.s4 + b.s4, a.s5 + b.s5, a.s6 + b.s6, a.s7 + b.s7); }
|
||||
|
||||
static __forceinline__ __device__ uint2_8 operator^ (const uint2_8 &a, const uint2_8 &b) { return make_uint2_8(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, a.s4 ^ b.s4, a.s5 ^ b.s5, a.s6 ^ b.s6, a.s7 ^ b.s7); }
|
||||
|
||||
static __forceinline__ __device__ uint2_8 operator+ (const uint2_8 &a, const uint2_8 &b) { return make_uint2_8(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, a.s4 + b.s4, a.s5 + b.s5, a.s6 + b.s6, a.s7 + b.s7); }
|
||||
|
||||
|
||||
////////////// mess++ //////
|
||||
|
||||
static __forceinline__ __device__ uint28 operator^ (const uint28 &a, const uint28 &b) {
|
||||
return make_uint28(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z, a.w ^ b.w);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint28 operator+ (const uint28 &a, const uint28 &b) {
|
||||
return make_uint28(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint48 operator+ (const uint48 &a, const uint48 &b) {
|
||||
return make_uint48(a.s0 + b.s0, a.s1 + b.s1);
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
|
||||
static __forceinline__ __device__ __host__ uint16 operator^ (const uint16 &a, const uint16 &b) {
|
||||
return make_uint16(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, a.s4 ^ b.s4, a.s5 ^ b.s5, a.s6 ^ b.s6, a.s7 ^ b.s7,
|
||||
a.s8 ^ b.s8, a.s9 ^ b.s9, a.sa ^ b.sa, a.sb ^ b.sb, a.sc ^ b.sc, a.sd ^ b.sd, a.se ^ b.se, a.sf ^ b.sf);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ __host__ uint16 operator+ (const uint16 &a, const uint16 &b) {
|
||||
return make_uint16(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, a.s4 + b.s4, a.s5 + b.s5, a.s6 + b.s6, a.s7 + b.s7,
|
||||
a.s8 + b.s8, a.s9 + b.s9, a.sa + b.sa, a.sb + b.sb, a.sc + b.sc, a.sd + b.sd, a.se + b.se, a.sf + b.sf);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint2_16 operator^ (const uint2_16 &a, const uint2_16 &b) {
|
||||
return make_uint2_16(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, a.s4 ^ b.s4, a.s5 ^ b.s5, a.s6 ^ b.s6, a.s7 ^ b.s7,
|
||||
a.s8 ^ b.s8, a.s9 ^ b.s9, a.sa ^ b.sa, a.sb ^ b.sb, a.sc ^ b.sc, a.sd ^ b.sd, a.se ^ b.se, a.sf ^ b.sf);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint2_16 operator+ (const uint2_16 &a, const uint2_16 &b) {
|
||||
return make_uint2_16(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, a.s4 + b.s4, a.s5 + b.s5, a.s6 + b.s6, a.s7 + b.s7,
|
||||
a.s8 + b.s8, a.s9 + b.s9, a.sa + b.sa, a.sb + b.sb, a.sc + b.sc, a.sd + b.sd, a.se + b.se, a.sf + b.sf);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint32 operator^ (const uint32 &a, const uint32 &b) {
|
||||
return make_uint32(a.lo ^ b.lo, a.hi ^ b.hi);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint32 operator+ (const uint32 &a, const uint32 &b) {
|
||||
return make_uint32(a.lo + b.lo, a.hi + b.hi);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ ulonglong16 operator^ (const ulonglong16 &a, const ulonglong16 &b) {
|
||||
return make_ulonglong16(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, a.s4 ^ b.s4, a.s5 ^ b.s5, a.s6 ^ b.s6, a.s7 ^ b.s7);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ ulonglong16 operator+ (const ulonglong16 &a, const ulonglong16 &b) {
|
||||
return make_ulonglong16(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, a.s4 + b.s4, a.s5 + b.s5, a.s6 + b.s6, a.s7 + b.s7);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ void operator^= (ulong8 &a, const ulong8 &b) { a = a ^ b; }
|
||||
|
||||
static __forceinline__ __device__ void operator^= (uint28 &a, const uint28 &b) { a = a ^ b; }
|
||||
static __forceinline__ __device__ void operator+= (uint28 &a, const uint28 &b) { a = a + b; }
|
||||
|
||||
static __forceinline__ __device__ void operator^= (uint2_8 &a, const uint2_8 &b) { a = a ^ b; }
|
||||
static __forceinline__ __device__ void operator+= (uint2_8 &a, const uint2_8 &b) { a = a + b; }
|
||||
|
||||
static __forceinline__ __device__ void operator^= (uint32 &a, const uint32 &b) { a = a ^ b; }
|
||||
static __forceinline__ __device__ void operator+= (uint32 &a, const uint32 &b) { a = a + b; }
|
||||
|
||||
static __forceinline__ __device__ void operator^= (uchar4 &a, uchar4 b) { a = a ^ b; }
|
||||
|
||||
static __forceinline__ __device__ __host__ void operator^= (uint8 &a, const uint8 &b) { a = a ^ b; }
|
||||
static __forceinline__ __device__ __host__ void operator^= (uint16 &a, const uint16 &b) { a = a ^ b; }
|
||||
|
||||
static __forceinline__ __device__ void operator^= (ulonglong16 &a, const ulonglong16 &b) { a = a ^ b; }
|
||||
static __forceinline__ __device__ void operator^= (ulonglong4 &a, const ulonglong4 &b) { a = a ^ b; }
|
||||
static __forceinline__ __device__ void operator+= (ulonglong4 &a, const ulonglong4 &b) { a = a + b; }
|
||||
|
||||
static __forceinline__ __device__ void operator^= (ulonglong2 &a, const ulonglong2 &b) { a = a ^ b; }
|
||||
static __forceinline__ __device__ void operator+= (ulonglong2 &a, const ulonglong2 &b) { a = a + b; }
|
||||
|
||||
static __forceinline__ __device__
|
||||
ulonglong2to8 operator^ (const ulonglong2to8 &a, const ulonglong2to8 &b)
|
||||
{
|
||||
return make_ulonglong2to8(a.l0 ^ b.l0, a.l1 ^ b.l1, a.l2 ^ b.l2, a.l3 ^ b.l3);
|
||||
}
|
||||
static __forceinline__ __device__
|
||||
ulonglong2to8 operator+ (const ulonglong2to8 &a, const ulonglong2to8 &b)
|
||||
{
|
||||
return make_ulonglong2to8(a.l0 + b.l0, a.l1 + b.l1, a.l2 + b.l2, a.l3 + b.l3);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__
|
||||
ulonglong8to16 operator^ (const ulonglong8to16 &a, const ulonglong8to16 &b)
|
||||
{
|
||||
return make_ulonglong8to16(a.lo ^ b.lo, a.hi ^ b.hi);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__
|
||||
ulonglong8to16 operator+ (const ulonglong8to16 &a, const ulonglong8to16 &b)
|
||||
{
|
||||
return make_ulonglong8to16(a.lo + b.lo, a.hi + b.hi);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__
|
||||
ulonglong16to32 operator^ (const ulonglong16to32 &a, const ulonglong16to32 &b)
|
||||
{
|
||||
return make_ulonglong16to32(a.lo ^ b.lo, a.hi ^ b.hi);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__
|
||||
ulonglong16to32 operator+ (const ulonglong16to32 &a, const ulonglong16to32 &b)
|
||||
{
|
||||
return make_ulonglong16to32(a.lo + b.lo, a.hi + b.hi);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__
|
||||
ulonglong32to64 operator^ (const ulonglong32to64 &a, const ulonglong32to64 &b)
|
||||
{
|
||||
return make_ulonglong32to64(a.lo ^ b.lo, a.hi ^ b.hi);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__
|
||||
ulonglong32to64 operator+ (const ulonglong32to64 &a, const ulonglong32to64 &b)
|
||||
{
|
||||
return make_ulonglong32to64(a.lo + b.lo, a.hi + b.hi);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ ulonglonglong operator^ (const ulonglonglong &a, const ulonglonglong &b) {
|
||||
return make_ulonglonglong(a.s0 ^ b.s0, a.s1 ^ b.s1, a.s2 ^ b.s2, a.s3 ^ b.s3, a.s4 ^ b.s4, a.s5 ^ b.s5);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ ulonglonglong operator+ (const ulonglonglong &a, const ulonglonglong &b) {
|
||||
return make_ulonglonglong(a.s0 + b.s0, a.s1 + b.s1, a.s2 + b.s2, a.s3 + b.s3, a.s4 + b.s4, a.s5 + b.s5);
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ void operator^= (ulonglong2to8 &a, const ulonglong2to8 &b) { a = a ^ b; }
|
||||
|
||||
static __forceinline__ __device__ void operator+= (uint4 &a, uint4 b) { a = a + b; }
|
||||
static __forceinline__ __device__ void operator+= (uchar4 &a, uchar4 b) { a = a + b; }
|
||||
static __forceinline__ __device__ __host__ void operator+= (uint8 &a, const uint8 &b) { a = a + b; }
|
||||
static __forceinline__ __device__ __host__ void operator+= (uint16 &a, const uint16 &b) { a = a + b; }
|
||||
static __forceinline__ __device__ void operator+= (uint2_16 &a, const uint2_16 &b) { a = a + b; }
|
||||
static __forceinline__ __device__ void operator^= (uint2_16 &a, const uint2_16 &b) { a = a + b; }
|
||||
|
||||
static __forceinline__ __device__ void operator+= (ulong8 &a, const ulong8 &b) { a = a + b; }
|
||||
static __forceinline__ __device__ void operator+= (ulonglong16 &a, const ulonglong16 &b) { a = a + b; }
|
||||
static __forceinline__ __device__ void operator+= (ulonglong8to16 &a, const ulonglong8to16 &b) { a = a + b; }
|
||||
static __forceinline__ __device__ void operator^= (ulonglong8to16 &a, const ulonglong8to16 &b) { a = a ^ b; }
|
||||
|
||||
static __forceinline__ __device__ void operator+= (ulonglong16to32 &a, const ulonglong16to32 &b) { a = a + b; }
|
||||
static __forceinline__ __device__ void operator^= (ulonglong16to32 &a, const ulonglong16to32 &b) { a = a ^ b; }
|
||||
|
||||
static __forceinline__ __device__ void operator+= (ulonglong32to64 &a, const ulonglong32to64 &b) { a = a + b; }
|
||||
static __forceinline__ __device__ void operator^= (ulonglong32to64 &a, const ulonglong32to64 &b) { a = a ^ b; }
|
||||
|
||||
static __forceinline__ __device__ void operator+= (ulonglonglong &a, const ulonglonglong &b) { a = a + b; }
|
||||
static __forceinline__ __device__ void operator^= (ulonglonglong &a, const ulonglonglong &b) { a = a ^ b; }
|
||||
|
||||
#if __CUDA_ARCH__ < 320
|
||||
|
||||
#define rotate ROTL32
|
||||
#define rotateR ROTR32
|
||||
|
||||
#else
|
||||
|
||||
static __forceinline__ __device__ uint4 rotate4(uint4 vec4, uint32_t shift)
|
||||
{
|
||||
uint4 ret;
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(ret.x) : "r"(vec4.x), "r"(vec4.x), "r"(shift));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(ret.y) : "r"(vec4.y), "r"(vec4.y), "r"(shift));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(ret.z) : "r"(vec4.z), "r"(vec4.z), "r"(shift));
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(ret.w) : "r"(vec4.w), "r"(vec4.w), "r"(shift));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint4 rotate4R(uint4 vec4, uint32_t shift)
|
||||
{
|
||||
uint4 ret;
|
||||
asm("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(ret.x) : "r"(vec4.x), "r"(vec4.x), "r"(shift));
|
||||
asm("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(ret.y) : "r"(vec4.y), "r"(vec4.y), "r"(shift));
|
||||
asm("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(ret.z) : "r"(vec4.z), "r"(vec4.z), "r"(shift));
|
||||
asm("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(ret.w) : "r"(vec4.w), "r"(vec4.w), "r"(shift));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint32_t rotate(uint32_t vec4, uint32_t shift)
|
||||
{
|
||||
uint32_t ret;
|
||||
asm("shf.l.wrap.b32 %0, %1, %2, %3;" : "=r"(ret) : "r"(vec4), "r"(vec4), "r"(shift));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint32_t rotateR(uint32_t vec4, uint32_t shift)
|
||||
{
|
||||
uint32_t ret;
|
||||
asm("shf.r.wrap.b32 %0, %1, %2, %3;" : "=r"(ret) : "r"(vec4), "r"(vec4), "r"(shift));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __device__ __inline__ ulonglong4 __ldg4(const ulonglong4 *ptr)
|
||||
{
|
||||
ulonglong4 ret;
|
||||
asm("ld.global.nc.v2.u64 {%0,%1}, [%2];" : "=l"(ret.x), "=l"(ret.y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v2.u64 {%0,%1}, [%2+16];" : "=l"(ret.z), "=l"(ret.w) : __LDG_PTR(ptr));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __device__ __inline__ void ldg4(const ulonglong4 *ptr,ulonglong4 *ret)
|
||||
{
|
||||
asm("ld.global.nc.v2.u64 {%0,%1}, [%2];" : "=l"(ret[0].x), "=l"(ret[0].y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v2.u64 {%0,%1}, [%2+16];" : "=l"(ret[0].z), "=l"(ret[0].w) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v2.u64 {%0,%1}, [%2+32];" : "=l"(ret[1].x), "=l"(ret[1].y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v2.u64 {%0,%1}, [%2+48];" : "=l"(ret[1].z), "=l"(ret[1].w) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v2.u64 {%0,%1}, [%2+64];" : "=l"(ret[2].x), "=l"(ret[2].y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v2.u64 {%0,%1}, [%2+80];" : "=l"(ret[2].z), "=l"(ret[2].w) : __LDG_PTR(ptr));
|
||||
}
|
||||
|
||||
static __device__ __inline__ uint28 __ldg4(const uint28 *ptr)
|
||||
{
|
||||
uint28 ret;
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4];" : "=r"(ret.x.x), "=r"(ret.x.y), "=r"(ret.y.x), "=r"(ret.y.y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+16];" : "=r"(ret.z.x), "=r"(ret.z.y), "=r"(ret.w.x), "=r"(ret.w.y) : __LDG_PTR(ptr));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __device__ __inline__ uint48 __ldg4(const uint48 *ptr)
|
||||
{
|
||||
uint48 ret;
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4];" : "=r"(ret.s0.x), "=r"(ret.s0.y), "=r"(ret.s0.z), "=r"(ret.s0.w) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+16];" : "=r"(ret.s1.x), "=r"(ret.s1.y), "=r"(ret.s1.z), "=r"(ret.s1.w) : __LDG_PTR(ptr));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static __device__ __inline__ void ldg4(const uint28 *ptr, uint28 *ret)
|
||||
{
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4];" : "=r"(ret[0].x.x), "=r"(ret[0].x.y), "=r"(ret[0].y.x), "=r"(ret[0].y.y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+16];" : "=r"(ret[0].z.x), "=r"(ret[0].z.y), "=r"(ret[0].w.x), "=r"(ret[0].w.y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+32];" : "=r"(ret[1].x.x), "=r"(ret[1].x.y), "=r"(ret[1].y.x), "=r"(ret[1].y.y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+48];" : "=r"(ret[1].z.x), "=r"(ret[1].z.y), "=r"(ret[1].w.x), "=r"(ret[1].w.y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+64];" : "=r"(ret[2].x.x), "=r"(ret[2].x.y), "=r"(ret[2].y.x), "=r"(ret[2].y.y) : __LDG_PTR(ptr));
|
||||
asm("ld.global.nc.v4.u32 {%0,%1,%2,%3}, [%4+80];" : "=r"(ret[2].z.x), "=r"(ret[2].z.y), "=r"(ret[2].w.x), "=r"(ret[2].w.y) : __LDG_PTR(ptr));
|
||||
}
|
||||
|
||||
#endif /* __CUDA_ARCH__ < 320 */
|
||||
|
||||
|
||||
static __forceinline__ __device__ uint8 swapvec(const uint8 &buf)
|
||||
{
|
||||
uint8 vec;
|
||||
vec.s0 = cuda_swab32(buf.s0);
|
||||
vec.s1 = cuda_swab32(buf.s1);
|
||||
vec.s2 = cuda_swab32(buf.s2);
|
||||
vec.s3 = cuda_swab32(buf.s3);
|
||||
vec.s4 = cuda_swab32(buf.s4);
|
||||
vec.s5 = cuda_swab32(buf.s5);
|
||||
vec.s6 = cuda_swab32(buf.s6);
|
||||
vec.s7 = cuda_swab32(buf.s7);
|
||||
return vec;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint8 swapvec(const uint8 *buf)
|
||||
{
|
||||
uint8 vec;
|
||||
vec.s0 = cuda_swab32(buf[0].s0);
|
||||
vec.s1 = cuda_swab32(buf[0].s1);
|
||||
vec.s2 = cuda_swab32(buf[0].s2);
|
||||
vec.s3 = cuda_swab32(buf[0].s3);
|
||||
vec.s4 = cuda_swab32(buf[0].s4);
|
||||
vec.s5 = cuda_swab32(buf[0].s5);
|
||||
vec.s6 = cuda_swab32(buf[0].s6);
|
||||
vec.s7 = cuda_swab32(buf[0].s7);
|
||||
return vec;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint16 swapvec(const uint16 *buf)
|
||||
{
|
||||
uint16 vec;
|
||||
vec.s0 = cuda_swab32(buf[0].s0);
|
||||
vec.s1 = cuda_swab32(buf[0].s1);
|
||||
vec.s2 = cuda_swab32(buf[0].s2);
|
||||
vec.s3 = cuda_swab32(buf[0].s3);
|
||||
vec.s4 = cuda_swab32(buf[0].s4);
|
||||
vec.s5 = cuda_swab32(buf[0].s5);
|
||||
vec.s6 = cuda_swab32(buf[0].s6);
|
||||
vec.s7 = cuda_swab32(buf[0].s7);
|
||||
vec.s8 = cuda_swab32(buf[0].s8);
|
||||
vec.s9 = cuda_swab32(buf[0].s9);
|
||||
vec.sa = cuda_swab32(buf[0].sa);
|
||||
vec.sb = cuda_swab32(buf[0].sb);
|
||||
vec.sc = cuda_swab32(buf[0].sc);
|
||||
vec.sd = cuda_swab32(buf[0].sd);
|
||||
vec.se = cuda_swab32(buf[0].se);
|
||||
vec.sf = cuda_swab32(buf[0].sf);
|
||||
return vec;
|
||||
}
|
||||
|
||||
static __forceinline__ __device__ uint16 swapvec(const uint16 &buf)
|
||||
{
|
||||
uint16 vec;
|
||||
vec.s0 = cuda_swab32(buf.s0);
|
||||
vec.s1 = cuda_swab32(buf.s1);
|
||||
vec.s2 = cuda_swab32(buf.s2);
|
||||
vec.s3 = cuda_swab32(buf.s3);
|
||||
vec.s4 = cuda_swab32(buf.s4);
|
||||
vec.s5 = cuda_swab32(buf.s5);
|
||||
vec.s6 = cuda_swab32(buf.s6);
|
||||
vec.s7 = cuda_swab32(buf.s7);
|
||||
vec.s8 = cuda_swab32(buf.s8);
|
||||
vec.s9 = cuda_swab32(buf.s9);
|
||||
vec.sa = cuda_swab32(buf.sa);
|
||||
vec.sb = cuda_swab32(buf.sb);
|
||||
vec.sc = cuda_swab32(buf.sc);
|
||||
vec.sd = cuda_swab32(buf.sd);
|
||||
vec.se = cuda_swab32(buf.se);
|
||||
vec.sf = cuda_swab32(buf.sf);
|
||||
return vec;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint28 shuffle4(const uint28 &var, int lane)
|
||||
{
|
||||
uint28 res;
|
||||
res.x.x = __shfl(var.x.x, lane);
|
||||
res.x.y = __shfl(var.x.y, lane);
|
||||
res.y.x = __shfl(var.y.x, lane);
|
||||
res.y.y = __shfl(var.y.y, lane);
|
||||
res.z.x = __shfl(var.z.x, lane);
|
||||
res.z.y = __shfl(var.z.y, lane);
|
||||
res.w.x = __shfl(var.w.x, lane);
|
||||
res.w.y = __shfl(var.w.y, lane);
|
||||
return res;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ ulonglong4 shuffle4(ulonglong4 var, int lane)
|
||||
{
|
||||
ulonglong4 res;
|
||||
uint2 temp;
|
||||
temp = vectorize(var.x);
|
||||
temp.x = __shfl(temp.x, lane);
|
||||
temp.y = __shfl(temp.y, lane);
|
||||
res.x = devectorize(temp);
|
||||
temp = vectorize(var.y);
|
||||
temp.x = __shfl(temp.x, lane);
|
||||
temp.y = __shfl(temp.y, lane);
|
||||
res.y = devectorize(temp);
|
||||
temp = vectorize(var.z);
|
||||
temp.x = __shfl(temp.x, lane);
|
||||
temp.y = __shfl(temp.y, lane);
|
||||
res.z = devectorize(temp);
|
||||
temp = vectorize(var.w);
|
||||
temp.x = __shfl(temp.x, lane);
|
||||
temp.y = __shfl(temp.y, lane);
|
||||
res.w = devectorize(temp);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif // #ifndef CUDA_LYRA_VECTOR_H
|
||||
@@ -0,0 +1,532 @@
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifdef __INTELLISENSE__
|
||||
/* just for vstudio code colors */
|
||||
#define __CUDA_ARCH__ 500
|
||||
#endif
|
||||
|
||||
#include "cuda_lyra2_vectors.h"
|
||||
|
||||
#define TPB 16
|
||||
|
||||
#define Nrow 4
|
||||
#define Ncol 4
|
||||
|
||||
#if __CUDA_ARCH__ < 500
|
||||
#define vectype ulonglong4
|
||||
#define u64type uint64_t
|
||||
#define memshift 4
|
||||
#elif __CUDA_ARCH__ == 500
|
||||
#define u64type uint2
|
||||
#define vectype uint28
|
||||
#define memshift 3
|
||||
#else
|
||||
#define u64type uint2
|
||||
#define vectype uint28
|
||||
#define memshift 3
|
||||
#endif
|
||||
|
||||
__device__ vectype *DMatrix;
|
||||
|
||||
#if __CUDA_ARCH__ >= 300
|
||||
|
||||
#if __CUDA_ARCH__ >= 500
|
||||
static __device__ __forceinline__
|
||||
void Gfunc_v35(uint2 &a, uint2 &b, uint2 &c, uint2 &d)
|
||||
{
|
||||
a += b; d ^= a; d = SWAPUINT2(d);
|
||||
c += d; b ^= c; b = ROR24(b);
|
||||
a += b; d ^= a; d = ROR16(d);
|
||||
c += d; b ^= c; b = ROR2(b, 63);
|
||||
}
|
||||
#else
|
||||
static __device__ __forceinline__
|
||||
void Gfunc_v35(unsigned long long &a, unsigned long long &b, unsigned long long &c, unsigned long long &d)
|
||||
{
|
||||
a += b; d ^= a; d = ROTR64(d, 32);
|
||||
c += d; b ^= c; b = ROTR64(b, 24);
|
||||
a += b; d ^= a; d = ROTR64(d, 16);
|
||||
c += d; b ^= c; b = ROTR64(b, 63);
|
||||
}
|
||||
#endif
|
||||
|
||||
static __device__ __forceinline__
|
||||
void round_lyra_v35(vectype* s)
|
||||
{
|
||||
Gfunc_v35(s[0].x, s[1].x, s[2].x, s[3].x);
|
||||
Gfunc_v35(s[0].y, s[1].y, s[2].y, s[3].y);
|
||||
Gfunc_v35(s[0].z, s[1].z, s[2].z, s[3].z);
|
||||
Gfunc_v35(s[0].w, s[1].w, s[2].w, s[3].w);
|
||||
|
||||
Gfunc_v35(s[0].x, s[1].y, s[2].z, s[3].w);
|
||||
Gfunc_v35(s[0].y, s[1].z, s[2].w, s[3].x);
|
||||
Gfunc_v35(s[0].z, s[1].w, s[2].x, s[3].y);
|
||||
Gfunc_v35(s[0].w, s[1].x, s[2].y, s[3].z);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void reduceDuplex(vectype state[4], uint32_t thread)
|
||||
{
|
||||
vectype state1[3];
|
||||
uint32_t ps1 = (Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps2 = (memshift * (Ncol-1) + memshift * Ncol + Nrow * Ncol * memshift * thread);
|
||||
|
||||
#pragma unroll 4
|
||||
for (int i = 0; i < Ncol; i++)
|
||||
{
|
||||
uint32_t s1 = ps1 + i*memshift;
|
||||
uint32_t s2 = ps2 - i*memshift;
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j] = __ldg4(&(DMatrix+s1)[j]);
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state[j] ^= state1[j];
|
||||
|
||||
round_lyra_v35(state);
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j] ^= state[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s2)[j] = state1[j];
|
||||
}
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void reduceDuplexV3(vectype state[4], uint32_t thread)
|
||||
{
|
||||
vectype state1[3];
|
||||
uint32_t ps1 = (Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps2 = (memshift * (Ncol - 1) * Nrow + memshift * 1 + Nrow * Ncol * memshift * thread);
|
||||
|
||||
#pragma unroll 4
|
||||
for (int i = 0; i < Ncol; i++)
|
||||
{
|
||||
uint32_t s1 = ps1 + Nrow * i *memshift;
|
||||
uint32_t s2 = ps2 - Nrow * i *memshift;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j] = __ldg4(&(DMatrix + s1)[j]);
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state[j] ^= state1[j];
|
||||
round_lyra_v35(state);
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j] ^= state[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s2)[j] = state1[j];
|
||||
}
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void reduceDuplexRowSetupV2(const int rowIn, const int rowInOut, const int rowOut, vectype state[4], uint32_t thread)
|
||||
{
|
||||
vectype state2[3],state1[3];
|
||||
|
||||
uint32_t ps1 = (memshift * Ncol * rowIn + Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps2 = (memshift * Ncol * rowInOut + Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps3 = (memshift * (Ncol-1) + memshift * Ncol * rowOut + Nrow * Ncol * memshift * thread);
|
||||
|
||||
//#pragma unroll 1
|
||||
for (int i = 0; i < Ncol; i++)
|
||||
{
|
||||
uint32_t s1 = ps1 + i*memshift;
|
||||
uint32_t s2 = ps2 + i*memshift;
|
||||
uint32_t s3 = ps3 - i*memshift;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j]= __ldg4(&(DMatrix + s1)[j]);
|
||||
for (int j = 0; j < 3; j++)
|
||||
state2[j]= __ldg4(&(DMatrix + s2)[j]);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
vectype tmp = state1[j] + state2[j];
|
||||
state[j] ^= tmp;
|
||||
}
|
||||
|
||||
round_lyra_v35(state);
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
state1[j] ^= state[j];
|
||||
(DMatrix + s3)[j] = state1[j];
|
||||
}
|
||||
|
||||
((uint2*)state2)[0] ^= ((uint2*)state)[11];
|
||||
|
||||
for (int j = 0; j < 11; j++)
|
||||
((uint2*)state2)[j+1] ^= ((uint2*)state)[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s2)[j] = state2[j];
|
||||
}
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void reduceDuplexRowSetupV3(const int rowIn, const int rowInOut, const int rowOut, vectype state[4], uint32_t thread)
|
||||
{
|
||||
vectype state2[3], state1[3];
|
||||
|
||||
uint32_t ps1 = (memshift * rowIn + Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps2 = (memshift * rowInOut + Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps3 = (Nrow * memshift * (Ncol - 1) + memshift * rowOut + Nrow * Ncol * memshift * thread);
|
||||
|
||||
for (int i = 0; i < Ncol; i++)
|
||||
{
|
||||
uint32_t s1 = ps1 + Nrow*i*memshift;
|
||||
uint32_t s2 = ps2 + Nrow*i*memshift;
|
||||
uint32_t s3 = ps3 - Nrow*i*memshift;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j] = __ldg4(&(DMatrix + s1 )[j]);
|
||||
for (int j = 0; j < 3; j++)
|
||||
state2[j] = __ldg4(&(DMatrix + s2 )[j]);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
vectype tmp = state1[j] + state2[j];
|
||||
state[j] ^= tmp;
|
||||
}
|
||||
|
||||
round_lyra_v35(state);
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
state1[j] ^= state[j];
|
||||
(DMatrix + s3)[j] = state1[j];
|
||||
}
|
||||
|
||||
((uint2*)state2)[0] ^= ((uint2*)state)[11];
|
||||
for (int j = 0; j < 11; j++)
|
||||
((uint2*)state2)[j + 1] ^= ((uint2*)state)[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s2)[j] = state2[j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static __device__ __forceinline__
|
||||
void reduceDuplexRowtV2(const int rowIn, const int rowInOut, const int rowOut, vectype* state, uint32_t thread)
|
||||
{
|
||||
vectype state1[3],state2[3];
|
||||
uint32_t ps1 = (memshift * Ncol * rowIn + Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps2 = (memshift * Ncol * rowInOut + Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps3 = (memshift * Ncol * rowOut + Nrow * Ncol * memshift * thread);
|
||||
|
||||
//#pragma unroll 1
|
||||
for (int i = 0; i < Ncol; i++)
|
||||
{
|
||||
uint32_t s1 = ps1 + i*memshift;
|
||||
uint32_t s2 = ps2 + i*memshift;
|
||||
uint32_t s3 = ps3 + i*memshift;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j] = __ldg4(&(DMatrix + s1)[j]);
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state2[j] = __ldg4(&(DMatrix + s2)[j]);
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j] += state2[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state[j] ^= state1[j];
|
||||
|
||||
round_lyra_v35(state);
|
||||
|
||||
((uint2*)state2)[0] ^= ((uint2*)state)[11];
|
||||
for (int j = 0; j < 11; j++)
|
||||
((uint2*)state2)[j + 1] ^= ((uint2*)state)[j];
|
||||
|
||||
if (rowInOut != rowOut) {
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s2)[j] = state2[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s3)[j] ^= state[j];
|
||||
|
||||
} else {
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state2[j] ^= state[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s2)[j]=state2[j];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void reduceDuplexRowtV3(const int rowIn, const int rowInOut, const int rowOut, vectype* state, uint32_t thread)
|
||||
{
|
||||
vectype state1[3], state2[3];
|
||||
uint32_t ps1 = (memshift * rowIn + Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps2 = (memshift * rowInOut + Nrow * Ncol * memshift * thread);
|
||||
uint32_t ps3 = (memshift * rowOut + Nrow * Ncol * memshift * thread);
|
||||
|
||||
#pragma nounroll
|
||||
for (int i = 0; i < Ncol; i++)
|
||||
{
|
||||
uint32_t s1 = ps1 + Nrow * i*memshift;
|
||||
uint32_t s2 = ps2 + Nrow * i*memshift;
|
||||
uint32_t s3 = ps3 + Nrow * i*memshift;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j] = __ldg4(&(DMatrix + s1)[j]);
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state2[j] = __ldg4(&(DMatrix + s2)[j]);
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state1[j] += state2[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state[j] ^= state1[j];
|
||||
|
||||
round_lyra_v35(state);
|
||||
|
||||
((uint2*)state2)[0] ^= ((uint2*)state)[11];
|
||||
|
||||
for (int j = 0; j < 11; j++)
|
||||
((uint2*)state2)[j + 1] ^= ((uint2*)state)[j];
|
||||
|
||||
if (rowInOut != rowOut) {
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s2)[j] = state2[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s3)[j] ^= state[j];
|
||||
|
||||
} else {
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state2[j] ^= state[j];
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s2)[j] = state2[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if __CUDA_ARCH__ < 500
|
||||
__global__ __launch_bounds__(128, 1)
|
||||
#elif __CUDA_ARCH__ == 500
|
||||
__global__ __launch_bounds__(16, 1)
|
||||
#else
|
||||
__global__ __launch_bounds__(TPB, 1)
|
||||
#endif
|
||||
void lyra2v2_gpu_hash_32_v3(uint32_t threads, uint32_t startNounce, uint2 *outputHash)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
|
||||
vectype state[4];
|
||||
uint28 blake2b_IV[2];
|
||||
uint28 padding[2];
|
||||
|
||||
if (threadIdx.x == 0) {
|
||||
|
||||
((uint16*)blake2b_IV)[0] = make_uint16(
|
||||
0xf3bcc908, 0x6a09e667 , 0x84caa73b, 0xbb67ae85 ,
|
||||
0xfe94f82b, 0x3c6ef372 , 0x5f1d36f1, 0xa54ff53a ,
|
||||
0xade682d1, 0x510e527f , 0x2b3e6c1f, 0x9b05688c ,
|
||||
0xfb41bd6b, 0x1f83d9ab , 0x137e2179, 0x5be0cd19
|
||||
);
|
||||
((uint16*)padding)[0] = make_uint16(
|
||||
0x20, 0x0 , 0x20, 0x0 , 0x20, 0x0 , 0x01, 0x0 ,
|
||||
0x04, 0x0 , 0x04, 0x0 , 0x80, 0x0 , 0x0, 0x01000000
|
||||
);
|
||||
}
|
||||
|
||||
#if __CUDA_ARCH__ <= 350
|
||||
if (thread < threads)
|
||||
#endif
|
||||
{
|
||||
((uint2*)state)[0] = __ldg(&outputHash[thread]);
|
||||
((uint2*)state)[1] = __ldg(&outputHash[thread + threads]);
|
||||
((uint2*)state)[2] = __ldg(&outputHash[thread + 2 * threads]);
|
||||
((uint2*)state)[3] = __ldg(&outputHash[thread + 3 * threads]);
|
||||
state[1] = state[0];
|
||||
state[2] = shuffle4(((vectype*)blake2b_IV)[0], 0);
|
||||
state[3] = shuffle4(((vectype*)blake2b_IV)[1], 0);
|
||||
|
||||
for (int i = 0; i<12; i++)
|
||||
round_lyra_v35(state);
|
||||
|
||||
state[0] ^= shuffle4(((vectype*)padding)[0], 0);
|
||||
state[1] ^= shuffle4(((vectype*)padding)[1], 0);
|
||||
|
||||
for (int i = 0; i<12; i++)
|
||||
round_lyra_v35(state);
|
||||
|
||||
uint32_t ps1 = (4 * memshift * 3 + 16 * memshift * thread);
|
||||
|
||||
//#pragma unroll 4
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
uint32_t s1 = ps1 - 4 * memshift * i;
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s1)[j] = (state)[j];
|
||||
|
||||
round_lyra_v35(state);
|
||||
}
|
||||
|
||||
reduceDuplexV3(state, thread);
|
||||
reduceDuplexRowSetupV3(1, 0, 2, state, thread);
|
||||
reduceDuplexRowSetupV3(2, 1, 3, state, thread);
|
||||
|
||||
uint32_t rowa;
|
||||
int prev = 3;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
rowa = ((uint2*)state)[0].x & 3; reduceDuplexRowtV3(prev, rowa, i, state, thread);
|
||||
prev = i;
|
||||
}
|
||||
|
||||
uint32_t shift = (memshift * rowa + 16 * memshift * thread);
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state[j] ^= __ldg4(&(DMatrix + shift)[j]);
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
round_lyra_v35(state);
|
||||
|
||||
outputHash[thread] = ((uint2*)state)[0];
|
||||
outputHash[thread + threads] = ((uint2*)state)[1];
|
||||
outputHash[thread + 2 * threads] = ((uint2*)state)[2];
|
||||
outputHash[thread + 3 * threads] = ((uint2*)state)[3];
|
||||
//((vectype*)outputHash)[thread] = state[0];
|
||||
|
||||
} //thread
|
||||
}
|
||||
|
||||
#if __CUDA_ARCH__ < 500
|
||||
__global__ __launch_bounds__(64, 1)
|
||||
#elif __CUDA_ARCH__ == 500
|
||||
__global__ __launch_bounds__(32, 1)
|
||||
#else
|
||||
__global__ __launch_bounds__(TPB, 1)
|
||||
#endif
|
||||
void lyra2v2_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint2 *outputHash)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
vectype state[4];
|
||||
uint28 blake2b_IV[2];
|
||||
uint28 padding[2];
|
||||
|
||||
if (threadIdx.x == 0) {
|
||||
|
||||
((uint16*)blake2b_IV)[0] = make_uint16(
|
||||
0xf3bcc908, 0x6a09e667, 0x84caa73b, 0xbb67ae85,
|
||||
0xfe94f82b, 0x3c6ef372, 0x5f1d36f1, 0xa54ff53a,
|
||||
0xade682d1, 0x510e527f, 0x2b3e6c1f, 0x9b05688c,
|
||||
0xfb41bd6b, 0x1f83d9ab, 0x137e2179, 0x5be0cd19
|
||||
);
|
||||
((uint16*)padding)[0] = make_uint16(
|
||||
0x20, 0x0, 0x20, 0x0, 0x20, 0x0, 0x01, 0x0,
|
||||
0x04, 0x0, 0x04, 0x0, 0x80, 0x0, 0x0, 0x01000000
|
||||
);
|
||||
}
|
||||
|
||||
#if __CUDA_ARCH__ <= 350
|
||||
if (thread < threads)
|
||||
#endif
|
||||
{
|
||||
((uint2*)state)[0] = __ldg(&outputHash[thread]);
|
||||
((uint2*)state)[1] = __ldg(&outputHash[thread + threads]);
|
||||
((uint2*)state)[2] = __ldg(&outputHash[thread + 2 * threads]);
|
||||
((uint2*)state)[3] = __ldg(&outputHash[thread + 3 * threads]);
|
||||
|
||||
state[1] = state[0];
|
||||
|
||||
state[2] = shuffle4(((vectype*)blake2b_IV)[0], 0);
|
||||
state[3] = shuffle4(((vectype*)blake2b_IV)[1], 0);
|
||||
|
||||
for (int i = 0; i<12; i++)
|
||||
round_lyra_v35(state);
|
||||
|
||||
state[0] ^= shuffle4(((vectype*)padding)[0], 0);
|
||||
state[1] ^= shuffle4(((vectype*)padding)[1], 0);
|
||||
|
||||
for (int i = 0; i<12; i++)
|
||||
round_lyra_v35(state);
|
||||
|
||||
uint32_t ps1 = (memshift * (Ncol - 1) + Nrow * Ncol * memshift * thread);
|
||||
|
||||
for (int i = 0; i < Ncol; i++)
|
||||
{
|
||||
uint32_t s1 = ps1 - memshift * i;
|
||||
for (int j = 0; j < 3; j++)
|
||||
(DMatrix + s1)[j] = (state)[j];
|
||||
|
||||
round_lyra_v35(state);
|
||||
}
|
||||
|
||||
reduceDuplex(state, thread);
|
||||
|
||||
reduceDuplexRowSetupV2(1, 0, 2, state, thread);
|
||||
reduceDuplexRowSetupV2(2, 1, 3, state, thread);
|
||||
|
||||
uint32_t rowa;
|
||||
int prev=3;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
rowa = ((uint2*)state)[0].x & 3;
|
||||
reduceDuplexRowtV2(prev, rowa, i, state, thread);
|
||||
prev=i;
|
||||
}
|
||||
|
||||
uint32_t shift = (memshift * Ncol * rowa + Nrow * Ncol * memshift * thread);
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
state[j] ^= __ldg4(&(DMatrix + shift)[j]);
|
||||
|
||||
for (int i = 0; i < 12; i++)
|
||||
round_lyra_v35(state);
|
||||
|
||||
outputHash[thread] = ((uint2*)state)[0];
|
||||
outputHash[thread + threads] = ((uint2*)state)[1];
|
||||
outputHash[thread + 2 * threads] = ((uint2*)state)[2];
|
||||
outputHash[thread + 3 * threads] = ((uint2*)state)[3];
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* if __CUDA_ARCH__ < 300 .. */
|
||||
__global__ void lyra2v2_gpu_hash_32(uint32_t threads, uint32_t startNounce, uint2 *outputHash) {}
|
||||
__global__ void lyra2v2_gpu_hash_32_v3(uint32_t threads, uint32_t startNounce, uint2 *outputHash) {}
|
||||
#endif
|
||||
|
||||
__host__
|
||||
void lyra2v2_cpu_init(int thr_id, uint32_t threads, uint64_t *d_hash2)
|
||||
{
|
||||
// just assign the device pointer allocated in main loop
|
||||
cudaMemcpyToSymbol(DMatrix, &d_hash2, sizeof(uint64_t*), 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
__host__
|
||||
void lyra2v2_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order)
|
||||
{
|
||||
uint32_t tpb;
|
||||
if (device_sm[device_map[thr_id]] == 350)
|
||||
tpb = 64;
|
||||
else if (device_sm[device_map[thr_id]] == 500)
|
||||
tpb = 32;
|
||||
else
|
||||
tpb = TPB;
|
||||
|
||||
dim3 grid((threads + tpb - 1) / tpb);
|
||||
dim3 block(tpb);
|
||||
|
||||
if (device_sm[device_map[thr_id]] >= 500)
|
||||
lyra2v2_gpu_hash_32 <<<grid, block>>> (threads, startNounce, (uint2*)d_outputHash);
|
||||
else
|
||||
lyra2v2_gpu_hash_32_v3 <<<grid, block>>> (threads, startNounce, (uint2*)d_outputHash);
|
||||
|
||||
MyStreamSynchronize(NULL, order, thr_id);
|
||||
}
|
||||
|
||||
+50
-8
@@ -10,6 +10,7 @@ extern "C" {
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static uint64_t* d_hash[MAX_GPUS];
|
||||
//static uint64_t* d_hash2[MAX_GPUS];
|
||||
|
||||
extern void blake256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void blake256_cpu_hash_80(const int thr_id, const uint32_t threads, const uint32_t startNonce, uint64_t *Hash, int order);
|
||||
@@ -19,14 +20,31 @@ extern void keccak256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void skein256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNonce, uint64_t *d_outputHash, int order);
|
||||
extern void skein256_cpu_init(int thr_id, uint32_t threads);
|
||||
|
||||
//extern void lyra2_cpu_init(int thr_id, uint32_t threads, uint64_t *hash);
|
||||
extern void lyra2_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNonce, uint64_t *d_outputHash, int order);
|
||||
|
||||
extern void groestl256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void groestl256_cpu_free(int thr_id);
|
||||
extern void groestl256_setTarget(const void *ptarget);
|
||||
extern uint32_t groestl256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_outputHash, int order);
|
||||
extern uint32_t groestl256_getSecNonce(int thr_id, int num);
|
||||
|
||||
extern "C" void lyra2_hash(void *state, const void *input)
|
||||
#ifdef _DEBUG
|
||||
#define TRACE(algo) { \
|
||||
if (max_nonce == 1 && pdata[19] <= 1) { \
|
||||
uint32_t* debugbuf = NULL; \
|
||||
cudaMallocHost(&debugbuf, 8*sizeof(uint32_t)); \
|
||||
cudaMemcpy(debugbuf, d_hash[thr_id], 8*sizeof(uint32_t), cudaMemcpyDeviceToHost); \
|
||||
printf("lyra %s %08x %08x %08x %08x...\n", algo, swab32(debugbuf[0]), swab32(debugbuf[1]), \
|
||||
swab32(debugbuf[2]), swab32(debugbuf[3])); \
|
||||
cudaFreeHost(debugbuf); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define TRACE(algo) {}
|
||||
#endif
|
||||
|
||||
extern "C" void lyra2re_hash(void *state, const void *input)
|
||||
{
|
||||
sph_blake256_context ctx_blake;
|
||||
sph_keccak256_context ctx_keccak;
|
||||
@@ -58,17 +76,17 @@ extern "C" void lyra2_hash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_lyra2(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_lyra2(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int intensity = (device_sm[device_map[thr_id]] >= 500 && !is_windows()) ? 18 : 17;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity); // 18=256*256*4;
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0000ff;
|
||||
((uint32_t*)ptarget)[7] = 0x00ff;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
@@ -79,7 +97,11 @@ extern "C" int scanhash_lyra2(int thr_id, uint32_t *pdata,
|
||||
skein256_cpu_init(thr_id, throughput);
|
||||
groestl256_cpu_init(thr_id, throughput);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], throughput * 64));
|
||||
// DMatrix
|
||||
// cudaMalloc(&d_hash2[thr_id], (size_t)16 * 8 * 8 * sizeof(uint64_t) * throughput);
|
||||
// lyra2_cpu_init(thr_id, throughput, d_hash2[thr_id]);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t)32 * throughput));
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
@@ -101,6 +123,7 @@ extern "C" int scanhash_lyra2(int thr_id, uint32_t *pdata,
|
||||
keccak256_cpu_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
lyra2_cpu_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
skein256_cpu_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
TRACE("S")
|
||||
|
||||
foundNonce = groestl256_cpu_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
@@ -108,18 +131,21 @@ extern "C" int scanhash_lyra2(int thr_id, uint32_t *pdata,
|
||||
uint32_t _ALIGN(64) vhash64[8];
|
||||
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
lyra2_hash(vhash64, endiandata);
|
||||
lyra2re_hash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = groestl256_getSecNonce(thr_id, 1);
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != UINT32_MAX)
|
||||
{
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
lyra2_hash(vhash64, endiandata);
|
||||
lyra2re_hash(vhash64, endiandata);
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
if (opt_debug)
|
||||
applog(LOG_BLUE, "GPU #%d: found second nonce %08x", device_map[thr_id], secNonce);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -137,3 +163,19 @@ extern "C" int scanhash_lyra2(int thr_id, uint32_t *pdata,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_lyra2(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
groestl256_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
extern "C" {
|
||||
#include "sph/sph_blake.h"
|
||||
#include "sph/sph_bmw.h"
|
||||
#include "sph/sph_skein.h"
|
||||
#include "sph/sph_keccak.h"
|
||||
#include "sph/sph_cubehash.h"
|
||||
#include "lyra2/Lyra2.h"
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
|
||||
static _ALIGN(64) uint64_t *d_hash[MAX_GPUS];
|
||||
static uint64_t *d_hash2[MAX_GPUS];
|
||||
|
||||
extern void blake256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void blake256_cpu_hash_80(const int thr_id, const uint32_t threads, const uint32_t startNonce, uint64_t *Hash, int order);
|
||||
extern void blake256_cpu_setBlock_80(uint32_t *pdata);
|
||||
extern void keccak256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNonce, uint64_t *d_outputHash, int order);
|
||||
extern void keccak256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void skein256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNonce, uint64_t *d_outputHash, int order);
|
||||
extern void skein256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void cubehash256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *d_hash, int order);
|
||||
|
||||
extern void lyra2v2_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNonce, uint64_t *d_outputHash, int order);
|
||||
extern void lyra2v2_cpu_init(int thr_id, uint32_t threads, uint64_t* matrix);
|
||||
|
||||
extern void bmw256_setTarget(const void *ptarget);
|
||||
extern void bmw256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void bmw256_cpu_free(int thr_id);
|
||||
extern void bmw256_cpu_hash_32(int thr_id, uint32_t threads, uint32_t startNounce, uint64_t *g_hash, uint32_t *resultnonces);
|
||||
|
||||
void lyra2v2_hash(void *state, const void *input)
|
||||
{
|
||||
uint32_t hashA[8], hashB[8];
|
||||
|
||||
sph_blake256_context ctx_blake;
|
||||
sph_keccak256_context ctx_keccak;
|
||||
sph_skein256_context ctx_skein;
|
||||
sph_bmw256_context ctx_bmw;
|
||||
sph_cubehash256_context ctx_cube;
|
||||
|
||||
sph_blake256_init(&ctx_blake);
|
||||
sph_blake256(&ctx_blake, input, 80);
|
||||
sph_blake256_close(&ctx_blake, hashA);
|
||||
|
||||
sph_keccak256_init(&ctx_keccak);
|
||||
sph_keccak256(&ctx_keccak, hashA, 32);
|
||||
sph_keccak256_close(&ctx_keccak, hashB);
|
||||
|
||||
sph_cubehash256_init(&ctx_cube);
|
||||
sph_cubehash256(&ctx_cube, hashB, 32);
|
||||
sph_cubehash256_close(&ctx_cube, hashA);
|
||||
|
||||
LYRA2(hashB, 32, hashA, 32, hashA, 32, 1, 4, 4);
|
||||
|
||||
sph_skein256_init(&ctx_skein);
|
||||
sph_skein256(&ctx_skein, hashB, 32);
|
||||
sph_skein256_close(&ctx_skein, hashA);
|
||||
|
||||
sph_cubehash256_init(&ctx_cube);
|
||||
sph_cubehash256(&ctx_cube, hashA, 32);
|
||||
sph_cubehash256_close(&ctx_cube, hashB);
|
||||
|
||||
sph_bmw256_init(&ctx_bmw);
|
||||
sph_bmw256(&ctx_bmw, hashB, 32);
|
||||
sph_bmw256_close(&ctx_bmw, hashA);
|
||||
|
||||
memcpy(state, hashA, 32);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_lyra2v2(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int intensity = (device_sm[device_map[thr_id]] > 500 && !is_windows()) ? 18 : 17;
|
||||
unsigned int defthr = 1U << intensity;
|
||||
uint32_t throughput = device_intensity(device_map[thr_id], __func__, defthr);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x00ff;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
//cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
//if (opt_n_gputhreads == 1)
|
||||
// cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
blake256_cpu_init(thr_id, throughput);
|
||||
keccak256_cpu_init(thr_id,throughput);
|
||||
skein256_cpu_init(thr_id, throughput);
|
||||
bmw256_cpu_init(thr_id, throughput);
|
||||
|
||||
if (device_sm[device_map[thr_id]] < 300) {
|
||||
applog(LOG_ERR, "Device SM 3.0 or more recent required!");
|
||||
proper_exit(1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// DMatrix
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash2[thr_id], 16 * 4 * 4 * sizeof(uint64_t) * throughput));
|
||||
lyra2v2_cpu_init(thr_id, throughput, d_hash2[thr_id]);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t)throughput * 32));
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t endiandata[20];
|
||||
for (int k=0; k < 20; k++)
|
||||
be32enc(&endiandata[k], ((uint32_t*)pdata)[k]);
|
||||
|
||||
blake256_cpu_setBlock_80(pdata);
|
||||
bmw256_setTarget(ptarget);
|
||||
|
||||
do {
|
||||
int order = 0;
|
||||
uint32_t foundNonces[2] = { 0, 0 };
|
||||
|
||||
blake256_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
keccak256_cpu_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
cubehash256_cpu_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
lyra2v2_cpu_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
skein256_cpu_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
cubehash256_cpu_hash_32(thr_id, throughput,pdata[19], d_hash[thr_id], order++);
|
||||
|
||||
bmw256_cpu_hash_32(thr_id, throughput, pdata[19], d_hash[thr_id], foundNonces);
|
||||
|
||||
if (foundNonces[0] != 0)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonces[0]);
|
||||
lyra2v2_hash(vhash64, endiandata);
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget))
|
||||
{
|
||||
int res = 1;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
// check if there was another one...
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
if (foundNonces[1] != 0)
|
||||
{
|
||||
be32enc(&endiandata[19], foundNonces[1]);
|
||||
lyra2v2_hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = foundNonces[1];
|
||||
res++;
|
||||
}
|
||||
pdata[19] = foundNonces[0];
|
||||
MyStreamSynchronize(NULL, 0, device_map[thr_id]);
|
||||
return res;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (vhash64[7] > Htarg) // don't show message if it is equal but fails fulltest
|
||||
applog(LOG_WARNING, "GPU #%d: result does not validate on CPU!", thr_id);
|
||||
}
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (!work_restart[thr_id].restart && (max_nonce > ((uint64_t)(pdata[19]) + throughput)));
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
MyStreamSynchronize(NULL, 0, device_map[thr_id]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_lyra2v2(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
cudaFree(d_hash2[thr_id]);
|
||||
|
||||
bmw256_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -245,10 +245,14 @@ void aligned_free(void *ptr);
|
||||
|
||||
#if JANSSON_MAJOR_VERSION >= 2
|
||||
#define JSON_LOADS(str, err_ptr) json_loads((str), 0, (err_ptr))
|
||||
#define JSON_LOADF(str, err_ptr) json_load_file((str), 0, (err_ptr))
|
||||
#else
|
||||
#define JSON_LOADS(str, err_ptr) json_loads((str), (err_ptr))
|
||||
#define JSON_LOADF(str, err_ptr) json_load_file((str), (err_ptr))
|
||||
#endif
|
||||
|
||||
json_t * json_load_url(char* cfg_url, json_error_t *err);
|
||||
|
||||
#define USER_AGENT PACKAGE_NAME "/" PACKAGE_VERSION
|
||||
|
||||
void sha256_init(uint32_t *state);
|
||||
@@ -260,128 +264,81 @@ void sha256d(unsigned char *hash, const unsigned char *data, int len);
|
||||
|
||||
struct work;
|
||||
|
||||
extern int scanhash_sha256d(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_blake256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, int8_t blakerounds);
|
||||
extern int scanhash_bmw(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_c11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_deep(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_keccak256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_fresh(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_fugue256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_groestlcoin(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_heavy(int thr_id,struct work *work, uint32_t max_nonce, unsigned long *hashes_done, uint32_t maxvote, int blocklen);
|
||||
extern int scanhash_jackpot(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_luffa(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_lyra2(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_lyra2v2(int thr_id,struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_myriad(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_neoscrypt(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_nist5(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_pentablake(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_quark(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_qubit(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_skeincoin(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_skein2(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_spreadx11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_s3(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_whirlx(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_x11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_x13(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_x14(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_x15(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_x17(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_zr5(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_deep(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
extern int scanhash_spreadx11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_luffa(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
extern int scanhash_sha256d(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
extern int scanhash_scrypt(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done,
|
||||
unsigned char *scratchbuf, struct timeval *tv_start, struct timeval *tv_end);
|
||||
extern int scanhash_scrypt_jane(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done,
|
||||
unsigned char *scratchbuf, struct timeval *tv_start, struct timeval *tv_end);
|
||||
|
||||
extern int scanhash_fugue256(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
/* free device allocated memory per algo */
|
||||
void miner_free_device(int thr_id);
|
||||
|
||||
extern int scanhash_groestlcoin(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_heavy(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done, uint32_t maxvote, int blocklen);
|
||||
|
||||
extern int scanhash_keccak256(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_myriad(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_jackpot(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_quark(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_anime(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_bitcoin(int thr_id, uint32_t *pdata,
|
||||
uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_blake256(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done, int8_t blakerounds);
|
||||
|
||||
extern int scanhash_credits(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
const uint32_t *midstate, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_fresh(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_lyra2(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_neoscrypt(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_nist5(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_pentablake(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_pluck(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_qubit(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_scrypt(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, unsigned char *scratchbuf, uint32_t max_nonce,
|
||||
unsigned long *hashes_done, struct timeval *tv_start, struct timeval *tv_end);
|
||||
|
||||
extern int scanhash_scrypt_jane(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, unsigned char *scratchbuf, uint32_t max_nonce,
|
||||
unsigned long *hashes_done, struct timeval *tv_start, struct timeval *tv_end);
|
||||
|
||||
extern int scanhash_skeincoin(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_skein2(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_s3(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_x11(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_x13(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_x14(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_x15(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_x17(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
|
||||
extern int scanhash_zr5(int thr_id, struct work *work, uint32_t max_nonce,
|
||||
unsigned long *hashes_done);
|
||||
extern void free_blake256(int thr_id);
|
||||
extern void free_bmw(int thr_id);
|
||||
extern void free_c11(int thr_id);
|
||||
extern void free_deep(int thr_id);
|
||||
extern void free_keccak256(int thr_id);
|
||||
extern void free_fresh(int thr_id);
|
||||
extern void free_fugue256(int thr_id);
|
||||
extern void free_groestlcoin(int thr_id);
|
||||
extern void free_heavy(int thr_id);
|
||||
extern void free_jackpot(int thr_id);
|
||||
extern void free_luffa(int thr_id);
|
||||
extern void free_lyra2(int thr_id);
|
||||
extern void free_lyra2v2(int thr_id);
|
||||
extern void free_myriad(int thr_id);
|
||||
extern void free_neoscrypt(int thr_id);
|
||||
extern void free_nist5(int thr_id);
|
||||
extern void free_pentablake(int thr_id);
|
||||
extern void free_quark(int thr_id);
|
||||
extern void free_qubit(int thr_id);
|
||||
extern void free_skeincoin(int thr_id);
|
||||
extern void free_skein2(int thr_id);
|
||||
extern void free_spreadx11(int thr_id);
|
||||
extern void free_s3(int thr_id);
|
||||
extern void free_whirlx(int thr_id);
|
||||
extern void free_x11(int thr_id);
|
||||
extern void free_x13(int thr_id);
|
||||
extern void free_x14(int thr_id);
|
||||
extern void free_x15(int thr_id);
|
||||
extern void free_x17(int thr_id);
|
||||
extern void free_zr5(int thr_id);
|
||||
//extern void free_sha256d(int thr_id);
|
||||
extern void free_scrypt(int thr_id);
|
||||
extern void free_scrypt_jane(int thr_id);
|
||||
|
||||
/* api related */
|
||||
void *api_thread(void *userdata);
|
||||
@@ -403,7 +360,7 @@ struct cgpu_info {
|
||||
int gpu_clock;
|
||||
int gpu_memclock;
|
||||
size_t gpu_mem;
|
||||
uint32_t gpu_usage;
|
||||
uint32_t gpu_power;
|
||||
double gpu_vddc;
|
||||
int16_t gpu_pstate;
|
||||
int16_t gpu_bus;
|
||||
@@ -491,6 +448,7 @@ extern bool opt_benchmark;
|
||||
extern bool opt_debug;
|
||||
extern bool opt_quiet;
|
||||
extern bool opt_protocol;
|
||||
extern bool opt_showdiff;
|
||||
extern bool opt_tracegpu;
|
||||
extern int opt_n_threads;
|
||||
extern int active_gpus;
|
||||
@@ -525,6 +483,7 @@ extern char* device_name[MAX_GPUS];
|
||||
extern short device_map[MAX_GPUS];
|
||||
extern long device_sm[MAX_GPUS];
|
||||
extern uint32_t gpus_intensity[MAX_GPUS];
|
||||
extern int opt_cudaschedule;
|
||||
|
||||
#define CL_N "\x1B[0m"
|
||||
#define CL_RED "\x1B[31m"
|
||||
@@ -566,13 +525,16 @@ extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
|
||||
extern int timeval_subtract(struct timeval *result, struct timeval *x,
|
||||
struct timeval *y);
|
||||
extern bool fulltest(const uint32_t *hash, const uint32_t *target);
|
||||
extern void diff_to_target(uint32_t *target, double diff);
|
||||
void diff_to_target(struct work* work, double diff);
|
||||
double target_to_diff(uint32_t* target);
|
||||
extern void get_currentalgo(char* buf, int sz);
|
||||
extern uint32_t device_intensity(int thr_id, const char *func, uint32_t defcount);
|
||||
|
||||
// bignum
|
||||
double bn_convert_nbits(const uint32_t nbits);
|
||||
void bn_nbits_to_uchar(const uint32_t nBits, uchar *target);
|
||||
double bn_hash_target_ratio(uint32_t* hash, uint32_t* target);
|
||||
void bn_store_hash_target_ratio(uint32_t* hash, uint32_t* target, struct work* work);
|
||||
|
||||
struct stratum_job {
|
||||
char *job_id;
|
||||
@@ -602,6 +564,7 @@ struct stratum_ctx {
|
||||
char *sockbuf;
|
||||
|
||||
double next_diff;
|
||||
double sharediff;
|
||||
|
||||
char *session_id;
|
||||
size_t xnonce1_size;
|
||||
@@ -625,8 +588,7 @@ struct tx {
|
||||
};
|
||||
|
||||
struct work {
|
||||
uint32_t data[48]; /* 168 bytes req */
|
||||
uint32_t midstate[8];
|
||||
uint32_t data[32];
|
||||
uint32_t target[8];
|
||||
uint32_t maxvote;
|
||||
|
||||
@@ -639,13 +601,18 @@ struct work {
|
||||
uint64_t u64[1];
|
||||
} noncerange;
|
||||
|
||||
double difficulty;
|
||||
double targetdiff;
|
||||
double shareratio;
|
||||
double sharediff;
|
||||
uint32_t height;
|
||||
uint8_t pooln;
|
||||
|
||||
uint32_t scanned_from;
|
||||
uint32_t scanned_to;
|
||||
|
||||
/* custom stuff */
|
||||
void * extradata;
|
||||
|
||||
/* pok getwork txs */
|
||||
uint32_t tx_count;
|
||||
struct tx txs[POK_MAX_TXS];
|
||||
@@ -773,10 +740,9 @@ void applog_hash(unsigned char *hash);
|
||||
void applog_compare_hash(unsigned char *hash, unsigned char *hash2);
|
||||
|
||||
void print_hash_tests(void);
|
||||
void animehash(void *state, const void *input);
|
||||
void bitcoin_hash(uint32_t *output, const uint32_t *data, uint32_t nonce, const uint32_t *midstate);
|
||||
void blake256hash(void *output, const void *input, int8_t rounds);
|
||||
void creditshash(void *state, const void *input);
|
||||
void bmw_hash(void *state, const void *input);
|
||||
void c11hash(void *output, const void *input);
|
||||
void deephash(void *state, const void *input);
|
||||
void luffa_hash(void *state, const void *input);
|
||||
void fresh_hash(void *state, const void *input);
|
||||
@@ -785,19 +751,21 @@ void heavycoin_hash(unsigned char* output, const unsigned char* input, int len);
|
||||
void keccak256_hash(void *state, const void *input);
|
||||
unsigned int jackpothash(void *state, const void *input);
|
||||
void groestlhash(void *state, const void *input);
|
||||
void lyra2_hash(void *state, const void *input);
|
||||
void lyra2re_hash(void *state, const void *input);
|
||||
void lyra2v2_hash(void *state, const void *input);
|
||||
void myriadhash(void *state, const void *input);
|
||||
void neoscrypt(uchar *output, const uchar *input, uint32_t profile);
|
||||
void nist5hash(void *state, const void *input);
|
||||
void pentablakehash(void *output, const void *input);
|
||||
void pluckhash(uint32_t *hash, const uint32_t *data, uchar *hashbuffer, const int N);
|
||||
void quarkhash(void *state, const void *input);
|
||||
void qubithash(void *state, const void *input);
|
||||
void scrypthash(void* output, const void* input);
|
||||
void scryptjane_hash(void* output, const void* input);
|
||||
void skeincoinhash(void *output, const void *input);
|
||||
void skein2hash(void *output, const void *input);
|
||||
void spreadhash(void *output, const void *input);
|
||||
void s3hash(void *output, const void *input);
|
||||
void whirlxHash(void *state, const void *input);
|
||||
void x11hash(void *output, const void *input);
|
||||
void x13hash(void *output, const void *input);
|
||||
void x14hash(void *output, const void *input);
|
||||
|
||||
+21
-5
@@ -8,6 +8,7 @@
|
||||
#include "miner.h"
|
||||
|
||||
void myriadgroestl_cpu_init(int thr_id, uint32_t threads);
|
||||
void myriadgroestl_cpu_free(int thr_id);
|
||||
void myriadgroestl_cpu_setBlock(int thr_id, void *data, void *pTargetIn);
|
||||
void myriadgroestl_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, void *outputHashes, uint32_t *nounce);
|
||||
|
||||
@@ -30,10 +31,11 @@ void myriadhash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
int scanhash_myriad(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
int scanhash_myriad(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[32];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
uint32_t start_nonce = pdata[19];
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1 << 17);
|
||||
throughput = min(throughput, max_nonce - start_nonce);
|
||||
@@ -67,10 +69,11 @@ int scanhash_myriad(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
|
||||
if (foundNounce < UINT32_MAX)
|
||||
{
|
||||
uint32_t _ALIGN(64) tmpHash[8];
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
endiandata[19] = swab32(foundNounce);
|
||||
myriadhash(tmpHash, endiandata);
|
||||
if (tmpHash[7] <= ptarget[7] && fulltest(tmpHash, ptarget)) {
|
||||
myriadhash(vhash, endiandata);
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
pdata[19] = foundNounce;
|
||||
free(outputHash);
|
||||
return 1;
|
||||
@@ -93,3 +96,16 @@ int scanhash_myriad(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
void free_myriad(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
myriadgroestl_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -735,6 +735,13 @@ void neoscrypt_cpu_init(int thr_id, uint32_t threads)
|
||||
cudaMemcpyToSymbol(BLAKE2S_SIGMA, BLAKE2S_SIGMA_host, sizeof(BLAKE2S_SIGMA_host), 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
__host__
|
||||
void neoscrypt_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_NNonce[thr_id]);
|
||||
cudaFree(d_buffer[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t neoscrypt_cpu_hash_k4(int thr_id, uint32_t threads, uint32_t startNounce, int have_stratum, int order)
|
||||
{
|
||||
|
||||
+20
-2
@@ -4,12 +4,16 @@
|
||||
|
||||
extern void neoscrypt_setBlockTarget(uint32_t * data, const void *ptarget);
|
||||
extern void neoscrypt_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void neoscrypt_cpu_free(int thr_id);
|
||||
extern uint32_t neoscrypt_cpu_hash_k4(int thr_id, uint32_t threads, uint32_t startNounce, int have_stratum, int order);
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
int scanhash_neoscrypt(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
int scanhash_neoscrypt(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
|
||||
int intensity = is_windows() ? 18 : 19;
|
||||
@@ -37,7 +41,6 @@ int scanhash_neoscrypt(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uin
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t endiandata[20];
|
||||
if (have_stratum) {
|
||||
for (int k = 0; k < 20; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
@@ -64,6 +67,7 @@ int scanhash_neoscrypt(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uin
|
||||
neoscrypt((uchar*)vhash64, (uchar*) endiandata, 0x80000620U);
|
||||
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[19] = foundNonce;
|
||||
return 1;
|
||||
} else {
|
||||
@@ -78,3 +82,17 @@ int scanhash_neoscrypt(int thr_id, uint32_t *pdata, const uint32_t *ptarget, uin
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
void free_neoscrypt(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
neoscrypt_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -36,8 +37,12 @@ static uint32_t device_bus_ids[MAX_GPUS] = { 0 };
|
||||
|
||||
extern uint32_t device_gpu_clocks[MAX_GPUS];
|
||||
extern uint32_t device_mem_clocks[MAX_GPUS];
|
||||
extern uint32_t device_plimit[MAX_GPUS];
|
||||
extern int8_t device_pstate[MAX_GPUS];
|
||||
|
||||
uint8_t gpu_clocks_changed[MAX_GPUS] = { 0 };
|
||||
uint32_t clock_prev[MAX_GPUS] = { 0 };
|
||||
uint32_t clock_prev_mem[MAX_GPUS] = { 0 };
|
||||
uint32_t limit_prev[MAX_GPUS] = { 0 };
|
||||
|
||||
/*
|
||||
* Wrappers to emulate dlopen() on other systems like Windows
|
||||
@@ -113,14 +118,12 @@ nvml_handle * nvml_create()
|
||||
|
||||
nvmlh->nvml_dll = nvml_dll;
|
||||
|
||||
nvmlh->nvmlInit = (nvmlReturn_t (*)(void))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlInit_v2");
|
||||
if (!nvmlh->nvmlInit) {
|
||||
nvmlh->nvmlInit = (nvmlReturn_t (*)(void))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlInit");
|
||||
}
|
||||
nvmlh->nvmlDeviceGetCount = (nvmlReturn_t (*)(int *))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCount_v2");
|
||||
nvmlh->nvmlInit = (nvmlReturn_t (*)(void)) wrap_dlsym(nvmlh->nvml_dll, "nvmlInit_v2");
|
||||
if (!nvmlh->nvmlInit)
|
||||
nvmlh->nvmlInit = (nvmlReturn_t (*)(void)) wrap_dlsym(nvmlh->nvml_dll, "nvmlInit");
|
||||
nvmlh->nvmlDeviceGetCount = (nvmlReturn_t (*)(int *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCount_v2");
|
||||
if (!nvmlh->nvmlDeviceGetCount)
|
||||
nvmlh->nvmlDeviceGetCount = (nvmlReturn_t (*)(int *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCount");
|
||||
nvmlh->nvmlDeviceGetHandleByIndex = (nvmlReturn_t (*)(int, nvmlDevice_t *))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetHandleByIndex_v2");
|
||||
nvmlh->nvmlDeviceGetAPIRestriction = (nvmlReturn_t (*)(nvmlDevice_t, nvmlRestrictedAPI_t, nvmlEnableState_t *))
|
||||
@@ -139,15 +142,31 @@ nvml_handle * nvml_create()
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetSupportedGraphicsClocks");
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *count, unsigned int *clocksMHz))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetSupportedMemoryClocks");
|
||||
/* NVML_ERROR_NOT_SUPPORTED
|
||||
nvmlh->nvmlDeviceGetAutoBoostedClocksEnabled = (nvmlReturn_t (*)(nvmlDevice_t, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetAutoBoostedClocksEnabled");
|
||||
nvmlh->nvmlDeviceSetAutoBoostedClocksEnabled = (nvmlReturn_t (*)(nvmlDevice_t, nvmlEnableState_t enabled))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceSetAutoBoostedClocksEnabled"); */
|
||||
nvmlh->nvmlDeviceGetClockInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlClockType_t, unsigned int *clock))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetClockInfo");
|
||||
nvmlh->nvmlDeviceGetPciInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlPciInfo_t *))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPciInfo");
|
||||
nvmlh->nvmlDeviceGetMaxClockInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlClockType_t, unsigned int *clock))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetMaxClockInfo");
|
||||
nvmlh->nvmlDeviceGetPciInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlPciInfo_t *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPciInfo_v2");
|
||||
if (!nvmlh->nvmlDeviceGetPciInfo)
|
||||
nvmlh->nvmlDeviceGetPciInfo = (nvmlReturn_t (*)(nvmlDevice_t, nvmlPciInfo_t *)) wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPciInfo");
|
||||
nvmlh->nvmlDeviceGetCurrPcieLinkGeneration = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *gen))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCurrPcieLinkGeneration");
|
||||
nvmlh->nvmlDeviceGetCurrPcieLinkWidth = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *width))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetCurrPcieLinkWidth");
|
||||
nvmlh->nvmlDeviceGetMaxPcieLinkGeneration = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *gen))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetMaxPcieLinkGeneration");
|
||||
nvmlh->nvmlDeviceGetMaxPcieLinkWidth = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *width))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetMaxPcieLinkWidth");
|
||||
nvmlh->nvmlDeviceGetPowerUsage = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerUsage");
|
||||
nvmlh->nvmlDeviceGetPowerManagementDefaultLimit = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *limit))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerManagementDefaultLimit");
|
||||
nvmlh->nvmlDeviceGetPowerManagementLimit = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *limit))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerManagementLimit");
|
||||
nvmlh->nvmlDeviceGetPowerManagementLimitConstraints = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *min, unsigned int *max))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPowerManagementLimitConstraints");
|
||||
nvmlh->nvmlDeviceSetPowerManagementLimit = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int limit))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceSetPowerManagementLimit");
|
||||
nvmlh->nvmlDeviceGetName = (nvmlReturn_t (*)(nvmlDevice_t, char *, int))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetName");
|
||||
nvmlh->nvmlDeviceGetTemperature = (nvmlReturn_t (*)(nvmlDevice_t, int, unsigned int *))
|
||||
@@ -168,25 +187,26 @@ nvml_handle * nvml_create()
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlErrorString");
|
||||
nvmlh->nvmlShutdown = (nvmlReturn_t (*)())
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlShutdown");
|
||||
|
||||
/*
|
||||
nvmlDeviceGetBrand(nvmlDevice_t device, nvmlBrandType_t *type)
|
||||
nvmlDeviceGetMaxPcieLinkWidth(nvmlDevice_t device, unsigned int *maxLinkWidth)
|
||||
nvmlDeviceGetMaxPcieLinkGeneration(nvmlDevice_t device, unsigned int *maxLinkGen)
|
||||
nvmlDeviceGetCurrPcieLinkWidth(nvmlDevice_t device, unsigned int *currLinkWidth)
|
||||
nvmlDeviceGetCurrPcieLinkGeneration(nvmlDevice_t device, unsigned int *currLinkGen)
|
||||
*/
|
||||
// v331
|
||||
nvmlh->nvmlDeviceGetEnforcedPowerLimit = (nvmlReturn_t (*)(nvmlDevice_t, unsigned int *limit))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetEnforcedPowerLimit");
|
||||
// v340
|
||||
/* NVML_ERROR_NOT_SUPPORTED
|
||||
nvmlh->nvmlDeviceGetAutoBoostedClocksEnabled = (nvmlReturn_t (*)(nvmlDevice_t, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetAutoBoostedClocksEnabled");
|
||||
nvmlh->nvmlDeviceSetAutoBoostedClocksEnabled = (nvmlReturn_t (*)(nvmlDevice_t, nvmlEnableState_t enabled))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceSetAutoBoostedClocksEnabled"); */
|
||||
// v346
|
||||
nvmlh->nvmlDeviceGetPcieThroughput = (nvmlReturn_t (*)(nvmlDevice_t, nvmlPcieUtilCounter_t, unsigned int *value))
|
||||
wrap_dlsym(nvmlh->nvml_dll, "nvmlDeviceGetPcieThroughput");
|
||||
|
||||
if (nvmlh->nvmlInit == NULL ||
|
||||
nvmlh->nvmlShutdown == NULL ||
|
||||
nvmlh->nvmlErrorString == NULL ||
|
||||
nvmlh->nvmlSystemGetDriverVersion == NULL ||
|
||||
nvmlh->nvmlDeviceGetCount == NULL ||
|
||||
nvmlh->nvmlDeviceGetHandleByIndex == NULL ||
|
||||
nvmlh->nvmlDeviceGetPciInfo == NULL ||
|
||||
nvmlh->nvmlDeviceGetName == NULL ||
|
||||
nvmlh->nvmlDeviceGetTemperature == NULL ||
|
||||
nvmlh->nvmlDeviceGetFanSpeed == NULL)
|
||||
nvmlh->nvmlDeviceGetName == NULL)
|
||||
{
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "Failed to obtain required NVML function pointers");
|
||||
@@ -196,7 +216,8 @@ nvml_handle * nvml_create()
|
||||
}
|
||||
|
||||
nvmlh->nvmlInit();
|
||||
nvmlh->nvmlSystemGetDriverVersion(driver_version, sizeof(driver_version));
|
||||
if (nvmlh->nvmlSystemGetDriverVersion)
|
||||
nvmlh->nvmlSystemGetDriverVersion(driver_version, sizeof(driver_version));
|
||||
nvmlh->nvmlDeviceGetCount(&nvmlh->nvml_gpucount);
|
||||
|
||||
/* Query CUDA device count, in case it doesn't agree with NVML, since */
|
||||
@@ -232,7 +253,7 @@ nvml_handle * nvml_create()
|
||||
nvmlh->nvml_pci_domain_id[i] = pciinfo.domain;
|
||||
nvmlh->nvml_pci_bus_id[i] = pciinfo.bus;
|
||||
nvmlh->nvml_pci_device_id[i] = pciinfo.device;
|
||||
nvmlh->nvml_pci_subsys_id[i] = pciinfo.pci_device_id;
|
||||
nvmlh->nvml_pci_subsys_id[i] = pciinfo.pci_subsystem_id;
|
||||
|
||||
nvmlh->app_clocks[i] = NVML_FEATURE_UNKNOWN;
|
||||
if (nvmlh->nvmlDeviceSetAPIRestriction) {
|
||||
@@ -280,41 +301,45 @@ int nvml_set_clocks(nvml_handle *nvmlh, int dev_id)
|
||||
uint32_t gpu_clk = 0, mem_clk = 0;
|
||||
int n = nvmlh->cuda_nvml_device_id[dev_id];
|
||||
if (n < 0 || n >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
|
||||
// prevent double operations on the same gpu... to enhance
|
||||
if (gpu_clocks_changed[dev_id])
|
||||
return 0;
|
||||
return -ENODEV;
|
||||
|
||||
if (!device_gpu_clocks[dev_id] && !device_mem_clocks[dev_id])
|
||||
return 0; // nothing to do
|
||||
|
||||
if (nvmlh->app_clocks[n] != NVML_FEATURE_ENABLED) {
|
||||
applog(LOG_WARNING, "GPU #%d: NVML application clock feature is not allowed!", dev_id);
|
||||
return -1;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
uint32_t mem_prev = clock_prev_mem[dev_id];
|
||||
if (!mem_prev)
|
||||
nvmlh->nvmlDeviceGetApplicationsClock(nvmlh->devs[n], NVML_CLOCK_MEM, &mem_prev);
|
||||
uint32_t gpu_prev = clock_prev[dev_id];
|
||||
if (!gpu_prev)
|
||||
nvmlh->nvmlDeviceGetApplicationsClock(nvmlh->devs[n], NVML_CLOCK_GRAPHICS, &gpu_prev);
|
||||
|
||||
nvmlh->nvmlDeviceGetDefaultApplicationsClock(nvmlh->devs[n], NVML_CLOCK_MEM, &mem_clk);
|
||||
rc = nvmlh->nvmlDeviceGetDefaultApplicationsClock(nvmlh->devs[n], NVML_CLOCK_GRAPHICS, &gpu_clk);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: unable to query application clocks", dev_id);
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "GPU #%d: default clocks are %u/%u", dev_id, mem_clk, gpu_clk);
|
||||
applog(LOG_DEBUG, "GPU #%d: default application clocks are %u/%u", dev_id, mem_clk, gpu_clk);
|
||||
|
||||
// get application config values
|
||||
if (device_mem_clocks[dev_id]) mem_clk = device_mem_clocks[dev_id];
|
||||
if (device_gpu_clocks[dev_id]) gpu_clk = device_gpu_clocks[dev_id];
|
||||
|
||||
// these functions works for the 960 and the 970 (346.72+), not for the 750 Ti
|
||||
uint32_t nclocks = 0, clocks[128] = { 0 };
|
||||
uint32_t nclocks = 0, clocks[127] = { 0 };
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, NULL);
|
||||
nclocks = min(nclocks, 128);
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, clocks);
|
||||
nclocks = min(nclocks, 127);
|
||||
if (nclocks)
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, clocks);
|
||||
for (uint8_t u=0; u < nclocks; u++) {
|
||||
// ordered desc, so get first
|
||||
// ordered by pstate (so highest is first memory clock - P0)
|
||||
if (clocks[u] <= mem_clk) {
|
||||
mem_clk = clocks[u];
|
||||
break;
|
||||
@@ -323,8 +348,9 @@ int nvml_set_clocks(nvml_handle *nvmlh, int dev_id)
|
||||
|
||||
nclocks = 0;
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, NULL);
|
||||
nclocks = min(nclocks, 128);
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, clocks);
|
||||
nclocks = min(nclocks, 127);
|
||||
if (nclocks)
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, clocks);
|
||||
for (uint8_t u=0; u < nclocks; u++) {
|
||||
// ordered desc, so get first
|
||||
if (clocks[u] <= gpu_clk) {
|
||||
@@ -337,32 +363,162 @@ int nvml_set_clocks(nvml_handle *nvmlh, int dev_id)
|
||||
if (rc == NVML_SUCCESS)
|
||||
applog(LOG_INFO, "GPU #%d: application clocks set to %u/%u", dev_id, mem_clk, gpu_clk);
|
||||
else {
|
||||
applog(LOG_ERR, "GPU #%d: %u/%u - %s", dev_id, mem_clk, gpu_clk, nvmlh->nvmlErrorString(rc));
|
||||
applog(LOG_WARNING, "GPU #%d: %u/%u - %s", dev_id, mem_clk, gpu_clk, nvmlh->nvmlErrorString(rc));
|
||||
return -1;
|
||||
}
|
||||
|
||||
gpu_clocks_changed[dev_id] = 1;
|
||||
// store previous clocks for reset on exit (or during wait...)
|
||||
clock_prev[dev_id] = gpu_prev;
|
||||
clock_prev_mem[dev_id] = mem_prev;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* reset default app clocks to an used device */
|
||||
/* reset default app clocks and limits on exit */
|
||||
int nvml_reset_clocks(nvml_handle *nvmlh, int dev_id)
|
||||
{
|
||||
int ret = 0;
|
||||
nvmlReturn_t rc;
|
||||
uint32_t gpu_clk = 0, mem_clk = 0;
|
||||
int n = nvmlh->cuda_nvml_device_id[dev_id];
|
||||
if (n < 0 || n >= nvmlh->nvml_gpucount)
|
||||
return -ENODEV;
|
||||
|
||||
if (clock_prev[dev_id]) {
|
||||
rc = nvmlh->nvmlDeviceResetApplicationsClocks(nvmlh->devs[n]);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: unable to reset application clocks", dev_id);
|
||||
}
|
||||
clock_prev[dev_id] = 0;
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
if (limit_prev[dev_id]) {
|
||||
uint32_t plimit = limit_prev[dev_id];
|
||||
if (nvmlh->nvmlDeviceGetPowerManagementDefaultLimit && !plimit) {
|
||||
rc = nvmlh->nvmlDeviceGetPowerManagementDefaultLimit(nvmlh->devs[n], &plimit);
|
||||
} else if (plimit) {
|
||||
rc = NVML_SUCCESS;
|
||||
}
|
||||
if (rc == NVML_SUCCESS)
|
||||
nvmlh->nvmlDeviceSetPowerManagementLimit(nvmlh->devs[n], plimit);
|
||||
ret = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set power state of a device (9xx)
|
||||
* Code is similar as clocks one, which allow the change of the pstate
|
||||
*/
|
||||
int nvml_set_pstate(nvml_handle *nvmlh, int dev_id)
|
||||
{
|
||||
nvmlReturn_t rc;
|
||||
uint32_t gpu_clk = 0, mem_clk = 0;
|
||||
int n = nvmlh->cuda_nvml_device_id[dev_id];
|
||||
if (n < 0 || n >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!gpu_clocks_changed[dev_id])
|
||||
return 0; // nothing to do
|
||||
if (device_pstate[dev_id] < 0)
|
||||
return 0;
|
||||
|
||||
rc = nvmlh->nvmlDeviceResetApplicationsClocks(nvmlh->devs[n]);
|
||||
if (nvmlh->app_clocks[n] != NVML_FEATURE_ENABLED) {
|
||||
applog(LOG_WARNING, "GPU #%d: NVML app. clock feature is not allowed!", dev_id);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
nvmlh->nvmlDeviceGetDefaultApplicationsClock(nvmlh->devs[n], NVML_CLOCK_MEM, &mem_clk);
|
||||
rc = nvmlh->nvmlDeviceGetDefaultApplicationsClock(nvmlh->devs[n], NVML_CLOCK_GRAPHICS, &gpu_clk);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: unable to reset application clocks", dev_id);
|
||||
applog(LOG_WARNING, "GPU #%d: unable to query application clocks", dev_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
// get application config values
|
||||
if (device_mem_clocks[dev_id]) mem_clk = device_mem_clocks[dev_id];
|
||||
if (device_gpu_clocks[dev_id]) gpu_clk = device_gpu_clocks[dev_id];
|
||||
|
||||
// these functions works for the 960 and the 970 (346.72+), not for the 750 Ti
|
||||
uint32_t nclocks = 0, clocks[127] = { 0 };
|
||||
int8_t wanted_pstate = device_pstate[dev_id];
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, NULL);
|
||||
nclocks = min(nclocks, 127);
|
||||
if (nclocks)
|
||||
nvmlh->nvmlDeviceGetSupportedMemoryClocks(nvmlh->devs[n], &nclocks, clocks);
|
||||
for (uint8_t u=0; u < nclocks; u++) {
|
||||
// ordered by pstate (so highest P0 first)
|
||||
if (u == wanted_pstate) {
|
||||
mem_clk = clocks[u];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nclocks = 0;
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, NULL);
|
||||
nclocks = min(nclocks, 127);
|
||||
if (nclocks)
|
||||
nvmlh->nvmlDeviceGetSupportedGraphicsClocks(nvmlh->devs[n], mem_clk, &nclocks, clocks);
|
||||
for (uint8_t u=0; u < nclocks; u++) {
|
||||
// ordered desc, so get first
|
||||
if (clocks[u] <= gpu_clk) {
|
||||
gpu_clk = clocks[u];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rc = nvmlh->nvmlDeviceSetApplicationsClocks(nvmlh->devs[n], mem_clk, gpu_clk);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: pstate %s", dev_id, nvmlh->nvmlErrorString(rc));
|
||||
return -1;
|
||||
}
|
||||
gpu_clocks_changed[dev_id] = 0;
|
||||
|
||||
if (!opt_quiet)
|
||||
applog(LOG_INFO, "GPU #%d: app clocks set to P%d (%u/%u)", dev_id, (int) wanted_pstate, mem_clk, gpu_clk);
|
||||
|
||||
clock_prev[dev_id] = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int nvml_set_plimit(nvml_handle *nvmlh, int dev_id)
|
||||
{
|
||||
nvmlReturn_t rc = NVML_ERROR_UNKNOWN;
|
||||
uint32_t gpu_clk = 0, mem_clk = 0;
|
||||
int n = nvmlh->cuda_nvml_device_id[dev_id];
|
||||
if (n < 0 || n >= nvmlh->nvml_gpucount)
|
||||
return -ENODEV;
|
||||
|
||||
if (!device_plimit[dev_id])
|
||||
return 0; // nothing to do
|
||||
|
||||
if (!nvmlh->nvmlDeviceSetPowerManagementLimit)
|
||||
return -ENOSYS;
|
||||
|
||||
uint32_t plimit = device_plimit[dev_id] * 1000;
|
||||
uint32_t pmin = 1000, pmax = 0, prev_limit = 0;
|
||||
if (nvmlh->nvmlDeviceGetPowerManagementLimitConstraints)
|
||||
rc = nvmlh->nvmlDeviceGetPowerManagementLimitConstraints(nvmlh->devs[n], &pmin, &pmax);
|
||||
|
||||
if (rc != NVML_SUCCESS) {
|
||||
if (!nvmlh->nvmlDeviceGetPowerManagementLimit)
|
||||
return -ENOSYS;
|
||||
}
|
||||
nvmlh->nvmlDeviceGetPowerManagementLimit(nvmlh->devs[n], &prev_limit);
|
||||
if (!pmax) pmax = prev_limit;
|
||||
|
||||
plimit = min(plimit, pmax);
|
||||
plimit = max(plimit, pmin);
|
||||
rc = nvmlh->nvmlDeviceSetPowerManagementLimit(nvmlh->devs[n], plimit);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
applog(LOG_WARNING, "GPU #%d: plimit %s", dev_id, nvmlh->nvmlErrorString(rc));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!opt_quiet) {
|
||||
applog(LOG_INFO, "GPU #%d: power limit set to %uW (allowed range is %u-%u)",
|
||||
dev_id, plimit/1000U, pmin/1000U, pmax/1000U);
|
||||
}
|
||||
|
||||
limit_prev[dev_id] = prev_limit;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -383,7 +539,10 @@ int nvml_get_gpu_name(nvml_handle *nvmlh, int cudaindex, char *namebuf, int bufs
|
||||
{
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetName)
|
||||
return -ENOSYS;
|
||||
|
||||
if (nvmlh->nvmlDeviceGetName(nvmlh->devs[gpuindex], namebuf, bufsize) != NVML_SUCCESS)
|
||||
return -1;
|
||||
@@ -397,7 +556,10 @@ int nvml_get_tempC(nvml_handle *nvmlh, int cudaindex, unsigned int *tempC)
|
||||
nvmlReturn_t rc;
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetTemperature)
|
||||
return -ENOSYS;
|
||||
|
||||
rc = nvmlh->nvmlDeviceGetTemperature(nvmlh->devs[gpuindex], 0u /* NVML_TEMPERATURE_GPU */, tempC);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
@@ -413,7 +575,10 @@ int nvml_get_fanpcnt(nvml_handle *nvmlh, int cudaindex, unsigned int *fanpcnt)
|
||||
nvmlReturn_t rc;
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetFanSpeed)
|
||||
return -ENOSYS;
|
||||
|
||||
rc = nvmlh->nvmlDeviceGetFanSpeed(nvmlh->devs[gpuindex], fanpcnt);
|
||||
if (rc != NVML_SUCCESS) {
|
||||
@@ -428,12 +593,15 @@ int nvml_get_power_usage(nvml_handle *nvmlh, int cudaindex, unsigned int *milliw
|
||||
{
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetPowerUsage)
|
||||
return -ENOSYS;
|
||||
|
||||
nvmlReturn_t res = nvmlh->nvmlDeviceGetPowerUsage(nvmlh->devs[gpuindex], milliwatts);
|
||||
if (res != NVML_SUCCESS) {
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "nvmlDeviceGetPowerUsage: %s", nvmlh->nvmlErrorString(res));
|
||||
//if (opt_debug)
|
||||
// applog(LOG_DEBUG, "nvmlDeviceGetPowerUsage: %s", nvmlh->nvmlErrorString(res));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -445,7 +613,10 @@ int nvml_get_pstate(nvml_handle *nvmlh, int cudaindex, int *pstate)
|
||||
{
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetPerformanceState)
|
||||
return -ENOSYS;
|
||||
|
||||
nvmlReturn_t res = nvmlh->nvmlDeviceGetPerformanceState(nvmlh->devs[gpuindex], pstate);
|
||||
if (res != NVML_SUCCESS) {
|
||||
@@ -461,7 +632,7 @@ int nvml_get_busid(nvml_handle *nvmlh, int cudaindex, int *busid)
|
||||
{
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
(*busid) = nvmlh->nvml_pci_bus_id[gpuindex];
|
||||
return 0;
|
||||
@@ -474,13 +645,17 @@ int nvml_get_serial(nvml_handle *nvmlh, int cudaindex, char *sn, int maxlen)
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
nvmlReturn_t res;
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
res = nvmlh->nvmlDeviceGetSerial(nvmlh->devs[gpuindex], sn, maxlen);
|
||||
if (res == NVML_SUCCESS) {
|
||||
return 0;
|
||||
if (nvmlh->nvmlDeviceGetSerial) {
|
||||
res = nvmlh->nvmlDeviceGetSerial(nvmlh->devs[gpuindex], sn, maxlen);
|
||||
if (res == NVML_SUCCESS)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetUUID)
|
||||
return -ENOSYS;
|
||||
|
||||
// nvmlDeviceGetUUID: GPU-f2bd642c-369f-5a14-e0b4-0d22dfe9a1fc
|
||||
// use a part of uuid to generate an unique serial
|
||||
// todo: check if there is vendor id is inside
|
||||
@@ -501,7 +676,10 @@ int nvml_get_bios(nvml_handle *nvmlh, int cudaindex, char *desc, int maxlen)
|
||||
uint32_t subids = 0;
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (!nvmlh->nvmlDeviceGetVbiosVersion)
|
||||
return -ENOSYS;
|
||||
|
||||
nvmlReturn_t res = nvmlh->nvmlDeviceGetVbiosVersion(nvmlh->devs[gpuindex], desc, maxlen);
|
||||
if (res != NVML_SUCCESS) {
|
||||
@@ -512,16 +690,16 @@ int nvml_get_bios(nvml_handle *nvmlh, int cudaindex, char *desc, int maxlen)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nvml_get_info(nvml_handle *nvmlh, int cudaindex, uint16_t *vid, uint16_t *pid)
|
||||
int nvml_get_info(nvml_handle *nvmlh, int cudaindex, uint16_t &vid, uint16_t &pid)
|
||||
{
|
||||
uint32_t subids = 0;
|
||||
int gpuindex = nvmlh->cuda_nvml_device_id[cudaindex];
|
||||
if (gpuindex < 0 || gpuindex >= nvmlh->nvml_gpucount)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
subids = nvmlh->nvml_pci_subsys_id[gpuindex];
|
||||
(*pid) = subids >> 16;
|
||||
(*vid) = subids & 0xFFFF;
|
||||
pid = subids >> 16;
|
||||
vid = subids & 0xFFFF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -561,7 +739,7 @@ int nvapi_temperature(unsigned int devNum, unsigned int *temperature)
|
||||
NvAPI_Status ret;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
NV_GPU_THERMAL_SETTINGS thermal;
|
||||
thermal.version = NV_GPU_THERMAL_SETTINGS_VER;
|
||||
@@ -584,7 +762,7 @@ int nvapi_fanspeed(unsigned int devNum, unsigned int *speed)
|
||||
NvAPI_Status ret;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
NvU32 fanspeed = 0;
|
||||
ret = NvAPI_GPU_GetTachReading(phys[devNum], &fanspeed);
|
||||
@@ -606,7 +784,7 @@ int nvapi_getpstate(unsigned int devNum, unsigned int *power)
|
||||
NvAPI_Status ret;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
NV_GPU_PERF_PSTATE_ID CurrentPstate = NVAPI_GPU_PERF_PSTATE_UNDEFINED; /* 16 */
|
||||
ret = NvAPI_GPU_GetCurrentPstate(phys[devNum], &CurrentPstate);
|
||||
@@ -631,7 +809,7 @@ int nvapi_getusage(unsigned int devNum, unsigned int *pct)
|
||||
NvAPI_Status ret;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
NV_GPU_DYNAMIC_PSTATES_INFO_EX info;
|
||||
info.version = NV_GPU_DYNAMIC_PSTATES_INFO_EX_VER;
|
||||
@@ -651,13 +829,13 @@ int nvapi_getusage(unsigned int devNum, unsigned int *pct)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nvapi_getinfo(unsigned int devNum, uint16_t *vid, uint16_t *pid)
|
||||
int nvapi_getinfo(unsigned int devNum, uint16_t &vid, uint16_t &pid)
|
||||
{
|
||||
NvAPI_Status ret;
|
||||
NvU32 pDeviceId, pSubSystemId, pRevisionId, pExtDeviceId;
|
||||
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
ret = NvAPI_GPU_GetPCIIdentifiers(phys[devNum], &pDeviceId, &pSubSystemId, &pRevisionId, &pExtDeviceId);
|
||||
if (ret != NVAPI_OK) {
|
||||
@@ -668,8 +846,8 @@ int nvapi_getinfo(unsigned int devNum, uint16_t *vid, uint16_t *pid)
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*pid) = pDeviceId >> 16;
|
||||
(*vid) = pDeviceId & 0xFFFF;
|
||||
pid = pDeviceId >> 16;
|
||||
vid = pDeviceId & 0xFFFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -678,7 +856,7 @@ int nvapi_getserial(unsigned int devNum, char *serial, unsigned int maxlen)
|
||||
{
|
||||
// NvAPI_Status ret;
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
sprintf(serial, "");
|
||||
|
||||
@@ -702,7 +880,7 @@ int nvapi_getbios(unsigned int devNum, char *desc, unsigned int maxlen)
|
||||
{
|
||||
NvAPI_Status ret;
|
||||
if (devNum >= nvapi_dev_cnt)
|
||||
return -1;
|
||||
return -ENODEV;
|
||||
|
||||
if (maxlen < 64) // Short String
|
||||
return -1;
|
||||
@@ -779,7 +957,7 @@ int nvapi_init()
|
||||
NvAPI_ShortString str;
|
||||
ret = NvAPI_SYS_GetDriverAndBranchVersion(&udv, str);
|
||||
if (ret == NVAPI_OK) {
|
||||
sprintf(driver_version,"%d.%d", udv/100, udv % 100);
|
||||
sprintf(driver_version,"%d.%02d", udv / 100, udv % 100);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -888,9 +1066,107 @@ unsigned int gpu_power(struct cgpu_info *gpu)
|
||||
return mw;
|
||||
}
|
||||
|
||||
static int translate_vendor_id(uint16_t vid, char *vendorname)
|
||||
{
|
||||
struct VENDORS {
|
||||
const uint16_t vid;
|
||||
const char *name;
|
||||
} vendors[] = {
|
||||
{ 0x1043, "ASUS" },
|
||||
{ 0x107D, "Leadtek" },
|
||||
{ 0x10B0, "Gainward" },
|
||||
// { 0x10DE, "NVIDIA" },
|
||||
{ 0x1458, "Gigabyte" },
|
||||
{ 0x1462, "MSI" },
|
||||
{ 0x154B, "PNY" },
|
||||
{ 0x1682, "XFX" },
|
||||
{ 0x196D, "Club3D" },
|
||||
{ 0x19DA, "Zotac" },
|
||||
{ 0x19F1, "BFG" },
|
||||
{ 0x1ACC, "PoV" },
|
||||
{ 0x1B4C, "KFA2" },
|
||||
{ 0x3842, "EVGA" },
|
||||
{ 0x7377, "Colorful" },
|
||||
{ 0, "" }
|
||||
};
|
||||
|
||||
if (!vendorname)
|
||||
return -EINVAL;
|
||||
|
||||
for(int v=0; v < ARRAY_SIZE(vendors); v++) {
|
||||
if (vid == vendors[v].vid) {
|
||||
strcpy(vendorname, vendors[v].name);
|
||||
return vid;
|
||||
}
|
||||
}
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "nvml: Unknown vendor %04x\n", vid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_PCIDEV
|
||||
extern "C" {
|
||||
#include <pci/pci.h>
|
||||
}
|
||||
static int linux_gpu_vendor(uint8_t pci_bus_id, char* vendorname, uint16_t &pid)
|
||||
{
|
||||
uint16_t subvendor = 0;
|
||||
struct pci_access *pci;
|
||||
struct pci_dev *dev;
|
||||
uint16_t subdevice;
|
||||
|
||||
if (!vendorname)
|
||||
return -EINVAL;
|
||||
|
||||
pci = pci_alloc();
|
||||
if (!pci)
|
||||
return -ENODEV;
|
||||
|
||||
pci_init(pci);
|
||||
pci_scan_bus(pci);
|
||||
|
||||
for(dev = pci->devices; dev; dev = dev->next)
|
||||
{
|
||||
if (dev->bus == pci_bus_id && dev->vendor_id == 0x10DE)
|
||||
{
|
||||
if (!(dev->known_fields & PCI_FILL_CLASS))
|
||||
pci_fill_info(dev, PCI_FILL_CLASS);
|
||||
if (dev->device_class != PCI_CLASS_DISPLAY_VGA)
|
||||
continue;
|
||||
subvendor = pci_read_word(dev, PCI_SUBSYSTEM_VENDOR_ID);
|
||||
subdevice = pci_read_word(dev, PCI_SUBSYSTEM_ID); // model
|
||||
|
||||
translate_vendor_id(subvendor, vendorname);
|
||||
}
|
||||
}
|
||||
pci_cleanup(pci);
|
||||
return (int) subvendor;
|
||||
}
|
||||
#endif
|
||||
|
||||
int gpu_vendor(uint8_t pci_bus_id, char *vendorname)
|
||||
{
|
||||
#ifdef HAVE_PCIDEV
|
||||
uint16_t pid = 0;
|
||||
return linux_gpu_vendor(pci_bus_id, vendorname, pid);
|
||||
#else
|
||||
uint16_t vid = 0, pid = 0;
|
||||
if (hnvml) { // may not be initialized on start...
|
||||
for (int id=0; id < hnvml->nvml_gpucount; id++) {
|
||||
if (hnvml->nvml_pci_bus_id[id] == pci_bus_id) {
|
||||
nvml_get_info(hnvml, id, vid, pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return translate_vendor_id(vid, vendorname);
|
||||
#endif
|
||||
}
|
||||
|
||||
int gpu_info(struct cgpu_info *gpu)
|
||||
{
|
||||
char vendorname[32] = { 0 };
|
||||
int id = gpu->gpu_id;
|
||||
uint8_t bus_id = 0;
|
||||
|
||||
gpu->nvml_id = -1;
|
||||
gpu->nvapi_id = -1;
|
||||
@@ -900,13 +1176,19 @@ int gpu_info(struct cgpu_info *gpu)
|
||||
|
||||
if (hnvml) {
|
||||
gpu->nvml_id = (int8_t) hnvml->cuda_nvml_device_id[id];
|
||||
nvml_get_info(hnvml, id, &gpu->gpu_vid, &gpu->gpu_pid);
|
||||
#ifdef HAVE_PCIDEV
|
||||
gpu->gpu_vid = linux_gpu_vendor(hnvml->nvml_pci_bus_id[id], vendorname, gpu->gpu_pid);
|
||||
if (!gpu->gpu_vid || !gpu->gpu_pid)
|
||||
nvml_get_info(hnvml, id, gpu->gpu_vid, gpu->gpu_pid);
|
||||
#else
|
||||
nvml_get_info(hnvml, id, gpu->gpu_vid, gpu->gpu_pid);
|
||||
#endif
|
||||
nvml_get_serial(hnvml, id, gpu->gpu_sn, sizeof(gpu->gpu_sn));
|
||||
nvml_get_bios(hnvml, id, gpu->gpu_desc, sizeof(gpu->gpu_desc));
|
||||
}
|
||||
#ifdef WIN32
|
||||
gpu->nvapi_id = (int8_t) nvapi_dev_map[id];
|
||||
nvapi_getinfo(nvapi_dev_map[id], &gpu->gpu_vid, &gpu->gpu_pid);
|
||||
nvapi_getinfo(nvapi_dev_map[id], gpu->gpu_vid, gpu->gpu_pid);
|
||||
nvapi_getserial(nvapi_dev_map[id], gpu->gpu_sn, sizeof(gpu->gpu_sn));
|
||||
nvapi_getbios(nvapi_dev_map[id], gpu->gpu_desc, sizeof(gpu->gpu_desc));
|
||||
#endif
|
||||
|
||||
@@ -66,6 +66,20 @@ enum nvmlClockType_t {
|
||||
NVML_CLOCK_MEM = 2
|
||||
};
|
||||
|
||||
enum nvmlPcieUtilCounter_t {
|
||||
NVML_PCIE_UTIL_TX_BYTES = 0,
|
||||
NVML_PCIE_UTIL_RX_BYTES = 1,
|
||||
NVML_PCIE_UTIL_COUNT
|
||||
};
|
||||
|
||||
enum nvmlValueType_t {
|
||||
NVML_VALUE_TYPE_DOUBLE = 0,
|
||||
NVML_VALUE_TYPE_UNSIGNED_INT = 1,
|
||||
NVML_VALUE_TYPE_UNSIGNED_LONG = 2,
|
||||
NVML_VALUE_TYPE_UNSIGNED_LONG_LONG = 3,
|
||||
NVML_VALUE_TYPE_COUNT
|
||||
};
|
||||
|
||||
#define NVML_DEVICE_SERIAL_BUFFER_SIZE 30
|
||||
#define NVML_DEVICE_UUID_BUFFER_SIZE 80
|
||||
#define NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE 32
|
||||
@@ -97,10 +111,17 @@ typedef struct {
|
||||
nvmlReturn_t (*nvmlDeviceResetApplicationsClocks)(nvmlDevice_t);
|
||||
nvmlReturn_t (*nvmlDeviceGetSupportedGraphicsClocks)(nvmlDevice_t, uint32_t mem, uint32_t *num, uint32_t *arr);
|
||||
nvmlReturn_t (*nvmlDeviceGetSupportedMemoryClocks)(nvmlDevice_t, unsigned int *count, unsigned int *clocksMHz);
|
||||
nvmlReturn_t (*nvmlDeviceGetAutoBoostedClocksEnabled)(nvmlDevice_t, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled);
|
||||
nvmlReturn_t (*nvmlDeviceSetAutoBoostedClocksEnabled)(nvmlDevice_t, nvmlEnableState_t enabled);
|
||||
nvmlReturn_t (*nvmlDeviceGetClockInfo)(nvmlDevice_t, nvmlClockType_t, unsigned int *);
|
||||
nvmlReturn_t (*nvmlDeviceGetMaxClockInfo)(nvmlDevice_t, nvmlClockType_t, unsigned int *);
|
||||
nvmlReturn_t (*nvmlDeviceGetPowerManagementDefaultLimit)(nvmlDevice_t, unsigned int *limit);
|
||||
nvmlReturn_t (*nvmlDeviceGetPowerManagementLimit)(nvmlDevice_t, unsigned int *limit);
|
||||
nvmlReturn_t (*nvmlDeviceGetPowerManagementLimitConstraints)(nvmlDevice_t, unsigned int *min, unsigned int *max);
|
||||
nvmlReturn_t (*nvmlDeviceSetPowerManagementLimit)(nvmlDevice_t device, unsigned int limit);
|
||||
nvmlReturn_t (*nvmlDeviceGetPciInfo)(nvmlDevice_t, nvmlPciInfo_t *);
|
||||
nvmlReturn_t (*nvmlDeviceGetCurrPcieLinkGeneration)(nvmlDevice_t device, unsigned int *gen);
|
||||
nvmlReturn_t (*nvmlDeviceGetCurrPcieLinkWidth)(nvmlDevice_t device, unsigned int *width);
|
||||
nvmlReturn_t (*nvmlDeviceGetMaxPcieLinkGeneration)(nvmlDevice_t device, unsigned int *gen);
|
||||
nvmlReturn_t (*nvmlDeviceGetMaxPcieLinkWidth)(nvmlDevice_t device, unsigned int *width);
|
||||
nvmlReturn_t (*nvmlDeviceGetName)(nvmlDevice_t, char *, int);
|
||||
nvmlReturn_t (*nvmlDeviceGetTemperature)(nvmlDevice_t, int, unsigned int *);
|
||||
nvmlReturn_t (*nvmlDeviceGetFanSpeed)(nvmlDevice_t, unsigned int *);
|
||||
@@ -112,6 +133,15 @@ typedef struct {
|
||||
nvmlReturn_t (*nvmlSystemGetDriverVersion)(char *version, unsigned int len);
|
||||
char* (*nvmlErrorString)(nvmlReturn_t);
|
||||
nvmlReturn_t (*nvmlShutdown)(void);
|
||||
// v331
|
||||
nvmlReturn_t (*nvmlDeviceGetEnforcedPowerLimit)(nvmlDevice_t, unsigned int *limit);
|
||||
// v340
|
||||
//nvmlReturn_t (*nvmlDeviceGetCpuAffinity)(nvmlDevice_t, unsigned int cpuSetSize, unsigned long* cpuSet);
|
||||
//nvmlReturn_t (*nvmlDeviceSetCpuAffinity)(nvmlDevice_t);
|
||||
//nvmlReturn_t (*nvmlDeviceGetAutoBoostedClocksEnabled)(nvmlDevice_t, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled);
|
||||
//nvmlReturn_t (*nvmlDeviceSetAutoBoostedClocksEnabled)(nvmlDevice_t, nvmlEnableState_t enabled);
|
||||
// v346
|
||||
nvmlReturn_t (*nvmlDeviceGetPcieThroughput)(nvmlDevice_t, nvmlPcieUtilCounter_t, unsigned int *value);
|
||||
} nvml_handle;
|
||||
|
||||
|
||||
@@ -123,43 +153,8 @@ int nvml_destroy(nvml_handle *nvmlh);
|
||||
*/
|
||||
int nvml_get_gpucount(nvml_handle *nvmlh, int *gpucount);
|
||||
|
||||
/*
|
||||
* Query the number of GPUs seen by CUDA
|
||||
*/
|
||||
int cuda_get_gpucount(nvml_handle *nvmlh, int *gpucount);
|
||||
|
||||
|
||||
/*
|
||||
* query the name of the GPU model from the CUDA device ID
|
||||
*
|
||||
*/
|
||||
int nvml_get_gpu_name(nvml_handle *nvmlh,
|
||||
int gpuindex,
|
||||
char *namebuf,
|
||||
int bufsize);
|
||||
|
||||
/*
|
||||
* Query the current GPU temperature (Celsius), from the CUDA device ID
|
||||
*/
|
||||
int nvml_get_tempC(nvml_handle *nvmlh,
|
||||
int gpuindex, unsigned int *tempC);
|
||||
|
||||
/*
|
||||
* Query the current GPU fan speed (percent) from the CUDA device ID
|
||||
*/
|
||||
int nvml_get_fanpcnt(nvml_handle *nvmlh,
|
||||
int gpuindex, unsigned int *fanpcnt);
|
||||
|
||||
/*
|
||||
* Query the current GPU power usage in millwatts from the CUDA device ID
|
||||
*
|
||||
* This feature is only available on recent GPU generations and may be
|
||||
* limited in some cases only to Tesla series GPUs.
|
||||
* If the query is run on an unsupported GPU, this routine will return -1.
|
||||
*/
|
||||
int nvml_get_power_usage(nvml_handle *nvmlh,
|
||||
int gpuindex,
|
||||
unsigned int *milliwatts);
|
||||
int nvml_set_plimit(nvml_handle *nvmlh, int dev_id);
|
||||
int nvml_set_pstate(nvml_handle *nvmlh, int dev_id);
|
||||
|
||||
int nvml_set_clocks(nvml_handle *nvmlh, int dev_id);
|
||||
int nvml_reset_clocks(nvml_handle *nvmlh, int dev_id);
|
||||
@@ -170,12 +165,13 @@ unsigned int gpu_fanpercent(struct cgpu_info *gpu);
|
||||
unsigned int gpu_fanrpm(struct cgpu_info *gpu);
|
||||
float gpu_temp(struct cgpu_info *gpu);
|
||||
unsigned int gpu_power(struct cgpu_info *gpu);
|
||||
unsigned int gpu_usage(struct cgpu_info *gpu);
|
||||
int gpu_pstate(struct cgpu_info *gpu);
|
||||
int gpu_busid(struct cgpu_info *gpu);
|
||||
|
||||
/* pid/vid, sn and bios rev */
|
||||
int gpu_info(struct cgpu_info *gpu);
|
||||
int gpu_vendor(uint8_t pci_bus_id, char *vendorname);
|
||||
|
||||
|
||||
/* nvapi functions */
|
||||
#ifdef WIN32
|
||||
|
||||
+31
-8
@@ -364,11 +364,12 @@ void pentablake_cpu_setBlock_80(uint32_t *pdata, const uint32_t *ptarget)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_pentablake(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
extern "C" int scanhash_pentablake(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t endiandata[20];
|
||||
int rc = 0;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 128U * 2560); // 18.5
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
@@ -403,20 +404,25 @@ extern "C" int scanhash_pentablake(int thr_id, uint32_t *pdata, const uint32_t *
|
||||
pentablake_cpu_hash_64(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
pentablake_cpu_hash_64(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
uint32_t foundNonce = pentablake_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhashcpu[8];
|
||||
uint32_t vhash[8];
|
||||
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
pentablakehash(vhashcpu, endiandata);
|
||||
pentablakehash(vhash, endiandata);
|
||||
|
||||
if (vhashcpu[7] <= Htarg && fulltest(vhashcpu, ptarget)) {
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
rc = 1;
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
if (extra_results[0] != UINT32_MAX) {
|
||||
// Rare but possible if the throughput is big
|
||||
be32enc(&endiandata[19], extra_results[0]);
|
||||
pentablakehash(vhash, endiandata);
|
||||
if (bn_hash_target_ratio(vhash, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
applog(LOG_NOTICE, "GPU found more than one result yippee!");
|
||||
pdata[21] = extra_results[0];
|
||||
extra_results[0] = UINT32_MAX;
|
||||
@@ -436,3 +442,20 @@ extern "C" int scanhash_pentablake(int thr_id, uint32_t *pdata, const uint32_t *
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
void free_pentablake(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
cudaFree(h_resNounce[thr_id]);
|
||||
cudaFree(d_resNounce[thr_id]);
|
||||
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -1,573 +0,0 @@
|
||||
/*
|
||||
* "pluck" kernel implementation.
|
||||
*
|
||||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2015 djm34
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ===========================(LICENSE END)=============================
|
||||
*
|
||||
* @author djm34
|
||||
* @author tpruvot
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "cuda_vector.h"
|
||||
|
||||
#include "miner.h"
|
||||
|
||||
uint32_t *d_PlNonce[MAX_GPUS];
|
||||
|
||||
__device__ uint8_t * hashbuffer;
|
||||
__constant__ uint32_t pTarget[8];
|
||||
__constant__ uint32_t c_data[20];
|
||||
|
||||
#define HASH_MEMORY_8bit 131072
|
||||
#define HASH_MEMORY_32bit 32768
|
||||
#define HASH_MEMORY 4096
|
||||
|
||||
static __constant__ uint32_t H256[8] = {
|
||||
0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
|
||||
0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
|
||||
};
|
||||
|
||||
static __constant__ uint32_t Ksha[64] = {
|
||||
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
|
||||
0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
|
||||
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
|
||||
0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
|
||||
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
|
||||
0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
|
||||
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
|
||||
0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
|
||||
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
|
||||
0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
|
||||
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
|
||||
0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
|
||||
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
|
||||
0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
|
||||
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
|
||||
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
|
||||
};
|
||||
|
||||
|
||||
#define SALSA(a,b,c,d) { \
|
||||
t = a+d; b^=rotateL(t, 7); \
|
||||
t = b+a; c^=rotateL(t, 9); \
|
||||
t = c+b; d^=rotateL(t, 13); \
|
||||
t = d+c; a^=rotateL(t, 18); \
|
||||
}
|
||||
|
||||
#define SALSA_CORE(state) { \
|
||||
SALSA(state.s0,state.s4,state.s8,state.sc); \
|
||||
SALSA(state.s5,state.s9,state.sd,state.s1); \
|
||||
SALSA(state.sa,state.se,state.s2,state.s6); \
|
||||
SALSA(state.sf,state.s3,state.s7,state.sb); \
|
||||
SALSA(state.s0,state.s1,state.s2,state.s3); \
|
||||
SALSA(state.s5,state.s6,state.s7,state.s4); \
|
||||
SALSA(state.sa,state.sb,state.s8,state.s9); \
|
||||
SALSA(state.sf,state.sc,state.sd,state.se); \
|
||||
}
|
||||
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
static __device__ __forceinline__ uint16 xor_salsa8(const uint16 &Bx)
|
||||
{
|
||||
uint32_t t;
|
||||
uint16 state = Bx;
|
||||
SALSA_CORE(state);
|
||||
SALSA_CORE(state);
|
||||
SALSA_CORE(state);
|
||||
SALSA_CORE(state);
|
||||
return(state+Bx);
|
||||
}
|
||||
#endif
|
||||
|
||||
// sha256
|
||||
|
||||
static __device__ __forceinline__ uint32_t bsg2_0(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 2);
|
||||
uint32_t r2 = ROTR32(x, 13);
|
||||
uint32_t r3 = ROTR32(x, 22);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint32_t bsg2_1(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 6);
|
||||
uint32_t r2 = ROTR32(x, 11);
|
||||
uint32_t r3 = ROTR32(x, 25);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint32_t ssg2_0(const uint32_t x)
|
||||
{
|
||||
uint64_t r1 = ROTR32(x, 7);
|
||||
uint64_t r2 = ROTR32(x, 18);
|
||||
uint64_t r3 = shr_t32(x, 3);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint32_t ssg2_1(const uint32_t x)
|
||||
{
|
||||
uint64_t r1 = ROTR32(x, 17);
|
||||
uint64_t r2 = ROTR32(x, 19);
|
||||
uint64_t r3 = shr_t32(x, 10);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ void sha2_step1(const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d, const uint32_t e,
|
||||
const uint32_t f, const uint32_t g, uint32_t &h, const uint32_t in, const uint32_t Kshared)
|
||||
{
|
||||
uint32_t t1, t2;
|
||||
uint32_t vxandx = xandx(e, f, g);
|
||||
uint32_t bsg21 = bsg2_1(e);
|
||||
uint32_t bsg20 = bsg2_0(a);
|
||||
uint32_t andorv = andor32(a, b, c);
|
||||
|
||||
t1 = h + bsg21 + vxandx + Kshared + in;
|
||||
t2 = bsg20 + andorv;
|
||||
d = d + t1;
|
||||
h = t1 + t2;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ void sha2_step2(const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d, const uint32_t e,
|
||||
const uint32_t f, const uint32_t g, uint32_t &h, uint32_t* in, const uint32_t pc, const uint32_t Kshared)
|
||||
{
|
||||
uint32_t t1, t2;
|
||||
|
||||
int pcidx1 = (pc - 2) & 0xF;
|
||||
int pcidx2 = (pc - 7) & 0xF;
|
||||
int pcidx3 = (pc - 15) & 0xF;
|
||||
uint32_t inx0 = in[pc];
|
||||
uint32_t inx1 = in[pcidx1];
|
||||
uint32_t inx2 = in[pcidx2];
|
||||
uint32_t inx3 = in[pcidx3];
|
||||
|
||||
uint32_t ssg21 = ssg2_1(inx1);
|
||||
uint32_t ssg20 = ssg2_0(inx3);
|
||||
uint32_t vxandx = xandx(e, f, g);
|
||||
uint32_t bsg21 = bsg2_1(e);
|
||||
uint32_t bsg20 = bsg2_0(a);
|
||||
uint32_t andorv = andor32(a, b, c);
|
||||
|
||||
in[pc] = ssg21 + inx2 + ssg20 + inx0;
|
||||
|
||||
t1 = h + bsg21 + vxandx + Kshared + in[pc];
|
||||
t2 = bsg20 + andorv;
|
||||
d = d + t1;
|
||||
h = t1 + t2;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void sha2_round_body(uint32_t* in, uint32_t* r)
|
||||
{
|
||||
uint32_t a = r[0];
|
||||
uint32_t b = r[1];
|
||||
uint32_t c = r[2];
|
||||
uint32_t d = r[3];
|
||||
uint32_t e = r[4];
|
||||
uint32_t f = r[5];
|
||||
uint32_t g = r[6];
|
||||
uint32_t h = r[7];
|
||||
|
||||
sha2_step1(a, b, c, d, e, f, g, h, in[0], Ksha[0]);
|
||||
sha2_step1(h, a, b, c, d, e, f, g, in[1], Ksha[1]);
|
||||
sha2_step1(g, h, a, b, c, d, e, f, in[2], Ksha[2]);
|
||||
sha2_step1(f, g, h, a, b, c, d, e, in[3], Ksha[3]);
|
||||
sha2_step1(e, f, g, h, a, b, c, d, in[4], Ksha[4]);
|
||||
sha2_step1(d, e, f, g, h, a, b, c, in[5], Ksha[5]);
|
||||
sha2_step1(c, d, e, f, g, h, a, b, in[6], Ksha[6]);
|
||||
sha2_step1(b, c, d, e, f, g, h, a, in[7], Ksha[7]);
|
||||
sha2_step1(a, b, c, d, e, f, g, h, in[8], Ksha[8]);
|
||||
sha2_step1(h, a, b, c, d, e, f, g, in[9], Ksha[9]);
|
||||
sha2_step1(g, h, a, b, c, d, e, f, in[10], Ksha[10]);
|
||||
sha2_step1(f, g, h, a, b, c, d, e, in[11], Ksha[11]);
|
||||
sha2_step1(e, f, g, h, a, b, c, d, in[12], Ksha[12]);
|
||||
sha2_step1(d, e, f, g, h, a, b, c, in[13], Ksha[13]);
|
||||
sha2_step1(c, d, e, f, g, h, a, b, in[14], Ksha[14]);
|
||||
sha2_step1(b, c, d, e, f, g, h, a, in[15], Ksha[15]);
|
||||
|
||||
#pragma unroll 3
|
||||
for (int i = 0; i<3; i++) {
|
||||
|
||||
sha2_step2(a, b, c, d, e, f, g, h, in, 0, Ksha[16 + 16 * i]);
|
||||
sha2_step2(h, a, b, c, d, e, f, g, in, 1, Ksha[17 + 16 * i]);
|
||||
sha2_step2(g, h, a, b, c, d, e, f, in, 2, Ksha[18 + 16 * i]);
|
||||
sha2_step2(f, g, h, a, b, c, d, e, in, 3, Ksha[19 + 16 * i]);
|
||||
sha2_step2(e, f, g, h, a, b, c, d, in, 4, Ksha[20 + 16 * i]);
|
||||
sha2_step2(d, e, f, g, h, a, b, c, in, 5, Ksha[21 + 16 * i]);
|
||||
sha2_step2(c, d, e, f, g, h, a, b, in, 6, Ksha[22 + 16 * i]);
|
||||
sha2_step2(b, c, d, e, f, g, h, a, in, 7, Ksha[23 + 16 * i]);
|
||||
sha2_step2(a, b, c, d, e, f, g, h, in, 8, Ksha[24 + 16 * i]);
|
||||
sha2_step2(h, a, b, c, d, e, f, g, in, 9, Ksha[25 + 16 * i]);
|
||||
sha2_step2(g, h, a, b, c, d, e, f, in, 10, Ksha[26 + 16 * i]);
|
||||
sha2_step2(f, g, h, a, b, c, d, e, in, 11, Ksha[27 + 16 * i]);
|
||||
sha2_step2(e, f, g, h, a, b, c, d, in, 12, Ksha[28 + 16 * i]);
|
||||
sha2_step2(d, e, f, g, h, a, b, c, in, 13, Ksha[29 + 16 * i]);
|
||||
sha2_step2(c, d, e, f, g, h, a, b, in, 14, Ksha[30 + 16 * i]);
|
||||
sha2_step2(b, c, d, e, f, g, h, a, in, 15, Ksha[31 + 16 * i]);
|
||||
|
||||
}
|
||||
|
||||
r[0] += a;
|
||||
r[1] += b;
|
||||
r[2] += c;
|
||||
r[3] += d;
|
||||
r[4] += e;
|
||||
r[5] += f;
|
||||
r[6] += g;
|
||||
r[7] += h;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint8 sha256_64(uint32_t *data)
|
||||
{
|
||||
uint32_t __align__(64) in[16];
|
||||
uint32_t __align__(32) buf[8];
|
||||
|
||||
((uint16 *)in)[0] = swapvec((uint16*)data);
|
||||
|
||||
((uint8*)buf)[0] = ((uint8*)H256)[0];
|
||||
|
||||
sha2_round_body(in, buf);
|
||||
|
||||
#pragma unroll 14
|
||||
for (int i = 0; i<14; i++) { in[i + 1] = 0; }
|
||||
|
||||
in[0] = 0x80000000;
|
||||
in[15] = 0x200;
|
||||
|
||||
sha2_round_body(in, buf);
|
||||
return swapvec((uint8*)buf);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__ uint8 sha256_80(uint32_t nonce)
|
||||
{
|
||||
uint32_t __align__(64) in[16];
|
||||
uint32_t __align__(32) buf[8];
|
||||
|
||||
((uint16 *)in)[0] = swapvec((uint16*)c_data);
|
||||
((uint8*)buf)[0] = ((uint8*)H256)[0];
|
||||
|
||||
sha2_round_body(in, buf);
|
||||
|
||||
#pragma unroll 3
|
||||
for (int i = 0; i<3; i++) { in[i] = cuda_swab32(c_data[i + 16]); }
|
||||
|
||||
// in[3] = cuda_swab32(nonce);
|
||||
in[3] = nonce;
|
||||
in[4] = 0x80000000;
|
||||
in[15] = 0x280;
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 5; i<15; i++) { in[i] = 0; }
|
||||
|
||||
sha2_round_body(in, buf);
|
||||
return swapvec((uint8*)buf);
|
||||
}
|
||||
|
||||
// Pluck Factor 128
|
||||
#define SHIFT (1024 * 128)
|
||||
|
||||
__global__ __launch_bounds__(256, 1)
|
||||
void pluck_gpu_hash0_v50(uint32_t threads, uint32_t startNonce)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
uint32_t shift = SHIFT * thread;
|
||||
((uint8*)(hashbuffer + shift))[0] = sha256_80(nonce);
|
||||
((uint8*)(hashbuffer + shift))[1] = make_uint8(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
for (int i = 2; i < 5; i++)
|
||||
{
|
||||
uint32_t randmax = i * 32 - 4;
|
||||
uint32_t randseed[16];
|
||||
uint32_t randbuffer[16];
|
||||
uint32_t joint[16];
|
||||
|
||||
((uint8*)randseed)[0] = __ldg8(&(hashbuffer + shift)[32 * i - 64]);
|
||||
((uint8*)randseed)[1] = __ldg8(&(hashbuffer + shift)[32 * i - 32]);
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
((uint8*)joint)[0] = ((uint8*)randseed)[1];
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; j++) {
|
||||
uint32_t rand = randbuffer[j] % (randmax - 32);
|
||||
joint[j + 8] = __ldgtoint_unaligned(&(hashbuffer + shift)[rand]);
|
||||
}
|
||||
|
||||
uint8 truc = sha256_64(joint);
|
||||
((uint8*)(hashbuffer + shift))[i] = truc;
|
||||
((uint8*)randseed)[0] = ((uint8*)joint)[0];
|
||||
((uint8*)randseed)[1] = truc;
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j / 2] % randmax;
|
||||
(hashbuffer + shift)[rand] = __ldg(&(hashbuffer + shift)[randmax + j]);
|
||||
(hashbuffer + shift)[rand + 1] = __ldg(&(hashbuffer + shift)[randmax + j + 1]);
|
||||
(hashbuffer + shift)[rand + 2] = __ldg(&(hashbuffer + shift)[randmax + j + 2]);
|
||||
(hashbuffer + shift)[rand + 3] = __ldg(&(hashbuffer + shift)[randmax + j + 3]);
|
||||
}
|
||||
} // main loop
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(256, 1)
|
||||
void pluck_gpu_hash_v50(uint32_t threads, uint32_t startNonce, uint32_t *nonceVector)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
uint32_t shift = SHIFT * thread;
|
||||
|
||||
for (int i = 5; i < HASH_MEMORY - 1; i++)
|
||||
{
|
||||
uint32_t randmax = i*32-4;
|
||||
uint32_t randseed[16];
|
||||
uint32_t randbuffer[16];
|
||||
uint32_t joint[16];
|
||||
uint8 Buffbuffer[2];
|
||||
|
||||
((uint8*)randseed)[0] = __ldg8(&(hashbuffer + shift)[32*i-64]);
|
||||
((uint8*)randseed)[1] = __ldg8(&(hashbuffer + shift)[32*i-32]);
|
||||
|
||||
|
||||
Buffbuffer[0] = __ldg8(&(hashbuffer + shift)[32*i - 128]);
|
||||
Buffbuffer[1] = __ldg8(&(hashbuffer + shift)[32*i - 96]);
|
||||
|
||||
((uint16*)randseed)[0] ^= ((uint16*)Buffbuffer)[0];
|
||||
((uint16*)randbuffer)[0]= xor_salsa8(((uint16*)randseed)[0]);
|
||||
((uint8*)joint)[0] = __ldg8(&(hashbuffer + shift)[(i-1)<<5]);
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; j++) {
|
||||
uint32_t rand = randbuffer[j] % (randmax - 32);
|
||||
joint[j+8] = __ldgtoint_unaligned(&(hashbuffer + shift)[rand]);
|
||||
}
|
||||
|
||||
uint8 truc = sha256_64(joint);
|
||||
((uint8*)(hashbuffer + shift))[i] = truc;
|
||||
((uint8*)randseed)[0] = ((uint8*)joint)[0];
|
||||
((uint8*)randseed)[1] = truc;
|
||||
|
||||
((uint16*)randseed)[0] ^= ((uint16*)Buffbuffer)[0];
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j / 2] % randmax;
|
||||
|
||||
(hashbuffer+shift)[rand] = __ldg(&(hashbuffer+shift)[randmax+j]);
|
||||
(hashbuffer + shift)[rand + 1] = __ldg(&(hashbuffer + shift)[randmax + j + 1]);
|
||||
(hashbuffer + shift)[rand + 2] = __ldg(&(hashbuffer + shift)[randmax + j + 2]);
|
||||
(hashbuffer + shift)[rand + 3] = __ldg(&(hashbuffer + shift)[randmax + j + 3]);
|
||||
}
|
||||
|
||||
} // main loop
|
||||
|
||||
uint32_t outbuf = __ldgtoint(&(hashbuffer + shift)[28]);
|
||||
|
||||
if (outbuf <= pTarget[7]) {
|
||||
nonceVector[0] = nonce;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(128, 3)
|
||||
void pluck_gpu_hash0(uint32_t threads, uint32_t startNonce)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
|
||||
uint32_t shift = SHIFT * thread;
|
||||
((uint8*)(hashbuffer + shift))[0] = sha256_80(nonce);
|
||||
((uint8*)(hashbuffer + shift))[1] = make_uint8(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
for (int i = 2; i < 5; i++)
|
||||
{
|
||||
uint32_t randmax = i * 32 - 4;
|
||||
uint32_t randseed[16];
|
||||
uint32_t randbuffer[16];
|
||||
uint32_t joint[16];
|
||||
|
||||
((uint8*)randseed)[0] = __ldg8(&(hashbuffer + shift)[32 * i - 64]);
|
||||
((uint8*)randseed)[1] = __ldg8(&(hashbuffer + shift)[32 * i - 32]);
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
((uint8*)joint)[0] = ((uint8*)randseed)[1];
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; j++) {
|
||||
uint32_t rand = randbuffer[j] % (randmax - 32);
|
||||
joint[j + 8] = __ldgtoint_unaligned(&(hashbuffer + shift)[rand]);
|
||||
}
|
||||
|
||||
uint8 truc = sha256_64(joint);
|
||||
((uint8*)(hashbuffer + shift))[i] = truc;
|
||||
((uint8*)randseed)[0] = ((uint8*)joint)[0];
|
||||
((uint8*)randseed)[1] = truc;
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j / 2] % randmax;
|
||||
(hashbuffer + shift)[rand] = __ldg(&(hashbuffer + shift)[randmax + j]);
|
||||
(hashbuffer + shift)[rand + 1] = __ldg(&(hashbuffer + shift)[randmax + j + 1]);
|
||||
(hashbuffer + shift)[rand + 2] = __ldg(&(hashbuffer + shift)[randmax + j + 2]);
|
||||
(hashbuffer + shift)[rand + 3] = __ldg(&(hashbuffer + shift)[randmax + j + 3]);
|
||||
}
|
||||
} // main loop
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(128, 3)
|
||||
void pluck_gpu_hash(uint32_t threads, uint32_t startNonce, uint32_t *nonceVector)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
const uint32_t nonce = startNonce + thread;
|
||||
|
||||
uint32_t shift = SHIFT * thread;
|
||||
|
||||
for (int i = 5; i < HASH_MEMORY - 1; i++)
|
||||
{
|
||||
uint32_t randmax = i * 32 - 4;
|
||||
uint32_t randseed[16];
|
||||
uint32_t randbuffer[16];
|
||||
uint32_t joint[16];
|
||||
uint8 Buffbuffer[2];
|
||||
|
||||
((uint8*)randseed)[0] = __ldg8(&(hashbuffer + shift)[32 * i - 64]);
|
||||
((uint8*)randseed)[1] = __ldg8(&(hashbuffer + shift)[32 * i - 32]);
|
||||
|
||||
|
||||
Buffbuffer[0] = __ldg8(&(hashbuffer + shift)[32 * i - 128]);
|
||||
Buffbuffer[1] = __ldg8(&(hashbuffer + shift)[32 * i - 96]);
|
||||
((uint16*)randseed)[0] ^= ((uint16*)Buffbuffer)[0];
|
||||
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
|
||||
((uint8*)joint)[0] = __ldg8(&(hashbuffer + shift)[(i - 1) << 5]);
|
||||
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; j++)
|
||||
{
|
||||
uint32_t rand = randbuffer[j] % (randmax - 32);
|
||||
joint[j + 8] = __ldgtoint_unaligned(&(hashbuffer + shift)[rand]);
|
||||
}
|
||||
|
||||
uint8 truc = sha256_64(joint);
|
||||
((uint8*)(hashbuffer + shift))[i] = truc;
|
||||
((uint8*)randseed)[0] = ((uint8*)joint)[0];
|
||||
((uint8*)randseed)[1] = truc;
|
||||
|
||||
|
||||
((uint16*)randseed)[0] ^= ((uint16*)Buffbuffer)[0];
|
||||
((uint16*)randbuffer)[0] = xor_salsa8(((uint16*)randseed)[0]);
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j / 2] % randmax;
|
||||
|
||||
(hashbuffer + shift)[rand] = __ldg(&(hashbuffer + shift)[randmax + j]);
|
||||
(hashbuffer + shift)[rand + 1] = __ldg(&(hashbuffer + shift)[randmax + j + 1]);
|
||||
(hashbuffer + shift)[rand + 2] = __ldg(&(hashbuffer + shift)[randmax + j + 2]);
|
||||
(hashbuffer + shift)[rand + 3] = __ldg(&(hashbuffer + shift)[randmax + j + 3]);
|
||||
}
|
||||
} // main loop
|
||||
|
||||
uint32_t outbuf = __ldgtoint(&(hashbuffer + shift)[28]);
|
||||
|
||||
if (outbuf <= pTarget[7]) {
|
||||
nonceVector[0] = nonce;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void pluck_cpu_init(int thr_id, uint32_t threads, uint32_t* hash)
|
||||
{
|
||||
cuda_get_arch(thr_id);
|
||||
cudaMemcpyToSymbol(hashbuffer, &hash, sizeof(hash), 0, cudaMemcpyHostToDevice);
|
||||
cudaMalloc(&d_PlNonce[thr_id], sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t pluck_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, int order)
|
||||
{
|
||||
uint32_t result[8] = { 0xffffffff };
|
||||
cudaMemset(d_PlNonce[thr_id], 0xff, sizeof(uint32_t));
|
||||
|
||||
const uint32_t threadsperblock = 128;
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
dim3 grid50((threads + 256 - 1) / 256);
|
||||
dim3 block50(256);
|
||||
|
||||
if (device_sm[device_map[thr_id]] <= 300) {
|
||||
applog(LOG_ERR,"Sorry pluck not supported on SM 3.0 devices");
|
||||
return 0;
|
||||
} else if (device_sm[device_map[thr_id]] >= 500) {
|
||||
pluck_gpu_hash0_v50 <<< grid50, block50 >>>(threads, startNounce);
|
||||
pluck_gpu_hash_v50 <<< grid50, block50 >>>(threads, startNounce, d_PlNonce[thr_id]);
|
||||
} else {
|
||||
pluck_gpu_hash0 <<< grid, block >>>(threads, startNounce);
|
||||
pluck_gpu_hash <<< grid, block >>>(threads, startNounce, d_PlNonce[thr_id]);
|
||||
}
|
||||
|
||||
//MyStreamSynchronize(NULL, order, thr_id);
|
||||
CUDA_SAFE_CALL(cudaThreadSynchronize());
|
||||
cudaMemcpy(&result[thr_id], d_PlNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
|
||||
return result[thr_id];
|
||||
}
|
||||
|
||||
__host__
|
||||
void pluck_setBlockTarget(const void *pdata, const void *ptarget)
|
||||
{
|
||||
unsigned char PaddedMessage[80];
|
||||
memcpy(PaddedMessage, pdata, 80);
|
||||
|
||||
cudaMemcpyToSymbol(c_data, PaddedMessage, 80, 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(pTarget, ptarget, 32, 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
-240
@@ -1,240 +0,0 @@
|
||||
/* Based on djm code */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS] ;
|
||||
|
||||
extern void pluck_setBlockTarget(const void* data, const void *ptarget);
|
||||
extern void pluck_cpu_init(int thr_id, uint32_t threads, uint32_t *d_outputHash);
|
||||
extern uint32_t pluck_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, int order);
|
||||
|
||||
extern float tp_coef[MAX_GPUS];
|
||||
|
||||
#define ROTL(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
|
||||
//note, this is 64 bytes
|
||||
static inline void xor_salsa8(uint32_t B[16], const uint32_t Bx[16])
|
||||
{
|
||||
#define ROTL(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
|
||||
uint32_t x00, x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, x11, x12, x13, x14, x15;
|
||||
int i;
|
||||
|
||||
x00 = (B[0] ^= Bx[0]);
|
||||
x01 = (B[1] ^= Bx[1]);
|
||||
x02 = (B[2] ^= Bx[2]);
|
||||
x03 = (B[3] ^= Bx[3]);
|
||||
x04 = (B[4] ^= Bx[4]);
|
||||
x05 = (B[5] ^= Bx[5]);
|
||||
x06 = (B[6] ^= Bx[6]);
|
||||
x07 = (B[7] ^= Bx[7]);
|
||||
x08 = (B[8] ^= Bx[8]);
|
||||
x09 = (B[9] ^= Bx[9]);
|
||||
x10 = (B[10] ^= Bx[10]);
|
||||
x11 = (B[11] ^= Bx[11]);
|
||||
x12 = (B[12] ^= Bx[12]);
|
||||
x13 = (B[13] ^= Bx[13]);
|
||||
x14 = (B[14] ^= Bx[14]);
|
||||
x15 = (B[15] ^= Bx[15]);
|
||||
for (i = 0; i < 8; i += 2) {
|
||||
/* Operate on columns. */
|
||||
x04 ^= ROTL(x00 + x12, 7); x09 ^= ROTL(x05 + x01, 7);
|
||||
x14 ^= ROTL(x10 + x06, 7); x03 ^= ROTL(x15 + x11, 7);
|
||||
|
||||
x08 ^= ROTL(x04 + x00, 9); x13 ^= ROTL(x09 + x05, 9);
|
||||
x02 ^= ROTL(x14 + x10, 9); x07 ^= ROTL(x03 + x15, 9);
|
||||
|
||||
x12 ^= ROTL(x08 + x04, 13); x01 ^= ROTL(x13 + x09, 13);
|
||||
x06 ^= ROTL(x02 + x14, 13); x11 ^= ROTL(x07 + x03, 13);
|
||||
|
||||
x00 ^= ROTL(x12 + x08, 18); x05 ^= ROTL(x01 + x13, 18);
|
||||
x10 ^= ROTL(x06 + x02, 18); x15 ^= ROTL(x11 + x07, 18);
|
||||
|
||||
/* Operate on rows. */
|
||||
x01 ^= ROTL(x00 + x03, 7); x06 ^= ROTL(x05 + x04, 7);
|
||||
x11 ^= ROTL(x10 + x09, 7); x12 ^= ROTL(x15 + x14, 7);
|
||||
|
||||
x02 ^= ROTL(x01 + x00, 9); x07 ^= ROTL(x06 + x05, 9);
|
||||
x08 ^= ROTL(x11 + x10, 9); x13 ^= ROTL(x12 + x15, 9);
|
||||
|
||||
x03 ^= ROTL(x02 + x01, 13); x04 ^= ROTL(x07 + x06, 13);
|
||||
x09 ^= ROTL(x08 + x11, 13); x14 ^= ROTL(x13 + x12, 13);
|
||||
|
||||
x00 ^= ROTL(x03 + x02, 18); x05 ^= ROTL(x04 + x07, 18);
|
||||
x10 ^= ROTL(x09 + x08, 18); x15 ^= ROTL(x14 + x13, 18);
|
||||
}
|
||||
B[0] += x00;
|
||||
B[1] += x01;
|
||||
B[2] += x02;
|
||||
B[3] += x03;
|
||||
B[4] += x04;
|
||||
B[5] += x05;
|
||||
B[6] += x06;
|
||||
B[7] += x07;
|
||||
B[8] += x08;
|
||||
B[9] += x09;
|
||||
B[10] += x10;
|
||||
B[11] += x11;
|
||||
B[12] += x12;
|
||||
B[13] += x13;
|
||||
B[14] += x14;
|
||||
B[15] += x15;
|
||||
#undef ROTL
|
||||
}
|
||||
|
||||
static void sha256_hash(uchar *hash, const uchar *data, int len)
|
||||
{
|
||||
SHA256_CTX ctx;
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, data, len);
|
||||
SHA256_Final(hash, &ctx);
|
||||
}
|
||||
|
||||
// hash exactly 64 bytes (ie, sha256 block size)
|
||||
static void sha256_hash512(uint32_t *hash, const uint32_t *data)
|
||||
{
|
||||
uint32_t _ALIGN(64) S[16];
|
||||
uint32_t _ALIGN(64) T[16];
|
||||
uchar _ALIGN(64) E[64] = { 0 };
|
||||
int i;
|
||||
|
||||
sha256_init(S);
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
T[i] = be32dec(&data[i]);
|
||||
sha256_transform(S, T, 0);
|
||||
|
||||
E[3] = 0x80;
|
||||
E[61] = 0x02; // T[15] = 8 * 64 => 0x200;
|
||||
sha256_transform(S, (uint32_t*)E, 0);
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
be32enc(&hash[i], S[i]);
|
||||
}
|
||||
|
||||
#define BLOCK_HEADER_SIZE 80
|
||||
void pluckhash(uint32_t *hash, const uint32_t *data, uchar *hashbuffer, const int N)
|
||||
{
|
||||
int size = N * 1024;
|
||||
sha256_hash(hashbuffer, (uchar*)data, BLOCK_HEADER_SIZE);
|
||||
memset(&hashbuffer[32], 0, 32);
|
||||
|
||||
for (int i = 64; i < size - 32; i += 32)
|
||||
{
|
||||
uint32_t _ALIGN(64) randseed[16];
|
||||
uint32_t _ALIGN(64) randbuffer[16];
|
||||
uint32_t _ALIGN(64) joint[16];
|
||||
//i-4 because we use integers for all references against this, and we don't want to go 3 bytes over the defined area
|
||||
//we could use size here, but then it's probable to use 0 as the value in most cases
|
||||
int randmax = i - 4;
|
||||
|
||||
//setup randbuffer to be an array of random indexes
|
||||
memcpy(randseed, &hashbuffer[i - 64], 64);
|
||||
|
||||
if (i > 128) memcpy(randbuffer, &hashbuffer[i - 128], 64);
|
||||
else memset(randbuffer, 0, 64);
|
||||
|
||||
xor_salsa8((uint32_t*)randbuffer, (uint32_t*)randseed);
|
||||
memcpy(joint, &hashbuffer[i - 32], 32);
|
||||
|
||||
//use the last hash value as the seed
|
||||
for (int j = 32; j < 64; j += 4)
|
||||
{
|
||||
//every other time, change to next random index
|
||||
//randmax - 32 as otherwise we go beyond memory that's already been written to
|
||||
uint32_t rand = randbuffer[(j - 32) >> 2] % (randmax - 32);
|
||||
joint[j >> 2] = *((uint32_t *)&hashbuffer[rand]);
|
||||
}
|
||||
|
||||
sha256_hash512((uint32_t*)&hashbuffer[i], joint);
|
||||
|
||||
//setup randbuffer to be an array of random indexes
|
||||
//use last hash value and previous hash value(post-mixing)
|
||||
memcpy(randseed, &hashbuffer[i - 32], 64);
|
||||
|
||||
if (i > 128) memcpy(randbuffer, &hashbuffer[i - 128], 64);
|
||||
else memset(randbuffer, 0, 64);
|
||||
|
||||
xor_salsa8((uint32_t*)randbuffer, (uint32_t*)randseed);
|
||||
|
||||
//use the last hash value as the seed
|
||||
for (int j = 0; j < 32; j += 2)
|
||||
{
|
||||
uint32_t rand = randbuffer[j >> 1] % randmax;
|
||||
*((uint32_t *)(hashbuffer + rand)) = *((uint32_t *)(hashbuffer + j + randmax));
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(hash, hashbuffer, 32);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
static __thread uchar* scratchbuf = NULL;
|
||||
|
||||
extern "C" int scanhash_pluck(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t endiandata[20];
|
||||
int opt_pluck_n = 128;
|
||||
|
||||
int intensity = is_windows() ? 17 : 19; /* beware > 20 could work and create diff problems later */
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity);
|
||||
// divide by 128 for this algo which require a lot of memory
|
||||
throughput = throughput / 128 - 256;
|
||||
throughput = min(throughput, max_nonce - first_nonce + 1);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0000ff;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
//cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
//cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
cudaMalloc(&d_hash[thr_id], opt_pluck_n * 1024 * throughput);
|
||||
|
||||
if (!scratchbuf)
|
||||
scratchbuf = (uchar*) calloc(opt_pluck_n, 1024);
|
||||
|
||||
pluck_cpu_init(thr_id, throughput, d_hash[thr_id]);
|
||||
|
||||
CUDA_SAFE_CALL(cudaGetLastError());
|
||||
applog(LOG_INFO, "Using %d cuda threads", throughput);
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int k = 0; k < 20; k++)
|
||||
be32enc(&endiandata[k], ((uint32_t*)pdata)[k]);
|
||||
|
||||
pluck_setBlockTarget(endiandata,ptarget);
|
||||
|
||||
do {
|
||||
uint32_t foundNonce = pluck_cpu_hash(thr_id, throughput, pdata[19], 0);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
pluckhash(vhash64, endiandata, scratchbuf, opt_pluck_n);
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
pdata[19] = foundNonce;
|
||||
return 1;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (pdata[19] < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
return 0;
|
||||
}
|
||||
@@ -21,6 +21,8 @@
|
||||
|
||||
"algo" : "zr5",
|
||||
|
||||
"timeout": 60,
|
||||
|
||||
"api-bind" : "0.0.0.0",
|
||||
"api-remote" : true,
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ extern time_t firstwork_time;
|
||||
extern volatile time_t g_work_time;
|
||||
extern volatile int pool_switch_count;
|
||||
extern volatile bool pool_is_switching;
|
||||
extern uint8_t conditional_state[MAX_GPUS];
|
||||
|
||||
extern struct option options[];
|
||||
|
||||
@@ -197,6 +198,9 @@ bool pool_switch(int pooln)
|
||||
// used to get the pool uptime
|
||||
firstwork_time = time(NULL);
|
||||
restart_threads();
|
||||
// reset wait states
|
||||
for (int n=0; n<opt_n_threads; n++)
|
||||
conditional_state[n] = false;
|
||||
|
||||
// restore flags
|
||||
allow_gbt = p->allow_gbt;
|
||||
|
||||
@@ -1,292 +0,0 @@
|
||||
extern "C"
|
||||
{
|
||||
#include "sph/sph_blake.h"
|
||||
#include "sph/sph_bmw.h"
|
||||
#include "sph/sph_groestl.h"
|
||||
#include "sph/sph_skein.h"
|
||||
#include "sph/sph_jh.h"
|
||||
#include "sph/sph_keccak.h"
|
||||
}
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
|
||||
// Speicher zur Generierung der Noncevektoren für die bedingten Hashes
|
||||
static uint32_t *d_branch1Nonces[MAX_GPUS];
|
||||
static uint32_t *d_branch2Nonces[MAX_GPUS];
|
||||
static uint32_t *d_branch3Nonces[MAX_GPUS];
|
||||
|
||||
extern void quark_blake512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_blake512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_bmw512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_bmw512_cpu_setBlock_80(void *pdata);
|
||||
extern void quark_bmw512_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_outputHash, int order);
|
||||
extern void quark_bmw512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_outputHash, int order);
|
||||
|
||||
extern void quark_groestl512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_groestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
extern void quark_doublegroestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_skein512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_skein512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_keccak512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_keccak512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_jh512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_jh512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes, uint32_t *d_validNonceTable,
|
||||
uint32_t *d_nonces1, uint32_t *nrm1,
|
||||
uint32_t *d_nonces2, uint32_t *nrm2,
|
||||
int order);
|
||||
extern void quark_compactTest_single_false_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes, uint32_t *d_validNonceTable,
|
||||
uint32_t *d_nonces1, uint32_t *nrm1,
|
||||
int order);
|
||||
|
||||
extern uint32_t cuda_check_hash_branch(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_inputHash, int order);
|
||||
|
||||
/* CPU Hash */
|
||||
extern "C" void animehash(void *state, const void *input)
|
||||
{
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_skein512_context ctx_skein;
|
||||
|
||||
unsigned char hash[64];
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
// ZBMW;
|
||||
sph_bmw512 (&ctx_bmw, (const void*) input, 80);
|
||||
sph_bmw512_close(&ctx_bmw, (void*) hash);
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
// ZBLAKE;
|
||||
sph_blake512 (&ctx_blake, hash, 64);
|
||||
sph_blake512_close(&ctx_blake, (void*) hash);
|
||||
|
||||
if (hash[0] & 0x8)
|
||||
{
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
// ZGROESTL;
|
||||
sph_groestl512 (&ctx_groestl, (const void*) hash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, (void*) hash);
|
||||
}
|
||||
else
|
||||
{
|
||||
sph_skein512_init(&ctx_skein);
|
||||
// ZSKEIN;
|
||||
sph_skein512 (&ctx_skein, (const void*) hash, 64);
|
||||
sph_skein512_close(&ctx_skein, (void*) hash);
|
||||
}
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
// ZGROESTL;
|
||||
sph_groestl512 (&ctx_groestl, (const void*) hash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, (void*) hash);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
// ZJH;
|
||||
sph_jh512 (&ctx_jh, (const void*) hash, 64);
|
||||
sph_jh512_close(&ctx_jh, (void*) hash);
|
||||
|
||||
if (hash[0] & 0x8)
|
||||
{
|
||||
sph_blake512_init(&ctx_blake);
|
||||
// ZBLAKE;
|
||||
sph_blake512 (&ctx_blake, (const void*) hash, 64);
|
||||
sph_blake512_close(&ctx_blake, (void*) hash);
|
||||
}
|
||||
else
|
||||
{
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
// ZBMW;
|
||||
sph_bmw512 (&ctx_bmw, (const void*) hash, 64);
|
||||
sph_bmw512_close(&ctx_bmw, (void*) hash);
|
||||
}
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
// ZKECCAK;
|
||||
sph_keccak512 (&ctx_keccak, (const void*) hash, 64);
|
||||
sph_keccak512_close(&ctx_keccak, (void*) hash);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
// SKEIN;
|
||||
sph_skein512 (&ctx_skein, (const void*) hash, 64);
|
||||
sph_skein512_close(&ctx_skein, (void*) hash);
|
||||
|
||||
if (hash[0] & 0x8)
|
||||
{
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
// ZKECCAK;
|
||||
sph_keccak512 (&ctx_keccak, (const void*) hash, 64);
|
||||
sph_keccak512_close(&ctx_keccak, (void*) hash);
|
||||
}
|
||||
else
|
||||
{
|
||||
sph_jh512_init(&ctx_jh);
|
||||
// ZJH;
|
||||
sph_jh512 (&ctx_jh, (const void*) hash, 64);
|
||||
sph_jh512_close(&ctx_jh, (void*) hash);
|
||||
}
|
||||
|
||||
memcpy(state, hash, 32);
|
||||
}
|
||||
|
||||
/*
|
||||
struct HashPredicate
|
||||
{
|
||||
HashPredicate(uint32_t *hashes, uint32_t startNonce) :
|
||||
m_hashes(hashes),
|
||||
m_startNonce(startNonce)
|
||||
{ }
|
||||
|
||||
__device__
|
||||
bool operator()(const uint32_t x)
|
||||
{
|
||||
uint32_t *hash = &m_hashes[(x - m_startNonce)*16];
|
||||
return hash[0] & 0x8;
|
||||
}
|
||||
|
||||
uint32_t *m_hashes;
|
||||
uint32_t m_startNonce;
|
||||
};
|
||||
*/
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_anime(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
{
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1 << 19); // 256*256*8
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x00000f;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], 16 * sizeof(uint32_t) * throughput));
|
||||
|
||||
quark_blake512_cpu_init(thr_id, throughput);
|
||||
quark_groestl512_cpu_init(thr_id, throughput);
|
||||
quark_skein512_cpu_init(thr_id, throughput);
|
||||
quark_bmw512_cpu_init(thr_id, throughput);
|
||||
quark_keccak512_cpu_init(thr_id, throughput);
|
||||
quark_jh512_cpu_init(thr_id, throughput);
|
||||
cuda_check_cpu_init(thr_id, throughput);
|
||||
quark_compactTest_cpu_init(thr_id, throughput);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_branch1Nonces[thr_id], sizeof(uint32_t)*throughput));
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_branch2Nonces[thr_id], sizeof(uint32_t)*throughput));
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_branch3Nonces[thr_id], sizeof(uint32_t)*throughput));
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t endiandata[20];
|
||||
for (int k=0; k < 20; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
|
||||
quark_bmw512_cpu_setBlock_80((void*)endiandata);
|
||||
cuda_check_cpu_setTarget(ptarget);
|
||||
|
||||
do {
|
||||
int order = 0;
|
||||
uint32_t nrm1=0, nrm2=0, nrm3=0;
|
||||
|
||||
// erstes BMW512 Hash mit CUDA
|
||||
quark_bmw512_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id], order++);
|
||||
|
||||
// das ist der unbedingte Branch für Blake512
|
||||
quark_blake512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
|
||||
quark_compactTest_single_false_cpu_hash_64(thr_id, throughput, pdata[19], d_hash[thr_id], NULL,
|
||||
d_branch3Nonces[thr_id], &nrm3,
|
||||
order++);
|
||||
|
||||
// nur den Skein Branch weiterverfolgen
|
||||
quark_skein512_cpu_hash_64(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
// das ist der unbedingte Branch für Groestl512
|
||||
quark_groestl512_cpu_hash_64(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
// das ist der unbedingte Branch für JH512
|
||||
quark_jh512_cpu_hash_64(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
// quarkNonces in branch1 und branch2 aufsplitten gemäss if (hash[0] & 0x8)
|
||||
quark_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash[thr_id], d_branch3Nonces[thr_id],
|
||||
d_branch1Nonces[thr_id], &nrm1,
|
||||
d_branch2Nonces[thr_id], &nrm2,
|
||||
order++);
|
||||
|
||||
// das ist der bedingte Branch für Blake512
|
||||
quark_blake512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
// das ist der bedingte Branch für Bmw512
|
||||
quark_bmw512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
// das ist der unbedingte Branch für Keccak512
|
||||
quark_keccak512_cpu_hash_64(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
// das ist der unbedingte Branch für Skein512
|
||||
quark_skein512_cpu_hash_64(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
// quarkNonces in branch1 und branch2 aufsplitten gemäss if (hash[0] & 0x8)
|
||||
quark_compactTest_cpu_hash_64(thr_id, nrm3, pdata[19], d_hash[thr_id], d_branch3Nonces[thr_id],
|
||||
d_branch1Nonces[thr_id], &nrm1,
|
||||
d_branch2Nonces[thr_id], &nrm2,
|
||||
order++);
|
||||
|
||||
// das ist der bedingte Branch für Keccak512
|
||||
quark_keccak512_cpu_hash_64(thr_id, nrm1, pdata[19], d_branch1Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
// das ist der bedingte Branch für JH512
|
||||
quark_jh512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
// Scan nach Gewinner Hashes auf der GPU
|
||||
uint32_t foundNonce = cuda_check_hash_branch(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
animehash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
if (secNonce != 0) {
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
pdata[19] = foundNonce;
|
||||
return res;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
if ((uint64_t)pdata[19] + throughput > (uint64_t)max_nonce) {
|
||||
pdata[19] = max_nonce;
|
||||
break;
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (!work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -27,7 +27,7 @@ __device__ cuda_compactTestFunction_t d_QuarkTrueFunction = QuarkTrueTest, d_Qua
|
||||
|
||||
cuda_compactTestFunction_t h_QuarkTrueFunction[MAX_GPUS], h_QuarkFalseFunction[MAX_GPUS];
|
||||
|
||||
// Setup-Funktionen
|
||||
// Setup/Alloc Function
|
||||
__host__ void quark_compactTest_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
cudaMemcpyFromSymbol(&h_QuarkTrueFunction[thr_id], d_QuarkTrueFunction, sizeof(cuda_compactTestFunction_t));
|
||||
@@ -45,6 +45,18 @@ __host__ void quark_compactTest_cpu_init(int thr_id, uint32_t threads)
|
||||
cudaMalloc(&d_partSum[1][thr_id], sizeof(uint32_t) * s1); // BLOCKSIZE (Threads/Block)
|
||||
}
|
||||
|
||||
// Because all alloc should have a free...
|
||||
__host__ void quark_compactTest_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_tempBranch1Nonces[thr_id]);
|
||||
cudaFree(d_numValid[thr_id]);
|
||||
|
||||
cudaFree(d_partSum[0][thr_id]);
|
||||
cudaFree(d_partSum[1][thr_id]);
|
||||
|
||||
cudaFreeHost(h_numValid[thr_id]);
|
||||
}
|
||||
|
||||
#if __CUDA_ARCH__ < 300
|
||||
/**
|
||||
* __shfl_up() calculates a source lane ID by subtracting delta from the caller's lane ID, and clamping to the range 0..width-1
|
||||
|
||||
+33
-8
@@ -41,6 +41,7 @@ extern void quark_jh512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_jh512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_compactTest_cpu_free(int thr_id);
|
||||
extern void quark_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes, uint32_t *d_validNonceTable,
|
||||
uint32_t *d_nonces1, uint32_t *nrm1,
|
||||
uint32_t *d_nonces2, uint32_t *nrm2,
|
||||
@@ -51,6 +52,7 @@ extern void quark_compactTest_single_false_cpu_hash_64(int thr_id, uint32_t thre
|
||||
|
||||
extern uint32_t cuda_check_hash_branch(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_inputHash, int order);
|
||||
|
||||
|
||||
// Original Quarkhash Funktion aus einem miner Quelltext
|
||||
extern "C" void quarkhash(void *state, const void *input)
|
||||
{
|
||||
@@ -131,10 +133,11 @@ extern "C" void quarkhash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_quark(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_quark(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1 << 20); // 256*4096
|
||||
@@ -166,7 +169,6 @@ extern "C" int scanhash_quark(int thr_id, uint32_t *pdata,
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t endiandata[20];
|
||||
for (int k=0; k < 20; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
|
||||
@@ -226,19 +228,19 @@ extern "C" int scanhash_quark(int thr_id, uint32_t *pdata,
|
||||
// das ist der bedingte Branch für JH512
|
||||
quark_jh512_cpu_hash_64(thr_id, nrm2, pdata[19], d_branch2Nonces[thr_id], d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
|
||||
// Scan nach Gewinner Hashes auf der GPU
|
||||
uint32_t foundNonce = cuda_check_hash_branch(thr_id, nrm3, pdata[19], d_branch3Nonces[thr_id], d_hash[thr_id], order++);
|
||||
if (foundNonce != 0xffffffff)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
quarkhash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[19] = foundNonce;
|
||||
*hashes_done = foundNonce - first_nonce + 1;
|
||||
return 1;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
@@ -252,3 +254,26 @@ extern "C" int scanhash_quark(int thr_id, uint32_t *pdata,
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_quark(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
cudaDeviceSynchronize();
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cudaFree(d_branch1Nonces[thr_id]);
|
||||
cudaFree(d_branch2Nonces[thr_id]);
|
||||
cudaFree(d_branch3Nonces[thr_id]);
|
||||
|
||||
quark_compactTest_cpu_free(thr_id);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+26
-3
@@ -52,10 +52,11 @@ extern "C" void deephash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_deep(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
extern "C" int scanhash_deep(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 19); // 256*256*8
|
||||
throughput = min(throughput, (max_nonce - first_nonce));
|
||||
@@ -91,6 +92,8 @@ extern "C" int scanhash_deep(int thr_id, uint32_t *pdata, const uint32_t *ptarge
|
||||
x11_cubehash512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
x11_echo512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
uint32_t foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
@@ -101,8 +104,12 @@ extern "C" int scanhash_deep(int thr_id, uint32_t *pdata, const uint32_t *ptarge
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
deephash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -121,3 +128,19 @@ extern "C" int scanhash_deep(int thr_id, uint32_t *pdata, const uint32_t *ptarge
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_deep(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+22
-3
@@ -30,10 +30,11 @@ extern "C" void luffa_hash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_luffa(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
extern "C" int scanhash_luffa(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 22); // 256*256*8*8
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
@@ -44,6 +45,8 @@ extern "C" int scanhash_luffa(int thr_id, uint32_t *pdata, const uint32_t *ptarg
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
if (opt_cudaschedule == -1) // to reduce cpu usage...
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], throughput * 64));
|
||||
|
||||
@@ -73,7 +76,7 @@ extern "C" int scanhash_luffa(int thr_id, uint32_t *pdata, const uint32_t *ptarg
|
||||
luffa_hash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
//*hashes_done = min(max_nonce - first_nonce, (uint64_t) pdata[19] - first_nonce + throughput);
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[19] = foundNonce;
|
||||
return 1;
|
||||
} else {
|
||||
@@ -93,3 +96,19 @@ extern "C" int scanhash_luffa(int thr_id, uint32_t *pdata, const uint32_t *ptarg
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_luffa(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+27
-5
@@ -74,11 +74,11 @@ extern "C" void qubithash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_qubit(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_qubit(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t endiandata[20];
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 19); // 256*256*8
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
@@ -119,6 +119,8 @@ extern "C" int scanhash_qubit(int thr_id, uint32_t *pdata,
|
||||
x11_simd512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
x11_echo512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
uint32_t foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
@@ -130,8 +132,12 @@ extern "C" int scanhash_qubit(int thr_id, uint32_t *pdata,
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
qubithash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -150,3 +156,19 @@ extern "C" int scanhash_qubit(int thr_id, uint32_t *pdata,
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_qubit(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+4
-4
@@ -60,8 +60,8 @@ IDI_ICON1 ICON "ccminer.ico"
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,6,4,0
|
||||
PRODUCTVERSION 1,6,4,0
|
||||
FILEVERSION 1,6,6,0
|
||||
PRODUCTVERSION 1,6,6,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x21L
|
||||
@@ -76,10 +76,10 @@ BEGIN
|
||||
BEGIN
|
||||
BLOCK "040904e4"
|
||||
BEGIN
|
||||
VALUE "FileVersion", "1.6.4"
|
||||
VALUE "FileVersion", "1.6.6"
|
||||
VALUE "LegalCopyright", "Copyright (C) 2015"
|
||||
VALUE "ProductName", "ccminer"
|
||||
VALUE "ProductVersion", "1.6.4"
|
||||
VALUE "ProductVersion", "1.6.6"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
||||
+11
-2
@@ -426,13 +426,21 @@ unsigned char GetNfactor(unsigned int nTimestamp)
|
||||
return Nfactor;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
void free_scrypt_jane(int thr_id)
|
||||
{
|
||||
// todo ?
|
||||
}
|
||||
|
||||
#define bswap_32x4(x) ((((x) << 24) & 0xff000000u) | (((x) << 8) & 0x00ff0000u) \
|
||||
| (((x) >> 8) & 0x0000ff00u) | (((x) >> 24) & 0x000000ffu))
|
||||
static int s_Nfactor = 0;
|
||||
|
||||
int scanhash_scrypt_jane(int thr_id, uint32_t *pdata, const uint32_t *ptarget, unsigned char *scratchbuf,
|
||||
uint32_t max_nonce, unsigned long *hashes_done, struct timeval *tv_start, struct timeval *tv_end)
|
||||
int scanhash_scrypt_jane(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done,
|
||||
unsigned char *scratchbuf, struct timeval *tv_start, struct timeval *tv_end)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t N;
|
||||
|
||||
@@ -594,6 +602,7 @@ int scanhash_scrypt_jane(int thr_id, uint32_t *pdata, const uint32_t *ptarget, u
|
||||
|
||||
if (memcmp(thash, &hash[cur][8*i], 32) == 0)
|
||||
{
|
||||
bn_store_hash_target_ratio(thash, ptarget, work);
|
||||
*hashes_done = n - pdata[19];
|
||||
pdata[19] = tmp_nonce;
|
||||
scrypt_free(&Vbuf);
|
||||
|
||||
+11
-2
@@ -685,14 +685,22 @@ static int lastFactor = 0;
|
||||
|
||||
static void computeGold(uint32_t* const input, uint32_t *reference, uchar *scratchpad);
|
||||
|
||||
// cleanup
|
||||
void free_scrypt(int thr_id)
|
||||
{
|
||||
// todo ?
|
||||
}
|
||||
|
||||
// Scrypt proof of work algorithm
|
||||
// using SSE2 vectorized HMAC SHA256 on CPU and
|
||||
// a salsa core implementation on GPU with CUDA
|
||||
//
|
||||
int scanhash_scrypt(int thr_id, uint32_t *pdata, const uint32_t *ptarget, unsigned char *scratchbuf,
|
||||
uint32_t max_nonce, unsigned long *hashes_done, struct timeval *tv_start, struct timeval *tv_end)
|
||||
int scanhash_scrypt(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done,
|
||||
unsigned char *scratchbuf, struct timeval *tv_start, struct timeval *tv_end)
|
||||
{
|
||||
int result = 0;
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
int throughput = cuda_throughput(thr_id);
|
||||
|
||||
if(throughput == 0)
|
||||
@@ -904,6 +912,7 @@ int scanhash_scrypt(int thr_id, uint32_t *pdata, const uint32_t *ptarget, unsign
|
||||
device_map[thr_id], device_name[thr_id], i, cur);
|
||||
} else {
|
||||
*hashes_done = n - pdata[19];
|
||||
bn_store_hash_target_ratio(refhash, ptarget, work);
|
||||
pdata[19] = nonce[cur] + i;
|
||||
result = 1;
|
||||
goto byebye;
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
/* bitcoin algo (by klaus) */
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static __thread uint32_t *h_nounce;
|
||||
|
||||
extern cudaStream_t gpustream[MAX_GPUS];
|
||||
|
||||
extern void bitcoin_cpu_init(int thr_id);
|
||||
extern void bitcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, const uint32_t *const ms, uint32_t merkle, uint32_t time, uint32_t compacttarget, uint32_t *const h_nounce);
|
||||
extern void bitcoin_midstate(const uint32_t *data, uint32_t *midstate);
|
||||
|
||||
uint32_t rrot(uint32_t x, unsigned int n)
|
||||
{
|
||||
return (x >> n) | (x << (32 - n));
|
||||
}
|
||||
|
||||
// CPU HASH
|
||||
void bitcoin_hash(uint32_t *output, const uint32_t *data, uint32_t nonce, const uint32_t *midstate)
|
||||
{
|
||||
uint32_t w[64];
|
||||
uint32_t s0, s1, t1, t2, maj, ch, a, b, c, d, e, f, g, h;
|
||||
int i;
|
||||
|
||||
const uint32_t k[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
const uint32_t hc[8] = {
|
||||
0x6a09e667U, 0xbb67ae85U, 0x3c6ef372U, 0xa54ff53aU,
|
||||
0x510e527fU, 0x9b05688cU, 0x1f83d9abU, 0x5be0cd19U
|
||||
};
|
||||
|
||||
for (i = 0; i <= 15; i++)
|
||||
{
|
||||
w[i] = data[i + 16];
|
||||
}
|
||||
w[3] = nonce;
|
||||
for (i = 16; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(w[i - 15], 7) ^ rrot(w[i - 15], 18) ^ (w[i - 15] >> 3);
|
||||
s1 = rrot(w[i - 2], 17) ^ rrot(w[i - 2], 19) ^ (w[i - 2] >> 10);
|
||||
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
||||
}
|
||||
a = midstate[0];
|
||||
b = midstate[1];
|
||||
c = midstate[2];
|
||||
d = midstate[3];
|
||||
e = midstate[4];
|
||||
f = midstate[5];
|
||||
g = midstate[6];
|
||||
h = midstate[7];
|
||||
for (i = 0; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22);
|
||||
maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
t2 = s0 + maj;
|
||||
s1 = rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25);
|
||||
ch = (e & f) ^ ((~e) & g);
|
||||
t1 = h + s1 + ch + k[i] + w[i];
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
w[0] = a + midstate[0];
|
||||
w[1] = b + midstate[1];
|
||||
w[2] = c + midstate[2];
|
||||
w[3] = d + midstate[3];
|
||||
w[4] = e + midstate[4];
|
||||
w[5] = f + midstate[5];
|
||||
w[6] = g + midstate[6];
|
||||
w[7] = h + midstate[7];
|
||||
w[8] = 0x80000000U;
|
||||
for (i = 9; i <= 14; i++)
|
||||
w[i] = 0U;
|
||||
w[15] = 0x100U;
|
||||
for (i = 16; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(w[i - 15], 7) ^ rrot(w[i - 15], 18) ^ (w[i - 15] >> 3);
|
||||
s1 = rrot(w[i - 2], 17) ^ rrot(w[i - 2], 19) ^ (w[i - 2] >> 10);
|
||||
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
||||
}
|
||||
a = hc[0];
|
||||
b = hc[1];
|
||||
c = hc[2];
|
||||
d = hc[3];
|
||||
e = hc[4];
|
||||
f = hc[5];
|
||||
g = hc[6];
|
||||
h = hc[7];
|
||||
for (i = 0; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22);
|
||||
maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
t2 = s0 + maj;
|
||||
s1 = rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25);
|
||||
ch = (e & f) ^ ((~e) & g);
|
||||
t1 = h + s1 + ch + k[i] + w[i];
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
be32enc(&output[0], a + hc[0]);
|
||||
be32enc(&output[1], b + hc[1]);
|
||||
be32enc(&output[2], c + hc[2]);
|
||||
be32enc(&output[3], d + hc[3]);
|
||||
be32enc(&output[4], e + hc[4]);
|
||||
be32enc(&output[5], f + hc[5]);
|
||||
be32enc(&output[6], g + hc[6]);
|
||||
be32enc(&output[7], h + hc[7]);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
int scanhash_bitcoin(int thr_id, uint32_t *pdata, uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 25);
|
||||
throughput = min(throughput, (max_nonce - first_nonce));
|
||||
|
||||
if (opt_benchmark)
|
||||
ptarget[7] = 0x0005;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaSetDevice(device_map[thr_id]));
|
||||
//cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
//cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
|
||||
CUDA_SAFE_CALL(cudaStreamCreate(&gpustream[thr_id]));
|
||||
bitcoin_cpu_init(thr_id);
|
||||
CUDA_SAFE_CALL(cudaMallocHost(&h_nounce, 2 * sizeof(uint32_t)));
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t ms[8];
|
||||
bitcoin_midstate(pdata, ms);
|
||||
|
||||
do
|
||||
{
|
||||
bitcoin_cpu_hash(thr_id, throughput, pdata[19], ms, pdata[16], pdata[17], pdata[18], h_nounce);
|
||||
if (abort_flag) {
|
||||
cudaStreamDestroy(gpustream[thr_id]);
|
||||
pthread_exit(NULL);
|
||||
return -1;
|
||||
}
|
||||
if (h_nounce[0] != UINT32_MAX)
|
||||
{
|
||||
uint32_t _ALIGN(64) vhash64[8];
|
||||
bitcoin_hash(vhash64, pdata, h_nounce[0], ms);
|
||||
if (vhash64[7] == 0 && fulltest(vhash64, ptarget))
|
||||
{
|
||||
int res = 1;
|
||||
// check if there was some other ones...
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
if (h_nounce[1] != UINT32_MAX)
|
||||
{
|
||||
bitcoin_hash(vhash64, pdata, h_nounce[1], ms);
|
||||
if (vhash64[7] == 0 && fulltest(vhash64, ptarget))
|
||||
{
|
||||
pdata[21] = h_nounce[1];
|
||||
res++;
|
||||
if (opt_benchmark)
|
||||
applog(LOG_INFO, "GPU #%d Found second nounce %08x", device_map[thr_id], h_nounce[1]);
|
||||
}
|
||||
else if (vhash64[7] > 0)
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], h_nounce[1]);
|
||||
}
|
||||
pdata[19] = h_nounce[0];
|
||||
if (opt_benchmark)
|
||||
applog(LOG_INFO, "GPU #%d Found nounce %08x", device_map[thr_id], h_nounce[0]);
|
||||
|
||||
cudaStreamSynchronize(NULL);
|
||||
return res;
|
||||
}
|
||||
else if (vhash64[7] > 0)
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], h_nounce[0]);
|
||||
}
|
||||
|
||||
pdata[19] += throughput; CUDA_SAFE_CALL(cudaGetLastError());
|
||||
|
||||
} while (!work_restart[thr_id].restart && (max_nonce > (uint64_t)(pdata[19]) + throughput));
|
||||
|
||||
cudaStreamSynchronize(NULL);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/* creditscoin SHA256 djm34 implementation - 2015 */
|
||||
|
||||
extern "C" {
|
||||
#include "sph/sph_types.h"
|
||||
#include "sph/sph_sha2.h"
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS] ;
|
||||
|
||||
extern void bitcredit_setBlockTarget(uint32_t * data,const uint32_t * midstate, const void *ptarget);
|
||||
extern void bitcredit_cpu_init(uint32_t thr_id, int threads, uint32_t* hash);
|
||||
|
||||
extern uint32_t bitcredit_cpu_hash(uint32_t thr_id, int threads, uint32_t startNounce, int order);
|
||||
|
||||
// CPU HASH
|
||||
void creditshash(void *state, const void *input)
|
||||
{
|
||||
uint32_t hash[8], hash2[8];
|
||||
sph_sha256_context sha1,sha2;
|
||||
|
||||
sph_sha256_init(&sha1);
|
||||
sph_sha256(&sha1, input, 168);
|
||||
sph_sha256_close(&sha1, hash);
|
||||
|
||||
sph_sha256_init(&sha2);
|
||||
sph_sha256(&sha2, hash, 32);
|
||||
sph_sha256_close(&sha2, hash2);
|
||||
|
||||
memcpy(state, hash2, 32);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_credits(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
const uint32_t *midstate, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t endiandata[42];
|
||||
const uint32_t first_nonce = pdata[35];
|
||||
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 25); // 256*256*64*8
|
||||
throughput = min(throughput, (max_nonce - first_nonce));
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0000ff;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
|
||||
bitcredit_cpu_init(thr_id, throughput, d_hash[thr_id]);
|
||||
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], throughput * 32));
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int k = 0; k < 42; k++)
|
||||
be32enc(&endiandata[k], ((uint32_t*)pdata)[k]);
|
||||
|
||||
bitcredit_setBlockTarget(pdata,midstate,ptarget);
|
||||
|
||||
// uint64_t nloop = max_nonce/throughput + 1;
|
||||
|
||||
do {
|
||||
int order = 0;
|
||||
uint32_t foundNonce = bitcredit_cpu_hash(thr_id, throughput, pdata[35], order++);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
pdata[35] = foundNonce;
|
||||
*hashes_done = foundNonce - first_nonce + 1;
|
||||
return 1;
|
||||
}
|
||||
if ((uint64_t)pdata[35] + throughput > UINT32_MAX) {
|
||||
pdata[35]= UINT32_MAX;
|
||||
*hashes_done = pdata[35] - first_nonce + 1; return 0;
|
||||
} else {
|
||||
pdata[35] += throughput;
|
||||
}
|
||||
|
||||
} while (pdata[19] < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[35] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,679 +0,0 @@
|
||||
// Original version written by Schleicher (KlausT @github)
|
||||
// Redistribution and use in source and binary forms, with or without modification, are permitted
|
||||
|
||||
//#ifdef __cplusplus
|
||||
//#include <cstdint>
|
||||
//#else
|
||||
#include <stdint.h>
|
||||
//#endif
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
void bitcoin_cpu_init(int thr_id);
|
||||
void bitcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, const uint32_t *const ms, uint32_t merkle, uint32_t time, uint32_t compacttarget, uint32_t *const h_nounce);
|
||||
void bitcoin_midstate(const uint32_t *data, uint32_t *midstate);
|
||||
|
||||
cudaStream_t gpustream[MAX_GPUS] = { 0 };
|
||||
|
||||
__constant__ uint32_t pTarget[8];
|
||||
static uint32_t *d_result[MAX_GPUS];
|
||||
|
||||
#define TPB 512
|
||||
#define NONCES_PER_THREAD 32
|
||||
|
||||
#define rrot(x, n) ((x >> n) | (x << (32 - n)))
|
||||
|
||||
__global__ __launch_bounds__(TPB, 2)
|
||||
void bitcoin_gpu_hash(const uint32_t threads, const uint32_t startNounce, uint32_t *const result, const uint32_t t1c, const uint32_t t2c,
|
||||
const uint32_t w16, const uint32_t w16rot, const uint32_t w17, const uint32_t w17rot, const uint32_t b2, const uint32_t c2, const uint32_t d2, const uint32_t f2, const uint32_t g2, const uint32_t h2,
|
||||
const uint32_t ms0, const uint32_t ms1, const uint32_t ms2, const uint32_t ms3, const uint32_t ms4, const uint32_t ms5, const uint32_t ms6, const uint32_t ms7, const uint32_t compacttarget)
|
||||
{
|
||||
uint32_t threadindex = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (threadindex < threads)
|
||||
{
|
||||
uint32_t t1, a, b, c, d, e, f, g, h;
|
||||
uint32_t w[64];
|
||||
const uint32_t numberofthreads = blockDim.x*gridDim.x;
|
||||
const uint32_t maxnonce = startNounce + threadindex + numberofthreads*NONCES_PER_THREAD - 1;
|
||||
const uint32_t threadindex = blockIdx.x*blockDim.x + threadIdx.x;
|
||||
|
||||
|
||||
#pragma unroll
|
||||
for (uint32_t nonce = startNounce + threadindex; nonce <= maxnonce; nonce += numberofthreads)
|
||||
{
|
||||
w[18] = (rrot(nonce, 7) ^ rrot(nonce, 18) ^ (nonce >> 3)) + w16rot;
|
||||
w[19] = nonce + w17rot;
|
||||
w[20] = 0x80000000U + (rrot(w[18], 17) ^ rrot(w[18], 19) ^ (w[18] >> 10));
|
||||
w[21] = (rrot(w[19], 17) ^ rrot(w[19], 19) ^ (w[19] >> 10));
|
||||
w[22] = 0x280U + (rrot(w[20], 17) ^ rrot(w[20], 19) ^ (w[20] >> 10));
|
||||
w[23] = w16 + (rrot(w[21], 17) ^ rrot(w[21], 19) ^ (w[21] >> 10));
|
||||
w[24] = w17 + (rrot(w[22], 17) ^ rrot(w[22], 19) ^ (w[22] >> 10));
|
||||
w[25] = w[18] + (rrot(w[23], 17) ^ rrot(w[23], 19) ^ (w[23] >> 10));
|
||||
w[26] = w[19] + (rrot(w[24], 17) ^ rrot(w[24], 19) ^ (w[24] >> 10));
|
||||
w[27] = w[20] + (rrot(w[25], 17) ^ rrot(w[25], 19) ^ (w[25] >> 10));
|
||||
w[28] = w[21] + (rrot(w[26], 17) ^ rrot(w[26], 19) ^ (w[26] >> 10));
|
||||
w[29] = w[22] + (rrot(w[27], 17) ^ rrot(w[27], 19) ^ (w[27] >> 10));
|
||||
w[30] = w[23] + 0xa00055U + (rrot(w[28], 17) ^ rrot(w[28], 19) ^ (w[28] >> 10));
|
||||
w[31] = 0x280U + w[24] + (rrot(w16, 7) ^ rrot(w16, 18) ^ (w16 >> 3)) + (rrot(w[29], 17) ^ rrot(w[29], 19) ^ (w[29] >> 10));
|
||||
w[32] = w16 + w[25] + (rrot(w17, 7) ^ rrot(w17, 18) ^ (w17 >> 3)) + (rrot(w[30], 17) ^ rrot(w[30], 19) ^ (w[30] >> 10));
|
||||
w[33] = w17 + w[26] + (rrot(w[18], 7) ^ rrot(w[18], 18) ^ (w[18] >> 3)) + (rrot(w[31], 17) ^ rrot(w[31], 19) ^ (w[31] >> 10));
|
||||
#pragma unroll
|
||||
for (int i = 34; i < 62; i++)
|
||||
w[i] = w[i-16] + w[i-7] + (rrot(w[i-15], 7) ^ rrot(w[i-15], 18) ^ (w[i-15] >> 3)) + (rrot(w[i-2], 17) ^ rrot(w[i-2], 19) ^ (w[i-2] >> 10));
|
||||
|
||||
t1 = t1c + (uint32_t)nonce;
|
||||
a = ms0 + t1;
|
||||
e = t1 + t2c;
|
||||
//
|
||||
t1 = d2 + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c2 ^ (a & (b2 ^ c2))) + 0xb956c25bU;
|
||||
h = h2 + t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g2 & f2) | (e & (g2 | f2)));
|
||||
//
|
||||
t1 = c2 + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b2 ^ (h & (a ^ b2))) + 0x59f111f1U;
|
||||
g = g2 + t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f2 & e) | (d & (f2 | e)));
|
||||
//
|
||||
t1 = b2 + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x923f82a4U;
|
||||
f = f2 + t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xab1c5ed5U;
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xd807aa98U;
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x12835b01U;
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x243185beU;
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x550c7dc3U;
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x72be5d74U;
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x80deb1feU;
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x9bdc06a7U;
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xc19bf3f4U;
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xe49b69c1U + w16;
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xefbe4786U + w17;
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x0fc19dc6U + w[18];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x240ca1ccU + w[19];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x2de92c6fU + w[20];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x4a7484aaU + w[21];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x5cb0a9dcU + w[22];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x76f988daU + w[23];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x983e5152U + w[24];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xa831c66dU + w[25];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0xb00327c8U + w[26];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0xbf597fc7U + w[27];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0xc6e00bf3U + w[28];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xd5a79147U + w[29];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x06ca6351U + w[30];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x14292967U + w[31];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x27b70a85U + w[32];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x2e1b2138U + w[33];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x4d2c6dfcU + w[34];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x53380d13U + w[35];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x650a7354U + w[36];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x766a0abbU + w[37];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x81c2c92eU + w[38];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x92722c85U + w[39];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xa2bfe8a1U + w[40];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xa81a664bU + w[41];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0xc24b8b70U + w[42];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0xc76c51a3U + w[43];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0xd192e819U + w[44];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xd6990624U + w[45];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0xf40e3585U + w[46];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x106aa070U + w[47];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x19a4c116U + w[48];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x1e376c08U + w[49];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x2748774cU + w[50];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x34b0bcb5U + w[51];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x391c0cb3U + w[52];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x4ed8aa4aU + w[53];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x5b9cca4fU + w[54];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x682e6ff3U + w[55];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x748f82eeU + w[56];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x78a5636fU + w[57];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x84c87814U + w[58];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x8cc70208U + w[59];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x90befffaU + w[60];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xa4506cebU + w[61];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0xbef9a3f7U + w[46] + w[55] + (rrot(w[47], 7) ^ rrot(w[47], 18) ^ (w[47] >> 3)) + (rrot(w[60], 17) ^ rrot(w[60], 19) ^ (w[60] >> 10));
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xc67178f2U + w[47] + w[56] + (rrot(w[48], 7) ^ rrot(w[48], 18) ^ (w[48] >> 3)) + (rrot(w[61], 17) ^ rrot(w[61], 19) ^ (w[61] >> 10));
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
w[0] = a + ms0; w[1] = b + ms1; w[2] = c + ms2; w[3] = d + ms3;
|
||||
w[4] = e + ms4; w[5] = f + ms5; w[6] = g + ms6; w[7] = h + ms7;
|
||||
// hash the hash ***************************************************************
|
||||
w[16] = w[0] + (rrot(w[1], 7) ^ rrot(w[1], 18) ^ (w[1] >> 3));
|
||||
w[17] = w[1] + (rrot(w[2], 7) ^ rrot(w[2], 18) ^ (w[2] >> 3)) + (rrot(0x100, 17) ^ rrot(0x100, 19) ^ (0x100 >> 10));
|
||||
w[18] = w[2] + (rrot(w[3], 7) ^ rrot(w[3], 18) ^ (w[3] >> 3)) + (rrot(w[16], 17) ^ rrot(w[16], 19) ^ (w[16] >> 10));
|
||||
w[19] = w[3] + (rrot(w[4], 7) ^ rrot(w[4], 18) ^ (w[4] >> 3)) + (rrot(w[17], 17) ^ rrot(w[17], 19) ^ (w[17] >> 10));
|
||||
w[20] = w[4] + (rrot(w[5], 7) ^ rrot(w[5], 18) ^ (w[5] >> 3)) + (rrot(w[18], 17) ^ rrot(w[18], 19) ^ (w[18] >> 10));
|
||||
w[21] = w[5] + (rrot(w[6], 7) ^ rrot(w[6], 18) ^ (w[6] >> 3)) + (rrot(w[19], 17) ^ rrot(w[19], 19) ^ (w[19] >> 10));
|
||||
w[22] = w[6] + 0x100 + (rrot(w[7], 7) ^ rrot(w[7], 18) ^ (w[7] >> 3)) + (rrot(w[20], 17) ^ rrot(w[20], 19) ^ (w[20] >> 10));
|
||||
w[23] = w[7] + w[16] + 0x11002000U + (rrot(w[21], 17) ^ rrot(w[21], 19) ^ (w[21] >> 10));
|
||||
w[24] = 0x80000000U + w[17] + (rrot(w[22], 17) ^ rrot(w[22], 19) ^ (w[22] >> 10));
|
||||
w[25] = w[18] + (rrot(w[23], 17) ^ rrot(w[23], 19) ^ (w[23] >> 10));
|
||||
w[26] = w[19] + (rrot(w[24], 17) ^ rrot(w[24], 19) ^ (w[24] >> 10));
|
||||
w[27] = w[20] + (rrot(w[25], 17) ^ rrot(w[25], 19) ^ (w[25] >> 10));
|
||||
w[28] = w[21] + (rrot(w[26], 17) ^ rrot(w[26], 19) ^ (w[26] >> 10));
|
||||
w[29] = w[22] + (rrot(w[27], 17) ^ rrot(w[27], 19) ^ (w[27] >> 10));
|
||||
w[30] = w[23] + (rrot(0x100, 7) ^ rrot(0x100, 18) ^ (0x100 >> 3)) + (rrot(w[28], 17) ^ rrot(w[28], 19) ^ (w[28] >> 10));
|
||||
w[31] = 0x100 + w[24] + (rrot(w[16], 7) ^ rrot(w[16], 18) ^ (w[16] >> 3)) + (rrot(w[29], 17) ^ rrot(w[29], 19) ^ (w[29] >> 10));
|
||||
#pragma unroll
|
||||
for (int i = 32; i < 59; i++)
|
||||
w[i] = w[i - 16] + w[i - 7] + (rrot(w[i - 15], 7) ^ rrot(w[i - 15], 18) ^ (w[i - 15] >> 3)) + (rrot(w[i - 2], 17) ^ rrot(w[i - 2], 19) ^ (w[i - 2] >> 10));
|
||||
|
||||
d = 0x98c7e2a2U + w[0];
|
||||
h = 0xfc08884dU + w[0];
|
||||
//
|
||||
t1 = (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (0x9b05688cU ^ (d & 0xca0b3af3)) + 0x90bb1e3cU + w[1];
|
||||
c = 0x3c6ef372U + t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + (0x2A01A605 | (h & 0xfb6feee7));
|
||||
//
|
||||
t1 = (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (0x510e527fU ^ (c & (d ^ 0x510e527fU))) + 0x50C6645BU + w[2];
|
||||
b = 0xbb67ae85U + t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((0x6a09e667U & h) | (g & (0x6a09e667U | h)));
|
||||
//
|
||||
t1 = (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x3AC42E24U + w[3];
|
||||
a = 0x6a09e667U + t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x3956c25bU + w[4];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x59f111f1U + w[5];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x923f82a4U + w[6];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xab1c5ed5U + w[7];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x5807aa98U;
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x12835b01U;
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x243185beU;
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x550c7dc3U;
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x72be5d74U;
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x80deb1feU;
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x9bdc06a7U;
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0xc19bf274U;
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xe49b69c1U + w[16];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xefbe4786U + w[17];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x0fc19dc6U + w[18];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x240ca1ccU + w[19];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x2de92c6fU + w[20];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x4a7484aaU + w[21];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x5cb0a9dcU + w[22];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x76f988daU + w[23];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x983e5152U + w[24];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xa831c66dU + w[25];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0xb00327c8U + w[26];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0xbf597fc7U + w[27];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0xc6e00bf3U + w[28];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xd5a79147U + w[29];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x06ca6351U + w[30];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x14292967U + w[31];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x27b70a85U + w[32];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x2e1b2138U + w[33];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x4d2c6dfcU + w[34];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x53380d13U + w[35];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x650a7354U + w[36];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x766a0abbU + w[37];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x81c2c92eU + w[38];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x92722c85U + w[39];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0xa2bfe8a1U + w[40];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0xa81a664bU + w[41];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0xc24b8b70U + w[42];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0xc76c51a3U + w[43];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0xd192e819U + w[44];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0xd6990624U + w[45];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0xf40e3585U + w[46];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x106aa070U + w[47];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x19a4c116U + w[48];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
t1 = g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x1e376c08U + w[49];
|
||||
c += t1;
|
||||
g = t1 + (rrot(h, 2) ^ rrot(h, 13) ^ rrot(h, 22)) + ((b & a) | (h & (b | a)));
|
||||
//
|
||||
t1 = f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x2748774cU + w[50];
|
||||
b += t1;
|
||||
f = t1 + (rrot(g, 2) ^ rrot(g, 13) ^ rrot(g, 22)) + ((a & h) | (g & (a | h)));
|
||||
//
|
||||
t1 = e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x34b0bcb5U + w[51];
|
||||
a += t1;
|
||||
e = t1 + (rrot(f, 2) ^ rrot(f, 13) ^ rrot(f, 22)) + ((h & g) | (f & (h | g)));
|
||||
//
|
||||
t1 = d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x391c0cb3U + w[52];
|
||||
h += t1;
|
||||
d = t1 + (rrot(e, 2) ^ rrot(e, 13) ^ rrot(e, 22)) + ((g & f) | (e & (g | f)));
|
||||
//
|
||||
t1 = c + (rrot(h, 6) ^ rrot(h, 11) ^ rrot(h, 25)) + (b ^ (h & (a ^ b))) + 0x4ed8aa4aU + w[53];
|
||||
g += t1;
|
||||
c = t1 + (rrot(d, 2) ^ rrot(d, 13) ^ rrot(d, 22)) + ((f & e) | (d & (f | e)));
|
||||
//
|
||||
t1 = b + (rrot(g, 6) ^ rrot(g, 11) ^ rrot(g, 25)) + (a ^ (g & (h ^ a))) + 0x5b9cca4fU + w[54];
|
||||
f += t1;
|
||||
b = t1 + (rrot(c, 2) ^ rrot(c, 13) ^ rrot(c, 22)) + ((e & d) | (c & (e | d)));
|
||||
//
|
||||
t1 = a + (rrot(f, 6) ^ rrot(f, 11) ^ rrot(f, 25)) + (h ^ (f & (g ^ h))) + 0x682e6ff3U + w[55];
|
||||
e += t1;
|
||||
a = t1 + (rrot(b, 2) ^ rrot(b, 13) ^ rrot(b, 22)) + ((d & c) | (b & (d | c)));
|
||||
//
|
||||
t1 = h + (rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25)) + (g ^ (e & (f ^ g))) + 0x748f82eeU + w[56];
|
||||
d += t1;
|
||||
h = t1 + (rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22)) + ((c & b) | (a & (c | b)));
|
||||
//
|
||||
c += g + (rrot(d, 6) ^ rrot(d, 11) ^ rrot(d, 25)) + (f ^ (d & (e ^ f))) + 0x78a5636fU + w[57];
|
||||
//
|
||||
b += f + (rrot(c, 6) ^ rrot(c, 11) ^ rrot(c, 25)) + (e ^ (c & (d ^ e))) + 0x84c87814U + w[58];
|
||||
//
|
||||
a += e + (rrot(b, 6) ^ rrot(b, 11) ^ rrot(b, 25)) + (d ^ (b & (c ^ d))) + 0x8cc70208U + w[43] + w[52] + (rrot(w[44], 7) ^ rrot(w[44], 18) ^ (w[44] >> 3)) + (rrot(w[57], 17) ^ rrot(w[57], 19) ^ (w[57] >> 10));
|
||||
//
|
||||
h += d + (rrot(a, 6) ^ rrot(a, 11) ^ rrot(a, 25)) + (c ^ (a & (b ^ c))) + 0x90befffaU + w[44] + w[53] + (rrot(w[45], 7) ^ rrot(w[45], 18) ^ (w[45] >> 3)) + (rrot(w[58], 17) ^ rrot(w[58], 19) ^ (w[58] >> 10));
|
||||
//
|
||||
if (h == 0xa41f32e7)
|
||||
{
|
||||
uint32_t tmp = atomicCAS(result, 0xffffffff, nonce);
|
||||
if (tmp != 0xffffffff)
|
||||
result[1] = nonce;
|
||||
}
|
||||
} // nonce loop
|
||||
} // if thread<threads
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcoin_midstate(const uint32_t *data, uint32_t *midstate)
|
||||
{
|
||||
int i;
|
||||
uint32_t s0, s1, t1, t2, maj, ch, a, b, c, d, e, f, g, h;
|
||||
uint32_t w[64];
|
||||
|
||||
const uint32_t k[64] = {
|
||||
0x428a2f98U, 0x71374491U, 0xb5c0fbcfU, 0xe9b5dba5U, 0x3956c25bU, 0x59f111f1U, 0x923f82a4U, 0xab1c5ed5U,
|
||||
0xd807aa98U, 0x12835b01U, 0x243185beU, 0x550c7dc3U, 0x72be5d74U, 0x80deb1feU, 0x9bdc06a7U, 0xc19bf174U,
|
||||
0xe49b69c1U, 0xefbe4786U, 0x0fc19dc6U, 0x240ca1ccU, 0x2de92c6fU, 0x4a7484aaU, 0x5cb0a9dcU, 0x76f988daU,
|
||||
0x983e5152U, 0xa831c66dU, 0xb00327c8U, 0xbf597fc7U, 0xc6e00bf3U, 0xd5a79147U, 0x06ca6351U, 0x14292967U,
|
||||
0x27b70a85U, 0x2e1b2138U, 0x4d2c6dfcU, 0x53380d13U, 0x650a7354U, 0x766a0abbU, 0x81c2c92eU, 0x92722c85U,
|
||||
0xa2bfe8a1U, 0xa81a664bU, 0xc24b8b70U, 0xc76c51a3U, 0xd192e819U, 0xd6990624U, 0xf40e3585U, 0x106aa070U,
|
||||
0x19a4c116U, 0x1e376c08U, 0x2748774cU, 0x34b0bcb5U, 0x391c0cb3U, 0x4ed8aa4aU, 0x5b9cca4fU, 0x682e6ff3U,
|
||||
0x748f82eeU, 0x78a5636fU, 0x84c87814U, 0x8cc70208U, 0x90befffaU, 0xa4506cebU, 0xbef9a3f7U, 0xc67178f2U
|
||||
};
|
||||
const uint32_t hc[8] = {
|
||||
0x6a09e667U, 0xbb67ae85U, 0x3c6ef372U, 0xa54ff53aU,
|
||||
0x510e527fU, 0x9b05688cU, 0x1f83d9abU, 0x5be0cd19U
|
||||
};
|
||||
|
||||
for (i = 0; i <= 15; i++)
|
||||
{
|
||||
w[i] = data[i];
|
||||
}
|
||||
for (i = 16; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(w[i - 15], 7) ^ rrot(w[i - 15], 18) ^ (w[i - 15] >> 3);
|
||||
s1 = rrot(w[i - 2], 17) ^ rrot(w[i - 2], 19) ^ (w[i - 2] >> 10);
|
||||
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
|
||||
}
|
||||
a = hc[0];
|
||||
b = hc[1];
|
||||
c = hc[2];
|
||||
d = hc[3];
|
||||
e = hc[4];
|
||||
f = hc[5];
|
||||
g = hc[6];
|
||||
h = hc[7];
|
||||
for (i = 0; i <= 63; i++)
|
||||
{
|
||||
s0 = rrot(a, 2) ^ rrot(a, 13) ^ rrot(a, 22);
|
||||
maj = (a & b) ^ (a & c) ^ (b & c);
|
||||
t2 = s0 + maj;
|
||||
s1 = rrot(e, 6) ^ rrot(e, 11) ^ rrot(e, 25);
|
||||
ch = (e & f) ^ ((~e) & g);
|
||||
t1 = h + s1 + ch + k[i] + w[i];
|
||||
h = g;
|
||||
g = f;
|
||||
f = e;
|
||||
e = d + t1;
|
||||
d = c;
|
||||
c = b;
|
||||
b = a;
|
||||
a = t1 + t2;
|
||||
}
|
||||
midstate[0] = a + hc[0];
|
||||
midstate[1] = b + hc[1];
|
||||
midstate[2] = c + hc[2];
|
||||
midstate[3] = d + hc[3];
|
||||
midstate[4] = e + hc[4];
|
||||
midstate[5] = f + hc[5];
|
||||
midstate[6] = g + hc[6];
|
||||
midstate[7] = h + hc[7];
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcoin_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce, const uint32_t *const ms, uint32_t merkle, uint32_t time, uint32_t compacttarget, uint32_t *const h_nounce)
|
||||
{
|
||||
uint32_t b2, c2, d2, f2, g2, h2, t1, w16, w17, t1c, t2c, w16rot, w17rot;
|
||||
|
||||
cudaMemsetAsync(d_result[thr_id], 0xff, 2 * sizeof(uint32_t), gpustream[thr_id]);
|
||||
|
||||
t1 = ms[7] + (rrot(ms[4], 6) ^ rrot(ms[4], 11) ^ rrot(ms[4], 25)) + (ms[6] ^ (ms[4] & (ms[5] ^ ms[6]))) + 0x428a2f98U + merkle;
|
||||
d2 = ms[3] + t1;
|
||||
h2 = t1 + (rrot(ms[0], 2) ^ rrot(ms[0], 13) ^ rrot(ms[0], 22)) + ((ms[2] & ms[1]) | (ms[0] & (ms[2] | ms[1])));
|
||||
//
|
||||
t1 = ms[6] + (rrot(d2, 6) ^ rrot(d2, 11) ^ rrot(d2, 25)) + (ms[5] ^ (d2 & (ms[4] ^ ms[5]))) + 0x71374491U + time;
|
||||
c2 = ms[2] + t1;
|
||||
g2 = t1 + (rrot(h2, 2) ^ rrot(h2, 13) ^ rrot(h2, 22)) + ((ms[1] & ms[0]) | (h2 & (ms[1] | ms[0])));
|
||||
//
|
||||
t1 = ms[5] + (rrot(c2, 6) ^ rrot(c2, 11) ^ rrot(c2, 25)) + (ms[4] ^ (c2 & (d2 ^ ms[4]))) + 0xb5c0fbcfU + compacttarget;
|
||||
b2 = ms[1] + t1;
|
||||
f2 = t1 + (rrot(g2, 2) ^ rrot(g2, 13) ^ rrot(g2, 22)) + ((ms[0] & h2) | (g2 & (ms[0] | h2)));
|
||||
|
||||
w16 = merkle + (rrot(time, 7) ^ rrot(time, 18) ^ (time >> 3));
|
||||
w16rot = (rrot(w16, 17) ^ rrot(w16, 19) ^ (w16 >> 10)) + compacttarget;
|
||||
w17 = time + (rrot(compacttarget, 7) ^ rrot(compacttarget, 18) ^ (compacttarget >> 3)) + 0x01100000U;
|
||||
w17rot = (rrot(w17, 17) ^ rrot(w17, 19) ^ (w17 >> 10)) + 0x11002000U;
|
||||
t2c = (rrot(f2, 2) ^ rrot(f2, 13) ^ rrot(f2, 22)) + ((h2 & g2) | (f2 & (h2 | g2)));
|
||||
t1c = ms[4] + (rrot(b2, 6) ^ rrot(b2, 11) ^ rrot(b2, 25)) + (d2 ^ (b2 & (c2 ^ d2))) + 0xe9b5dba5U;
|
||||
|
||||
dim3 grid((threads + TPB*NONCES_PER_THREAD - 1) / TPB / NONCES_PER_THREAD);
|
||||
dim3 block(TPB);
|
||||
bitcoin_gpu_hash << <grid, block, 0, gpustream[thr_id]>>> (threads, startNounce, d_result[thr_id], t1c, t2c, w16, w16rot, w17, w17rot, b2, c2, d2, f2, g2, h2, ms[0], ms[1], ms[2], ms[3], ms[4], ms[5], ms[6], ms[7], compacttarget);
|
||||
CUDA_SAFE_CALL(cudaMemcpyAsync(h_nounce, d_result[thr_id], 2 * sizeof(uint32_t), cudaMemcpyDeviceToHost, gpustream[thr_id])); cudaStreamSynchronize(gpustream[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcoin_cpu_init(int thr_id)
|
||||
{
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_result[thr_id], 4 * sizeof(uint32_t)));
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
/* CreditsCoin [CRD] djm34 implementation - 2015 */
|
||||
|
||||
/*
|
||||
#include <cuda.h>
|
||||
#include "cuda_runtime.h"
|
||||
#include "device_launch_parameters.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "cuda_vector.h"
|
||||
|
||||
// extern cudaError_t MyStreamSynchronize(cudaStream_t stream, int situation, int thr_id);
|
||||
|
||||
// __device__ uint4 * S;
|
||||
__device__ uint8 *TheHash;
|
||||
uint32_t *d_BitNonce[MAX_GPUS];
|
||||
__constant__ uint32_t pTarget[8];
|
||||
__constant__ uint8 midstate;
|
||||
__constant__ uint32_t c_data[48];
|
||||
__constant__ uint16 shapad;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////// sha256 Transform function /////////////////////////
|
||||
|
||||
static __constant__ uint8 pad4 = {
|
||||
0x80000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000100
|
||||
};
|
||||
|
||||
static __constant__ uint8 H256 = {
|
||||
0x6A09E667, 0xBB67AE85, 0x3C6EF372,
|
||||
0xA54FF53A, 0x510E527F, 0x9B05688C,
|
||||
0x1F83D9AB, 0x5BE0CD19
|
||||
};
|
||||
|
||||
static __constant__ uint32_t Ksha[64] = {
|
||||
0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
|
||||
0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
|
||||
0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
|
||||
0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
|
||||
0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
|
||||
0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
|
||||
0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
|
||||
0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
|
||||
0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
|
||||
0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
|
||||
0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
|
||||
0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
|
||||
0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
|
||||
0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
|
||||
0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
|
||||
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
|
||||
};
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint32_t bsg2_0(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 2);
|
||||
uint32_t r2 = ROTR32(x, 13);
|
||||
uint32_t r3 = ROTR32(x, 22);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint32_t bsg2_1(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 6);
|
||||
uint32_t r2 = ROTR32(x, 11);
|
||||
uint32_t r3 = ROTR32(x, 25);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint32_t ssg2_0(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 7);
|
||||
uint32_t r2 = ROTR32(x, 18);
|
||||
uint32_t r3 = shr_t32(x, 3);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint32_t ssg2_1(const uint32_t x)
|
||||
{
|
||||
uint32_t r1 = ROTR32(x, 17);
|
||||
uint32_t r2 = ROTR32(x, 19);
|
||||
uint32_t r3 = shr_t32(x, 10);
|
||||
return xor3b(r1, r2, r3);
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void sha2_step1(const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d, const uint32_t e,
|
||||
const uint32_t f, const uint32_t g, uint32_t &h, const uint32_t in, const uint32_t Kshared)
|
||||
{
|
||||
uint32_t t1, t2;
|
||||
uint32_t vxandx = xandx(e, f, g);
|
||||
uint32_t bsg21 = bsg2_1(e);
|
||||
uint32_t bsg20 = bsg2_0(a);
|
||||
uint32_t andorv = andor32(a, b, c);
|
||||
|
||||
t1 = h + bsg21 + vxandx + Kshared + in;
|
||||
t2 = bsg20 + andorv;
|
||||
d = d + t1;
|
||||
h = t1 + t2;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
void sha2_step2(const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d, const uint32_t e,
|
||||
const uint32_t f, const uint32_t g, uint32_t &h, uint32_t* in, const uint32_t pc, const uint32_t Kshared)
|
||||
{
|
||||
uint32_t t1, t2;
|
||||
|
||||
int pcidx1 = (pc - 2) & 0xF;
|
||||
int pcidx2 = (pc - 7) & 0xF;
|
||||
int pcidx3 = (pc - 15) & 0xF;
|
||||
uint32_t inx0 = in[pc];
|
||||
uint32_t inx1 = in[pcidx1];
|
||||
uint32_t inx2 = in[pcidx2];
|
||||
uint32_t inx3 = in[pcidx3];
|
||||
|
||||
uint32_t ssg21 = ssg2_1(inx1);
|
||||
uint32_t ssg20 = ssg2_0(inx3);
|
||||
uint32_t vxandx = xandx(e, f, g);
|
||||
uint32_t bsg21 = bsg2_1(e);
|
||||
uint32_t bsg20 = bsg2_0(a);
|
||||
uint32_t andorv = andor32(a, b, c);
|
||||
|
||||
in[pc] = ssg21 + inx2 + ssg20 + inx0;
|
||||
|
||||
t1 = h + bsg21 + vxandx + Kshared + in[pc];
|
||||
t2 = bsg20 + andorv;
|
||||
d = d + t1;
|
||||
h = t1 + t2;
|
||||
}
|
||||
|
||||
static __device__ __forceinline__
|
||||
uint8 sha256_Transform2(uint16 in[1], const uint8 &r) // also known as sha2_round_body
|
||||
{
|
||||
uint8 tmp = r;
|
||||
#define a tmp.s0
|
||||
#define b tmp.s1
|
||||
#define c tmp.s2
|
||||
#define d tmp.s3
|
||||
#define e tmp.s4
|
||||
#define f tmp.s5
|
||||
#define g tmp.s6
|
||||
#define h tmp.s7
|
||||
|
||||
sha2_step1(a, b, c, d, e, f, g, h, in[0].s0, Ksha[0]);
|
||||
sha2_step1(h, a, b, c, d, e, f, g, in[0].s1, Ksha[1]);
|
||||
sha2_step1(g, h, a, b, c, d, e, f, in[0].s2, Ksha[2]);
|
||||
sha2_step1(f, g, h, a, b, c, d, e, in[0].s3, Ksha[3]);
|
||||
sha2_step1(e, f, g, h, a, b, c, d, in[0].s4, Ksha[4]);
|
||||
sha2_step1(d, e, f, g, h, a, b, c, in[0].s5, Ksha[5]);
|
||||
sha2_step1(c, d, e, f, g, h, a, b, in[0].s6, Ksha[6]);
|
||||
sha2_step1(b, c, d, e, f, g, h, a, in[0].s7, Ksha[7]);
|
||||
sha2_step1(a, b, c, d, e, f, g, h, in[0].s8, Ksha[8]);
|
||||
sha2_step1(h, a, b, c, d, e, f, g, in[0].s9, Ksha[9]);
|
||||
sha2_step1(g, h, a, b, c, d, e, f, in[0].sa, Ksha[10]);
|
||||
sha2_step1(f, g, h, a, b, c, d, e, in[0].sb, Ksha[11]);
|
||||
sha2_step1(e, f, g, h, a, b, c, d, in[0].sc, Ksha[12]);
|
||||
sha2_step1(d, e, f, g, h, a, b, c, in[0].sd, Ksha[13]);
|
||||
sha2_step1(c, d, e, f, g, h, a, b, in[0].se, Ksha[14]);
|
||||
sha2_step1(b, c, d, e, f, g, h, a, in[0].sf, Ksha[15]);
|
||||
|
||||
#pragma unroll
|
||||
for (int i = 0; i<3; i++) {
|
||||
|
||||
sha2_step2(a, b, c, d, e, f, g, h, (uint32_t*)in, 0, Ksha[16 + 16 * i]);
|
||||
sha2_step2(h, a, b, c, d, e, f, g, (uint32_t*)in, 1, Ksha[17 + 16 * i]);
|
||||
sha2_step2(g, h, a, b, c, d, e, f, (uint32_t*)in, 2, Ksha[18 + 16 * i]);
|
||||
sha2_step2(f, g, h, a, b, c, d, e, (uint32_t*)in, 3, Ksha[19 + 16 * i]);
|
||||
sha2_step2(e, f, g, h, a, b, c, d, (uint32_t*)in, 4, Ksha[20 + 16 * i]);
|
||||
sha2_step2(d, e, f, g, h, a, b, c, (uint32_t*)in, 5, Ksha[21 + 16 * i]);
|
||||
sha2_step2(c, d, e, f, g, h, a, b, (uint32_t*)in, 6, Ksha[22 + 16 * i]);
|
||||
sha2_step2(b, c, d, e, f, g, h, a, (uint32_t*)in, 7, Ksha[23 + 16 * i]);
|
||||
sha2_step2(a, b, c, d, e, f, g, h, (uint32_t*)in, 8, Ksha[24 + 16 * i]);
|
||||
sha2_step2(h, a, b, c, d, e, f, g, (uint32_t*)in, 9, Ksha[25 + 16 * i]);
|
||||
sha2_step2(g, h, a, b, c, d, e, f, (uint32_t*)in, 10, Ksha[26 + 16 * i]);
|
||||
sha2_step2(f, g, h, a, b, c, d, e, (uint32_t*)in, 11, Ksha[27 + 16 * i]);
|
||||
sha2_step2(e, f, g, h, a, b, c, d, (uint32_t*)in, 12, Ksha[28 + 16 * i]);
|
||||
sha2_step2(d, e, f, g, h, a, b, c, (uint32_t*)in, 13, Ksha[29 + 16 * i]);
|
||||
sha2_step2(c, d, e, f, g, h, a, b, (uint32_t*)in, 14, Ksha[30 + 16 * i]);
|
||||
sha2_step2(b, c, d, e, f, g, h, a, (uint32_t*)in, 15, Ksha[31 + 16 * i]);
|
||||
}
|
||||
|
||||
#undef a
|
||||
#undef b
|
||||
#undef c
|
||||
#undef d
|
||||
#undef e
|
||||
#undef f
|
||||
return (r + tmp);
|
||||
}
|
||||
|
||||
|
||||
__global__ __launch_bounds__(256, 3)
|
||||
void bitcredit_gpu_hash(int threads, uint32_t startNonce,uint32_t* NonceVector)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
uint32_t nonce = startNonce + thread;
|
||||
|
||||
uint16 data[1];
|
||||
uint8 state,state2;
|
||||
|
||||
data[0] = ((uint16*)c_data)[2];
|
||||
data[0].s3 = nonce;
|
||||
state = sha256_Transform2(data, midstate);
|
||||
|
||||
data[0].lo=state;
|
||||
data[0].hi=pad4;
|
||||
state2 = sha256_Transform2(data, H256);
|
||||
|
||||
if (MAKE_ULONGLONG(cuda_swab32(state2.s6), cuda_swab32(state2.s7)) <= ((uint64_t*)pTarget)[3])
|
||||
NonceVector[0] = nonce;
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcredit_cpu_init(uint32_t thr_id, int threads, uint32_t *hash)
|
||||
{
|
||||
cudaMemcpyToSymbol(TheHash, &hash, sizeof(hash), 0, cudaMemcpyHostToDevice);
|
||||
cudaMalloc(&d_BitNonce[thr_id], sizeof(uint32_t));
|
||||
}
|
||||
|
||||
__host__
|
||||
void bitcredit_setBlockTarget(uint32_t* pdata, const uint32_t* zmidstate,const void *target)
|
||||
{
|
||||
unsigned char PaddedMessage[192]; //bring balance to the force
|
||||
|
||||
memcpy(PaddedMessage, pdata, 168);
|
||||
memset(PaddedMessage+168, 0, 24);
|
||||
((uint32_t*)PaddedMessage)[42] = 0x80000000;
|
||||
((uint32_t*)PaddedMessage)[47] = 0x00000540;
|
||||
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(midstate, zmidstate, 32, 0, cudaMemcpyHostToDevice));
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(pTarget, target, 32, 0, cudaMemcpyHostToDevice));
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_data, PaddedMessage, 48 * sizeof(uint32_t), 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t bitcredit_cpu_hash(uint32_t thr_id, int threads, uint32_t startNounce, int order)
|
||||
{
|
||||
uint32_t result[MAX_GPUS];
|
||||
const int threadsperblock = 256;
|
||||
|
||||
memset(result, 0xff, sizeof(result));
|
||||
cudaMemset(d_BitNonce[thr_id], 0xff, sizeof(uint32_t));
|
||||
|
||||
dim3 grid((threads + threadsperblock - 1) / threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
bitcredit_gpu_hash << <grid, block >> >(threads, startNounce, d_BitNonce[thr_id]);
|
||||
|
||||
cudaMemcpy(&result[thr_id], d_BitNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
|
||||
return result[thr_id];
|
||||
}
|
||||
@@ -346,10 +346,11 @@ static __inline uint32_t swab32_if(uint32_t val, bool iftrue) {
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_skeincoin(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
extern "C" int scanhash_skeincoin(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t _ALIGN(64) endiandata[20];
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const int swap = 1;
|
||||
@@ -409,23 +410,28 @@ extern "C" int scanhash_skeincoin(int thr_id, uint32_t *pdata, const uint32_t *p
|
||||
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
uint32_t _ALIGN(64) vhash64[8];
|
||||
uint32_t _ALIGN(64) vhash[8];
|
||||
|
||||
endiandata[19] = swab32_if(foundNonce, swap);
|
||||
skeincoinhash(vhash64, endiandata);
|
||||
skeincoinhash(vhash, endiandata);
|
||||
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
int res = 1;
|
||||
uint8_t num = res;
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
if (checkSecnonce) {
|
||||
secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], num);
|
||||
}
|
||||
while (secNonce != 0 && res < 2) /* todo: up to 6 */
|
||||
{
|
||||
endiandata[19] = swab32_if(secNonce, swap);
|
||||
skeincoinhash(vhash64, endiandata);
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
skeincoinhash(vhash, endiandata);
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
// todo: use 19 20 21... zr5 pok to adapt...
|
||||
endiandata[19] = swab32_if(secNonce, swap);
|
||||
skeincoinhash(vhash, endiandata);
|
||||
if (bn_hash_target_ratio(vhash, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
pdata[19+res*2] = swab32_if(secNonce, !swap);
|
||||
res++;
|
||||
}
|
||||
@@ -458,3 +464,19 @@ extern "C" int scanhash_skeincoin(int thr_id, uint32_t *pdata, const uint32_t *p
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_skeincoin(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+25
-2
@@ -36,9 +36,10 @@ void skein2hash(void *output, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
int scanhash_skein2(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
int scanhash_skein2(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1 << 19); // 256*256*8
|
||||
@@ -88,9 +89,15 @@ int scanhash_skein2(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
if (!opt_quiet)
|
||||
applog(LOG_BLUE, "GPU #%d: found second nonce %08x !", device_map[thr_id], swab32(secNonce));
|
||||
|
||||
endiandata[19] = secNonce;
|
||||
skein2hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = swab32(secNonce);
|
||||
res++;
|
||||
}
|
||||
@@ -113,3 +120,19 @@ int scanhash_skein2(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
void free_skein2(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+603
-664
File diff suppressed because it is too large.
Load diff
-630
@@ -1,630 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 ArtForz
|
||||
* Copyright 2011-2013 pooler
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version. See COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "cpuminer-config.h"
|
||||
#include "miner.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#if defined(__arm__) && defined(__APCS_32__)
|
||||
#define EXTERN_SHA256
|
||||
#endif
|
||||
|
||||
static const uint32_t sha256_h[8] = {
|
||||
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
||||
};
|
||||
|
||||
static const uint32_t sha256_k[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
|
||||
void sha256_init(uint32_t *state)
|
||||
{
|
||||
memcpy(state, sha256_h, 32);
|
||||
}
|
||||
|
||||
/* Elementary functions used by SHA256 */
|
||||
#define Ch(x, y, z) ((x & (y ^ z)) ^ z)
|
||||
#define Maj(x, y, z) ((x & (y | z)) | (y & z))
|
||||
#define ROTR(x, n) ((x >> n) | (x << (32 - n)))
|
||||
#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22))
|
||||
#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25))
|
||||
#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ (x >> 3))
|
||||
#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ (x >> 10))
|
||||
|
||||
/* SHA256 round function */
|
||||
#define RND(a, b, c, d, e, f, g, h, k) \
|
||||
do { \
|
||||
t0 = h + S1(e) + Ch(e, f, g) + k; \
|
||||
t1 = S0(a) + Maj(a, b, c); \
|
||||
d += t0; \
|
||||
h = t0 + t1; \
|
||||
} while (0)
|
||||
|
||||
/* Adjusted round function for rotating state */
|
||||
#define RNDr(S, W, i) \
|
||||
RND(S[(64 - i) % 8], S[(65 - i) % 8], \
|
||||
S[(66 - i) % 8], S[(67 - i) % 8], \
|
||||
S[(68 - i) % 8], S[(69 - i) % 8], \
|
||||
S[(70 - i) % 8], S[(71 - i) % 8], \
|
||||
W[i] + sha256_k[i])
|
||||
|
||||
#ifndef EXTERN_SHA256
|
||||
|
||||
/*
|
||||
* SHA256 block compression function. The 256-bit state is transformed via
|
||||
* the 512-bit input block to produce a new state.
|
||||
*/
|
||||
void sha256_transform(uint32_t *state, const uint32_t *block, int swap)
|
||||
{
|
||||
uint32_t W[64];
|
||||
uint32_t S[8];
|
||||
uint32_t t0, t1;
|
||||
int i;
|
||||
|
||||
/* 1. Prepare message schedule W. */
|
||||
if (swap) {
|
||||
for (i = 0; i < 16; i++)
|
||||
W[i] = swab32(block[i]);
|
||||
} else
|
||||
memcpy(W, block, 64);
|
||||
for (i = 16; i < 64; i += 2) {
|
||||
W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];
|
||||
W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15];
|
||||
}
|
||||
|
||||
/* 2. Initialize working variables. */
|
||||
memcpy(S, state, 32);
|
||||
|
||||
/* 3. Mix. */
|
||||
RNDr(S, W, 0);
|
||||
RNDr(S, W, 1);
|
||||
RNDr(S, W, 2);
|
||||
RNDr(S, W, 3);
|
||||
RNDr(S, W, 4);
|
||||
RNDr(S, W, 5);
|
||||
RNDr(S, W, 6);
|
||||
RNDr(S, W, 7);
|
||||
RNDr(S, W, 8);
|
||||
RNDr(S, W, 9);
|
||||
RNDr(S, W, 10);
|
||||
RNDr(S, W, 11);
|
||||
RNDr(S, W, 12);
|
||||
RNDr(S, W, 13);
|
||||
RNDr(S, W, 14);
|
||||
RNDr(S, W, 15);
|
||||
RNDr(S, W, 16);
|
||||
RNDr(S, W, 17);
|
||||
RNDr(S, W, 18);
|
||||
RNDr(S, W, 19);
|
||||
RNDr(S, W, 20);
|
||||
RNDr(S, W, 21);
|
||||
RNDr(S, W, 22);
|
||||
RNDr(S, W, 23);
|
||||
RNDr(S, W, 24);
|
||||
RNDr(S, W, 25);
|
||||
RNDr(S, W, 26);
|
||||
RNDr(S, W, 27);
|
||||
RNDr(S, W, 28);
|
||||
RNDr(S, W, 29);
|
||||
RNDr(S, W, 30);
|
||||
RNDr(S, W, 31);
|
||||
RNDr(S, W, 32);
|
||||
RNDr(S, W, 33);
|
||||
RNDr(S, W, 34);
|
||||
RNDr(S, W, 35);
|
||||
RNDr(S, W, 36);
|
||||
RNDr(S, W, 37);
|
||||
RNDr(S, W, 38);
|
||||
RNDr(S, W, 39);
|
||||
RNDr(S, W, 40);
|
||||
RNDr(S, W, 41);
|
||||
RNDr(S, W, 42);
|
||||
RNDr(S, W, 43);
|
||||
RNDr(S, W, 44);
|
||||
RNDr(S, W, 45);
|
||||
RNDr(S, W, 46);
|
||||
RNDr(S, W, 47);
|
||||
RNDr(S, W, 48);
|
||||
RNDr(S, W, 49);
|
||||
RNDr(S, W, 50);
|
||||
RNDr(S, W, 51);
|
||||
RNDr(S, W, 52);
|
||||
RNDr(S, W, 53);
|
||||
RNDr(S, W, 54);
|
||||
RNDr(S, W, 55);
|
||||
RNDr(S, W, 56);
|
||||
RNDr(S, W, 57);
|
||||
RNDr(S, W, 58);
|
||||
RNDr(S, W, 59);
|
||||
RNDr(S, W, 60);
|
||||
RNDr(S, W, 61);
|
||||
RNDr(S, W, 62);
|
||||
RNDr(S, W, 63);
|
||||
|
||||
/* 4. Mix local working variables into global state */
|
||||
for (i = 0; i < 8; i++)
|
||||
state[i] += S[i];
|
||||
}
|
||||
|
||||
#endif /* EXTERN_SHA256 */
|
||||
|
||||
|
||||
static const uint32_t sha256d_hash1[16] = {
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x80000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000100
|
||||
};
|
||||
|
||||
static void sha256d_80_swap(uint32_t *hash, const uint32_t *data)
|
||||
{
|
||||
uint32_t S[16];
|
||||
int i;
|
||||
|
||||
sha256_init(S);
|
||||
sha256_transform(S, data, 0);
|
||||
sha256_transform(S, data + 16, 0);
|
||||
memcpy(S + 8, sha256d_hash1 + 8, 32);
|
||||
sha256_init(hash);
|
||||
sha256_transform(hash, S, 0);
|
||||
for (i = 0; i < 8; i++)
|
||||
hash[i] = swab32(hash[i]);
|
||||
}
|
||||
|
||||
void sha256d(unsigned char *hash, const unsigned char *data, int len)
|
||||
{
|
||||
uint32_t S[16], T[16];
|
||||
int i, r;
|
||||
|
||||
sha256_init(S);
|
||||
for (r = len; r > -9; r -= 64) {
|
||||
if (r < 64)
|
||||
memset(T, 0, 64);
|
||||
memcpy(T, data + len - r, r > 64 ? 64 : (r < 0 ? 0 : r));
|
||||
if (r >= 0 && r < 64)
|
||||
((unsigned char *)T)[r] = 0x80;
|
||||
for (i = 0; i < 16; i++)
|
||||
T[i] = be32dec(T + i);
|
||||
if (r < 56)
|
||||
T[15] = 8 * len;
|
||||
sha256_transform(S, T, 0);
|
||||
}
|
||||
memcpy(S + 8, sha256d_hash1 + 8, 32);
|
||||
sha256_init(T);
|
||||
sha256_transform(T, S, 0);
|
||||
for (i = 0; i < 8; i++)
|
||||
be32enc((uint32_t *)hash + i, T[i]);
|
||||
}
|
||||
|
||||
static inline void sha256d_preextend(uint32_t *W)
|
||||
{
|
||||
W[16] = s1(W[14]) + W[ 9] + s0(W[ 1]) + W[ 0];
|
||||
W[17] = s1(W[15]) + W[10] + s0(W[ 2]) + W[ 1];
|
||||
W[18] = s1(W[16]) + W[11] + W[ 2];
|
||||
W[19] = s1(W[17]) + W[12] + s0(W[ 4]);
|
||||
W[20] = W[13] + s0(W[ 5]) + W[ 4];
|
||||
W[21] = W[14] + s0(W[ 6]) + W[ 5];
|
||||
W[22] = W[15] + s0(W[ 7]) + W[ 6];
|
||||
W[23] = W[16] + s0(W[ 8]) + W[ 7];
|
||||
W[24] = W[17] + s0(W[ 9]) + W[ 8];
|
||||
W[25] = s0(W[10]) + W[ 9];
|
||||
W[26] = s0(W[11]) + W[10];
|
||||
W[27] = s0(W[12]) + W[11];
|
||||
W[28] = s0(W[13]) + W[12];
|
||||
W[29] = s0(W[14]) + W[13];
|
||||
W[30] = s0(W[15]) + W[14];
|
||||
W[31] = s0(W[16]) + W[15];
|
||||
}
|
||||
|
||||
static inline void sha256d_prehash(uint32_t *S, const uint32_t *W)
|
||||
{
|
||||
uint32_t t0, t1;
|
||||
RNDr(S, W, 0);
|
||||
RNDr(S, W, 1);
|
||||
RNDr(S, W, 2);
|
||||
}
|
||||
|
||||
#ifdef EXTERN_SHA256
|
||||
|
||||
void sha256d_ms(uint32_t *hash, uint32_t *W,
|
||||
const uint32_t *midstate, const uint32_t *prehash);
|
||||
|
||||
#else
|
||||
|
||||
static inline void sha256d_ms(uint32_t *hash, uint32_t *W,
|
||||
const uint32_t *midstate, const uint32_t *prehash)
|
||||
{
|
||||
uint32_t S[64];
|
||||
uint32_t t0, t1;
|
||||
int i;
|
||||
|
||||
S[18] = W[18];
|
||||
S[19] = W[19];
|
||||
S[20] = W[20];
|
||||
S[22] = W[22];
|
||||
S[23] = W[23];
|
||||
S[24] = W[24];
|
||||
S[30] = W[30];
|
||||
S[31] = W[31];
|
||||
|
||||
W[18] += s0(W[3]);
|
||||
W[19] += W[3];
|
||||
W[20] += s1(W[18]);
|
||||
W[21] = s1(W[19]);
|
||||
W[22] += s1(W[20]);
|
||||
W[23] += s1(W[21]);
|
||||
W[24] += s1(W[22]);
|
||||
W[25] = s1(W[23]) + W[18];
|
||||
W[26] = s1(W[24]) + W[19];
|
||||
W[27] = s1(W[25]) + W[20];
|
||||
W[28] = s1(W[26]) + W[21];
|
||||
W[29] = s1(W[27]) + W[22];
|
||||
W[30] += s1(W[28]) + W[23];
|
||||
W[31] += s1(W[29]) + W[24];
|
||||
for (i = 32; i < 64; i += 2) {
|
||||
W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16];
|
||||
W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15];
|
||||
}
|
||||
|
||||
memcpy(S, prehash, 32);
|
||||
|
||||
RNDr(S, W, 3);
|
||||
RNDr(S, W, 4);
|
||||
RNDr(S, W, 5);
|
||||
RNDr(S, W, 6);
|
||||
RNDr(S, W, 7);
|
||||
RNDr(S, W, 8);
|
||||
RNDr(S, W, 9);
|
||||
RNDr(S, W, 10);
|
||||
RNDr(S, W, 11);
|
||||
RNDr(S, W, 12);
|
||||
RNDr(S, W, 13);
|
||||
RNDr(S, W, 14);
|
||||
RNDr(S, W, 15);
|
||||
RNDr(S, W, 16);
|
||||
RNDr(S, W, 17);
|
||||
RNDr(S, W, 18);
|
||||
RNDr(S, W, 19);
|
||||
RNDr(S, W, 20);
|
||||
RNDr(S, W, 21);
|
||||
RNDr(S, W, 22);
|
||||
RNDr(S, W, 23);
|
||||
RNDr(S, W, 24);
|
||||
RNDr(S, W, 25);
|
||||
RNDr(S, W, 26);
|
||||
RNDr(S, W, 27);
|
||||
RNDr(S, W, 28);
|
||||
RNDr(S, W, 29);
|
||||
RNDr(S, W, 30);
|
||||
RNDr(S, W, 31);
|
||||
RNDr(S, W, 32);
|
||||
RNDr(S, W, 33);
|
||||
RNDr(S, W, 34);
|
||||
RNDr(S, W, 35);
|
||||
RNDr(S, W, 36);
|
||||
RNDr(S, W, 37);
|
||||
RNDr(S, W, 38);
|
||||
RNDr(S, W, 39);
|
||||
RNDr(S, W, 40);
|
||||
RNDr(S, W, 41);
|
||||
RNDr(S, W, 42);
|
||||
RNDr(S, W, 43);
|
||||
RNDr(S, W, 44);
|
||||
RNDr(S, W, 45);
|
||||
RNDr(S, W, 46);
|
||||
RNDr(S, W, 47);
|
||||
RNDr(S, W, 48);
|
||||
RNDr(S, W, 49);
|
||||
RNDr(S, W, 50);
|
||||
RNDr(S, W, 51);
|
||||
RNDr(S, W, 52);
|
||||
RNDr(S, W, 53);
|
||||
RNDr(S, W, 54);
|
||||
RNDr(S, W, 55);
|
||||
RNDr(S, W, 56);
|
||||
RNDr(S, W, 57);
|
||||
RNDr(S, W, 58);
|
||||
RNDr(S, W, 59);
|
||||
RNDr(S, W, 60);
|
||||
RNDr(S, W, 61);
|
||||
RNDr(S, W, 62);
|
||||
RNDr(S, W, 63);
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
S[i] += midstate[i];
|
||||
|
||||
W[18] = S[18];
|
||||
W[19] = S[19];
|
||||
W[20] = S[20];
|
||||
W[22] = S[22];
|
||||
W[23] = S[23];
|
||||
W[24] = S[24];
|
||||
W[30] = S[30];
|
||||
W[31] = S[31];
|
||||
|
||||
memcpy(S + 8, sha256d_hash1 + 8, 32);
|
||||
S[16] = s1(sha256d_hash1[14]) + sha256d_hash1[ 9] + s0(S[ 1]) + S[ 0];
|
||||
S[17] = s1(sha256d_hash1[15]) + sha256d_hash1[10] + s0(S[ 2]) + S[ 1];
|
||||
S[18] = s1(S[16]) + sha256d_hash1[11] + s0(S[ 3]) + S[ 2];
|
||||
S[19] = s1(S[17]) + sha256d_hash1[12] + s0(S[ 4]) + S[ 3];
|
||||
S[20] = s1(S[18]) + sha256d_hash1[13] + s0(S[ 5]) + S[ 4];
|
||||
S[21] = s1(S[19]) + sha256d_hash1[14] + s0(S[ 6]) + S[ 5];
|
||||
S[22] = s1(S[20]) + sha256d_hash1[15] + s0(S[ 7]) + S[ 6];
|
||||
S[23] = s1(S[21]) + S[16] + s0(sha256d_hash1[ 8]) + S[ 7];
|
||||
S[24] = s1(S[22]) + S[17] + s0(sha256d_hash1[ 9]) + sha256d_hash1[ 8];
|
||||
S[25] = s1(S[23]) + S[18] + s0(sha256d_hash1[10]) + sha256d_hash1[ 9];
|
||||
S[26] = s1(S[24]) + S[19] + s0(sha256d_hash1[11]) + sha256d_hash1[10];
|
||||
S[27] = s1(S[25]) + S[20] + s0(sha256d_hash1[12]) + sha256d_hash1[11];
|
||||
S[28] = s1(S[26]) + S[21] + s0(sha256d_hash1[13]) + sha256d_hash1[12];
|
||||
S[29] = s1(S[27]) + S[22] + s0(sha256d_hash1[14]) + sha256d_hash1[13];
|
||||
S[30] = s1(S[28]) + S[23] + s0(sha256d_hash1[15]) + sha256d_hash1[14];
|
||||
S[31] = s1(S[29]) + S[24] + s0(S[16]) + sha256d_hash1[15];
|
||||
for (i = 32; i < 60; i += 2) {
|
||||
S[i] = s1(S[i - 2]) + S[i - 7] + s0(S[i - 15]) + S[i - 16];
|
||||
S[i+1] = s1(S[i - 1]) + S[i - 6] + s0(S[i - 14]) + S[i - 15];
|
||||
}
|
||||
S[60] = s1(S[58]) + S[53] + s0(S[45]) + S[44];
|
||||
|
||||
sha256_init(hash);
|
||||
|
||||
RNDr(hash, S, 0);
|
||||
RNDr(hash, S, 1);
|
||||
RNDr(hash, S, 2);
|
||||
RNDr(hash, S, 3);
|
||||
RNDr(hash, S, 4);
|
||||
RNDr(hash, S, 5);
|
||||
RNDr(hash, S, 6);
|
||||
RNDr(hash, S, 7);
|
||||
RNDr(hash, S, 8);
|
||||
RNDr(hash, S, 9);
|
||||
RNDr(hash, S, 10);
|
||||
RNDr(hash, S, 11);
|
||||
RNDr(hash, S, 12);
|
||||
RNDr(hash, S, 13);
|
||||
RNDr(hash, S, 14);
|
||||
RNDr(hash, S, 15);
|
||||
RNDr(hash, S, 16);
|
||||
RNDr(hash, S, 17);
|
||||
RNDr(hash, S, 18);
|
||||
RNDr(hash, S, 19);
|
||||
RNDr(hash, S, 20);
|
||||
RNDr(hash, S, 21);
|
||||
RNDr(hash, S, 22);
|
||||
RNDr(hash, S, 23);
|
||||
RNDr(hash, S, 24);
|
||||
RNDr(hash, S, 25);
|
||||
RNDr(hash, S, 26);
|
||||
RNDr(hash, S, 27);
|
||||
RNDr(hash, S, 28);
|
||||
RNDr(hash, S, 29);
|
||||
RNDr(hash, S, 30);
|
||||
RNDr(hash, S, 31);
|
||||
RNDr(hash, S, 32);
|
||||
RNDr(hash, S, 33);
|
||||
RNDr(hash, S, 34);
|
||||
RNDr(hash, S, 35);
|
||||
RNDr(hash, S, 36);
|
||||
RNDr(hash, S, 37);
|
||||
RNDr(hash, S, 38);
|
||||
RNDr(hash, S, 39);
|
||||
RNDr(hash, S, 40);
|
||||
RNDr(hash, S, 41);
|
||||
RNDr(hash, S, 42);
|
||||
RNDr(hash, S, 43);
|
||||
RNDr(hash, S, 44);
|
||||
RNDr(hash, S, 45);
|
||||
RNDr(hash, S, 46);
|
||||
RNDr(hash, S, 47);
|
||||
RNDr(hash, S, 48);
|
||||
RNDr(hash, S, 49);
|
||||
RNDr(hash, S, 50);
|
||||
RNDr(hash, S, 51);
|
||||
RNDr(hash, S, 52);
|
||||
RNDr(hash, S, 53);
|
||||
RNDr(hash, S, 54);
|
||||
RNDr(hash, S, 55);
|
||||
RNDr(hash, S, 56);
|
||||
|
||||
hash[2] += hash[6] + S1(hash[3]) + Ch(hash[3], hash[4], hash[5])
|
||||
+ S[57] + sha256_k[57];
|
||||
hash[1] += hash[5] + S1(hash[2]) + Ch(hash[2], hash[3], hash[4])
|
||||
+ S[58] + sha256_k[58];
|
||||
hash[0] += hash[4] + S1(hash[1]) + Ch(hash[1], hash[2], hash[3])
|
||||
+ S[59] + sha256_k[59];
|
||||
hash[7] += hash[3] + S1(hash[0]) + Ch(hash[0], hash[1], hash[2])
|
||||
+ S[60] + sha256_k[60]
|
||||
+ sha256_h[7];
|
||||
}
|
||||
|
||||
#endif /* EXTERN_SHA256 */
|
||||
|
||||
#if HAVE_SHA256_4WAY
|
||||
|
||||
void sha256d_ms_4way(uint32_t *hash, uint32_t *data,
|
||||
const uint32_t *midstate, const uint32_t *prehash);
|
||||
|
||||
static inline int scanhash_sha256d_4way(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t data[4 * 64] __attribute__((aligned(128)));
|
||||
uint32_t hash[4 * 8] __attribute__((aligned(32)));
|
||||
uint32_t midstate[4 * 8] __attribute__((aligned(32)));
|
||||
uint32_t prehash[4 * 8] __attribute__((aligned(32)));
|
||||
uint32_t n = pdata[19] - 1;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
int i, j;
|
||||
|
||||
memcpy(data, pdata + 16, 64);
|
||||
sha256d_preextend(data);
|
||||
for (i = 31; i >= 0; i--)
|
||||
for (j = 0; j < 4; j++)
|
||||
data[i * 4 + j] = data[i];
|
||||
|
||||
sha256_init(midstate);
|
||||
sha256_transform(midstate, pdata, 0);
|
||||
memcpy(prehash, midstate, 32);
|
||||
sha256d_prehash(prehash, pdata + 16);
|
||||
for (i = 7; i >= 0; i--) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
midstate[i * 4 + j] = midstate[i];
|
||||
prehash[i * 4 + j] = prehash[i];
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
for (i = 0; i < 4; i++)
|
||||
data[4 * 3 + i] = ++n;
|
||||
|
||||
sha256d_ms_4way(hash, data, midstate, prehash);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
if (swab32(hash[4 * 7 + i]) <= Htarg) {
|
||||
pdata[19] = data[4 * 3 + i];
|
||||
sha256d_80_swap(hash, pdata);
|
||||
if (fulltest(hash, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* HAVE_SHA256_4WAY */
|
||||
|
||||
#if HAVE_SHA256_8WAY
|
||||
|
||||
void sha256d_ms_8way(uint32_t *hash, uint32_t *data,
|
||||
const uint32_t *midstate, const uint32_t *prehash);
|
||||
|
||||
static inline int scanhash_sha256d_8way(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t data[8 * 64] __attribute__((aligned(128)));
|
||||
uint32_t hash[8 * 8] __attribute__((aligned(32)));
|
||||
uint32_t midstate[8 * 8] __attribute__((aligned(32)));
|
||||
uint32_t prehash[8 * 8] __attribute__((aligned(32)));
|
||||
uint32_t n = pdata[19] - 1;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
int i, j;
|
||||
|
||||
memcpy(data, pdata + 16, 64);
|
||||
sha256d_preextend(data);
|
||||
for (i = 31; i >= 0; i--)
|
||||
for (j = 0; j < 8; j++)
|
||||
data[i * 8 + j] = data[i];
|
||||
|
||||
sha256_init(midstate);
|
||||
sha256_transform(midstate, pdata, 0);
|
||||
memcpy(prehash, midstate, 32);
|
||||
sha256d_prehash(prehash, pdata + 16);
|
||||
for (i = 7; i >= 0; i--) {
|
||||
for (j = 0; j < 8; j++) {
|
||||
midstate[i * 8 + j] = midstate[i];
|
||||
prehash[i * 8 + j] = prehash[i];
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
for (i = 0; i < 8; i++)
|
||||
data[8 * 3 + i] = ++n;
|
||||
|
||||
sha256d_ms_8way(hash, data, midstate, prehash);
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (swab32(hash[8 * 7 + i]) <= Htarg) {
|
||||
pdata[19] = data[8 * 3 + i];
|
||||
sha256d_80_swap(hash, pdata);
|
||||
if (fulltest(hash, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* HAVE_SHA256_8WAY */
|
||||
|
||||
int scanhash_sha256d(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
|
||||
uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t data[64] /* __attribute__((aligned(128))) */;
|
||||
uint32_t hash[8] /* __attribute__((aligned(32))) */;
|
||||
uint32_t midstate[8] /* __attribute__((aligned(32))) */;
|
||||
uint32_t prehash[8] /* __attribute__((aligned(32))) */;
|
||||
uint32_t n = pdata[19] - 1;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
|
||||
#if HAVE_SHA256_8WAY
|
||||
if (sha256_use_8way())
|
||||
return scanhash_sha256d_8way(thr_id, pdata, ptarget,
|
||||
max_nonce, hashes_done);
|
||||
#endif
|
||||
#if HAVE_SHA256_4WAY
|
||||
if (sha256_use_4way())
|
||||
return scanhash_sha256d_4way(thr_id, pdata, ptarget,
|
||||
max_nonce, hashes_done);
|
||||
#endif
|
||||
|
||||
memcpy(data, pdata + 16, 64);
|
||||
sha256d_preextend(data);
|
||||
|
||||
sha256_init(midstate);
|
||||
sha256_transform(midstate, pdata, 0);
|
||||
memcpy(prehash, midstate, 32);
|
||||
sha256d_prehash(prehash, pdata + 16);
|
||||
|
||||
do {
|
||||
data[3] = ++n;
|
||||
sha256d_ms(hash, data, midstate, prehash);
|
||||
if (swab32(hash[7]) <= Htarg) {
|
||||
pdata[19] = data[3];
|
||||
sha256d_80_swap(hash, pdata);
|
||||
if (fulltest(hash, ptarget)) {
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} while (n < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = n - first_nonce + 1;
|
||||
pdata[19] = n;
|
||||
return 0;
|
||||
}
|
||||
Executable
+695
@@ -0,0 +1,695 @@
|
||||
/*
|
||||
|
||||
Based on libtommath and tomsfastmath by Tom St Denis
|
||||
|
||||
This is basically Barret reduction and it's setup from libtommath and
|
||||
basic bignum types and functions from tomsfastmath with some application
|
||||
specific optimizations like dropping sign handling and branches that are
|
||||
never reached, hard coding for a specific digit size (replacing slow ops like
|
||||
x % DIGIT_BIT with x & 31 etc).
|
||||
|
||||
Could probably do a lot better with CUDA, this code spills to local memory
|
||||
like a mofo due to dynamic array indexes.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef CHAR_BIT
|
||||
#define CHAR_BIT 8
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(x,y) ((x)<(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(x,y) ((x)>(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
#define DIGIT_BIT 32
|
||||
#define FP_SIZE 20
|
||||
|
||||
typedef uint32_t fp_digit;
|
||||
typedef uint64_t fp_word;
|
||||
typedef fp_digit fp_min_u32;
|
||||
|
||||
/* return codes */
|
||||
#define FP_OKAY 0
|
||||
#define FP_VAL 1
|
||||
#define FP_MEM 2
|
||||
|
||||
/* equalities */
|
||||
#define FP_LT -1 /* less than */
|
||||
#define FP_EQ 0 /* equal to */
|
||||
#define FP_GT 1 /* greater than */
|
||||
|
||||
/* replies */
|
||||
#define FP_YES 1 /* yes response */
|
||||
#define FP_NO 0 /* no response */
|
||||
|
||||
typedef int fp_err;
|
||||
|
||||
typedef struct {
|
||||
int used;
|
||||
fp_digit dp[FP_SIZE];
|
||||
} fp_int;
|
||||
|
||||
#define USED(m) ((m)->used)
|
||||
#define DIGIT(m,k) ((m)->dp[(k)])
|
||||
|
||||
#define fp_iszero(a) (((a)->used == 0) ? FP_YES : FP_NO)
|
||||
#define fp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? FP_YES : FP_NO)
|
||||
#define fp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? FP_YES : FP_NO)
|
||||
#define fp_init(a) fp_zero((a))
|
||||
#define fp_mul(a,b,c) fp_mul_comba((a), (b), (c))
|
||||
|
||||
/* clamp digits */
|
||||
#define fp_clamp(a) { while ((a)->used && (a)->dp[(a)->used-1] == 0) --((a)->used); }
|
||||
|
||||
__device__ __host__ void fp_zero( fp_int *a )
|
||||
{
|
||||
for( int i = 0; i < FP_SIZE; i++ ) a->dp[i] = 0;
|
||||
a->used = 0;
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_set( fp_int *a, fp_digit b )
|
||||
{
|
||||
fp_zero(a);
|
||||
a->dp[0] = b;
|
||||
a->used = a->dp[0] ? 1 : 0;
|
||||
}
|
||||
|
||||
__device__ __host__ int fp_cmp_mag( fp_int *a, fp_int *b )
|
||||
{
|
||||
if( a->used > b->used ) return FP_GT;
|
||||
else if( a->used < b->used ) return FP_LT;
|
||||
|
||||
for( int x = a->used - 1; x >= 0; x-- ) {
|
||||
|
||||
if( a->dp[x] > b->dp[x] ) return FP_GT;
|
||||
else if( a->dp[x] < b->dp[x] ) return FP_LT;
|
||||
}
|
||||
|
||||
return FP_EQ;
|
||||
}
|
||||
|
||||
/* unsigned addition */
|
||||
__device__ __host__ void s_fp_add(fp_int *a, fp_int *b, fp_int *c)
|
||||
{
|
||||
int x, y, oldused;
|
||||
fp_word t;
|
||||
|
||||
y = MAX(a->used, b->used);
|
||||
oldused = c->used;
|
||||
c->used = y;
|
||||
|
||||
t = 0;
|
||||
for (x = 0; x < y; x++) {
|
||||
t += ((fp_word)a->dp[x]) + ((fp_word)b->dp[x]);
|
||||
c->dp[x] = (fp_digit)t;
|
||||
t >>= DIGIT_BIT;
|
||||
}
|
||||
if (t != 0 && x < FP_SIZE) {
|
||||
c->dp[c->used++] = (fp_digit)t;
|
||||
++x;
|
||||
}
|
||||
|
||||
c->used = x;
|
||||
for (; x < oldused; x++) {
|
||||
c->dp[x] = 0;
|
||||
}
|
||||
fp_clamp(c);
|
||||
}
|
||||
|
||||
/* unsigned subtraction ||a|| >= ||b|| ALWAYS! */
|
||||
__device__ __host__ void s_fp_sub(fp_int *a, fp_int *b, fp_int *c)
|
||||
{
|
||||
int x, oldbused, oldused;
|
||||
fp_word t;
|
||||
|
||||
oldused = c->used;
|
||||
oldbused = b->used;
|
||||
c->used = a->used;
|
||||
t = 0;
|
||||
for (x = 0; x < oldbused; x++) {
|
||||
t = ((fp_word)a->dp[x]) - (((fp_word)b->dp[x]) + t);
|
||||
c->dp[x] = (fp_digit)t;
|
||||
t = (t >> DIGIT_BIT)&1;
|
||||
}
|
||||
for (; x < a->used; x++) {
|
||||
t = ((fp_word)a->dp[x]) - t;
|
||||
c->dp[x] = (fp_digit)t;
|
||||
t = (t >> DIGIT_BIT)&1;
|
||||
}
|
||||
for (; x < oldused; x++) {
|
||||
c->dp[x] = 0;
|
||||
}
|
||||
fp_clamp(c);
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_add( fp_int *a, fp_int *b, fp_int *c )
|
||||
{
|
||||
s_fp_add (a, b, c);
|
||||
}
|
||||
|
||||
/* c = a - b */
|
||||
__device__ __host__ void fp_sub(fp_int *a, fp_int *b, fp_int *c)
|
||||
{
|
||||
// int sa, sb;
|
||||
|
||||
/* The first has a larger or equal magnitude */
|
||||
s_fp_sub (a, b, c);
|
||||
}
|
||||
|
||||
__device__ __host__ int fp_cmp(fp_int *a, fp_int *b)
|
||||
{
|
||||
return fp_cmp_mag(a, b);
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_copy( fp_int *a, fp_int *b )
|
||||
{
|
||||
for( int i = 0; i < FP_SIZE; i++ ) b->dp[i] = a->dp[i];
|
||||
b->used = a->used;
|
||||
}
|
||||
|
||||
// TODO: use clz, return a->used - clz(a->dp[a->used-1])
|
||||
__device__ __host__ int fp_count_bits( fp_int *a )
|
||||
{
|
||||
int r;
|
||||
fp_digit q;
|
||||
|
||||
/* shortcut */
|
||||
if (a->used == 0) return 0;
|
||||
|
||||
/* get number of digits and add that */
|
||||
r = (a->used - 1) << 5;
|
||||
|
||||
/* take the last digit and count the bits in it */
|
||||
q = a->dp[a->used - 1];
|
||||
while (q > ((fp_digit) 0)) {
|
||||
++r;
|
||||
q >>= ((fp_digit) 1);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_rshd( fp_int *a, int x )
|
||||
{
|
||||
int y;
|
||||
|
||||
/* too many digits just zero and return */
|
||||
if (x >= a->used) {
|
||||
|
||||
fp_zero(a);
|
||||
return;
|
||||
}
|
||||
|
||||
/* shift */
|
||||
for (y = 0; y < a->used - x; y++) a->dp[y] = a->dp[y+x];
|
||||
|
||||
/* zero rest */
|
||||
for (; y < a->used; y++) a->dp[y] = 0;
|
||||
|
||||
/* decrement count */
|
||||
a->used -= x;
|
||||
fp_clamp(a);
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_lshd(fp_int *a, int x)
|
||||
{
|
||||
int y;
|
||||
|
||||
/* move up and truncate as required */
|
||||
y = MIN(a->used + x - 1, (int)(FP_SIZE-1));
|
||||
|
||||
/* store new size */
|
||||
a->used = y + 1;
|
||||
|
||||
/* move digits */
|
||||
for (; y >= x; y--) a->dp[y] = a->dp[y-x];
|
||||
|
||||
/* zero lower digits */
|
||||
for (; y >= 0; y--) a->dp[y] = 0;
|
||||
|
||||
/* clamp digits */
|
||||
fp_clamp(a);
|
||||
}
|
||||
|
||||
/* c = a * 2**d */
|
||||
__device__ __host__ void fp_mul_2d( fp_int *a, int b, fp_int *c )
|
||||
{
|
||||
fp_digit carry, carrytmp, shift;
|
||||
int x;
|
||||
|
||||
/* copy it */
|
||||
fp_copy(a, c);
|
||||
|
||||
/* handle whole digits */
|
||||
if (b >= DIGIT_BIT) {
|
||||
fp_lshd(c, b >> 5);
|
||||
}
|
||||
b &= 31;
|
||||
|
||||
/* shift the digits */
|
||||
if (b != 0) {
|
||||
carry = 0;
|
||||
shift = DIGIT_BIT - b;
|
||||
for (x = 0; x < c->used; x++) {
|
||||
carrytmp = c->dp[x] >> shift;
|
||||
c->dp[x] = (c->dp[x] << b) + carry;
|
||||
carry = carrytmp;
|
||||
}
|
||||
|
||||
/* store last carry if room */
|
||||
if (carry && x < FP_SIZE) c->dp[c->used++] = carry;
|
||||
}
|
||||
fp_clamp(c);
|
||||
}
|
||||
|
||||
/* c = a * b */
|
||||
__device__ __host__ void fp_mul_d( fp_int *a, fp_digit b, fp_int *c )
|
||||
{
|
||||
fp_word w;
|
||||
int x, oldused;
|
||||
|
||||
oldused = c->used;
|
||||
c->used = a->used;
|
||||
w = 0;
|
||||
|
||||
for (x = 0; x < a->used; x++) {
|
||||
w = ((fp_word)a->dp[x]) * ((fp_word)b) + w;
|
||||
c->dp[x] = (fp_digit)w;
|
||||
w = w >> DIGIT_BIT;
|
||||
}
|
||||
|
||||
if (w != 0 && (a->used != FP_SIZE)) {
|
||||
c->dp[c->used++] = w;
|
||||
++x;
|
||||
}
|
||||
|
||||
for (; x < oldused; x++) c->dp[x] = 0;
|
||||
|
||||
fp_clamp(c);
|
||||
}
|
||||
|
||||
/* c = a mod 2**d */
|
||||
__device__ __host__ void fp_mod_2d( fp_int *a, int b, fp_int *c )
|
||||
{
|
||||
int x;
|
||||
|
||||
/* zero if count less than or equal to zero */
|
||||
if (b <= 0) {
|
||||
fp_zero(c);
|
||||
return;
|
||||
}
|
||||
|
||||
/* get copy of input */
|
||||
fp_copy(a, c);
|
||||
|
||||
/* if 2**d is larger than we just return */
|
||||
if (b >= (a->used << 5)) return;
|
||||
|
||||
/* zero digits above the last digit of the modulus */
|
||||
for (x = (b >> 5) + ((b & 31) == 0 ? 0 : 1); x < c->used; x++) {
|
||||
c->dp[x] = 0;
|
||||
}
|
||||
|
||||
/* clear the digit that is not completely outside/inside the modulus */
|
||||
c->dp[b >> 5] &= ~((fp_digit)0) >> (DIGIT_BIT - b);
|
||||
fp_clamp (c);
|
||||
}
|
||||
|
||||
/* c = a / 2**b */
|
||||
__device__ __host__ void fp_div_2d( fp_int *a, int b, fp_int *c, fp_int *d )
|
||||
{
|
||||
fp_digit D, r, rr;
|
||||
int x;
|
||||
fp_int t;
|
||||
|
||||
/* if the shift count is <= 0 then we do no work */
|
||||
if (b <= 0) {
|
||||
fp_copy (a, c);
|
||||
if (d != NULL) fp_zero (d);
|
||||
return;
|
||||
}
|
||||
|
||||
fp_zero(&t);
|
||||
|
||||
/* get the remainder */
|
||||
if (d != NULL) fp_mod_2d (a, b, &t);
|
||||
|
||||
/* copy */
|
||||
fp_copy(a, c);
|
||||
|
||||
/* shift by as many digits in the bit count */
|
||||
if (b >= (int)DIGIT_BIT) fp_rshd (c, b >> 5);
|
||||
|
||||
/* shift any bit count < DIGIT_BIT */
|
||||
D = (fp_digit) (b & 31);
|
||||
if (D != 0) {
|
||||
fp_digit *tmpc, mask, shift;
|
||||
|
||||
/* mask */
|
||||
mask = (((fp_digit)1) << D) - 1;
|
||||
|
||||
/* shift for lsb */
|
||||
shift = DIGIT_BIT - D;
|
||||
|
||||
/* alias */
|
||||
tmpc = c->dp + (c->used - 1);
|
||||
|
||||
/* carry */
|
||||
r = 0;
|
||||
for (x = c->used - 1; x >= 0; x--) {
|
||||
/* get the lower bits of this word in a temp */
|
||||
rr = *tmpc & mask;
|
||||
|
||||
/* shift the current word and mix in the carry bits from the previous word */
|
||||
*tmpc = (*tmpc >> D) | (r << shift);
|
||||
--tmpc;
|
||||
|
||||
/* set the carry to the carry bits of the current word found above */
|
||||
r = rr;
|
||||
}
|
||||
}
|
||||
fp_clamp (c);
|
||||
|
||||
if (d != NULL) fp_copy (&t, d);
|
||||
}
|
||||
|
||||
/* a/b => cb + d == a */
|
||||
__device__ __host__ void fp_div( fp_int *a, fp_int *b, fp_int *c, fp_int *d )
|
||||
{
|
||||
fp_int q, x, y, t1, t2;
|
||||
int n, t, i, norm;
|
||||
|
||||
/* if a < b then q=0, r = a */
|
||||
if( fp_cmp_mag(a, b) == FP_LT ) {
|
||||
|
||||
if (d != NULL) fp_copy(a, d);
|
||||
if (c != NULL) fp_zero(c);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
fp_init(&q);
|
||||
q.used = a->used + 2;
|
||||
fp_init(&t1);
|
||||
fp_init(&t2);
|
||||
fp_copy(a, &x);
|
||||
fp_copy(b, &y);
|
||||
|
||||
/* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */
|
||||
norm = fp_count_bits(&y) & 31;
|
||||
if (norm < (int)(DIGIT_BIT-1)) {
|
||||
norm = (DIGIT_BIT-1) - norm;
|
||||
fp_mul_2d (&x, norm, &x);
|
||||
fp_mul_2d (&y, norm, &y);
|
||||
}
|
||||
else {
|
||||
norm = 0;
|
||||
}
|
||||
|
||||
/* note hac does 0 based, so if used==5 then its 0,1,2,3,4, e.g. use 4 */
|
||||
n = x.used - 1;
|
||||
t = y.used - 1;
|
||||
|
||||
/* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */
|
||||
fp_lshd (&y, n - t); /* y = y*b**{n-t} */
|
||||
|
||||
while (fp_cmp (&x, &y) != FP_LT) {
|
||||
++(q.dp[n - t]);
|
||||
fp_sub (&x, &y, &x);
|
||||
}
|
||||
|
||||
/* reset y by shifting it back down */
|
||||
fp_rshd (&y, n - t);
|
||||
|
||||
/* step 3. for i from n down to (t + 1) */
|
||||
for (i = n; i >= (t + 1); i--) {
|
||||
|
||||
if (i > x.used) continue;
|
||||
|
||||
/* step 3.1 if xi == yt then set q{i-t-1} to b-1,
|
||||
* otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
|
||||
if (x.dp[i] == y.dp[t]) {
|
||||
q.dp[i - t - 1] = ((((fp_word)1) << DIGIT_BIT) - 1);
|
||||
}
|
||||
else {
|
||||
fp_word tmp;
|
||||
tmp = ((fp_word) x.dp[i]) << ((fp_word) DIGIT_BIT);
|
||||
tmp |= ((fp_word) x.dp[i - 1]);
|
||||
tmp /= ((fp_word) y.dp[t]);
|
||||
q.dp[i - t - 1] = (fp_digit) (tmp);
|
||||
}
|
||||
|
||||
/* while (q{i-t-1} * (yt * b + y{t-1})) >
|
||||
xi * b**2 + xi-1 * b + xi-2
|
||||
|
||||
do q{i-t-1} -= 1;
|
||||
*/
|
||||
q.dp[i - t - 1] = (q.dp[i - t - 1] + 1);
|
||||
do {
|
||||
q.dp[i - t - 1] = (q.dp[i - t - 1] - 1);
|
||||
|
||||
/* find left hand */
|
||||
fp_zero (&t1);
|
||||
t1.dp[0] = (t - 1 < 0) ? 0 : y.dp[t - 1];
|
||||
t1.dp[1] = y.dp[t];
|
||||
t1.used = 2;
|
||||
fp_mul_d (&t1, q.dp[i - t - 1], &t1);
|
||||
|
||||
/* find right hand */
|
||||
t2.dp[0] = (i - 2 < 0) ? 0 : x.dp[i - 2];
|
||||
t2.dp[1] = (i - 1 < 0) ? 0 : x.dp[i - 1];
|
||||
t2.dp[2] = x.dp[i];
|
||||
t2.used = 3;
|
||||
} while (fp_cmp_mag(&t1, &t2) == FP_GT);
|
||||
|
||||
/* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
|
||||
fp_mul_d (&y, q.dp[i - t - 1], &t1);
|
||||
fp_lshd (&t1, i - t - 1);
|
||||
fp_sub (&x, &t1, &x);
|
||||
|
||||
}
|
||||
|
||||
/* now q is the quotient and x is the remainder
|
||||
* [which we have to normalize]
|
||||
*/
|
||||
|
||||
if (c != NULL) {
|
||||
fp_clamp (&q);
|
||||
fp_copy (&q, c);
|
||||
}
|
||||
|
||||
if (d != NULL) {
|
||||
fp_div_2d (&x, norm, &x, NULL);
|
||||
|
||||
/* the following is a kludge, essentially we were seeing the right remainder but
|
||||
with excess digits that should have been zero
|
||||
*/
|
||||
for (i = b->used; i < x.used; i++) x.dp[i] = 0;
|
||||
|
||||
fp_clamp(&x);
|
||||
fp_copy (&x, d);
|
||||
}
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_2expt( fp_int *a, int b )
|
||||
{
|
||||
int z;
|
||||
|
||||
fp_zero (a);
|
||||
|
||||
z = b >> 5;
|
||||
|
||||
/* set the used count of where the bit will go */
|
||||
a->used = z + 1;
|
||||
|
||||
/* put the single bit in its place */
|
||||
a->dp[z] = ((fp_digit)1) << (b & 31);
|
||||
}
|
||||
|
||||
/* generic PxQ multiplier */
|
||||
__device__ __host__ void fp_mul_comba(fp_int *A, fp_int *B, fp_int *C)
|
||||
{
|
||||
int ix, iy, iz, tx, ty, pa;
|
||||
fp_digit c0, c1, c2, *tmpx, *tmpy;
|
||||
fp_int tmp, *dst;
|
||||
|
||||
c0 = c1 = c2 = 0;
|
||||
|
||||
/* get size of output and trim */
|
||||
pa = A->used + B->used;
|
||||
if (pa >= FP_SIZE) pa = FP_SIZE-1;
|
||||
|
||||
if (A == C || B == C) {
|
||||
fp_zero(&tmp);
|
||||
dst = &tmp;
|
||||
}
|
||||
else {
|
||||
fp_zero(C);
|
||||
dst = C;
|
||||
}
|
||||
|
||||
for (ix = 0; ix < pa; ix++) {
|
||||
|
||||
/* get offsets into the two bignums */
|
||||
ty = MIN(ix, B->used-1);
|
||||
tx = ix - ty;
|
||||
|
||||
/* setup temp aliases */
|
||||
tmpx = A->dp + tx;
|
||||
tmpy = B->dp + ty;
|
||||
|
||||
/* this is the number of times the loop will iterrate, essentially its
|
||||
while (tx++ < a->used && ty-- >= 0) { ... }
|
||||
*/
|
||||
iy = MIN(A->used-tx, ty+1);
|
||||
|
||||
/* execute loop */
|
||||
c0 = c1; c1 = c2; c2 = 0;
|
||||
|
||||
for (iz = 0; iz < iy; ++iz) {
|
||||
|
||||
fp_word t;
|
||||
t = (fp_word)c0 + ((fp_word)*tmpx++) * ((fp_word)*tmpy--);
|
||||
c0 = t;
|
||||
t = (fp_word)c1 + (t >> DIGIT_BIT);
|
||||
c1 = t;
|
||||
c2 += t >> DIGIT_BIT;
|
||||
}
|
||||
|
||||
/* store term */
|
||||
dst->dp[ix] = c0;
|
||||
}
|
||||
|
||||
dst->used = pa;
|
||||
fp_clamp(dst);
|
||||
fp_copy(dst, C);
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_read_unsigned_bin(fp_int *a, unsigned char *b, int c)
|
||||
{
|
||||
/* zero the int */
|
||||
fp_zero (a);
|
||||
|
||||
unsigned char *pd = (unsigned char *)a->dp;
|
||||
|
||||
if ((unsigned)c > (FP_SIZE * sizeof(fp_digit))) {
|
||||
int excess = c - (FP_SIZE * sizeof(fp_digit));
|
||||
c -= excess;
|
||||
b += excess;
|
||||
}
|
||||
a->used = (c + sizeof(fp_digit) - 1)/sizeof(fp_digit);
|
||||
/* read the bytes in */
|
||||
for (c -= 1; c >= 0; c -= 1) {
|
||||
pd[c] = *b++;
|
||||
}
|
||||
|
||||
fp_clamp (a);
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_reverse( unsigned char *s, int len )
|
||||
{
|
||||
int ix, iy;
|
||||
unsigned char t;
|
||||
|
||||
ix = 0;
|
||||
iy = len - 1;
|
||||
while (ix < iy) {
|
||||
t = s[ix];
|
||||
s[ix] = s[iy];
|
||||
s[iy] = t;
|
||||
++ix;
|
||||
--iy;
|
||||
}
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_to_unsigned_bin( fp_int *a, unsigned char *b )
|
||||
{
|
||||
int x;
|
||||
fp_int t;
|
||||
|
||||
fp_copy(a, &t);
|
||||
|
||||
x = 0;
|
||||
while (fp_iszero (&t) == FP_NO) {
|
||||
b[x++] = (unsigned char) (t.dp[0] & 255);
|
||||
fp_div_2d (&t, 8, &t, NULL);
|
||||
}
|
||||
fp_reverse (b, x);
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_reduce_setup( fp_int *a, fp_int *b )
|
||||
{
|
||||
fp_2expt (a, b->used << 6);
|
||||
fp_div (a, b, a, NULL);
|
||||
}
|
||||
|
||||
/* compare against a single digit */
|
||||
__device__ __host__ int fp_cmp_d( fp_int *a, fp_digit b )
|
||||
{
|
||||
/* compare based on magnitude */
|
||||
if (a->used > 1) return FP_GT;
|
||||
|
||||
/* compare the only digit of a to b */
|
||||
if (a->dp[0] > b) return FP_GT;
|
||||
else if (a->dp[0] < b) return FP_LT;
|
||||
|
||||
return FP_EQ;
|
||||
}
|
||||
|
||||
__device__ __host__ void fp_reduce( fp_int *x, fp_int *m, fp_int *mu )
|
||||
{
|
||||
fp_int q;
|
||||
int um = m->used;
|
||||
|
||||
if( fp_cmp (x, m) == FP_LT ) return;
|
||||
|
||||
/* q = x */
|
||||
fp_copy (x, &q);
|
||||
|
||||
/* q1 = x / b**(k-1) */
|
||||
fp_rshd (&q, um - 1);
|
||||
|
||||
fp_mul (&q, mu, &q);
|
||||
|
||||
/* q3 = q2 / b**(k+1) */
|
||||
fp_rshd (&q, um + 1);
|
||||
|
||||
/* x = x mod b**(k+1), quick (no division) */
|
||||
fp_mod_2d (x, ((um + 1) << 5), x);
|
||||
|
||||
/* q = q * m mod b**(k+1), quick (no division) */
|
||||
//s_fp_mul_digs (&q, m, &q, um + 1);
|
||||
// FIXME: actually multiply up to required digits instead of full multiply + truncation
|
||||
fp_mul(&q, m, &q);
|
||||
q.used = um + 1;
|
||||
for( int i = q.used; i < FP_SIZE; i++ ) q.dp[i] = 0;
|
||||
|
||||
/* x = x - q */
|
||||
fp_sub (x, &q, x);
|
||||
|
||||
/* If x < 0, add b**(k+1) to it */
|
||||
// FIXME: does this ever happen..?
|
||||
if (fp_cmp_d (x, 0) == FP_LT) {
|
||||
fp_set (&q, 1);
|
||||
fp_lshd (&q, um + 1);
|
||||
fp_add (x, &q, x);
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
/* Back off if it's too big */
|
||||
while( fp_cmp (x, m) != FP_LT ) {
|
||||
s_fp_sub (x, m, x);
|
||||
count++;
|
||||
if( count > 100 ) {
|
||||
|
||||
//printf("FUCK ME I GOT STUCK IN THE REDUCE WHILE LOOP, AGAIN!!!!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "../cuda_helper.h"
|
||||
|
||||
__constant__ uint64_t c_PaddedMessage[32];
|
||||
|
||||
__constant__ uint32_t c_sigma[16][16];
|
||||
const uint32_t host_sigma[16][16] =
|
||||
{
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
||||
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
|
||||
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
|
||||
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
|
||||
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
|
||||
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
|
||||
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
||||
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
||||
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
||||
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
||||
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
||||
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
|
||||
};
|
||||
|
||||
static __device__ uint32_t HIWORD(const uint64_t x)
|
||||
{
|
||||
uint32_t result;
|
||||
asm(
|
||||
"{\n\t"
|
||||
".reg .u32 xl; \n\t"
|
||||
"mov.b64 {xl,%0},%1; \n\t"
|
||||
"}" : "=r"(result) : "l"(x)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
static __device__ uint32_t LOWORD(const uint64_t x)
|
||||
{
|
||||
uint32_t result;
|
||||
asm(
|
||||
"{\n\t"
|
||||
".reg .u32 xh; \n\t"
|
||||
"mov.b64 {%0,xh},%1; \n\t"
|
||||
"}" : "=r"(result) : "l"(x)
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
__device__ __forceinline__ uint64_t SWAP64( const uint64_t x)
|
||||
{
|
||||
uint64_t temp[2];
|
||||
temp[0] = __byte_perm(HIWORD(x), 0, 0x0123);
|
||||
temp[1] = __byte_perm(LOWORD(x), 0, 0x0123);
|
||||
|
||||
return temp[0] | (temp[1]<<32);
|
||||
}
|
||||
|
||||
__host__ uint64_t host_SWAP64( uint64_t x )
|
||||
{
|
||||
return
|
||||
((x & 0xff00000000000000) >> 56) |
|
||||
((x & 0x00ff000000000000) >> 40) |
|
||||
((x & 0x0000ff0000000000) >> 24) |
|
||||
((x & 0x000000ff00000000) >> 8) |
|
||||
((x & 0x00000000ff000000) << 8) |
|
||||
((x & 0x0000000000ff0000) << 24) |
|
||||
((x & 0x000000000000ff00) << 40) |
|
||||
((x & 0x00000000000000ff) << 56);
|
||||
}
|
||||
|
||||
__constant__ uint64_t c_u512[16];
|
||||
const uint64_t host_u512[16] =
|
||||
{
|
||||
0x243f6a8885a308d3ULL, 0x13198a2e03707344ULL,
|
||||
0xa4093822299f31d0ULL, 0x082efa98ec4e6c89ULL,
|
||||
0x452821e638d01377ULL, 0xbe5466cf34e90c6cULL,
|
||||
0xc0ac29b7c97c50ddULL, 0x3f84d5b5b5470917ULL,
|
||||
0x9216d5d98979fb1bULL, 0xd1310ba698dfb5acULL,
|
||||
0x2ffd72dbd01adfb7ULL, 0xb8e1afed6a267e96ULL,
|
||||
0xba7c9045f12c7f99ULL, 0x24a19947b3916cf7ULL,
|
||||
0x0801f2e2858efc16ULL, 0x636920d871574e69ULL
|
||||
};
|
||||
|
||||
|
||||
__forceinline__ __device__ uint64_t ROTR(const uint64_t value, const int offset) {
|
||||
uint64_t result;
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
if(offset < 32) {
|
||||
asm("{\n\t"
|
||||
" .reg .u32 tl,th,vl,vh; \n\t"
|
||||
"mov.b64 {tl,th},%1; \n\t"
|
||||
"shf.r.wrap.b32 vl,tl,th,%2; \n\t"
|
||||
"shf.r.wrap.b32 vh,th,tl,%2; \n\t"
|
||||
"mov.b64 %0,{vl,vh}; \n\t"
|
||||
"}"
|
||||
: "=l"(result) : "l"(value) , "r"(offset));
|
||||
} else {
|
||||
asm("{\n\t"
|
||||
" .reg .u32 tl,th,vl,vh; \n\t"
|
||||
"mov.b64 {tl,th},%1; \n\t"
|
||||
"shf.r.wrap.b32 vh,tl,th,%2; \n\t"
|
||||
"shf.r.wrap.b32 vl,th,tl,%2; \n\t"
|
||||
"mov.b64 %0,{vl,vh}; \n\t"
|
||||
"}"
|
||||
: "=l"(result) : "l"(value) , "r"(offset));
|
||||
}
|
||||
#else
|
||||
result = (value >> offset) | (value << (64-offset));
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
__device__ __forceinline__ uint64_t ROTR64_32( uint64_t val )
|
||||
{
|
||||
asm("{\n\t"
|
||||
".reg .u32 tl,th; \n\t"
|
||||
"mov.b64 {tl,th},%1; \n\t"
|
||||
"mov.b64 %0,{th,tl}; \n\t"
|
||||
"}"
|
||||
: "=l"(val) : "l"(val));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
__device__ __forceinline__ uint64_t ROTR64_16( uint64_t val )
|
||||
{
|
||||
asm("{\n\t"
|
||||
".reg .u16 b0, b1, b2, b3; \n\t"
|
||||
"mov.b64 { b0, b1, b2, b3 }, %1; \n\t"
|
||||
"mov.b64 %0, {b1, b2, b3, b0}; \n\t"
|
||||
"}"
|
||||
: "=l"(val) : "l"(val));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
#define G(a,b,c,d,e) \
|
||||
v[a] += (m[c_sigma[i][e]] ^ c_u512[c_sigma[i][e+1]]) + v[b]; \
|
||||
v[d] = ROTR64_32(v[d] ^ v[a]); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = ROTR( v[b] ^ v[c],25); \
|
||||
v[a] += (m[c_sigma[i][e+1]] ^ c_u512[c_sigma[i][e]])+v[b]; \
|
||||
v[d] = ROTR64_16(v[d] ^ v[a]); \
|
||||
v[c] += v[d]; \
|
||||
v[b] = ROTR( v[b] ^ v[c],11); \
|
||||
|
||||
|
||||
__device__ void blake_compress( uint64_t *h, const uint64_t *m, const int bits )
|
||||
{
|
||||
uint64_t v[16];
|
||||
|
||||
#pragma unroll 8
|
||||
for( int i = 0; i < 8; ++i ) v[i] = h[i];
|
||||
|
||||
v[ 8] = c_u512[0];
|
||||
v[ 9] = c_u512[1];
|
||||
v[10] = c_u512[2];
|
||||
v[11] = c_u512[3];
|
||||
v[12] = c_u512[4] ^ bits;
|
||||
v[13] = c_u512[5] ^ bits;
|
||||
v[14] = c_u512[6];
|
||||
v[15] = c_u512[7];
|
||||
|
||||
#pragma unroll 2
|
||||
for( int i = 0; i < 16; ++i )
|
||||
{
|
||||
/* column step */
|
||||
G( 0, 4, 8, 12, 0 );
|
||||
G( 1, 5, 9, 13, 2 );
|
||||
G( 2, 6, 10, 14, 4 );
|
||||
G( 3, 7, 11, 15, 6 );
|
||||
/* diagonal step */
|
||||
G( 0, 5, 10, 15, 8 );
|
||||
G( 1, 6, 11, 12, 10 );
|
||||
G( 2, 7, 8, 13, 12 );
|
||||
G( 3, 4, 9, 14, 14 );
|
||||
}
|
||||
|
||||
#pragma unroll 8
|
||||
for( int i = 0; i < 8; ++i ) h[i] ^= v[i] ^ v[i+8];
|
||||
}
|
||||
|
||||
static __device__ uint32_t cuda_swap32(uint32_t x)
|
||||
{
|
||||
return __byte_perm(x, 0, 0x0123);
|
||||
}
|
||||
|
||||
static __constant__ uint64_t d_IV[8];
|
||||
static const uint64_t h_IV[8] = {
|
||||
0x6a09e667f3bcc908ULL,
|
||||
0xbb67ae8584caa73bULL,
|
||||
0x3c6ef372fe94f82bULL,
|
||||
0xa54ff53a5f1d36f1ULL,
|
||||
0x510e527fade682d1ULL,
|
||||
0x9b05688c2b3e6c1fULL,
|
||||
0x1f83d9abfb41bd6bULL,
|
||||
0x5be0cd19137e2179ULL
|
||||
};
|
||||
|
||||
__global__ void blake_gpu_hash_185(uint32_t threads, uint32_t startNonce, uint32_t *outputHash, uint32_t *g_signature, uint32_t *g_hashwholeblock)
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
// bestimme den aktuellen Zähler
|
||||
uint32_t nonce = startNonce + thread;
|
||||
uint32_t idx64 = thread >> 6;
|
||||
uint64_t h[8];
|
||||
uint64_t buf[16];
|
||||
uint64_t *hashwholeblock = (uint64_t *)&g_hashwholeblock[idx64 << 3];
|
||||
uint64_t *signature = (uint64_t *)&g_signature[idx64 << 3];
|
||||
|
||||
#pragma unroll 8
|
||||
for(int i=0;i<8;i++)
|
||||
h[i] = d_IV[i];
|
||||
|
||||
#pragma unroll 11
|
||||
for (int i=0; i < 11; ++i) buf[i] = SWAP64(c_PaddedMessage[i]);
|
||||
|
||||
((uint32_t *)buf)[20] = cuda_swap32(nonce);
|
||||
|
||||
#pragma unroll 4
|
||||
for (int i=0; i < 4; ++i) buf[i+11] = SWAP64(hashwholeblock[i]);
|
||||
|
||||
buf[15] = SWAP64(c_PaddedMessage[15]);
|
||||
|
||||
blake_compress( h, buf, 1024 );
|
||||
|
||||
#pragma unroll 16
|
||||
for (int i=0; i < 16; ++i) buf[i] = c_PaddedMessage[i+16];
|
||||
|
||||
#pragma unroll 32
|
||||
for (int i=0; i < 32; ++i) ((unsigned char *)buf)[25+i] = ((unsigned char *)signature)[i];//SWAP64(signature[i]);
|
||||
|
||||
for (int i=0; i < 16; ++i) buf[i] = SWAP64(buf[i]);
|
||||
|
||||
blake_compress( h, buf, 1480 );
|
||||
|
||||
uint32_t *outHash = (uint32_t *)outputHash + 16 * thread;
|
||||
|
||||
#pragma unroll 8
|
||||
for (int i=0; i < 8; ++i) {
|
||||
outHash[2*i+0] = cuda_swap32( HIWORD(h[i]) );
|
||||
outHash[2*i+1] = cuda_swap32( LOWORD(h[i]) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void blake_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
cudaMemcpyToSymbol(c_sigma, host_sigma, sizeof(host_sigma), 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(c_u512, host_u512, sizeof(host_u512), 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(d_IV, h_IV, sizeof(h_IV), 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
__host__
|
||||
void blake_cpu_setBlock_185(void *pdata)
|
||||
{
|
||||
unsigned char PaddedMessage[256];
|
||||
memcpy(PaddedMessage, pdata, 185);
|
||||
memset(PaddedMessage+185, 0, 71);
|
||||
PaddedMessage[185] = 0x80;
|
||||
PaddedMessage[239] = 1;
|
||||
PaddedMessage[254] = 0x05;
|
||||
PaddedMessage[255] = 0xC8;
|
||||
|
||||
//for( int i = 0; i < 32; i++ ) ((uint64_t *)PaddedMessage)[i] = host_SWAP64(((uint64_t *)PaddedMessage)[i]);
|
||||
|
||||
cudaMemcpyToSymbol(c_PaddedMessage, PaddedMessage, 32*sizeof(uint64_t), 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
__host__
|
||||
void blake_cpu_hash_185(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_outputHash, uint32_t *d_signature, uint32_t *d_hashwholeblock)
|
||||
{
|
||||
const int threadsperblock = 64;
|
||||
|
||||
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
size_t shared_size = 0;
|
||||
|
||||
blake_gpu_hash_185<<<grid, block, shared_size>>>(threads, startNonce, d_outputHash, d_signature, d_hashwholeblock);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -0,0 +1,501 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "miner.h"
|
||||
#include "spreadx11.h"
|
||||
|
||||
__constant__ uint32_t c_PaddedMessage88[32]; // padded message, 88 bytes + padding to 128 bytes
|
||||
|
||||
// precalculated state for sha256double_88
|
||||
static __constant__ uint32_t d_state[8];
|
||||
|
||||
// init vector
|
||||
static __constant__ uint32_t d_IV[8];
|
||||
static const uint32_t h_IV[8] = {
|
||||
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
||||
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
||||
};
|
||||
// round constants
|
||||
static __constant__ uint32_t d_K[64];
|
||||
static const uint32_t h_K[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
||||
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
|
||||
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
||||
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
|
||||
0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
||||
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
|
||||
0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
||||
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
|
||||
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
||||
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
|
||||
0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
||||
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
|
||||
0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
||||
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
// padding for 400000 bytes of input data
|
||||
static __constant__ uint32_t padding400000[16] = {
|
||||
0x80000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x0030d400
|
||||
};
|
||||
|
||||
// padding for 32 bytes of input data
|
||||
static __constant__ uint32_t padding32[16] = {
|
||||
0x80000000, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000000, 0x00000000, 0x00000000, 0x00000100
|
||||
};
|
||||
|
||||
__device__ __host__ __forceinline__ uint32_t ROTR32( const uint32_t val, const size_t offset )
|
||||
{
|
||||
#if __CUDA_ARCH__ >= 320
|
||||
return __funnelshift_r(val, val, offset);
|
||||
#else
|
||||
return (val >> offset) | (val << (32-offset));
|
||||
#endif
|
||||
}
|
||||
|
||||
static __device__ uint32_t cuda_swab32(uint32_t x)
|
||||
{
|
||||
return __byte_perm(x, x, 0x0123);
|
||||
}
|
||||
|
||||
__host__ uint32_t bswap32( const uint32_t x )
|
||||
{
|
||||
return
|
||||
((x & 0xff000000) >> 24 ) |
|
||||
((x & 0x00ff0000) >> 8 ) |
|
||||
((x & 0x0000ff00) << 8 ) |
|
||||
((x & 0x000000ff) << 24 );
|
||||
}
|
||||
|
||||
__device__ __host__ __forceinline__ uint32_t BSG2_0( const uint32_t x )
|
||||
{
|
||||
return
|
||||
ROTR32(x, 2) ^
|
||||
ROTR32(x, 13) ^
|
||||
ROTR32(x, 22);
|
||||
}
|
||||
|
||||
__device__ __host__ __forceinline__ uint32_t BSG2_1( const uint32_t x )
|
||||
{
|
||||
return
|
||||
ROTR32(x, 6) ^
|
||||
ROTR32(x, 11) ^
|
||||
ROTR32(x, 25);
|
||||
}
|
||||
|
||||
__device__ __host__ __forceinline__ uint32_t SSG2_0( const uint32_t x )
|
||||
{
|
||||
return
|
||||
ROTR32(x, 7) ^
|
||||
ROTR32(x, 18) ^
|
||||
(x >> 3);
|
||||
}
|
||||
|
||||
__device__ __host__ __forceinline__ uint32_t SSG2_1( const uint32_t x )
|
||||
{
|
||||
return
|
||||
ROTR32(x, 17) ^
|
||||
ROTR32(x, 19) ^
|
||||
(x >> 10);
|
||||
}
|
||||
|
||||
__device__ __host__ __forceinline__ uint32_t CH( const uint32_t x, const uint32_t y, const uint32_t z )
|
||||
{
|
||||
return ((y ^ z) & x) ^ z;
|
||||
}
|
||||
|
||||
__device__ __host__ __forceinline__ uint32_t MAJ( const uint32_t x, const uint32_t y, const uint32_t z )
|
||||
{
|
||||
return (x & y) | ((x | y) & z);
|
||||
}
|
||||
|
||||
|
||||
__device__ __host__ __forceinline__ void sha2_step1( uint32_t *W, const uint32_t *K, const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d,
|
||||
const uint32_t e, const uint32_t f, const uint32_t g, uint32_t &h, const uint32_t *in, const uint32_t pc, const uint32_t pcount )
|
||||
{
|
||||
W[pc] = in[pc];
|
||||
uint32_t t1 =
|
||||
h + BSG2_1(e) + CH(e, f, g) +
|
||||
K[pcount + pc] + W[pc];
|
||||
d += t1;
|
||||
h = t1 + BSG2_0(a) + MAJ(a, b, c);
|
||||
}
|
||||
|
||||
__device__ __host__ __forceinline__ void sha2_step2( uint32_t *W, const uint32_t *K, const uint32_t a, const uint32_t b, const uint32_t c, uint32_t &d,
|
||||
const uint32_t e, const uint32_t f, const uint32_t g, uint32_t &h, const uint32_t *in, const uint32_t pc, const uint32_t pcount )
|
||||
{
|
||||
uint32_t t1;
|
||||
W[pc] = SSG2_1(W[(pc - 2) & 0x0F])
|
||||
+ W[(pc - 7) & 0x0F]
|
||||
+ SSG2_0(W[(pc - 15) & 0x0F]) + W[pc];
|
||||
t1 = h + BSG2_1(e) + CH(e, f, g)
|
||||
+ K[pcount + (pc)] + W[(pc)];
|
||||
d += t1;
|
||||
h = t1 + BSG2_0(a) + MAJ(a, b, c);
|
||||
}
|
||||
|
||||
__device__
|
||||
void sha2_transform(const uint32_t *in, uint32_t *state)
|
||||
{
|
||||
uint32_t a, b, c, d, e, f, g, h;
|
||||
uint32_t w[16];
|
||||
uint32_t pcount;
|
||||
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
f = state[5];
|
||||
g = state[6];
|
||||
h = state[7];
|
||||
pcount = 0;
|
||||
|
||||
sha2_step1(w, d_K, a, b, c, d, e, f, g, h, in, 0, pcount);
|
||||
sha2_step1(w, d_K, h, a, b, c, d, e, f, g, in, 1, pcount);
|
||||
sha2_step1(w, d_K, g, h, a, b, c, d, e, f, in, 2, pcount);
|
||||
sha2_step1(w, d_K, f, g, h, a, b, c, d, e, in, 3, pcount);
|
||||
sha2_step1(w, d_K, e, f, g, h, a, b, c, d, in, 4, pcount);
|
||||
sha2_step1(w, d_K, d, e, f, g, h, a, b, c, in, 5, pcount);
|
||||
sha2_step1(w, d_K, c, d, e, f, g, h, a, b, in, 6, pcount);
|
||||
sha2_step1(w, d_K, b, c, d, e, f, g, h, a, in, 7, pcount);
|
||||
sha2_step1(w, d_K, a, b, c, d, e, f, g, h, in, 8, pcount);
|
||||
sha2_step1(w, d_K, h, a, b, c, d, e, f, g, in, 9, pcount);
|
||||
sha2_step1(w, d_K, g, h, a, b, c, d, e, f, in, 10, pcount);
|
||||
sha2_step1(w, d_K, f, g, h, a, b, c, d, e, in, 11, pcount);
|
||||
sha2_step1(w, d_K, e, f, g, h, a, b, c, d, in, 12, pcount);
|
||||
sha2_step1(w, d_K, d, e, f, g, h, a, b, c, in, 13, pcount);
|
||||
sha2_step1(w, d_K, c, d, e, f, g, h, a, b, in, 14, pcount);
|
||||
sha2_step1(w, d_K, b, c, d, e, f, g, h, a, in, 15, pcount);
|
||||
|
||||
for (pcount = 16; pcount < 64; pcount += 16) {
|
||||
|
||||
sha2_step2(w, d_K, a, b, c, d, e, f, g, h, in, 0, pcount);
|
||||
sha2_step2(w, d_K, h, a, b, c, d, e, f, g, in, 1, pcount);
|
||||
sha2_step2(w, d_K, g, h, a, b, c, d, e, f, in, 2, pcount);
|
||||
sha2_step2(w, d_K, f, g, h, a, b, c, d, e, in, 3, pcount);
|
||||
sha2_step2(w, d_K, e, f, g, h, a, b, c, d, in, 4, pcount);
|
||||
sha2_step2(w, d_K, d, e, f, g, h, a, b, c, in, 5, pcount);
|
||||
sha2_step2(w, d_K, c, d, e, f, g, h, a, b, in, 6, pcount);
|
||||
sha2_step2(w, d_K, b, c, d, e, f, g, h, a, in, 7, pcount);
|
||||
sha2_step2(w, d_K, a, b, c, d, e, f, g, h, in, 8, pcount);
|
||||
sha2_step2(w, d_K, h, a, b, c, d, e, f, g, in, 9, pcount);
|
||||
sha2_step2(w, d_K, g, h, a, b, c, d, e, f, in, 10, pcount);
|
||||
sha2_step2(w, d_K, f, g, h, a, b, c, d, e, in, 11, pcount);
|
||||
sha2_step2(w, d_K, e, f, g, h, a, b, c, d, in, 12, pcount);
|
||||
sha2_step2(w, d_K, d, e, f, g, h, a, b, c, in, 13, pcount);
|
||||
sha2_step2(w, d_K, c, d, e, f, g, h, a, b, in, 14, pcount);
|
||||
sha2_step2(w, d_K, b, c, d, e, f, g, h, a, in, 15, pcount);
|
||||
}
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
state[5] += f;
|
||||
state[6] += g;
|
||||
state[7] += h;
|
||||
}
|
||||
|
||||
__host__
|
||||
void host_sha2_transform(const uint32_t *in, uint32_t *state)
|
||||
{
|
||||
uint32_t a, b, c, d, e, f, g, h;
|
||||
uint32_t w[16];
|
||||
uint32_t pcount;
|
||||
|
||||
a = state[0];
|
||||
b = state[1];
|
||||
c = state[2];
|
||||
d = state[3];
|
||||
e = state[4];
|
||||
f = state[5];
|
||||
g = state[6];
|
||||
h = state[7];
|
||||
pcount = 0;
|
||||
|
||||
sha2_step1(w, h_K, a, b, c, d, e, f, g, h, in, 0, pcount);
|
||||
sha2_step1(w, h_K, h, a, b, c, d, e, f, g, in, 1, pcount);
|
||||
sha2_step1(w, h_K, g, h, a, b, c, d, e, f, in, 2, pcount);
|
||||
sha2_step1(w, h_K, f, g, h, a, b, c, d, e, in, 3, pcount);
|
||||
sha2_step1(w, h_K, e, f, g, h, a, b, c, d, in, 4, pcount);
|
||||
sha2_step1(w, h_K, d, e, f, g, h, a, b, c, in, 5, pcount);
|
||||
sha2_step1(w, h_K, c, d, e, f, g, h, a, b, in, 6, pcount);
|
||||
sha2_step1(w, h_K, b, c, d, e, f, g, h, a, in, 7, pcount);
|
||||
sha2_step1(w, h_K, a, b, c, d, e, f, g, h, in, 8, pcount);
|
||||
sha2_step1(w, h_K, h, a, b, c, d, e, f, g, in, 9, pcount);
|
||||
sha2_step1(w, h_K, g, h, a, b, c, d, e, f, in, 10, pcount);
|
||||
sha2_step1(w, h_K, f, g, h, a, b, c, d, e, in, 11, pcount);
|
||||
sha2_step1(w, h_K, e, f, g, h, a, b, c, d, in, 12, pcount);
|
||||
sha2_step1(w, h_K, d, e, f, g, h, a, b, c, in, 13, pcount);
|
||||
sha2_step1(w, h_K, c, d, e, f, g, h, a, b, in, 14, pcount);
|
||||
sha2_step1(w, h_K, b, c, d, e, f, g, h, a, in, 15, pcount);
|
||||
|
||||
for (pcount = 16; pcount < 64; pcount += 16) {
|
||||
|
||||
sha2_step2(w, h_K, a, b, c, d, e, f, g, h, in, 0, pcount);
|
||||
sha2_step2(w, h_K, h, a, b, c, d, e, f, g, in, 1, pcount);
|
||||
sha2_step2(w, h_K, g, h, a, b, c, d, e, f, in, 2, pcount);
|
||||
sha2_step2(w, h_K, f, g, h, a, b, c, d, e, in, 3, pcount);
|
||||
sha2_step2(w, h_K, e, f, g, h, a, b, c, d, in, 4, pcount);
|
||||
sha2_step2(w, h_K, d, e, f, g, h, a, b, c, in, 5, pcount);
|
||||
sha2_step2(w, h_K, c, d, e, f, g, h, a, b, in, 6, pcount);
|
||||
sha2_step2(w, h_K, b, c, d, e, f, g, h, a, in, 7, pcount);
|
||||
sha2_step2(w, h_K, a, b, c, d, e, f, g, h, in, 8, pcount);
|
||||
sha2_step2(w, h_K, h, a, b, c, d, e, f, g, in, 9, pcount);
|
||||
sha2_step2(w, h_K, g, h, a, b, c, d, e, f, in, 10, pcount);
|
||||
sha2_step2(w, h_K, f, g, h, a, b, c, d, e, in, 11, pcount);
|
||||
sha2_step2(w, h_K, e, f, g, h, a, b, c, d, in, 12, pcount);
|
||||
sha2_step2(w, h_K, d, e, f, g, h, a, b, c, in, 13, pcount);
|
||||
sha2_step2(w, h_K, c, d, e, f, g, h, a, b, in, 14, pcount);
|
||||
sha2_step2(w, h_K, b, c, d, e, f, g, h, a, in, 15, pcount);
|
||||
}
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
state[4] += e;
|
||||
state[5] += f;
|
||||
state[6] += g;
|
||||
state[7] += h;
|
||||
}
|
||||
|
||||
__global__
|
||||
void spreadx11_sha256_gpu_hash_wholeblock(uint32_t threads, uint32_t startNonce, uint32_t *g_input, uint32_t *g_hash, uint32_t *g_signature)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t state[8];
|
||||
uint32_t input[16];
|
||||
uint32_t *outputHash = (uint32_t *)&g_hash[thread<<3];
|
||||
uint8_t *signature = (uint8_t *)&g_signature[thread<<3];
|
||||
|
||||
#pragma unroll 8
|
||||
for( int i=0; i < 8; i++ ) state[i] = d_IV[i];
|
||||
|
||||
/*
|
||||
Input is as follows, we need to replace nonce and MinerSignature for each hash.
|
||||
This means the first two blocks need to be handled separately.
|
||||
|
||||
4 bytes (nNonce & ~NONCE_MASK)
|
||||
8 bytes nTime;
|
||||
65 bytes MinerSignature;
|
||||
4 bytes nVersion;
|
||||
and so on....
|
||||
*/
|
||||
|
||||
// we process the same 200000 bytes of data twice
|
||||
for( int round = 0; round < 2; round++ ) {
|
||||
|
||||
// insert nonce
|
||||
input[0] = startNonce + (thread << 6);
|
||||
|
||||
// read the rest of the block
|
||||
#pragma unroll 15
|
||||
for( int i=1; i < 16; i++ ) input[i] = g_input[i];
|
||||
|
||||
// first 19 bytes of signature go into the first block
|
||||
#pragma unroll 19
|
||||
for( int i = 0; i < 19; i++ ) ((uint8_t *)input)[45+i] = signature[i];
|
||||
|
||||
// endian swap the block and transform
|
||||
#pragma unroll 16
|
||||
for( int i=0; i < 16; i++ ) input[i] = cuda_swab32(input[i]);
|
||||
sha2_transform(input, state);
|
||||
|
||||
// read the second block
|
||||
#pragma unroll 16
|
||||
for( int i=0; i < 16; i++ ) input[i] = g_input[i+16];
|
||||
|
||||
// replace in the remaining bytes of the signature
|
||||
#pragma unroll 13
|
||||
for( int i = 0; i < 13; i++ ) ((uint8_t *)input)[i] = signature[i+19];
|
||||
|
||||
// endian swap the second block and transform
|
||||
#pragma unroll 16
|
||||
for( int i=0; i < 16; i++ ) input[i] = cuda_swab32(input[i]);
|
||||
sha2_transform(input, state);
|
||||
|
||||
// transform the remaining blocks as they are
|
||||
for( int block = 2; block < 3125; block++ ) {
|
||||
|
||||
#pragma unroll 16
|
||||
for( int i=0; i < 16; i++ ) input[i] = cuda_swab32(g_input[i+(block << 4)]);
|
||||
|
||||
sha2_transform(input, state);
|
||||
}
|
||||
}
|
||||
|
||||
// load and transform the padding block
|
||||
#pragma unroll 16
|
||||
for( int i = 0; i < 16; i++ ) input[i] = padding400000[i];
|
||||
sha2_transform(input, state);
|
||||
|
||||
#pragma unroll 8
|
||||
for( int i=0; i < 8; i++ ) outputHash[i] = cuda_swab32(state[i]);
|
||||
}
|
||||
}
|
||||
|
||||
__global__
|
||||
void spreadx11_sha256double_gpu_hash_88(uint32_t threads, uint32_t startNonce, uint32_t *g_hash)
|
||||
{
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint32_t state[8];
|
||||
uint32_t input[16];
|
||||
uint32_t nonce = startNonce + (thread << 6);
|
||||
uint32_t *outputHash = (uint32_t *)&g_hash[thread<<3];
|
||||
|
||||
// load precalculated state from the first block
|
||||
#pragma unroll 8
|
||||
for( int i = 0; i < 8; i++ ) state[i] = d_state[i];
|
||||
|
||||
#pragma unroll 16
|
||||
for( int i = 0; i < 16; i++ ) input[i] = cuda_swab32(c_PaddedMessage88[i+16]);
|
||||
input[5] = cuda_swab32(nonce);
|
||||
sha2_transform(input, state);
|
||||
|
||||
// finished hashing the input data, next step: hash the first result hash
|
||||
|
||||
#pragma unroll 8
|
||||
for( int i = 0; i < 8; i++ ) {
|
||||
input[i] = state[i];
|
||||
input[i+8] = padding32[i];
|
||||
state[i] = d_IV[i];
|
||||
}
|
||||
|
||||
sha2_transform(input, state);
|
||||
|
||||
#pragma unroll 8
|
||||
for( int i = 0; i < 8; i++ ) outputHash[i] = cuda_swab32(state[i]);
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void spreadx11_sha256_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
cudaMemcpyToSymbol(d_K, h_K, sizeof(h_K), 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(d_IV, h_IV, sizeof(h_IV), 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
__host__
|
||||
void spreadx11_sha256double_cpu_hash_88(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash)
|
||||
{
|
||||
const uint32_t threadsperblock = 256;
|
||||
|
||||
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
spreadx11_sha256double_gpu_hash_88<<<grid, block>>>(threads, startNonce, d_hash);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
|
||||
__host__
|
||||
void spreadx11_sha256double_setBlock_88(void *data)
|
||||
{
|
||||
unsigned char PaddedMessage[128];
|
||||
uint32_t tmpstate[8], tmpinput[16];
|
||||
|
||||
memcpy(PaddedMessage, data, 88);
|
||||
memset(PaddedMessage+88, 0, 40);
|
||||
PaddedMessage[ 88] = 0x80;
|
||||
PaddedMessage[126] = 0x02;
|
||||
PaddedMessage[127] = 0xC0;
|
||||
|
||||
// we can transform the first block here and start the CUDA kernel with the precalculated state
|
||||
for( int i = 0; i < 8; i++ ) tmpstate[i] = h_IV[i];
|
||||
for( int i = 0; i < 16; i++ ) tmpinput[i] = bswap32(((uint32_t *)PaddedMessage)[i]);
|
||||
host_sha2_transform(tmpinput, tmpstate);
|
||||
|
||||
cudaMemcpyToSymbol(d_state, tmpstate, 8*sizeof(uint32_t), 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(c_PaddedMessage88, PaddedMessage, 128, 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
__host__
|
||||
void spreadx11_sha256_setBlock_wholeblock(struct work *work, uint32_t *d_wholeblock)
|
||||
{
|
||||
unsigned char paddedmessage[200000];
|
||||
struct spreadwork *swork = (struct spreadwork *) work->extradata;
|
||||
|
||||
/*
|
||||
We need a hash of:
|
||||
offset size field
|
||||
0 4 nNonce & 0xffffffc0
|
||||
4 8 nTime
|
||||
12 65 MinerSignature
|
||||
77 4 nVersion
|
||||
81 32 hashPrevBlock
|
||||
113 32 hashMerkleRoot
|
||||
145 4 nBits
|
||||
149 4 nHeight
|
||||
153 x transactions, variable length
|
||||
padding calculated backwards from the copy of hashPrevBlock at the end
|
||||
199968 32 hashPrevBlock
|
||||
|
||||
We have in work->data:
|
||||
offset size field data
|
||||
0 4 nVersion 02000000
|
||||
4 32 hashPrevBlock 83ac9d7e96c4bb15d1a9a2fe3dbc81747768125009efc14e3824fbacaec65fad
|
||||
36 32 HashMerkleRoot 4e06a8366a959df705ea34dfe7eafea0d8a9e6fe3ba6b83afddb145b27da2362
|
||||
68 8 nTime ed71585400000000
|
||||
76 4 nBits 19850d1d
|
||||
80 4 nHeight 33d20100
|
||||
84 4 nNonce 00000000
|
||||
88 32 hashWholeBlock 0000000000000000000000000000000000000000000000000000000000000000
|
||||
120 33 MinerSignature1 1cad95a3e3e3598b74a1b8e2e3c013ababf6c45c83534029dbe8b4698916f78255
|
||||
153 32 MinerSignature2 0000000000000000000000000000000000000000000000000000000000000000
|
||||
*/
|
||||
|
||||
memcpy(paddedmessage+0, swork->data+84, 4); // nNonce
|
||||
memcpy(paddedmessage+4, swork->data+68, 8); // nTime
|
||||
memcpy(paddedmessage+12, swork->data+120, 65); // MinerSignature
|
||||
memcpy(paddedmessage+77, swork->data+0, 4); // nVersion
|
||||
memcpy(paddedmessage+81, swork->data+4, 32); // hashPrevBlock
|
||||
memcpy(paddedmessage+113, swork->data+36, 32); // HashMerkleRoot
|
||||
memcpy(paddedmessage+145, swork->data+76, 4); // nBits
|
||||
memcpy(paddedmessage+149, swork->data+80, 4); // nHeight
|
||||
memcpy(paddedmessage+153, swork->tx, swork->txsize); // tx
|
||||
|
||||
// the total amount of bytes in our data
|
||||
int blocksize = 153 + swork->txsize;
|
||||
|
||||
// pad the block with 0x07 bytes to make it a multiple of uint32_t
|
||||
while( blocksize & 3 ) paddedmessage[blocksize++] = 0x07;
|
||||
|
||||
// figure out the offsets for the padding
|
||||
uint32_t *pFillBegin = (uint32_t*)&paddedmessage[blocksize];
|
||||
uint32_t *pFillEnd = (uint32_t*)&paddedmessage[MAX_BLOCK_SIZE]; // FIXME: isn't this out of bounds by one... but it seems to work out...
|
||||
uint32_t *pFillFooter = pFillBegin > pFillEnd - 8 ? pFillBegin : pFillEnd - 8;
|
||||
|
||||
memcpy(pFillFooter, swork->data+4, (pFillEnd - pFillFooter)*4);
|
||||
for (uint32_t *pI = pFillFooter; pI < pFillEnd; pI++)
|
||||
*pI |= 1;
|
||||
|
||||
for (uint32_t *pI = pFillFooter - 1; pI >= pFillBegin; pI--)
|
||||
pI[0] = pI[3]*pI[7];
|
||||
|
||||
// copy the whole monstrosity into device memory for processing
|
||||
cudaMemcpy(d_wholeblock, paddedmessage, 200000, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
__host__
|
||||
void spreadx11_sha256_cpu_hash_wholeblock(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash, uint32_t *d_signature, uint32_t *d_wholeblock)
|
||||
{
|
||||
const uint32_t threadsperblock = 256;
|
||||
|
||||
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
spreadx11_sha256_gpu_hash_wholeblock<<<grid, block>>>(threads, startNonce, d_wholeblock, d_hash, d_signature);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#include "miner.h"
|
||||
#include "bignum_fp.h"
|
||||
#include "spreadx11.h"
|
||||
|
||||
__constant__ uint32_t d_privkey_data[8]; // 32 bytes
|
||||
__constant__ uint32_t d_kinv_data[8]; // 32 bytes
|
||||
|
||||
__constant__ uint32_t d_m_data[8] = {
|
||||
0xd0364141, 0xbfd25e8c, 0xaf48a03b, 0xbaaedce6,
|
||||
0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff
|
||||
};
|
||||
|
||||
__constant__ uint32_t d_mu_data[9] = {
|
||||
0x2fc9bec0, 0x402da173, 0x50b75fc4, 0x45512319,
|
||||
0x00000001, 0x00000000, 0x00000000, 0x00000000,
|
||||
0x00000001
|
||||
};
|
||||
|
||||
__global__
|
||||
void spreadx11_sign_gpu(uint32_t threads, uint32_t startNonce, uint32_t *g_sha256hash, uint32_t *g_signature )
|
||||
{
|
||||
const uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
|
||||
if (thread < threads)
|
||||
{
|
||||
fp_int hash, result, m, mu, privkey, kinv;
|
||||
unsigned char *sha256hash = (unsigned char *)&g_sha256hash[thread<<3];
|
||||
uint32_t *signature = (uint32_t *)&g_signature[thread<<3];
|
||||
|
||||
fp_zero(&result);
|
||||
fp_read_unsigned_bin(&hash, sha256hash, 32);
|
||||
|
||||
privkey.used = 8;
|
||||
kinv.used = 8;
|
||||
m.used = 8;
|
||||
mu.used = 9;
|
||||
|
||||
#pragma unroll 8
|
||||
for( int i = 0; i < 8; i++ ) {
|
||||
privkey.dp[i] = d_privkey_data[i];
|
||||
kinv.dp[i] = d_kinv_data[i];
|
||||
m.dp[i] = d_m_data[i];
|
||||
mu.dp[i] = d_mu_data[i];
|
||||
signature[i] = 0;
|
||||
}
|
||||
mu.dp[8] = d_mu_data[8];
|
||||
m.dp[8] = 0;
|
||||
|
||||
#pragma unroll
|
||||
for( int i = 9; i < FP_SIZE; i++ ) {
|
||||
|
||||
m.dp[i] = 0;
|
||||
mu.dp[i] = 0;
|
||||
}
|
||||
|
||||
fp_add(&hash, &privkey, &result);
|
||||
fp_mul(&result, &kinv, &result);
|
||||
fp_reduce(&result, &m, &mu);
|
||||
fp_to_unsigned_bin(&result, &((unsigned char *)signature)[32-(fp_count_bits(&result)+7)/8]);
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
void spreadx11_sign_cpu_init(int thr_id, uint32_t throughput)
|
||||
{
|
||||
}
|
||||
|
||||
__host__
|
||||
void spreadx11_sign_cpu_setInput(struct work *work)
|
||||
{
|
||||
fp_int fp_privkey, fp_kinv;
|
||||
struct spreadwork* swork = (struct spreadwork*) work->extradata;
|
||||
|
||||
fp_read_unsigned_bin(&fp_privkey, swork->privkey, 32);
|
||||
fp_read_unsigned_bin(&fp_kinv, swork->kinv, 32);
|
||||
|
||||
cudaMemcpyToSymbol(d_privkey_data, fp_privkey.dp, 32, 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(d_kinv_data, fp_kinv.dp, 32, 0, cudaMemcpyHostToDevice);
|
||||
}
|
||||
|
||||
__host__
|
||||
void spreadx11_sign_cpu(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash, uint32_t *d_signature)
|
||||
{
|
||||
const uint32_t threadsperblock = 256;
|
||||
|
||||
dim3 grid((threads + threadsperblock-1)/threadsperblock);
|
||||
dim3 block(threadsperblock);
|
||||
|
||||
spreadx11_sign_gpu<<<grid, block>>>(threads, startNonce, d_hash, d_signature);
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,540 @@
|
||||
/**
|
||||
* From the SpreadX11 spreadminer Cuda Implementation by tsiv
|
||||
*
|
||||
* Adapted to common ccminer by tpruvot@github - 2015
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "sph/sph_blake.h"
|
||||
#include "sph/sph_bmw.h"
|
||||
#include "sph/sph_groestl.h"
|
||||
#include "sph/sph_skein.h"
|
||||
#include "sph/sph_jh.h"
|
||||
#include "sph/sph_keccak.h"
|
||||
|
||||
#include "sph/sph_luffa.h"
|
||||
#include "sph/sph_cubehash.h"
|
||||
#include "sph/sph_shavite.h"
|
||||
#include "sph/sph_simd.h"
|
||||
#include "sph/sph_echo.h"
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/sha.h>
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
#include "spreadx11.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static uint32_t *d_sha256hash[MAX_GPUS];
|
||||
static uint32_t *d_signature[MAX_GPUS];
|
||||
static uint32_t *d_hashwholeblock[MAX_GPUS];
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
static uint32_t *d_wholeblockdata[MAX_GPUS];
|
||||
|
||||
extern void spreadx11_sha256double_cpu_hash_88(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash);
|
||||
extern void spreadx11_sha256double_setBlock_88(void *data);
|
||||
extern void spreadx11_sha256_cpu_init( int thr_id, uint32_t threads);
|
||||
|
||||
extern void spreadx11_sha256_cpu_hash_wholeblock(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash, uint32_t *d_signature, uint32_t *d_wholeblock);
|
||||
extern void spreadx11_sha256_setBlock_wholeblock(struct work *work, uint32_t *d_wholeblock);
|
||||
|
||||
extern void spreadx11_sign_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void spreadx11_sign_cpu_setInput(struct work *work);
|
||||
extern void spreadx11_sign_cpu(int thr_id, uint32_t threads, uint32_t startNonce, uint32_t *d_hash, uint32_t *d_signature);
|
||||
|
||||
extern void blake_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void blake_cpu_setBlock_185(void *pdata);
|
||||
extern void blake_cpu_hash_185(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash, uint32_t *d_signature, uint32_t *d_hashwholeblock);
|
||||
|
||||
extern void quark_bmw512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_bmw512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_groestl512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_groestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_skein512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_skein512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_keccak512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_keccak512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_jh512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_jh512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_luffa512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_luffa512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_cubehash512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_cubehash512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_shavite512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_shavite512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_simd512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_simd512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
//extern void spreadx11_echo512_cpu_init(int thr_id, uint32_t threads);
|
||||
//extern void spreadx11_echo512_cpu_setTarget(const void *ptarget);
|
||||
//extern uint32_t spreadx11_echo512_cpu_hash_64_final(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, uint32_t *hashidx);
|
||||
|
||||
extern void x11_echo512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_echo512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
#define PROFILE 0
|
||||
#if PROFILE == 1
|
||||
#define PRINTTIME(s) do { \
|
||||
double duration; \
|
||||
gettimeofday(&tv_end, NULL); \
|
||||
duration = 1e-6 * (tv_end.tv_usec-tv_start.tv_usec) + (tv_end.tv_sec-tv_start.tv_sec); \
|
||||
printf("%s: %.2f ms, %.2f MH/s\n", s, duration*1000.0, (double)throughput / 1000000.0 / duration); \
|
||||
} while(0)
|
||||
#define TRACE(algo) { \
|
||||
if (nonce == first_nonce) { \
|
||||
uint32_t* debugbuf = NULL; \
|
||||
cudaMallocHost(&debugbuf, 8*sizeof(uint32_t)); \
|
||||
cudaMemcpy(debugbuf, d_hash[thr_id], 32, cudaMemcpyDeviceToHost); \
|
||||
printf(" %s %08x %08x %08x %08x...\n", algo, swab32(debugbuf[0]), swab32(debugbuf[1]), \
|
||||
swab32(debugbuf[2]), swab32(debugbuf[3])); \
|
||||
cudaFreeHost(debugbuf); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define PRINTTIME(s)
|
||||
#define TRACE(s)
|
||||
#endif
|
||||
|
||||
void hextobin(unsigned char *p, const char *hexstr, size_t len)
|
||||
{
|
||||
char hex_byte[3];
|
||||
char *ep;
|
||||
|
||||
hex_byte[2] = '\0';
|
||||
|
||||
while (*hexstr && len) {
|
||||
if (!hexstr[1]) {
|
||||
applog(LOG_ERR, "hex2bin str truncated");
|
||||
return;
|
||||
}
|
||||
hex_byte[0] = hexstr[0];
|
||||
hex_byte[1] = hexstr[1];
|
||||
*p = (unsigned char) strtol(hex_byte, &ep, 16);
|
||||
if (*ep) {
|
||||
applog(LOG_ERR, "hex2bin failed on '%s'", hex_byte);
|
||||
return;
|
||||
}
|
||||
p++;
|
||||
hexstr += 2;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
static void spreadx11_hash(void *output, struct work *work, uint32_t nonce)
|
||||
{
|
||||
SHA256_CTX ctx_sha;
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_skein512_context ctx_skein;
|
||||
sph_luffa512_context ctx_luffa;
|
||||
sph_cubehash512_context ctx_cubehash;
|
||||
sph_shavite512_context ctx_shavite;
|
||||
sph_simd512_context ctx_simd;
|
||||
sph_echo512_context ctx_echo;
|
||||
|
||||
unsigned char mod[32] = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
|
||||
0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41
|
||||
};
|
||||
unsigned char tmp[185];
|
||||
unsigned char hashforsig[32];
|
||||
unsigned char wholeblock[MAX_BLOCK_SIZE];
|
||||
unsigned char finalhash[64];
|
||||
BIGNUM *bn_hash, *bn_privkey, *bn_kinv, *bn_mod, *bn_res;
|
||||
BN_CTX *bn_ctx;
|
||||
|
||||
struct spreadwork* swork = (struct spreadwork*) work->extradata;
|
||||
|
||||
uint32_t *nonceptr = (uint32_t *)&tmp[84];
|
||||
unsigned char *hashwholeblockptr = &tmp[88];
|
||||
unsigned char *signatureptr = &tmp[153];
|
||||
|
||||
memcpy(tmp, swork->data, 185);
|
||||
nonceptr[0] = nonce & 0xffffffc0;
|
||||
|
||||
SHA256_Init(&ctx_sha);
|
||||
SHA256_Update(&ctx_sha, tmp, 88);
|
||||
SHA256_Final(hashforsig, &ctx_sha);
|
||||
SHA256_Init(&ctx_sha);
|
||||
SHA256_Update(&ctx_sha, hashforsig, 32);
|
||||
SHA256_Final(hashforsig, &ctx_sha);
|
||||
|
||||
bn_ctx = BN_CTX_new();
|
||||
bn_hash = BN_new();
|
||||
bn_privkey = BN_new();
|
||||
bn_kinv = BN_new();
|
||||
bn_mod = BN_new();
|
||||
bn_res = BN_new();
|
||||
|
||||
BN_bin2bn(hashforsig, 32, bn_hash);
|
||||
BN_bin2bn(swork->privkey, 32, bn_privkey);
|
||||
BN_bin2bn(swork->kinv, 32, bn_kinv);
|
||||
BN_bin2bn(mod, 32, bn_mod);
|
||||
|
||||
BN_mod_add_quick(bn_privkey, bn_privkey, bn_hash, bn_mod);
|
||||
BN_mod_mul(bn_res, bn_privkey, bn_kinv, bn_mod, bn_ctx);
|
||||
int nBitsS = BN_num_bits(bn_res);
|
||||
memset(signatureptr, 0, 32);
|
||||
BN_bn2bin(bn_res, &signatureptr[32-(nBitsS+7)/8]);
|
||||
|
||||
BN_CTX_free(bn_ctx);
|
||||
BN_clear_free(bn_hash);
|
||||
BN_clear_free(bn_privkey);
|
||||
BN_clear_free(bn_kinv);
|
||||
BN_clear_free(bn_mod);
|
||||
BN_clear_free(bn_res);
|
||||
|
||||
memcpy(wholeblock+0, tmp+84, 4); // nNonce
|
||||
memcpy(wholeblock+4, tmp+68, 8); // nTime
|
||||
memcpy(wholeblock+12, tmp+120, 65); // MinerSignature
|
||||
memcpy(wholeblock+77, tmp+0, 4); // nVersion
|
||||
memcpy(wholeblock+81, tmp+4, 32); // hashPrevBlock
|
||||
memcpy(wholeblock+113, tmp+36, 32); // HashMerkleRoot
|
||||
memcpy(wholeblock+145, tmp+76, 4); // nBits
|
||||
memcpy(wholeblock+149, tmp+80, 4); // nHeight
|
||||
memcpy(wholeblock+153, swork->tx, swork->txsize); // tx
|
||||
|
||||
// the total amount of bytes in our data
|
||||
int blocksize = 153 + swork->txsize;
|
||||
|
||||
// pad the block with 0x07 bytes to make it a multiple of uint32_t
|
||||
while( blocksize & 3 ) wholeblock[blocksize++] = 0x07;
|
||||
|
||||
// figure out the offsets for the padding
|
||||
uint32_t *pFillBegin = (uint32_t*)&wholeblock[blocksize];
|
||||
uint32_t *pFillEnd = (uint32_t*)&wholeblock[MAX_BLOCK_SIZE]; // FIXME: isn't this out of bounds by one... but it seems to work out...
|
||||
uint32_t *pFillFooter = pFillBegin > pFillEnd - 8 ? pFillBegin : pFillEnd - 8;
|
||||
|
||||
memcpy(pFillFooter, tmp+4, (pFillEnd - pFillFooter)*4);
|
||||
for (uint32_t *pI = pFillFooter; pI < pFillEnd; pI++)
|
||||
*pI |= 1;
|
||||
|
||||
for (uint32_t *pI = pFillFooter - 1; pI >= pFillBegin; pI--)
|
||||
pI[0] = pI[3]*pI[7];
|
||||
|
||||
SHA256_Init(&ctx_sha);
|
||||
SHA256_Update(&ctx_sha, wholeblock, MAX_BLOCK_SIZE);
|
||||
SHA256_Update(&ctx_sha, wholeblock, MAX_BLOCK_SIZE);
|
||||
SHA256_Final(hashwholeblockptr, &ctx_sha);
|
||||
//applog_hash(hashwholeblockptr);
|
||||
|
||||
nonceptr[0] = nonce;
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, tmp, 185);
|
||||
sph_blake512_close(&ctx_blake, (void*) finalhash);
|
||||
//applog_hash(finalhash);
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, (const void*) finalhash, 64);
|
||||
sph_bmw512_close(&ctx_bmw, (void*) finalhash);
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, (const void*) finalhash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, (void*) finalhash);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, (const void*) finalhash, 64);
|
||||
sph_skein512_close(&ctx_skein, (void*) finalhash);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, (const void*) finalhash, 64);
|
||||
sph_jh512_close(&ctx_jh, (void*) finalhash);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, (const void*) finalhash, 64);
|
||||
sph_keccak512_close(&ctx_keccak, (void*) finalhash);
|
||||
|
||||
sph_luffa512_init(&ctx_luffa);
|
||||
sph_luffa512 (&ctx_luffa, (const void*) finalhash, 64);
|
||||
sph_luffa512_close (&ctx_luffa, (void*) finalhash);
|
||||
|
||||
sph_cubehash512_init(&ctx_cubehash);
|
||||
sph_cubehash512 (&ctx_cubehash, (const void*) finalhash, 64);
|
||||
sph_cubehash512_close(&ctx_cubehash, (void*) finalhash);
|
||||
|
||||
sph_shavite512_init(&ctx_shavite);
|
||||
sph_shavite512 (&ctx_shavite, (const void*) finalhash, 64);
|
||||
sph_shavite512_close(&ctx_shavite, (void*) finalhash);
|
||||
|
||||
sph_simd512_init(&ctx_simd);
|
||||
sph_simd512 (&ctx_simd, (const void*) finalhash, 64);
|
||||
sph_simd512_close(&ctx_simd, (void*) finalhash);
|
||||
|
||||
sph_echo512_init(&ctx_echo);
|
||||
sph_echo512 (&ctx_echo, (const void*) finalhash, 64);
|
||||
sph_echo512_close(&ctx_echo, (void*) finalhash);
|
||||
|
||||
memcpy(output, finalhash, 32);
|
||||
}
|
||||
|
||||
// cpu hash only used as dev test (--cputest)
|
||||
extern "C" void spreadhash(void *output, const void *input)
|
||||
{
|
||||
struct work work;
|
||||
struct spreadwork swork;
|
||||
memset(&work, 0, sizeof(struct work));
|
||||
memset(&swork, 0, sizeof(struct spreadwork));
|
||||
memcpy(swork.data, input, 128); // 185 but made for a simple empty
|
||||
const char hextest[371] = { 0 };
|
||||
hex2bin(swork.data, &hextest[0], 185);
|
||||
work.extradata = (void*) &swork;
|
||||
uint32_t *nonceptr = (uint32_t*) (&swork.data[84]);
|
||||
spreadx11_hash(output, &work, nonceptr[0]);
|
||||
}
|
||||
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
// GPU Search
|
||||
extern "C" int scanhash_spreadx11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
int dev_id = device_map[thr_id % MAX_GPUS];
|
||||
|
||||
// multiple of 64 to keep things simple with signatures
|
||||
//const uint32_t throughput = opt_throughput * 1024 * 64;
|
||||
|
||||
uint32_t *ptarget = work->target;
|
||||
|
||||
struct spreadwork* swork = (struct spreadwork*) work->extradata;
|
||||
if (!swork) {
|
||||
work->extradata = swork = (struct spreadwork*) calloc(1, sizeof(struct spreadwork));
|
||||
applog(LOG_ERR, "GPU #%d: missing block data!", dev_id);
|
||||
sleep(1);
|
||||
//return -1;
|
||||
}
|
||||
|
||||
unsigned char *blocktemplate = swork->data;
|
||||
uint32_t *pnonce = (uint32_t*) (&blocktemplate[84]);
|
||||
uint32_t nonce = (*pnonce);
|
||||
uint32_t first_nonce = nonce;
|
||||
|
||||
int intensity = (device_sm[dev_id] >= 500 && !is_windows()) ? 19 : 18;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity); // 19=256*256*8;
|
||||
throughput = min(throughput, max_nonce - first_nonce) & 0xFFFFFFC0UL;
|
||||
|
||||
if (opt_benchmark)
|
||||
ptarget[7] = 0x00ff;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
//cudaDeviceReset();
|
||||
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync);
|
||||
cudaDeviceSetCacheConfig(cudaFuncCachePreferL1);
|
||||
|
||||
// a 512-bit buffer for every nonce to hold the x11 intermediate hashes
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_hash[thr_id], (size_t)64 * throughput));
|
||||
|
||||
// sha256 hashes used for signing, 32 bytes for every 64 nonces
|
||||
cudaMalloc(&d_sha256hash[thr_id], (size_t)32*(throughput>>6));
|
||||
// changing part of MinerSignature, 32 bytes for every 64 nonces
|
||||
cudaMalloc(&d_signature[thr_id], (size_t)32*(throughput>>6));
|
||||
// sha256 hashes for the whole block, 32 bytes for every 64 nonces
|
||||
cudaMalloc(&d_hashwholeblock[thr_id], (size_t)32*(throughput>>6));
|
||||
|
||||
spreadx11_sha256_cpu_init(thr_id, throughput);
|
||||
spreadx11_sign_cpu_init(thr_id, throughput);
|
||||
blake_cpu_init(thr_id, throughput);
|
||||
quark_groestl512_cpu_init(thr_id, throughput);
|
||||
quark_skein512_cpu_init(thr_id, throughput);
|
||||
quark_bmw512_cpu_init(thr_id, throughput);
|
||||
quark_keccak512_cpu_init(thr_id, throughput);
|
||||
quark_jh512_cpu_init(thr_id, throughput);
|
||||
x11_luffa512_cpu_init(thr_id, throughput);
|
||||
x11_cubehash512_cpu_init(thr_id, throughput);
|
||||
x11_shavite512_cpu_init(thr_id, throughput);
|
||||
x11_simd512_cpu_init(thr_id, throughput);
|
||||
//spreadx11_echo512_cpu_init(thr_id, throughput);
|
||||
x11_echo512_cpu_init(thr_id, throughput);
|
||||
|
||||
cuda_check_cpu_init(thr_id, throughput);
|
||||
|
||||
// single buffer to hold the padded whole block data
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_wholeblockdata[thr_id], 200000));
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
struct timeval tv_start;
|
||||
#if PROFILE == 1
|
||||
struct timeval tv_end;
|
||||
#endif
|
||||
|
||||
spreadx11_sign_cpu_setInput(work);
|
||||
spreadx11_sha256_setBlock_wholeblock(work, d_wholeblockdata[thr_id]);
|
||||
spreadx11_sha256double_setBlock_88((void *)blocktemplate);
|
||||
blake_cpu_setBlock_185((void *)blocktemplate);
|
||||
//spreadx11_echo512_cpu_setTarget(ptarget);
|
||||
cuda_check_cpu_setTarget(ptarget);
|
||||
|
||||
do {
|
||||
int order = 0;
|
||||
gettimeofday(&tv_start, NULL);
|
||||
spreadx11_sha256double_cpu_hash_88(thr_id, throughput>>6, nonce, d_sha256hash[thr_id]);
|
||||
//PRINTTIME("sha256 sig");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
spreadx11_sign_cpu(thr_id, throughput>>6, nonce, d_sha256hash[thr_id], d_signature[thr_id]);
|
||||
//PRINTTIME("signing ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
spreadx11_sha256_cpu_hash_wholeblock(thr_id, throughput>>6, nonce, d_hashwholeblock[thr_id], d_signature[thr_id], d_wholeblockdata[thr_id]);
|
||||
//PRINTTIME("hashwhole ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
blake_cpu_hash_185(thr_id, throughput, nonce, d_hash[thr_id], d_signature[thr_id], d_hashwholeblock[thr_id]);
|
||||
TRACE("blake ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
quark_bmw512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("bmw ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
quark_groestl512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("groestl ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
quark_skein512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("skein ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
quark_jh512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("jh ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
quark_keccak512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("keccak ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
x11_luffa512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("luffa ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
x11_cubehash512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("cubehash ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
x11_shavite512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("shavite ");
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
x11_simd512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("simd ");
|
||||
|
||||
|
||||
uint32_t winnerthread = 0;
|
||||
uint32_t foundNonce;
|
||||
|
||||
gettimeofday(&tv_start, NULL);
|
||||
//foundNonce = spreadx11_echo512_cpu_hash_64_final(thr_id, throughput, nonce, NULL, d_hash[thr_id], &winnerthread);
|
||||
x11_echo512_cpu_hash_64(thr_id, throughput, nonce, NULL, d_hash[thr_id], order++);
|
||||
TRACE("echo ");
|
||||
|
||||
*hashes_done = nonce - first_nonce + throughput;
|
||||
|
||||
foundNonce = cuda_check_hash(thr_id, throughput, nonce, d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
uint32_t cpuhash[8], hash[8];
|
||||
char hexbuffer[MAX_BLOCK_SIZE*2] = { 0 };
|
||||
|
||||
uint32_t *resnonce = (uint32_t*) (&swork->data[84]);
|
||||
uint32_t *reshashwholeblock = (uint32_t*) (&swork->data[88]);
|
||||
uint32_t *ressignature = (uint32_t*) (&swork->data[153]);
|
||||
|
||||
for (uint32_t u = 0; u < swork->txsize && u < MAX_BLOCK_SIZE; u++)
|
||||
sprintf(&hexbuffer[u*2], "%02x", swork->tx[u]);
|
||||
|
||||
winnerthread = (foundNonce - nonce);
|
||||
|
||||
uint32_t idx64 = winnerthread >> 6;
|
||||
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG,
|
||||
"Thread %d found a solution\n"
|
||||
"First nonce : %08x\n"
|
||||
"Found nonce : %08x\n"
|
||||
"Threadidx : %d\n"
|
||||
"Threadidx64 : %d\n"
|
||||
"VTX (%d) : %s\n",
|
||||
dev_id, first_nonce, foundNonce, winnerthread, idx64, swork->txsize, hexbuffer);
|
||||
else applog(LOG_INFO, "GPU #%d: found a solution, nonce %08x", dev_id, foundNonce);
|
||||
|
||||
*resnonce = foundNonce;
|
||||
cudaMemcpy(reshashwholeblock, d_hashwholeblock[thr_id] + idx64 * 8, 32, cudaMemcpyDeviceToHost);
|
||||
cudaMemcpy(ressignature, d_signature[thr_id] + idx64 * 8, 32, cudaMemcpyDeviceToHost);
|
||||
cudaMemcpy(hash, d_hash[thr_id] + winnerthread * 16, 32, cudaMemcpyDeviceToHost);
|
||||
|
||||
if (opt_debug) {
|
||||
|
||||
memset(hexbuffer, 0, sizeof(hexbuffer));
|
||||
for( int i = 0; i < 32; i++ ) sprintf(&hexbuffer[i*2], "%02x", ((uint8_t *)hash)[i]);
|
||||
applog(LOG_DEBUG, "Final hash 256 : %s", hexbuffer);
|
||||
|
||||
memset(hexbuffer, 0, sizeof(hexbuffer));
|
||||
for( int i = 0; i < 185; i++ ) sprintf(&hexbuffer[i*2], "%02x", ((uint8_t *)swork->data)[i]);
|
||||
applog(LOG_DEBUG, "Submit data : %s", hexbuffer);
|
||||
|
||||
memset(hexbuffer, 0, sizeof(hexbuffer));
|
||||
for( int i = 0; i < 32; i++ ) sprintf(&hexbuffer[i*2], "%02x", ((uint8_t *)reshashwholeblock)[i]);
|
||||
applog(LOG_DEBUG, "HashWholeBlock : %s", hexbuffer);
|
||||
|
||||
memset(hexbuffer, 0, sizeof(hexbuffer));
|
||||
for( int i = 0; i < 32; i++ ) sprintf(&hexbuffer[i*2], "%02x", ((uint8_t *)ressignature)[i]);
|
||||
applog(LOG_DEBUG, "MinerSignature : %s", hexbuffer);
|
||||
}
|
||||
|
||||
spreadx11_hash((void *)cpuhash, work, foundNonce);
|
||||
|
||||
if(cpuhash[7] == hash[7] && fulltest(hash, ptarget) ) {
|
||||
bn_store_hash_target_ratio(cpuhash, ptarget, work);
|
||||
return 1;
|
||||
} else if(cpuhash[7] != hash[7]) {
|
||||
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not validate on CPU %08x<>%08x!", dev_id, foundNonce, cpuhash[7], hash[7]);
|
||||
applog_hash((uchar*)cpuhash);
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for nonce %08x does not pass the full test!", dev_id, foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
nonce += throughput;
|
||||
|
||||
} while (nonce < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_spreadx11(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#define MAX_BLOCK_SIZE 200000
|
||||
|
||||
struct spreadwork {
|
||||
unsigned char data[185];
|
||||
unsigned char privkey[32];
|
||||
unsigned char kinv[32];
|
||||
unsigned char tx[MAX_BLOCK_SIZE];
|
||||
size_t txsize;
|
||||
};
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
extern pthread_mutex_t stratum_sock_lock;
|
||||
extern pthread_mutex_t stratum_work_lock;
|
||||
extern bool opt_debug_diff;
|
||||
|
||||
bool opt_tracegpu = false;
|
||||
|
||||
@@ -105,13 +106,10 @@ void applog(int prio, const char *fmt, ...)
|
||||
const char* color = "";
|
||||
char *f;
|
||||
int len;
|
||||
struct tm tm, *tm_p;
|
||||
struct tm tm;
|
||||
time_t now = time(NULL);
|
||||
|
||||
pthread_mutex_lock(&applog_lock);
|
||||
tm_p = localtime(&now);
|
||||
memcpy(&tm, tm_p, sizeof(tm));
|
||||
pthread_mutex_unlock(&applog_lock);
|
||||
localtime_r(&now, &tm);
|
||||
|
||||
switch (prio) {
|
||||
case LOG_ERR: color = CL_RED; break;
|
||||
@@ -404,7 +402,7 @@ static json_t *json_rpc_call(CURL *curl, const char *url,
|
||||
char *httpdata;
|
||||
char len_hdr[64], hashrate_hdr[64];
|
||||
char curl_err_str[CURL_ERROR_SIZE] = { 0 };
|
||||
long timeout = longpoll ? opt_timeout*2 : opt_timeout;
|
||||
long timeout = longpoll ? opt_timeout : opt_timeout/2;
|
||||
struct header_info hi = { 0 };
|
||||
bool lp_scanning = longpoll_scan && !have_longpoll;
|
||||
|
||||
@@ -598,11 +596,56 @@ json_t *json_rpc_longpoll(CURL *curl, char *lp_url, struct pool_infos *pool, con
|
||||
strlen(pool->pass)?':':'\0', pool->pass);
|
||||
|
||||
// on pool rotate by time-limit, this keepalive can be a problem
|
||||
bool keepalive = pool->time_limit == 0 || pool->time_limit > opt_timeout*4;
|
||||
bool keepalive = pool->time_limit == 0 || pool->time_limit > opt_timeout;
|
||||
|
||||
return json_rpc_call(curl, lp_url, userpass, req, false, true, keepalive, curl_err);
|
||||
}
|
||||
|
||||
json_t *json_load_url(char* cfg_url, json_error_t *err)
|
||||
{
|
||||
char err_str[CURL_ERROR_SIZE] = { 0 };
|
||||
struct data_buffer all_data = { 0 };
|
||||
int rc = 0; json_t *cfg = NULL;
|
||||
CURL *curl = curl_easy_init();
|
||||
if (unlikely(!curl)) {
|
||||
applog(LOG_ERR, "Remote config init failed!");
|
||||
return NULL;
|
||||
}
|
||||
curl_easy_setopt(curl, CURLOPT_URL, cfg_url);
|
||||
curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15);
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, err_str);
|
||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, all_data_cb);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &all_data);
|
||||
if (opt_proxy) {
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy);
|
||||
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type);
|
||||
} else if (getenv("http_proxy")) {
|
||||
if (getenv("all_proxy"))
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, getenv("all_proxy"));
|
||||
else if (getenv("ALL_PROXY"))
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, getenv("ALL_PROXY"));
|
||||
else
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, "");
|
||||
}
|
||||
rc = curl_easy_perform(curl);
|
||||
if (rc) {
|
||||
applog(LOG_ERR, "Remote config read failed: %s", err_str);
|
||||
goto err_out;
|
||||
}
|
||||
if (!all_data.buf || !all_data.len) {
|
||||
applog(LOG_ERR, "Empty data received for config");
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
cfg = JSON_LOADS((char*)all_data.buf, err);
|
||||
err_out:
|
||||
curl_easy_cleanup(curl);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlike malloc, calloc set the memory to zero
|
||||
*/
|
||||
@@ -723,7 +766,7 @@ bool fulltest(const uint32_t *hash, const uint32_t *target)
|
||||
}
|
||||
}
|
||||
|
||||
if (!rc && opt_debug) {
|
||||
if ((!rc && opt_debug) || opt_debug_diff) {
|
||||
uint32_t hash_be[8], target_be[8];
|
||||
char *hash_str, *target_str;
|
||||
|
||||
@@ -747,11 +790,15 @@ bool fulltest(const uint32_t *hash, const uint32_t *target)
|
||||
return rc;
|
||||
}
|
||||
|
||||
void diff_to_target(uint32_t *target, double diff)
|
||||
// Only used by stratum pools
|
||||
void diff_to_target(struct work* work, double diff)
|
||||
{
|
||||
uint32_t *target = work->target;
|
||||
uint64_t m;
|
||||
int k;
|
||||
|
||||
|
||||
work->targetdiff = diff;
|
||||
|
||||
for (k = 6; k > 0 && diff > 1.0; k--)
|
||||
diff /= 4294967296.0;
|
||||
m = (uint64_t)(4294901760.0 / diff);
|
||||
@@ -764,6 +811,26 @@ void diff_to_target(uint32_t *target, double diff)
|
||||
}
|
||||
}
|
||||
|
||||
// Only used by longpoll pools
|
||||
double target_to_diff(uint32_t* target)
|
||||
{
|
||||
uchar* tgt = (uchar*) target;
|
||||
uint64_t m =
|
||||
(uint64_t)tgt[29] << 56 |
|
||||
(uint64_t)tgt[28] << 48 |
|
||||
(uint64_t)tgt[27] << 40 |
|
||||
(uint64_t)tgt[26] << 32 |
|
||||
(uint64_t)tgt[25] << 24 |
|
||||
(uint64_t)tgt[24] << 16 |
|
||||
(uint64_t)tgt[23] << 8 |
|
||||
(uint64_t)tgt[22] << 0;
|
||||
|
||||
if (!m)
|
||||
return 0.;
|
||||
else
|
||||
return (double)0x0000ffff00000000/m;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#define socket_blocks() (WSAGetLastError() == WSAEWOULDBLOCK)
|
||||
#else
|
||||
@@ -853,6 +920,7 @@ char *stratum_recv_line(struct stratum_ctx *sctx)
|
||||
{
|
||||
ssize_t len, buflen;
|
||||
char *tok, *sret = NULL;
|
||||
int timeout = opt_timeout;
|
||||
|
||||
if (!sctx->sockbuf)
|
||||
return NULL;
|
||||
@@ -860,7 +928,7 @@ char *stratum_recv_line(struct stratum_ctx *sctx)
|
||||
if (!strstr(sctx->sockbuf, "\n")) {
|
||||
bool ret = true;
|
||||
time_t rstart = time(NULL);
|
||||
if (!socket_full(sctx->sock, opt_timeout)) {
|
||||
if (!socket_full(sctx->sock, timeout)) {
|
||||
applog(LOG_ERR, "stratum_recv_line timed out");
|
||||
goto out;
|
||||
}
|
||||
@@ -881,7 +949,7 @@ char *stratum_recv_line(struct stratum_ctx *sctx)
|
||||
}
|
||||
} else
|
||||
stratum_buffer_append(sctx, s);
|
||||
} while (time(NULL) - rstart < opt_timeout && !strstr(sctx->sockbuf, "\n"));
|
||||
} while (time(NULL) - rstart < timeout && !strstr(sctx->sockbuf, "\n"));
|
||||
|
||||
if (!ret) {
|
||||
applog(LOG_ERR, "stratum_recv_line failed");
|
||||
@@ -1756,33 +1824,19 @@ void do_gpu_tests(void)
|
||||
unsigned long done;
|
||||
char s[128] = { '\0' };
|
||||
uchar buf[160];
|
||||
uint32_t tgt[8] = { 0 };
|
||||
struct work work;
|
||||
memset(&work, 0, sizeof(work));
|
||||
|
||||
opt_tracegpu = true;
|
||||
work_restart = (struct work_restart*) malloc(sizeof(struct work_restart));
|
||||
work_restart[0].restart = 1;
|
||||
tgt[7] = 0xffff;
|
||||
work.target[7] = 0xffff;
|
||||
|
||||
//memset(buf, 0, sizeof buf);
|
||||
//scanhash_skeincoin(0, (uint32_t*)buf, tgt, 1, &done);
|
||||
//memset(work.data, 0, sizeof(work.data));
|
||||
//scanhash_spreadx11(0, &work, 1, &done);
|
||||
|
||||
//memset(buf, 0, sizeof buf);
|
||||
//memcpy(buf, zrtest, 80);
|
||||
//scanhash_zr5(0, (uint32_t*)buf, tgt, zrtest[19]+1, &done);
|
||||
|
||||
//struct timeval tv;
|
||||
//memset(buf, 0, sizeof buf);
|
||||
//scanhash_scrypt_jane(0, (uint32_t*)buf, tgt, NULL, 1, &done, &tv, &tv);
|
||||
|
||||
memset(buf, 0, sizeof buf);
|
||||
scanhash_x11(0, (uint32_t*)buf, tgt, 1, &done);
|
||||
|
||||
//memset(buf, 0, sizeof buf);
|
||||
// buf[0] = 1; buf[64] = 2; // for endian tests
|
||||
//scanhash_blake256(0, (uint32_t*)buf, tgt, 1, &done, 14);
|
||||
|
||||
//memset(buf, 0, sizeof buf);
|
||||
//scanhash_heavy(0, (uint32_t*)buf, tgt, 1, &done, 1, 84); // HEAVYCOIN_BLKHDR_SZ=84
|
||||
memset(work.data, 0, sizeof(work.data));
|
||||
scanhash_lyra2(0, &work, 1, &done);
|
||||
|
||||
free(work_restart);
|
||||
work_restart = NULL;
|
||||
@@ -1795,7 +1849,7 @@ void print_hash_tests(void)
|
||||
uchar *scratchbuf = NULL;
|
||||
char s[128] = {'\0'};
|
||||
uchar hash[128];
|
||||
uchar buf[168];
|
||||
uchar buf[128];
|
||||
|
||||
// work space for scratchpad based algos
|
||||
scratchbuf = (uchar*)calloc(128, 1024);
|
||||
@@ -1805,17 +1859,17 @@ void print_hash_tests(void)
|
||||
|
||||
printf(CL_WHT "CPU HASH ON EMPTY BUFFER RESULTS:" CL_N "\n");
|
||||
|
||||
animehash(&hash[0], &buf[0]);
|
||||
printpfx("anime", hash);
|
||||
|
||||
blake256hash(&hash[0], &buf[0], 8);
|
||||
printpfx("blakecoin", hash);
|
||||
|
||||
blake256hash(&hash[0], &buf[0], 14);
|
||||
printpfx("blake", hash);
|
||||
|
||||
creditshash(&hash[0], &buf[0]);
|
||||
printpfx("credits", hash);
|
||||
bmw_hash(&hash[0], &buf[0]);
|
||||
printpfx("bmw", hash);
|
||||
|
||||
c11hash(&hash[0], &buf[0]);
|
||||
printpfx("c11", hash);
|
||||
|
||||
deephash(&hash[0], &buf[0]);
|
||||
printpfx("deep", hash);
|
||||
@@ -1841,9 +1895,12 @@ void print_hash_tests(void)
|
||||
luffa_hash(&hash[0], &buf[0]);
|
||||
printpfx("luffa", hash);
|
||||
|
||||
lyra2_hash(&hash[0], &buf[0]);
|
||||
lyra2re_hash(&hash[0], &buf[0]);
|
||||
printpfx("lyra2", hash);
|
||||
|
||||
lyra2v2_hash(&hash[0], &buf[0]);
|
||||
printpfx("lyra2v2", hash);
|
||||
|
||||
myriadhash(&hash[0], &buf[0]);
|
||||
printpfx("myriad", hash);
|
||||
|
||||
@@ -1856,9 +1913,6 @@ void print_hash_tests(void)
|
||||
pentablakehash(&hash[0], &buf[0]);
|
||||
printpfx("pentablake", hash);
|
||||
|
||||
pluckhash((uint32_t*)&hash[0], (uint32_t*)&buf[0], scratchbuf, 128);
|
||||
printpfx("pluck", hash);
|
||||
|
||||
quarkhash(&hash[0], &buf[0]);
|
||||
printpfx("quark", hash);
|
||||
|
||||
@@ -1877,9 +1931,15 @@ void print_hash_tests(void)
|
||||
skein2hash(&hash[0], &buf[0]);
|
||||
printpfx("skein2", hash);
|
||||
|
||||
spreadhash(&hash[0], &buf[0]);
|
||||
printpfx("spread", hash);
|
||||
|
||||
s3hash(&hash[0], &buf[0]);
|
||||
printpfx("S3", hash);
|
||||
|
||||
whirlxHash(&hash[0], &buf[0]);
|
||||
printpfx("whirlpoolx", hash);
|
||||
|
||||
x11hash(&hash[0], &buf[0]);
|
||||
printpfx("X11", hash);
|
||||
|
||||
|
||||
+263
@@ -0,0 +1,263 @@
|
||||
extern "C"
|
||||
{
|
||||
#include "sph/sph_blake.h"
|
||||
#include "sph/sph_bmw.h"
|
||||
#include "sph/sph_groestl.h"
|
||||
#include "sph/sph_skein.h"
|
||||
#include "sph/sph_jh.h"
|
||||
#include "sph/sph_keccak.h"
|
||||
|
||||
#include "sph/sph_luffa.h"
|
||||
#include "sph/sph_cubehash.h"
|
||||
#include "sph/sph_shavite.h"
|
||||
#include "sph/sph_simd.h"
|
||||
#include "sph/sph_echo.h"
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
|
||||
extern void quark_blake512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_blake512_cpu_setBlock_80(int thr_id, uint32_t *pdata);
|
||||
extern void quark_blake512_cpu_hash_80(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_hash);
|
||||
|
||||
extern void quark_bmw512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_bmw512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_groestl512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_groestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
extern void quark_doublegroestl512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_skein512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_skein512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_keccak512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_keccak512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_jh512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_jh512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_luffaCubehash512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_luffaCubehash512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_shavite512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_shavite512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern int x11_simd512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_simd512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void x11_echo512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_echo512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
|
||||
// Flax/C11 CPU Hash
|
||||
extern "C" void c11hash(void *output, const void *input)
|
||||
{
|
||||
// blake1-bmw2-grs3-skein4-jh5-keccak6-luffa7-cubehash8-shavite9-simd10-echo11
|
||||
|
||||
sph_blake512_context ctx_blake;
|
||||
sph_bmw512_context ctx_bmw;
|
||||
sph_groestl512_context ctx_groestl;
|
||||
sph_jh512_context ctx_jh;
|
||||
sph_keccak512_context ctx_keccak;
|
||||
sph_skein512_context ctx_skein;
|
||||
sph_luffa512_context ctx_luffa;
|
||||
sph_cubehash512_context ctx_cubehash;
|
||||
sph_shavite512_context ctx_shavite;
|
||||
sph_simd512_context ctx_simd;
|
||||
sph_echo512_context ctx_echo;
|
||||
|
||||
unsigned char hash[128];
|
||||
memset(hash, 0, sizeof hash);
|
||||
|
||||
sph_blake512_init(&ctx_blake);
|
||||
sph_blake512 (&ctx_blake, input, 80);
|
||||
sph_blake512_close(&ctx_blake, (void*) hash);
|
||||
|
||||
sph_bmw512_init(&ctx_bmw);
|
||||
sph_bmw512 (&ctx_bmw, (const void*) hash, 64);
|
||||
sph_bmw512_close(&ctx_bmw, (void*) hash);
|
||||
|
||||
sph_groestl512_init(&ctx_groestl);
|
||||
sph_groestl512 (&ctx_groestl, (const void*) hash, 64);
|
||||
sph_groestl512_close(&ctx_groestl, (void*) hash);
|
||||
|
||||
sph_jh512_init(&ctx_jh);
|
||||
sph_jh512 (&ctx_jh, (const void*) hash, 64);
|
||||
sph_jh512_close(&ctx_jh, (void*) hash);
|
||||
|
||||
sph_keccak512_init(&ctx_keccak);
|
||||
sph_keccak512 (&ctx_keccak, (const void*) hash, 64);
|
||||
sph_keccak512_close(&ctx_keccak, (void*) hash);
|
||||
|
||||
sph_skein512_init(&ctx_skein);
|
||||
sph_skein512 (&ctx_skein, (const void*) hash, 64);
|
||||
sph_skein512_close(&ctx_skein, (void*) hash);
|
||||
|
||||
sph_luffa512_init(&ctx_luffa);
|
||||
sph_luffa512 (&ctx_luffa, (const void*) hash, 64);
|
||||
sph_luffa512_close (&ctx_luffa, (void*) hash);
|
||||
|
||||
sph_cubehash512_init(&ctx_cubehash);
|
||||
sph_cubehash512 (&ctx_cubehash, (const void*) hash, 64);
|
||||
sph_cubehash512_close(&ctx_cubehash, (void*) hash);
|
||||
|
||||
sph_shavite512_init(&ctx_shavite);
|
||||
sph_shavite512 (&ctx_shavite, (const void*) hash, 64);
|
||||
sph_shavite512_close(&ctx_shavite, (void*) hash);
|
||||
|
||||
sph_simd512_init(&ctx_simd);
|
||||
sph_simd512 (&ctx_simd, (const void*) hash, 64);
|
||||
sph_simd512_close(&ctx_simd, (void*) hash);
|
||||
|
||||
sph_echo512_init(&ctx_echo);
|
||||
sph_echo512 (&ctx_echo, (const void*) hash, 64);
|
||||
sph_echo512_close(&ctx_echo, (void*) hash);
|
||||
|
||||
memcpy(output, hash, 32);
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define TRACE(algo) { \
|
||||
if (max_nonce == 1 && pdata[19] <= 1) { \
|
||||
uint32_t* debugbuf = NULL; \
|
||||
cudaMallocHost(&debugbuf, 8*sizeof(uint32_t)); \
|
||||
cudaMemcpy(debugbuf, d_hash[thr_id], 8*sizeof(uint32_t), cudaMemcpyDeviceToHost); \
|
||||
printf("X11 %s %08x %08x %08x %08x...\n", algo, swab32(debugbuf[0]), swab32(debugbuf[1]), \
|
||||
swab32(debugbuf[2]), swab32(debugbuf[3])); \
|
||||
cudaFreeHost(debugbuf); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define TRACE(algo) {}
|
||||
#endif
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_c11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int intensity = (device_sm[device_map[thr_id]] >= 500 && !is_windows()) ? 20 : 19;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity); // 19=256*256*8;
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x5;
|
||||
|
||||
if (!init[thr_id])
|
||||
{
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
quark_blake512_cpu_init(thr_id, throughput);
|
||||
quark_bmw512_cpu_init(thr_id, throughput);
|
||||
quark_groestl512_cpu_init(thr_id, throughput);
|
||||
quark_skein512_cpu_init(thr_id, throughput);
|
||||
quark_keccak512_cpu_init(thr_id, throughput);
|
||||
quark_jh512_cpu_init(thr_id, throughput);
|
||||
x11_luffaCubehash512_cpu_init(thr_id, throughput);
|
||||
x11_shavite512_cpu_init(thr_id, throughput);
|
||||
x11_echo512_cpu_init(thr_id, throughput);
|
||||
if (x11_simd512_cpu_init(thr_id, throughput) != 0) {
|
||||
return 0;
|
||||
}
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_hash[thr_id], 64 * throughput), 0); // why 64 ?
|
||||
|
||||
cuda_check_cpu_init(thr_id, throughput);
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
uint32_t endiandata[20];
|
||||
for (int k=0; k < 20; k++)
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
|
||||
quark_blake512_cpu_setBlock_80(thr_id, endiandata);
|
||||
cuda_check_cpu_setTarget(ptarget);
|
||||
|
||||
do {
|
||||
int order = 0;
|
||||
uint32_t foundNonce;
|
||||
|
||||
// Hash with CUDA
|
||||
quark_blake512_cpu_hash_80(thr_id, throughput, pdata[19], d_hash[thr_id]); order++;
|
||||
TRACE("blake :");
|
||||
quark_bmw512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("bmw :");
|
||||
quark_groestl512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("groestl:");
|
||||
quark_jh512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("jh512 :");
|
||||
quark_keccak512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("keccak :");
|
||||
quark_skein512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("skein :");
|
||||
x11_luffaCubehash512_cpu_hash_64(thr_id, throughput, d_hash[thr_id], order++);
|
||||
TRACE("luffa+c:");
|
||||
x11_shavite512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("shavite:");
|
||||
x11_simd512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("simd :");
|
||||
x11_echo512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
TRACE("echo => ");
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
c11hash(vhash64, endiandata);
|
||||
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
// check if there was some other ones...
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
c11hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
pdata[19] = foundNonce;
|
||||
return res;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
pdata[19] = foundNonce + 1;
|
||||
}
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
} while (pdata[19] < max_nonce && !work_restart[thr_id].restart);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_c11(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+25
-8
@@ -25,10 +25,6 @@ extern void x11_simd512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t start
|
||||
extern void x11_echo512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_echo512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes,
|
||||
uint32_t *d_noncesTrue, size_t *nrmTrue, uint32_t *d_noncesFalse, size_t *nrmFalse,
|
||||
int order);
|
||||
|
||||
// CPU Hash
|
||||
extern "C" void fresh_hash(void *state, const void *input)
|
||||
@@ -70,10 +66,10 @@ extern "C" void fresh_hash(void *state, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_fresh(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_fresh(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t endiandata[20];
|
||||
|
||||
@@ -122,6 +118,7 @@ extern "C" int scanhash_fresh(int thr_id, uint32_t *pdata,
|
||||
CUDA_SAFE_CALL(cudaThreadSynchronize());
|
||||
print_hash((unsigned char*)buf); printf("\n");
|
||||
#endif
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
@@ -133,8 +130,12 @@ extern "C" int scanhash_fresh(int thr_id, uint32_t *pdata,
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
fresh_hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -152,3 +153,19 @@ extern "C" int scanhash_fresh(int thr_id, uint32_t *pdata,
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_fresh(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -52,10 +52,10 @@ extern "C" void s3hash(void *output, const void *input)
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
/* Main S3 entry point */
|
||||
extern "C" int scanhash_s3(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_s3(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int intensity = 20; // 256*256*8*2;
|
||||
#ifdef WIN32
|
||||
@@ -99,6 +99,8 @@ extern "C" int scanhash_s3(int thr_id, uint32_t *pdata,
|
||||
x11_simd512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
quark_skein512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
|
||||
if (foundNonce != UINT32_MAX)
|
||||
@@ -110,8 +112,12 @@ extern "C" int scanhash_s3(int thr_id, uint32_t *pdata,
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
s3hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -130,3 +136,19 @@ extern "C" int scanhash_s3(int thr_id, uint32_t *pdata,
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_s3(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+25
-7
@@ -54,10 +54,6 @@ extern void x11_simd512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t start
|
||||
extern void x11_echo512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x11_echo512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes,
|
||||
uint32_t *d_noncesTrue, size_t *nrmTrue, uint32_t *d_noncesFalse, size_t *nrmFalse, int order);
|
||||
|
||||
// X11 CPU Hash
|
||||
extern "C" void x11hash(void *output, const void *input)
|
||||
{
|
||||
@@ -142,10 +138,10 @@ extern "C" void x11hash(void *output, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_x11(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_x11(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int intensity = (device_sm[device_map[thr_id]] >= 500 && !is_windows()) ? 20 : 19;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity); // 19=256*256*8;
|
||||
@@ -222,8 +218,13 @@ extern "C" int scanhash_x11(int thr_id, uint32_t *pdata,
|
||||
int res = 1;
|
||||
// check if there was some other ones...
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
x11hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -231,6 +232,7 @@ extern "C" int scanhash_x11(int thr_id, uint32_t *pdata,
|
||||
return res;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
pdata[19] = foundNonce + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,3 +243,19 @@ extern "C" int scanhash_x11(int thr_id, uint32_t *pdata,
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_x11(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+32
-12
@@ -62,9 +62,6 @@ extern void x13_hamsi512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t star
|
||||
extern void x13_fugue512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x13_fugue512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes,
|
||||
uint32_t *d_noncesTrue, size_t *nrmTrue, uint32_t *d_noncesFalse, size_t *nrmFalse, int order);
|
||||
|
||||
// X13 CPU Hash
|
||||
extern "C" void x13hash(void *output, const void *input)
|
||||
@@ -145,10 +142,10 @@ extern "C" void x13hash(void *output, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_x13(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_x13(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
int intensity = 19; // (device_sm[device_map[thr_id]] > 500 && !is_windows()) ? 20 : 19;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1 << intensity); // 19=256*256*8;
|
||||
@@ -207,23 +204,30 @@ extern "C" int scanhash_x13(int thr_id, uint32_t *pdata,
|
||||
x13_hamsi512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
x13_fugue512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
uint32_t vhash[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
x13hash(vhash64, endiandata);
|
||||
x13hash(vhash, endiandata);
|
||||
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
if (vhash[7] <= ptarget[7] && fulltest(vhash, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
pdata[19] = foundNonce;
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
x13hash(vhash, endiandata);
|
||||
pdata[21] = secNonce;
|
||||
if (bn_hash_target_ratio(vhash, ptarget) > work->shareratio) {
|
||||
bn_store_hash_target_ratio(vhash, ptarget, work);
|
||||
xchg(pdata[19], pdata[21]);
|
||||
}
|
||||
res++;
|
||||
}
|
||||
pdata[19] = foundNonce;
|
||||
return res;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
@@ -241,3 +245,19 @@ extern "C" int scanhash_x13(int thr_id, uint32_t *pdata,
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_x13(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -0,0 +1,594 @@
|
||||
/*
|
||||
* Built on cbuchner1's implementation, actual hashing code
|
||||
* based on sphlib 3.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
|
||||
#define threadsPerBlock 1024
|
||||
|
||||
#include "cuda_helper.h"
|
||||
|
||||
__constant__ uint64_t c_PaddedMessage80[16]; // padded message (80 bytes + padding)
|
||||
__constant__ uint64_t c_xtra[8];
|
||||
__constant__ uint64_t c_tmp[72];
|
||||
__constant__ uint64_t pTarget[4];
|
||||
|
||||
static uint32_t *h_wxnounce[MAX_GPUS] = { 0 };
|
||||
static uint32_t *d_WXNonce[MAX_GPUS] = { 0 };
|
||||
|
||||
/**
|
||||
* Whirlpool CUDA kernel implementation.
|
||||
*
|
||||
* ==========================(LICENSE BEGIN)============================
|
||||
*
|
||||
* Copyright (c) 2014 djm34 & tpruvot & SP & Provos Alexis
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ===========================(LICENSE END)=============================
|
||||
* @author djm34
|
||||
* @author tpruvot
|
||||
* @author SP
|
||||
* @author Provos Alexis
|
||||
*/
|
||||
|
||||
__constant__ __align__(64) uint64_t mixTob0Tox[256];
|
||||
|
||||
const uint64_t plain_T0[256]= {
|
||||
0xD83078C018601818,0x2646AF05238C2323,0xB891F97EC63FC6C6,0xFBCD6F13E887E8E8,0xCB13A14C87268787,0x116D62A9B8DAB8B8,0x0902050801040101,0x0D9E6E424F214F4F,0x9B6CEEAD36D83636,
|
||||
0xFF510459A6A2A6A6,0x0CB9BDDED26FD2D2,0x0EF706FBF5F3F5F5,0x96F280EF79F97979,0x30DECE5F6FA16F6F,0x6D3FEFFC917E9191,0xF8A407AA52555252,0x47C0FD27609D6060,0x35657689BCCABCBC,
|
||||
0x372BCDAC9B569B9B,0x8A018C048E028E8E,0xD25B1571A3B6A3A3,0x6C183C600C300C0C,0x84F68AFF7BF17B7B,0x806AE1B535D43535,0xF53A69E81D741D1D,0xB3DD4753E0A7E0E0,0x21B3ACF6D77BD7D7,
|
||||
0x9C99ED5EC22FC2C2,0x435C966D2EB82E2E,0x29967A624B314B4B,0x5DE121A3FEDFFEFE,0xD5AE168257415757,0xBD2A41A815541515,0xE8EEB69F77C17777,0x926EEBA537DC3737,0x9ED7567BE5B3E5E5,
|
||||
0x1323D98C9F469F9F,0x23FD17D3F0E7F0F0,0x20947F6A4A354A4A,0x44A9959EDA4FDADA,0xA2B025FA587D5858,0xCF8FCA06C903C9C9,0x7C528D5529A42929,0x5A1422500A280A0A,0x507F4FE1B1FEB1B1,
|
||||
0xC95D1A69A0BAA0A0,0x14D6DA7F6BB16B6B,0xD917AB5C852E8585,0x3C677381BDCEBDBD,0x8FBA34D25D695D5D,0x9020508010401010,0x07F503F3F4F7F4F4,0xDD8BC016CB0BCBCB,0xD37CC6ED3EF83E3E,
|
||||
0x2D0A112805140505,0x78CEE61F67816767,0x97D55373E4B7E4E4,0x024EBB25279C2727,0x7382583241194141,0xA70B9D2C8B168B8B,0xF6530151A7A6A7A7,0xB2FA94CF7DE97D7D,0x4937FBDC956E9595,
|
||||
0x56AD9F8ED847D8D8,0x70EB308BFBCBFBFB,0xCDC17123EE9FEEEE,0xBBF891C77CED7C7C,0x71CCE31766856666,0x7BA78EA6DD53DDDD,0xAF2E4BB8175C1717,0x458E460247014747,0x1A21DC849E429E9E,
|
||||
0xD489C51ECA0FCACA,0x585A99752DB42D2D,0x2E637991BFC6BFBF,0x3F0E1B38071C0707,0xAC472301AD8EADAD,0xB0B42FEA5A755A5A,0xEF1BB56C83368383,0xB666FF8533CC3333,0x5CC6F23F63916363,
|
||||
0x12040A1002080202,0x93493839AA92AAAA,0xDEE2A8AF71D97171,0xC68DCF0EC807C8C8,0xD1327DC819641919,0x3B92707249394949,0x5FAF9A86D943D9D9,0x31F91DC3F2EFF2F2,0xA8DB484BE3ABE3E3,
|
||||
0xB9B62AE25B715B5B,0xBC0D9234881A8888,0x3E29C8A49A529A9A,0x0B4CBE2D26982626,0xBF64FA8D32C83232,0x597D4AE9B0FAB0B0,0xF2CF6A1BE983E9E9,0x771E33780F3C0F0F,0x33B7A6E6D573D5D5,
|
||||
0xF41DBA74803A8080,0x27617C99BEC2BEBE,0xEB87DE26CD13CDCD,0x8968E4BD34D03434,0x3290757A483D4848,0x54E324ABFFDBFFFF,0x8DF48FF77AF57A7A,0x643DEAF4907A9090,0x9DBE3EC25F615F5F,
|
||||
0x3D40A01D20802020,0x0FD0D56768BD6868,0xCA3472D01A681A1A,0xB7412C19AE82AEAE,0x7D755EC9B4EAB4B4,0xCEA8199A544D5454,0x7F3BE5EC93769393,0x2F44AA0D22882222,0x63C8E907648D6464,
|
||||
0x2AFF12DBF1E3F1F1,0xCCE6A2BF73D17373,0x82245A9012481212,0x7A805D3A401D4040,0x4810284008200808,0x959BE856C32BC3C3,0xDFC57B33EC97ECEC,0x4DAB9096DB4BDBDB,0xC05F1F61A1BEA1A1,
|
||||
0x9107831C8D0E8D8D,0xC87AC9F53DF43D3D,0x5B33F1CC97669797,0x0000000000000000,0xF983D436CF1BCFCF,0x6E5687452BAC2B2B,0xE1ECB39776C57676,0xE619B06482328282,0x28B1A9FED67FD6D6,
|
||||
0xC33677D81B6C1B1B,0x74775BC1B5EEB5B5,0xBE432911AF86AFAF,0x1DD4DF776AB56A6A,0xEAA00DBA505D5050,0x578A4C1245094545,0x38FB18CBF3EBF3F3,0xAD60F09D30C03030,0xC4C3742BEF9BEFEF,
|
||||
0xDA7EC3E53FFC3F3F,0xC7AA1C9255495555,0xDB591079A2B2A2A2,0xE9C96503EA8FEAEA,0x6ACAEC0F65896565,0x036968B9BAD2BABA,0x4A5E93652FBC2F2F,0x8E9DE74EC027C0C0,0x60A181BEDE5FDEDE,
|
||||
0xFC386CE01C701C1C,0x46E72EBBFDD3FDFD,0x1F9A64524D294D4D,0x7639E0E492729292,0xFAEABC8F75C97575,0x360C1E3006180606,0xAE0998248A128A8A,0x4B7940F9B2F2B2B2,0x85D15963E6BFE6E6,
|
||||
0x7E1C36700E380E0E,0xE73E63F81F7C1F1F,0x55C4F73762956262,0x3AB5A3EED477D4D4,0x814D3229A89AA8A8,0x5231F4C496629696,0x62EF3A9BF9C3F9F9,0xA397F666C533C5C5,0x104AB13525942525,
|
||||
0xABB220F259795959,0xD015AE54842A8484,0xC5E4A7B772D57272,0xEC72DDD539E43939,0x1698615A4C2D4C4C,0x94BC3BCA5E655E5E,0x9FF085E778FD7878,0xE570D8DD38E03838,0x980586148C0A8C8C,
|
||||
0x17BFB2C6D163D1D1,0xE4570B41A5AEA5A5,0xA1D94D43E2AFE2E2,0x4EC2F82F61996161,0x427B45F1B3F6B3B3,0x3442A51521842121,0x0825D6949C4A9C9C,0xEE3C66F01E781E1E,0x6186522243114343,
|
||||
0xB193FC76C73BC7C7,0x4FE52BB3FCD7FCFC,0x2408142004100404,0xE3A208B251595151,0x252FC7BC995E9999,0x22DAC44F6DA96D6D,0x651A39680D340D0D,0x79E93583FACFFAFA,0x69A384B6DF5BDFDF,
|
||||
0xA9FC9BD77EE57E7E,0x1948B43D24902424,0xFE76D7C53BEC3B3B,0x9A4B3D31AB96ABAB,0xF081D13ECE1FCECE,0x9922558811441111,0x8303890C8F068F8F,0x049C6B4A4E254E4E,0x667351D1B7E6B7B7,
|
||||
0xE0CB600BEB8BEBEB,0xC178CCFD3CF03C3C,0xFD1FBF7C813E8181,0x4035FED4946A9494,0x1CF30CEBF7FBF7F7,0x186F67A1B9DEB9B9,0x8B265F98134C1313,0x51589C7D2CB02C2C,0x05BBB8D6D36BD3D3,
|
||||
0x8CD35C6BE7BBE7E7,0x39DCCB576EA56E6E,0xAA95F36EC437C4C4,0x1B060F18030C0303,0xDCAC138A56455656,0x5E88491A440D4444,0xA0FE9EDF7FE17F7F,0x884F3721A99EA9A9,0x6754824D2AA82A2A,
|
||||
0x0A6B6DB1BBD6BBBB,0x879FE246C123C1C1,0xF1A602A253515353,0x72A58BAEDC57DCDC,0x531627580B2C0B0B,0x0127D39C9D4E9D9D,0x2BD8C1476CAD6C6C,0xA462F59531C43131,0xF3E8B98774CD7474,
|
||||
0x15F109E3F6FFF6F6,0x4C8C430A46054646,0xA5452609AC8AACAC,0xB50F973C891E8989,0xB42844A014501414,0xBADF425BE1A3E1E1,0xA62C4EB016581616,0xF774D2CD3AE83A3A,0x06D2D06F69B96969,
|
||||
0x41122D4809240909,0xD7E0ADA770DD7070,0x6F7154D9B6E2B6B6,0x1EBDB7CED067D0D0,0xD6C77E3BED93EDED,0xE285DB2ECC17CCCC,0x6884572A42154242,0x2C2DC2B4985A9898,0xED550E49A4AAA4A4,
|
||||
0x7550885D28A02828,0x86B831DA5C6D5C5C,0x6BED3F93F8C7F8F8,0xC211A44486228686
|
||||
};
|
||||
|
||||
/**
|
||||
* Round constants.
|
||||
*/
|
||||
__constant__ uint64_t InitVector_RC[10];
|
||||
|
||||
const uint64_t plain_RC[10] = {
|
||||
0x4F01B887E8C62318,0x52916F79F5D2A636,0x357B0CA38E9BBC60,0x57FE4B2EC2D7E01D,0xDA4AF09FE5377715,
|
||||
0x856BA0B10A29C958,0x67053ECBF4105DBD,0xD8957DA78B4127E4,0x9E4717DD667CEEFB,0x33835AAD07BF2DCA
|
||||
};
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
__device__ __forceinline__
|
||||
static uint64_t ROUND_ELT(const uint64_t* sharedMemory, const uint64_t* __restrict__ in, const int i0, const int i1, const int i2, const int i3, const int i4, const int i5, const int i6, const int i7)
|
||||
{
|
||||
uint32_t* in32 = (uint32_t*)in;
|
||||
return xor8( sharedMemory[__byte_perm(in32[(i0 << 1)], 0, 0x4440)],
|
||||
sharedMemory[__byte_perm(in32[(i1 << 1)], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(in32[(i2 << 1)], 0, 0x4442) + 512],
|
||||
sharedMemory[__byte_perm(in32[(i3 << 1)], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(in32[(i4 << 1) + 1], 0, 0x4440) + 1024],
|
||||
sharedMemory[__byte_perm(in32[(i5 << 1) + 1], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(in32[(i6 << 1) + 1], 0, 0x4442) + 1536],
|
||||
sharedMemory[__byte_perm(in32[(i7 << 1) + 1], 0, 0x4443) + 1792]);
|
||||
}
|
||||
|
||||
#define TRANSFER(dst, src) { \
|
||||
dst[0] = src ## 0; \
|
||||
dst[1] = src ## 1; \
|
||||
dst[2] = src ## 2; \
|
||||
dst[3] = src ## 3; \
|
||||
dst[4] = src ## 4; \
|
||||
dst[5] = src ## 5; \
|
||||
dst[6] = src ## 6; \
|
||||
dst[7] = src ## 7; \
|
||||
}
|
||||
|
||||
#define ROUND(table, in, out, c0, c1, c2, c3, c4, c5, c6, c7) { \
|
||||
out ## 0 = xor1(ROUND_ELT(table, in, 0, 7, 6, 5, 4, 3, 2, 1), c0); \
|
||||
out ## 1 = xor1(ROUND_ELT(table, in, 1, 0, 7, 6, 5, 4, 3, 2), c1); \
|
||||
out ## 2 = xor1(ROUND_ELT(table, in, 2, 1, 0, 7, 6, 5, 4, 3), c2); \
|
||||
out ## 3 = xor1(ROUND_ELT(table, in, 3, 2, 1, 0, 7, 6, 5, 4), c3); \
|
||||
out ## 4 = xor1(ROUND_ELT(table, in, 4, 3, 2, 1, 0, 7, 6, 5), c4); \
|
||||
out ## 5 = xor1(ROUND_ELT(table, in, 5, 4, 3, 2, 1, 0, 7, 6), c5); \
|
||||
out ## 6 = xor1(ROUND_ELT(table, in, 6, 5, 4, 3, 2, 1, 0, 7), c6); \
|
||||
out ## 7 = xor1(ROUND_ELT(table, in, 7, 6, 5, 4, 3, 2, 1, 0), c7); \
|
||||
}
|
||||
|
||||
#define ROUND1(table, in, out, c) { \
|
||||
out ## 0 = xor1(ROUND_ELT(table, in, 0, 7, 6, 5, 4, 3, 2, 1), c); \
|
||||
out ## 1 = ROUND_ELT(table, in, 1, 0, 7, 6, 5, 4, 3, 2); \
|
||||
out ## 2 = ROUND_ELT(table, in, 2, 1, 0, 7, 6, 5, 4, 3); \
|
||||
out ## 3 = ROUND_ELT(table, in, 3, 2, 1, 0, 7, 6, 5, 4); \
|
||||
out ## 4 = ROUND_ELT(table, in, 4, 3, 2, 1, 0, 7, 6, 5); \
|
||||
out ## 5 = ROUND_ELT(table, in, 5, 4, 3, 2, 1, 0, 7, 6); \
|
||||
out ## 6 = ROUND_ELT(table, in, 6, 5, 4, 3, 2, 1, 0, 7); \
|
||||
out ## 7 = ROUND_ELT(table, in, 7, 6, 5, 4, 3, 2, 1, 0); \
|
||||
}
|
||||
|
||||
#define ROUND_KSCHED(table, in, out, c) \
|
||||
ROUND1(table, in, out, c) \
|
||||
TRANSFER(in, out)
|
||||
|
||||
#define ROUND_WENC(table, in, key, out) \
|
||||
ROUND(table, in, out, key[0], key[1], key[2],key[3], key[4], key[5], key[6], key[7]) \
|
||||
TRANSFER(in, out)
|
||||
|
||||
static uint64_t* d_xtra[MAX_GPUS] = { 0 };
|
||||
static uint64_t* d_tmp[MAX_GPUS] = { 0 };
|
||||
|
||||
__device__ __forceinline__
|
||||
static void whirlpoolx_getShared(uint64_t* sharedMemory)
|
||||
{
|
||||
if (threadIdx.x < 256) {
|
||||
sharedMemory[threadIdx.x] = mixTob0Tox[threadIdx.x];
|
||||
sharedMemory[threadIdx.x+256] = ROTL64(sharedMemory[threadIdx.x], 8);
|
||||
sharedMemory[threadIdx.x+512] = ROTL64(sharedMemory[threadIdx.x],16);
|
||||
sharedMemory[threadIdx.x+768] = ROTL64(sharedMemory[threadIdx.x],24);
|
||||
sharedMemory[threadIdx.x+1024] = ROTL64(sharedMemory[threadIdx.x],32);
|
||||
sharedMemory[threadIdx.x+1280] = ROTR64(sharedMemory[threadIdx.x],24);
|
||||
sharedMemory[threadIdx.x+1536] = ROTR64(sharedMemory[threadIdx.x],16);
|
||||
sharedMemory[threadIdx.x+1792] = ROTR64(sharedMemory[threadIdx.x], 8);
|
||||
}
|
||||
__syncthreads();
|
||||
}
|
||||
|
||||
|
||||
__global__
|
||||
void whirlpoolx_gpu_precompute(uint32_t threads, uint64_t* d_xtra, uint64_t* d_tmp)
|
||||
{
|
||||
__shared__ uint64_t sharedMemory[2048];
|
||||
|
||||
whirlpoolx_getShared(sharedMemory);
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint64_t n[8];
|
||||
uint64_t h[8] = { 0 };
|
||||
|
||||
#pragma unroll 8
|
||||
for (int i=0; i<8; i++) {
|
||||
n[i] = c_PaddedMessage80[i]; // read data
|
||||
}
|
||||
//#pragma unroll 10
|
||||
for (unsigned int r=0; r < 10; r++) {
|
||||
uint64_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
|
||||
ROUND_KSCHED(sharedMemory, h, tmp, InitVector_RC[r]);
|
||||
ROUND_WENC(sharedMemory, n, h, tmp);
|
||||
}
|
||||
#pragma unroll 8
|
||||
for (int i=0; i < 8; i++) {
|
||||
h[i] = xor1(n[i],c_PaddedMessage80[i]);
|
||||
}
|
||||
|
||||
if(threadIdx.x==0)d_xtra[threadIdx.x]=h[1];
|
||||
uint64_t atLastCalc=xor1(h[3],h[5]);
|
||||
|
||||
//////////////////////////////////
|
||||
n[0] = c_PaddedMessage80[8]; //read data
|
||||
n[1] = c_PaddedMessage80[9]; //whirlpool
|
||||
n[2] = 0x0000000000000080; //whirlpool
|
||||
n[3] = 0;
|
||||
n[4] = 0;
|
||||
n[5] = 0;
|
||||
n[6] = 0;
|
||||
n[7] = 0x8002000000000000;
|
||||
|
||||
n[0] = xor1(n[0],h[0]);
|
||||
n[2] = xor1(n[2],h[2]); n[3] = h[3];
|
||||
n[4] = h[4]; n[5] = h[5];
|
||||
n[6] = h[6]; n[7] = xor1(n[7],h[7]);
|
||||
uint64_t tmp[8];
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, h, 0, 7, 6, 5, 4, 3, 2, 1),InitVector_RC[0]);
|
||||
tmp[1] = ROUND_ELT(sharedMemory, h, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp[2] = ROUND_ELT(sharedMemory, h, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp[3] = ROUND_ELT(sharedMemory, h, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp[4] = ROUND_ELT(sharedMemory, h, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp[5] = ROUND_ELT(sharedMemory, h, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp[6] = ROUND_ELT(sharedMemory, h, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp[7] = ROUND_ELT(sharedMemory, h, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
uint64_t tmp2[8];
|
||||
uint32_t* n32 = (uint32_t*)n;
|
||||
tmp2[0]=xor8( sharedMemory[__byte_perm(n32[ 0], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[14], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[12], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[10], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[ 9], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[ 7], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4442) + 1536] ,tmp[0]);
|
||||
|
||||
tmp2[1]=xor8( tmp[1] ,sharedMemory[__byte_perm(n32[ 0], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[14], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[12], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[11], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[ 9], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[ 7], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[ 5], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[2]=xor8( sharedMemory[__byte_perm(n32[ 4], 0, 0x4440)] ,tmp[2] ,
|
||||
sharedMemory[__byte_perm(n32[ 0], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[14], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[13], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[11], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[ 9], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[ 7], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[3]=xor8( sharedMemory[__byte_perm(n32[ 6], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[ 4], 0, 0x4441) + 256],
|
||||
tmp[3] ,sharedMemory[__byte_perm(n32[ 0], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[15], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[13], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[11], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[ 9], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[4]=xor8( sharedMemory[__byte_perm(n32[ 8], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[ 6], 0, 0x4441) + 256] ,
|
||||
sharedMemory[__byte_perm(n32[ 4], 0, 0x4442) + 512] ,tmp[4] ,
|
||||
sharedMemory[__byte_perm(n32[ 1], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[15], 0, 0x4441) + 1280] ,
|
||||
sharedMemory[__byte_perm(n32[13], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[11], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[5]=xor8( sharedMemory[__byte_perm(n32[10], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[ 8], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[ 6], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[ 4], 0, 0x4443) + 768],
|
||||
tmp[5] ,sharedMemory[__byte_perm(n32[ 1], 0, 0x4441) + 1280],
|
||||
sharedMemory[__byte_perm(n32[15], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[13], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[6]=xor8( sharedMemory[__byte_perm(n32[12], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[10], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[ 8], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[ 6], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4440) + 1024] ,tmp[6],
|
||||
sharedMemory[__byte_perm(n32[ 1], 0, 0x4442) + 1536] ,sharedMemory[__byte_perm(n32[15], 0, 0x4443) + 1792]);
|
||||
|
||||
tmp2[7]=xor8( sharedMemory[__byte_perm(n32[14], 0, 0x4440)] ,sharedMemory[__byte_perm(n32[12], 0, 0x4441) + 256],
|
||||
sharedMemory[__byte_perm(n32[10], 0, 0x4442) + 512] ,sharedMemory[__byte_perm(n32[ 8], 0, 0x4443) + 768],
|
||||
sharedMemory[__byte_perm(n32[ 7], 0, 0x4440) + 1024] ,sharedMemory[__byte_perm(n32[ 5], 0, 0x4441) + 1280],
|
||||
tmp[7] ,sharedMemory[__byte_perm(n32[ 1], 0, 0x4443) + 1792]);
|
||||
|
||||
n[1] ^= h[1];
|
||||
tmp2[1]^=sharedMemory[__byte_perm(n32[2], 0, 0x4440)];
|
||||
tmp2[2]^=sharedMemory[__byte_perm(n32[2], 0, 0x4441) + 256];
|
||||
tmp2[3]^=sharedMemory[__byte_perm(n32[2], 0, 0x4442) + 512];
|
||||
tmp2[4]^=sharedMemory[__byte_perm(n32[2], 0, 0x4443) + 768];
|
||||
|
||||
d_tmp[threadIdx.x]=tmp2[threadIdx.x];
|
||||
|
||||
uint64_t tmp3[8];
|
||||
tmp3[0] = xor1(ROUND_ELT(sharedMemory, tmp, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[1]);
|
||||
tmp3[1] = ROUND_ELT(sharedMemory, tmp, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp3[2] = ROUND_ELT(sharedMemory, tmp, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp3[3] = ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp3[4] = ROUND_ELT(sharedMemory, tmp, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp3[5] = ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp3[6] = ROUND_ELT(sharedMemory, tmp, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp3[7] = ROUND_ELT(sharedMemory, tmp, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
n32 = (uint32_t*)tmp2;
|
||||
uint64_t tmp4[8];
|
||||
tmp4[0]=( sharedMemory[__byte_perm(n32[ 9], 0, 0x4440) + 1024] ^sharedMemory[__byte_perm(n32[ 7], 0, 0x4441) + 1280]^
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4442) + 1536] ^sharedMemory[__byte_perm(n32[ 3], 0, 0x4443) + 1792]) ^tmp3[0];
|
||||
|
||||
tmp4[1]=(sharedMemory[__byte_perm(n32[ 2], 0, 0x4440)] ^sharedMemory[__byte_perm(n32[ 9], 0, 0x4441) + 1280]^
|
||||
sharedMemory[__byte_perm(n32[ 7], 0, 0x4442) + 1536] ^sharedMemory[__byte_perm(n32[ 5], 0, 0x4443) + 1792]) ^tmp3[1];
|
||||
|
||||
tmp4[2]=(sharedMemory[__byte_perm(n32[ 4], 0, 0x4440)] ^sharedMemory[__byte_perm(n32[ 2], 0, 0x4441) + 256]^
|
||||
sharedMemory[__byte_perm(n32[ 9], 0, 0x4442) + 1536] ^sharedMemory[__byte_perm(n32[ 7], 0, 0x4443) + 1792]) ^tmp3[2];
|
||||
|
||||
tmp4[3]=(sharedMemory[__byte_perm(n32[ 6], 0, 0x4440)] ^sharedMemory[__byte_perm(n32[ 4], 0, 0x4441) + 256]^
|
||||
sharedMemory[__byte_perm(n32[ 2], 0, 0x4442) + 512] ^sharedMemory[__byte_perm(n32[ 9], 0, 0x4443) + 1792]) ^tmp3[3];
|
||||
|
||||
tmp4[4]=(sharedMemory[__byte_perm(n32[ 8], 0, 0x4440)] ^sharedMemory[__byte_perm(n32[ 6], 0, 0x4441) + 256]^
|
||||
sharedMemory[__byte_perm(n32[ 4], 0, 0x4442) + 512] ^sharedMemory[__byte_perm(n32[ 2], 0, 0x4443) + 768]) ^tmp3[4];
|
||||
|
||||
tmp4[5]=(sharedMemory[__byte_perm(n32[ 8], 0, 0x4441) + 256] ^sharedMemory[__byte_perm(n32[ 6], 0, 0x4442) + 512]^
|
||||
sharedMemory[__byte_perm(n32[ 4], 0, 0x4443) + 768] ^sharedMemory[__byte_perm(n32[ 3], 0, 0x4440) + 1024]) ^tmp3[5];
|
||||
|
||||
tmp4[6]=(sharedMemory[__byte_perm(n32[ 8], 0, 0x4442) + 512] ^sharedMemory[__byte_perm(n32[ 6], 0, 0x4443) + 768]^
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4440) + 1024] ^sharedMemory[__byte_perm(n32[ 3], 0, 0x4441) + 1280]) ^tmp3[6];
|
||||
|
||||
tmp4[7]=(sharedMemory[__byte_perm(n32[ 8], 0, 0x4443) + 768] ^sharedMemory[__byte_perm(n32[ 7], 0, 0x4440) + 1024]^
|
||||
sharedMemory[__byte_perm(n32[ 5], 0, 0x4441) + 1280] ^sharedMemory[__byte_perm(n32[ 3], 0, 0x4442) + 1536]) ^tmp3[7];
|
||||
|
||||
d_tmp[threadIdx.x+16]=tmp4[threadIdx.x];
|
||||
|
||||
uint64_t tmp5[8];
|
||||
tmp5[0] = xor1(ROUND_ELT(sharedMemory, tmp3, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[2]);
|
||||
tmp5[1] = ROUND_ELT(sharedMemory, tmp3, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp5[2] = ROUND_ELT(sharedMemory, tmp3, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp5[3] = ROUND_ELT(sharedMemory, tmp3, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp5[4] = ROUND_ELT(sharedMemory, tmp3, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp5[5] = ROUND_ELT(sharedMemory, tmp3, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp5[6] = ROUND_ELT(sharedMemory, tmp3, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp5[7] = ROUND_ELT(sharedMemory, tmp3, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+8]=tmp5[threadIdx.x];
|
||||
|
||||
uint64_t tmp6[8];
|
||||
tmp6[0] = xor1(ROUND_ELT(sharedMemory, tmp5, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[3]);
|
||||
tmp6[1] = ROUND_ELT(sharedMemory, tmp5, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp6[2] = ROUND_ELT(sharedMemory, tmp5, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp6[3] = ROUND_ELT(sharedMemory, tmp5, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp6[4] = ROUND_ELT(sharedMemory, tmp5, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp6[5] = ROUND_ELT(sharedMemory, tmp5, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp6[6] = ROUND_ELT(sharedMemory, tmp5, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp6[7] = ROUND_ELT(sharedMemory, tmp5, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+24]=tmp6[threadIdx.x];
|
||||
|
||||
uint64_t tmp7[8];
|
||||
tmp7[0] = xor1(ROUND_ELT(sharedMemory, tmp6, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[4]);
|
||||
tmp7[1] = ROUND_ELT(sharedMemory, tmp6, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp7[2] = ROUND_ELT(sharedMemory, tmp6, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp7[3] = ROUND_ELT(sharedMemory, tmp6, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp7[4] = ROUND_ELT(sharedMemory, tmp6, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp7[5] = ROUND_ELT(sharedMemory, tmp6, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp7[6] = ROUND_ELT(sharedMemory, tmp6, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp7[7] = ROUND_ELT(sharedMemory, tmp6, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+32]=tmp7[threadIdx.x];
|
||||
|
||||
uint64_t tmp8[8];
|
||||
tmp8[0] = xor1(ROUND_ELT(sharedMemory, tmp7, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[5]);
|
||||
tmp8[1] = ROUND_ELT(sharedMemory, tmp7, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp8[2] = ROUND_ELT(sharedMemory, tmp7, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp8[3] = ROUND_ELT(sharedMemory, tmp7, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp8[4] = ROUND_ELT(sharedMemory, tmp7, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp8[5] = ROUND_ELT(sharedMemory, tmp7, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp8[6] = ROUND_ELT(sharedMemory, tmp7, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp8[7] = ROUND_ELT(sharedMemory, tmp7, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+40]=tmp8[threadIdx.x];
|
||||
|
||||
uint64_t tmp9[8];
|
||||
tmp9[0] = xor1(ROUND_ELT(sharedMemory, tmp8, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[6]);
|
||||
tmp9[1] = ROUND_ELT(sharedMemory, tmp8, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp9[2] = ROUND_ELT(sharedMemory, tmp8, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp9[3] = ROUND_ELT(sharedMemory, tmp8, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp9[4] = ROUND_ELT(sharedMemory, tmp8, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp9[5] = ROUND_ELT(sharedMemory, tmp8, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp9[6] = ROUND_ELT(sharedMemory, tmp8, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp9[7] = ROUND_ELT(sharedMemory, tmp8, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+48]=tmp9[threadIdx.x];
|
||||
|
||||
uint64_t tmp10[8];
|
||||
tmp10[0] = xor1(ROUND_ELT(sharedMemory, tmp9, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[7]);
|
||||
tmp10[1] = ROUND_ELT(sharedMemory, tmp9, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp10[2] = ROUND_ELT(sharedMemory, tmp9, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp10[3] = ROUND_ELT(sharedMemory, tmp9, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp10[4] = ROUND_ELT(sharedMemory, tmp9, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp10[5] = ROUND_ELT(sharedMemory, tmp9, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp10[6] = ROUND_ELT(sharedMemory, tmp9, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp10[7] = ROUND_ELT(sharedMemory, tmp9, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
|
||||
d_tmp[threadIdx.x+56]=tmp10[threadIdx.x];
|
||||
|
||||
uint64_t tmp11[8];
|
||||
tmp11[0] = xor1(ROUND_ELT(sharedMemory, tmp10, 0, 7, 6, 5, 4, 3, 2, 1), InitVector_RC[8]);
|
||||
tmp11[1] = ROUND_ELT(sharedMemory, tmp10, 1, 0, 7, 6, 5, 4, 3, 2);
|
||||
tmp11[2] = ROUND_ELT(sharedMemory, tmp10, 2, 1, 0, 7, 6, 5, 4, 3);
|
||||
tmp11[3] = ROUND_ELT(sharedMemory, tmp10, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp11[4] = ROUND_ELT(sharedMemory, tmp10, 4, 3, 2, 1, 0, 7, 6, 5);
|
||||
tmp11[5] = ROUND_ELT(sharedMemory, tmp10, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp11[6] = ROUND_ELT(sharedMemory, tmp10, 6, 5, 4, 3, 2, 1, 0, 7);
|
||||
tmp11[7] = ROUND_ELT(sharedMemory, tmp10, 7, 6, 5, 4, 3, 2, 1, 0);
|
||||
|
||||
d_tmp[threadIdx.x+64]=tmp11[threadIdx.x];
|
||||
|
||||
if(threadIdx.x==1){
|
||||
tmp[0]=ROUND_ELT(sharedMemory,tmp11, 3, 2, 1, 0, 7, 6, 5, 4);
|
||||
tmp[1]=ROUND_ELT(sharedMemory,tmp11, 5, 4, 3, 2, 1, 0, 7, 6);
|
||||
tmp[4] = xor3(tmp[0],tmp[1],atLastCalc);
|
||||
d_xtra[threadIdx.x]=tmp[4];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__global__ __launch_bounds__(threadsPerBlock,2)
|
||||
void whirlpoolx_gpu_hash(uint32_t threads, uint32_t startNounce, uint32_t *resNounce)
|
||||
{
|
||||
__shared__ uint64_t sharedMemory[2048];
|
||||
|
||||
whirlpoolx_getShared(sharedMemory);
|
||||
|
||||
uint32_t thread = (blockDim.x * blockIdx.x + threadIdx.x);
|
||||
if (thread < threads)
|
||||
{
|
||||
uint64_t n[8];
|
||||
uint64_t tmp[8];
|
||||
uint32_t nounce = startNounce + thread;
|
||||
|
||||
n[1] = xor1(REPLACE_HIDWORD(c_PaddedMessage80[9], cuda_swab32(nounce)),c_xtra[0]);
|
||||
|
||||
uint32_t* n32 = (uint32_t*)&n[0];
|
||||
n[0]=sharedMemory[__byte_perm(n32[3], 0, 0x4443) + 1792];
|
||||
n[5]=sharedMemory[__byte_perm(n32[3], 0, 0x4440) + 1024];
|
||||
n[6]=sharedMemory[__byte_perm(n32[3], 0, 0x4441) + 1280];
|
||||
n[7]=sharedMemory[__byte_perm(n32[3], 0, 0x4442) + 1536];
|
||||
n[0]=xor1(c_tmp[0],n[0]);
|
||||
n[1]=c_tmp[1];
|
||||
n[2]=c_tmp[2];
|
||||
n[3]=c_tmp[3];
|
||||
n[4]=c_tmp[4];
|
||||
n[5]=xor1(c_tmp[5],n[5]);
|
||||
n[6]=xor1(c_tmp[6],n[6]);
|
||||
n[7]=xor1(c_tmp[7],n[7]);
|
||||
|
||||
tmp[0]=xor3(sharedMemory[__byte_perm(n32[10],0,0x4443)+768],sharedMemory[__byte_perm(n32[12],0,0x4442)+512],sharedMemory[__byte_perm(n32[14],0,0x4441)+256]);
|
||||
tmp[1]=xor3(sharedMemory[__byte_perm(n32[11],0,0x4440)+1024],sharedMemory[__byte_perm(n32[12],0,0x4443)+768],sharedMemory[__byte_perm(n32[14],0,0x4442)+512]);
|
||||
tmp[2]=xor3(sharedMemory[__byte_perm(n32[11],0,0x4441)+1280],sharedMemory[__byte_perm(n32[13],0,0x4440)+1024],sharedMemory[__byte_perm(n32[14],0,0x4443)+768]);
|
||||
tmp[3]=xor3(sharedMemory[__byte_perm(n32[11],0,0x4442)+1536],sharedMemory[__byte_perm(n32[13],0,0x4441)+1280],sharedMemory[__byte_perm(n32[15],0,0x4440)+1024]);
|
||||
tmp[4]=xor3(sharedMemory[__byte_perm(n32[11],0,0x4443)+1792],sharedMemory[__byte_perm(n32[13],0,0x4442)+1536],sharedMemory[__byte_perm(n32[15],0,0x4441)+1280]);
|
||||
tmp[5]=xor3(sharedMemory[__byte_perm(n32[10],0,0x4440)],sharedMemory[__byte_perm(n32[13],0,0x4443)+1792],sharedMemory[__byte_perm(n32[15],0,0x4442)+1536]);
|
||||
tmp[6]=xor3(sharedMemory[__byte_perm(n32[12],0,0x4440)],sharedMemory[__byte_perm(n32[10],0,0x4441)+256],sharedMemory[__byte_perm(n32[15],0,0x4443)+1792]);
|
||||
tmp[7]=xor3(sharedMemory[__byte_perm(n32[14],0,0x4440)],sharedMemory[__byte_perm(n32[12],0,0x4441)+256],sharedMemory[__byte_perm(n32[10],0,0x4442)+ 512]);
|
||||
|
||||
tmp[0]=xor3(sharedMemory[__byte_perm(n32[ 0], 0, 0x4440)],tmp[0],c_tmp[0+16]);
|
||||
tmp[1]=xor3(sharedMemory[__byte_perm(n32[ 0], 0, 0x4441) + 256],tmp[1],c_tmp[1+16]);
|
||||
tmp[2]=xor3(sharedMemory[__byte_perm(n32[ 0], 0, 0x4442) + 512],tmp[2],c_tmp[2+16]);
|
||||
tmp[3]=xor3(sharedMemory[__byte_perm(n32[ 0], 0, 0x4443) + 768],tmp[3],c_tmp[3+16]);
|
||||
tmp[4]=xor3(sharedMemory[__byte_perm(n32[ 1], 0, 0x4440) + 1024],tmp[4],c_tmp[4+16]);
|
||||
tmp[5]=xor3(sharedMemory[__byte_perm(n32[ 1], 0, 0x4441) + 1280],tmp[5],c_tmp[5+16]);
|
||||
tmp[6]=xor3(sharedMemory[__byte_perm(n32[ 1], 0, 0x4442) + 1536],tmp[6],c_tmp[6+16]);
|
||||
tmp[7]=xor3(sharedMemory[__byte_perm(n32[ 1], 0, 0x4443) + 1792],tmp[7],c_tmp[7+16]);
|
||||
|
||||
n[0]=tmp[0];
|
||||
n[1]=tmp[1];
|
||||
n[2]=tmp[2];
|
||||
n[3]=tmp[3];
|
||||
n[4]=tmp[4];
|
||||
n[5]=tmp[5];
|
||||
n[6]=tmp[6];
|
||||
n[7]=tmp[7];
|
||||
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, n, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+8]);
|
||||
tmp[1] = xor1(ROUND_ELT(sharedMemory, n, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+8]);
|
||||
tmp[2] = xor1(ROUND_ELT(sharedMemory, n, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+8]);
|
||||
tmp[3] = xor1(ROUND_ELT(sharedMemory, n, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+8]);
|
||||
tmp[4] = xor1(ROUND_ELT(sharedMemory, n, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+8]);
|
||||
tmp[5] = xor1(ROUND_ELT(sharedMemory, n, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+8]);
|
||||
tmp[6] = xor1(ROUND_ELT(sharedMemory, n, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+8]);
|
||||
tmp[7] = xor1(ROUND_ELT(sharedMemory, n, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+8]);
|
||||
|
||||
n[0] = xor1(ROUND_ELT(sharedMemory, tmp, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+24]);
|
||||
n[1] = xor1(ROUND_ELT(sharedMemory, tmp, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+24]);
|
||||
n[2] = xor1(ROUND_ELT(sharedMemory, tmp, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+24]);
|
||||
n[3] = xor1(ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+24]);
|
||||
n[4] = xor1(ROUND_ELT(sharedMemory, tmp, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+24]);
|
||||
n[5] = xor1(ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+24]);
|
||||
n[6] = xor1(ROUND_ELT(sharedMemory, tmp, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+24]);
|
||||
n[7] = xor1(ROUND_ELT(sharedMemory, tmp, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+24]);
|
||||
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, n, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+32]);
|
||||
tmp[1] = xor1(ROUND_ELT(sharedMemory, n, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+32]);
|
||||
tmp[2] = xor1(ROUND_ELT(sharedMemory, n, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+32]);
|
||||
tmp[3] = xor1(ROUND_ELT(sharedMemory, n, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+32]);
|
||||
tmp[4] = xor1(ROUND_ELT(sharedMemory, n, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+32]);
|
||||
tmp[5] = xor1(ROUND_ELT(sharedMemory, n, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+32]);
|
||||
tmp[6] = xor1(ROUND_ELT(sharedMemory, n, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+32]);
|
||||
tmp[7] = xor1(ROUND_ELT(sharedMemory, n, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+32]);
|
||||
|
||||
n[0] = xor1(ROUND_ELT(sharedMemory, tmp, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+40]);
|
||||
n[1] = xor1(ROUND_ELT(sharedMemory, tmp, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+40]);
|
||||
n[2] = xor1(ROUND_ELT(sharedMemory, tmp, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+40]);
|
||||
n[3] = xor1(ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+40]);
|
||||
n[4] = xor1(ROUND_ELT(sharedMemory, tmp, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+40]);
|
||||
n[5] = xor1(ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+40]);
|
||||
n[6] = xor1(ROUND_ELT(sharedMemory, tmp, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+40]);
|
||||
n[7] = xor1(ROUND_ELT(sharedMemory, tmp, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+40]);
|
||||
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, n, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+48]);
|
||||
tmp[1] = xor1(ROUND_ELT(sharedMemory, n, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+48]);
|
||||
tmp[2] = xor1(ROUND_ELT(sharedMemory, n, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+48]);
|
||||
tmp[3] = xor1(ROUND_ELT(sharedMemory, n, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+48]);
|
||||
tmp[4] = xor1(ROUND_ELT(sharedMemory, n, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+48]);
|
||||
tmp[5] = xor1(ROUND_ELT(sharedMemory, n, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+48]);
|
||||
tmp[6] = xor1(ROUND_ELT(sharedMemory, n, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+48]);
|
||||
tmp[7] = xor1(ROUND_ELT(sharedMemory, n, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+48]);
|
||||
|
||||
n[0] = xor1(ROUND_ELT(sharedMemory, tmp, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+56]);
|
||||
n[1] = xor1(ROUND_ELT(sharedMemory, tmp, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+56]);
|
||||
n[2] = xor1(ROUND_ELT(sharedMemory, tmp, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+56]);
|
||||
n[3] = xor1(ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+56]);
|
||||
n[4] = xor1(ROUND_ELT(sharedMemory, tmp, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+56]);
|
||||
n[5] = xor1(ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+56]);
|
||||
n[6] = xor1(ROUND_ELT(sharedMemory, tmp, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+56]);
|
||||
n[7] = xor1(ROUND_ELT(sharedMemory, tmp, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+56]);
|
||||
|
||||
tmp[0] = xor1(ROUND_ELT(sharedMemory, n, 0, 7, 6, 5, 4, 3, 2, 1), c_tmp[0+64]);
|
||||
tmp[1] = xor1(ROUND_ELT(sharedMemory, n, 1, 0, 7, 6, 5, 4, 3, 2), c_tmp[1+64]);
|
||||
tmp[2] = xor1(ROUND_ELT(sharedMemory, n, 2, 1, 0, 7, 6, 5, 4, 3), c_tmp[2+64]);
|
||||
tmp[3] = xor1(ROUND_ELT(sharedMemory, n, 3, 2, 1, 0, 7, 6, 5, 4), c_tmp[3+64]);
|
||||
tmp[4] = xor1(ROUND_ELT(sharedMemory, n, 4, 3, 2, 1, 0, 7, 6, 5), c_tmp[4+64]);
|
||||
tmp[5] = xor1(ROUND_ELT(sharedMemory, n, 5, 4, 3, 2, 1, 0, 7, 6), c_tmp[5+64]);
|
||||
tmp[6] = xor1(ROUND_ELT(sharedMemory, n, 6, 5, 4, 3, 2, 1, 0, 7), c_tmp[6+64]);
|
||||
tmp[7] = xor1(ROUND_ELT(sharedMemory, n, 7, 6, 5, 4, 3, 2, 1, 0), c_tmp[7+64]);
|
||||
|
||||
if (xor3(c_xtra[1], ROUND_ELT(sharedMemory, tmp, 3, 2, 1, 0, 7, 6, 5, 4), ROUND_ELT(sharedMemory, tmp, 5, 4, 3, 2, 1, 0, 7, 6)) <= pTarget[3]) {
|
||||
atomicMin(&resNounce[0], nounce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__host__
|
||||
extern void whirlpoolx_cpu_init(int thr_id, uint32_t threads)
|
||||
{
|
||||
cudaMemcpyToSymbol(InitVector_RC, plain_RC, sizeof(plain_RC), 0, cudaMemcpyHostToDevice);
|
||||
cudaMemcpyToSymbol(mixTob0Tox, plain_T0, sizeof(plain_T0), 0, cudaMemcpyHostToDevice);
|
||||
cudaMalloc(&d_WXNonce[thr_id], sizeof(uint32_t));
|
||||
cudaMallocHost(&h_wxnounce[thr_id], sizeof(uint32_t));
|
||||
cudaMalloc(&d_xtra[thr_id], 8 * sizeof(uint64_t));
|
||||
CUDA_SAFE_CALL(cudaMalloc(&d_tmp[thr_id], 8 * 9 * sizeof(uint64_t))); // d_tmp[threadIdx.x+64] (7+64)
|
||||
}
|
||||
|
||||
__host__
|
||||
extern void whirlpoolx_cpu_free(int thr_id)
|
||||
{
|
||||
cudaFree(d_WXNonce[thr_id]);
|
||||
cudaFreeHost(h_wxnounce[thr_id]);
|
||||
cudaFree(d_xtra[thr_id]);
|
||||
cudaFree(d_tmp[thr_id]);
|
||||
}
|
||||
|
||||
__host__
|
||||
void whirlpoolx_setBlock_80(void *pdata, const void *ptarget)
|
||||
{
|
||||
uint64_t PaddedMessage[16];
|
||||
memcpy(PaddedMessage, pdata, 80);
|
||||
memset((uint8_t*)&PaddedMessage+80, 0, 48);
|
||||
((uint8_t*)PaddedMessage)[80] = 0x80; /* ending */
|
||||
cudaMemcpyToSymbol(pTarget, ptarget, 4*sizeof(uint64_t), 0, cudaMemcpyHostToDevice);
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_PaddedMessage80, PaddedMessage, 16 * sizeof(uint64_t), 0, cudaMemcpyHostToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
void whirlpoolx_precompute(int thr_id)
|
||||
{
|
||||
dim3 grid(1);
|
||||
dim3 block(256);
|
||||
|
||||
whirlpoolx_gpu_precompute <<<grid, block>>>(8, d_xtra[thr_id], d_tmp[thr_id]);
|
||||
cudaThreadSynchronize();
|
||||
|
||||
cudaMemcpyToSymbol(c_xtra, d_xtra[thr_id], 8 * sizeof(uint64_t), 0, cudaMemcpyDeviceToDevice);
|
||||
CUDA_SAFE_CALL(cudaMemcpyToSymbol(c_tmp, d_tmp[thr_id], 8 * 9 * sizeof(uint64_t), 0, cudaMemcpyDeviceToDevice));
|
||||
}
|
||||
|
||||
__host__
|
||||
uint32_t whirlpoolx_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce)
|
||||
{
|
||||
dim3 grid((threads + threadsPerBlock-1) / threadsPerBlock);
|
||||
dim3 block(threadsPerBlock);
|
||||
|
||||
cudaMemset(d_WXNonce[thr_id], 0xff, sizeof(uint32_t));
|
||||
|
||||
whirlpoolx_gpu_hash<<<grid, block>>>(threads, startNounce, d_WXNonce[thr_id]);
|
||||
cudaThreadSynchronize();
|
||||
|
||||
cudaMemcpy(h_wxnounce[thr_id], d_WXNonce[thr_id], sizeof(uint32_t), cudaMemcpyDeviceToHost);
|
||||
|
||||
return *(h_wxnounce[thr_id]);
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* whirlpool routine (djm)
|
||||
* whirlpoolx routine (provos alexis, tpruvot)
|
||||
*/
|
||||
extern "C" {
|
||||
#include "sph/sph_whirlpool.h"
|
||||
}
|
||||
|
||||
#include "miner.h"
|
||||
#include "cuda_helper.h"
|
||||
|
||||
static uint32_t *d_hash[MAX_GPUS];
|
||||
|
||||
extern void whirlpoolx_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void whirlpoolx_cpu_free(int thr_id);
|
||||
extern void whirlpoolx_setBlock_80(void *pdata, const void *ptarget);
|
||||
extern uint32_t whirlpoolx_cpu_hash(int thr_id, uint32_t threads, uint32_t startNounce);
|
||||
extern void whirlpoolx_precompute(int thr_id);
|
||||
|
||||
// CPU Hash function
|
||||
extern "C" void whirlxHash(void *state, const void *input)
|
||||
{
|
||||
sph_whirlpool_context ctx_whirlpool;
|
||||
|
||||
unsigned char hash[64];
|
||||
unsigned char hash_xored[32];
|
||||
|
||||
sph_whirlpool_init(&ctx_whirlpool);
|
||||
sph_whirlpool(&ctx_whirlpool, input, 80);
|
||||
sph_whirlpool_close(&ctx_whirlpool, hash);
|
||||
|
||||
// compress the 48 first bytes of the hash to 32
|
||||
for (int i = 0; i < 32; i++) {
|
||||
hash_xored[i] = hash[i] ^ hash[i + 16];
|
||||
}
|
||||
memcpy(state, hash_xored, 32);
|
||||
}
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_whirlx(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t endiandata[20];
|
||||
int intensity = is_windows() ? 20 : 22;
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << intensity);
|
||||
throughput = min(throughput, max_nonce - first_nonce);
|
||||
|
||||
if (opt_benchmark)
|
||||
((uint32_t*)ptarget)[7] = 0x0000ff;
|
||||
|
||||
if (!init[thr_id]) {
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
CUDA_CALL_OR_RET_X(cudaMalloc(&d_hash[thr_id], 64 * throughput), 0);
|
||||
|
||||
whirlpoolx_cpu_init(thr_id, throughput);
|
||||
|
||||
init[thr_id] = true;
|
||||
}
|
||||
|
||||
for (int k=0; k < 20; k++) {
|
||||
be32enc(&endiandata[k], pdata[k]);
|
||||
}
|
||||
|
||||
whirlpoolx_setBlock_80((void*)endiandata, ptarget);
|
||||
whirlpoolx_precompute(thr_id);
|
||||
|
||||
do {
|
||||
uint32_t foundNonce = whirlpoolx_cpu_hash(thr_id, throughput, pdata[19]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
const uint32_t Htarg = ptarget[7];
|
||||
uint32_t vhash64[8];
|
||||
be32enc(&endiandata[19], foundNonce);
|
||||
whirlxHash(vhash64, endiandata);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[19] = foundNonce;
|
||||
return 1;
|
||||
} else {
|
||||
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
|
||||
}
|
||||
}
|
||||
|
||||
pdata[19] += throughput;
|
||||
|
||||
if (((uint64_t)pdata[19]+throughput) >= max_nonce) {
|
||||
break;
|
||||
}
|
||||
|
||||
} while (!work_restart[thr_id].restart);
|
||||
|
||||
*(hashes_done) = pdata[19] - first_nonce + 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_whirlx(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
whirlpoolx_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+26
-7
@@ -69,9 +69,6 @@ extern void x13_fugue512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t star
|
||||
extern void x14_shabal512_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x14_shabal512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes,
|
||||
uint32_t *d_noncesTrue, size_t *nrmTrue, uint32_t *d_noncesFalse, size_t *nrmFalse, int order);
|
||||
|
||||
// X14 CPU Hash function
|
||||
extern "C" void x14hash(void *output, const void *input)
|
||||
@@ -157,10 +154,10 @@ extern "C" void x14hash(void *output, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_x14(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_x14(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t endiandata[20];
|
||||
|
||||
@@ -216,6 +213,8 @@ extern "C" int scanhash_x14(int thr_id, uint32_t *pdata,
|
||||
x13_fugue512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
x14_shabal512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
uint32_t foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
@@ -228,8 +227,12 @@ extern "C" int scanhash_x14(int thr_id, uint32_t *pdata,
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
x14hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -246,3 +249,19 @@ extern "C" int scanhash_x14(int thr_id, uint32_t *pdata,
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_x14(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+26
-7
@@ -74,9 +74,6 @@ extern void x15_whirlpool_cpu_init(int thr_id, uint32_t threads, int mode);
|
||||
extern void x15_whirlpool_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
extern void x15_whirlpool_cpu_free(int thr_id);
|
||||
|
||||
extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes,
|
||||
uint32_t *d_noncesTrue, size_t *nrmTrue, uint32_t *d_noncesFalse, size_t *nrmFalse, int order);
|
||||
|
||||
// X15 CPU Hash function
|
||||
extern "C" void x15hash(void *output, const void *input)
|
||||
@@ -167,10 +164,10 @@ extern "C" void x15hash(void *output, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_x15(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_x15(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
uint32_t endiandata[20];
|
||||
|
||||
@@ -228,6 +225,8 @@ extern "C" int scanhash_x15(int thr_id, uint32_t *pdata,
|
||||
x14_shabal512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
x15_whirlpool_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
uint32_t foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
@@ -240,8 +239,12 @@ extern "C" int scanhash_x15(int thr_id, uint32_t *pdata,
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
x15hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -261,3 +264,19 @@ extern "C" int scanhash_x15(int thr_id, uint32_t *pdata,
|
||||
x15_whirlpool_cpu_free(thr_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_x15(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
+26
-8
@@ -82,10 +82,6 @@ extern void x17_sha512_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startN
|
||||
extern void x17_haval256_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void x17_haval256_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *d_nonceVector, uint32_t *d_hash, int order);
|
||||
|
||||
extern void quark_compactTest_cpu_init(int thr_id, uint32_t threads);
|
||||
extern void quark_compactTest_cpu_hash_64(int thr_id, uint32_t threads, uint32_t startNounce, uint32_t *inpHashes,
|
||||
uint32_t *d_noncesTrue, size_t *nrmTrue, uint32_t *d_noncesFalse, size_t *nrmFalse,
|
||||
int order);
|
||||
|
||||
// X17 Hashfunktion
|
||||
extern "C" void x17hash(void *output, const void *input)
|
||||
@@ -186,10 +182,10 @@ extern "C" void x17hash(void *output, const void *input)
|
||||
|
||||
static bool init[MAX_GPUS] = { 0 };
|
||||
|
||||
extern "C" int scanhash_x17(int thr_id, uint32_t *pdata,
|
||||
const uint32_t *ptarget, uint32_t max_nonce,
|
||||
unsigned long *hashes_done)
|
||||
extern "C" int scanhash_x17(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done)
|
||||
{
|
||||
uint32_t *pdata = work->data;
|
||||
uint32_t *ptarget = work->target;
|
||||
const uint32_t first_nonce = pdata[19];
|
||||
|
||||
uint32_t throughput = device_intensity(thr_id, __func__, 1U << 19); // 19=256*256*8;
|
||||
@@ -254,6 +250,8 @@ extern "C" int scanhash_x17(int thr_id, uint32_t *pdata,
|
||||
x17_sha512_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
x17_haval256_cpu_hash_64(thr_id, throughput, pdata[19], NULL, d_hash[thr_id], order++);
|
||||
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
|
||||
uint32_t foundNonce = cuda_check_hash(thr_id, throughput, pdata[19], d_hash[thr_id]);
|
||||
if (foundNonce != UINT32_MAX)
|
||||
{
|
||||
@@ -265,8 +263,12 @@ extern "C" int scanhash_x17(int thr_id, uint32_t *pdata,
|
||||
if (vhash64[7] <= Htarg && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, pdata[19], d_hash[thr_id], 1);
|
||||
*hashes_done = pdata[19] - first_nonce + throughput;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
if (secNonce != 0) {
|
||||
be32enc(&endiandata[19], secNonce);
|
||||
x17hash(vhash64, endiandata);
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
res++;
|
||||
}
|
||||
@@ -284,3 +286,19 @@ extern "C" int scanhash_x17(int thr_id, uint32_t *pdata,
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_x17(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
@@ -435,6 +435,7 @@ extern "C" int scanhash_zr5(int thr_id, struct work *work,
|
||||
zr5hash(vhash64, pdata);
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
int res = 1;
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
uint32_t secNonce = cuda_check_hash_suppl(thr_id, throughput, oldp19, d_hash[thr_id], 1);
|
||||
if (secNonce != 0) {
|
||||
offset = secNonce - oldp19;
|
||||
@@ -444,6 +445,8 @@ extern "C" int scanhash_zr5(int thr_id, struct work *work,
|
||||
tmpdata[0] = pok; tmpdata[19] = secNonce;
|
||||
zr5hash(vhash64, tmpdata);
|
||||
if (vhash64[7] <= ptarget[7] && fulltest(vhash64, ptarget)) {
|
||||
if (bn_hash_target_ratio(vhash64, ptarget) > work->shareratio)
|
||||
bn_store_hash_target_ratio(vhash64, ptarget, work);
|
||||
pdata[21] = secNonce;
|
||||
pdata[22] = pok;
|
||||
res++;
|
||||
@@ -466,3 +469,30 @@ extern "C" int scanhash_zr5(int thr_id, struct work *work,
|
||||
*hashes_done = pdata[19] - first_nonce + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// cleanup
|
||||
extern "C" void free_zr5(int thr_id)
|
||||
{
|
||||
if (!init[thr_id])
|
||||
return;
|
||||
|
||||
cudaSetDevice(device_map[thr_id]);
|
||||
|
||||
cudaFree(d_hash[thr_id]);
|
||||
|
||||
cudaFree(d_poks[thr_id]);
|
||||
cudaFree(d_permut[thr_id]);
|
||||
cudaFree(d_buffers[thr_id]);
|
||||
|
||||
cudaFree(d_blake[thr_id]);
|
||||
cudaFree(d_groes[thr_id]);
|
||||
cudaFree(d_jh512[thr_id]);
|
||||
cudaFree(d_skein[thr_id]);
|
||||
|
||||
cudaFree(d_txs[thr_id]);
|
||||
|
||||
cuda_check_cpu_free(thr_id);
|
||||
init[thr_id] = false;
|
||||
|
||||
cudaDeviceSynchronize();
|
||||
}
|
||||
Reference in new issue
Block a user