Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
tpruvot
GitHub Repository: tpruvot/cpuminer-multi
Path: blob/linux/algo/qubit.c
1201 views
1
#include "miner.h"
2
3
#include <stdlib.h>
4
#include <stdint.h>
5
#include <string.h>
6
#include <stdio.h>
7
8
#include "sha3/sph_luffa.h"
9
#include "sha3/sph_cubehash.h"
10
#include "sha3/sph_shavite.h"
11
#include "sha3/sph_simd.h"
12
#include "sha3/sph_echo.h"
13
14
void qubithash(void *output, const void *input)
15
{
16
sph_luffa512_context ctx_luffa;
17
sph_cubehash512_context ctx_cubehash;
18
sph_shavite512_context ctx_shavite;
19
sph_simd512_context ctx_simd;
20
sph_echo512_context ctx_echo;
21
22
uint8_t hash[64];
23
24
sph_luffa512_init(&ctx_luffa);
25
sph_luffa512 (&ctx_luffa, input, 80);
26
sph_luffa512_close(&ctx_luffa, (void*) hash);
27
28
sph_cubehash512_init(&ctx_cubehash);
29
sph_cubehash512 (&ctx_cubehash, (const void*) hash, 64);
30
sph_cubehash512_close(&ctx_cubehash, (void*) hash);
31
32
sph_shavite512_init(&ctx_shavite);
33
sph_shavite512 (&ctx_shavite, (const void*) hash, 64);
34
sph_shavite512_close(&ctx_shavite, (void*) hash);
35
36
sph_simd512_init(&ctx_simd);
37
sph_simd512 (&ctx_simd, (const void*) hash, 64);
38
sph_simd512_close(&ctx_simd, (void*) hash);
39
40
sph_echo512_init(&ctx_echo);
41
sph_echo512 (&ctx_echo, (const void*) hash, 64);
42
sph_echo512_close(&ctx_echo, (void*) hash);
43
44
memcpy(output, hash, 32);
45
}
46
47
int scanhash_qubit(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
48
{
49
uint32_t _ALIGN(128) hash32[8];
50
uint32_t _ALIGN(128) endiandata[20];
51
uint32_t *pdata = work->data;
52
uint32_t *ptarget = work->target;
53
54
uint32_t n = pdata[19] - 1;
55
const uint32_t first_nonce = pdata[19];
56
const uint32_t Htarg = ptarget[7];
57
58
uint64_t htmax[] = {
59
0,
60
0xF,
61
0xFF,
62
0xFFF,
63
0xFFFF,
64
0x10000000
65
};
66
uint32_t masks[] = {
67
0xFFFFFFFF,
68
0xFFFFFFF0,
69
0xFFFFFF00,
70
0xFFFFF000,
71
0xFFFF0000,
72
0
73
};
74
75
// we need bigendian data...
76
for (int i=0; i < 19; i++) {
77
be32enc(&endiandata[i], pdata[i]);
78
}
79
80
#ifdef DEBUG_ALGO
81
printf("[%d] Htarg=%X\n", thr_id, Htarg);
82
#endif
83
for (int m=0; m < 6; m++) {
84
if (Htarg <= htmax[m]) {
85
uint32_t mask = masks[m];
86
do {
87
pdata[19] = ++n;
88
be32enc(&endiandata[19], n);
89
qubithash(hash32, endiandata);
90
#ifndef DEBUG_ALGO
91
if ((!(hash32[7] & mask)) && fulltest(hash32, ptarget)) {
92
work_set_target_ratio(work, hash32);
93
*hashes_done = n - first_nonce + 1;
94
return 1;
95
}
96
#else
97
if (!(n % 0x1000) && !thr_id) printf(".");
98
if (!(hash32[7] & mask)) {
99
printf("[%d]",thr_id);
100
if (fulltest(hash32, ptarget)) {
101
work_set_target_ratio(work, hash32);
102
*hashes_done = n - first_nonce + 1;
103
return 1;
104
}
105
}
106
#endif
107
} while (n < max_nonce && !work_restart[thr_id].restart);
108
// see blake.c if else to understand the loop on htmax => mask
109
break;
110
}
111
}
112
113
*hashes_done = n - first_nonce + 1;
114
pdata[19] = n;
115
return 0;
116
}
117
118