Skip to content

Commit 632ea79

Browse files
committed
Merge remote-tracking branch 'sgminer-dev/master'
Getting updated with others, nothing more.
2 parents 7811d37 + 137519d commit 632ea79

12 files changed

+669
-1459
lines changed

algorithm.c

+26-34
Original file line numberDiff line numberDiff line change
@@ -638,21 +638,36 @@ static cl_int queue_whirlcoin_kernel(struct __clState *clState, struct _dev_blk_
638638

639639
static cl_int queue_whirlpoolx_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
640640
{
641-
cl_kernel *kernel;
641+
uint64_t midblock[8], key[8] = { 0 }, tmp[8] = { 0 };
642642
cl_ulong le_target;
643-
cl_int status = 0;
643+
cl_int status;
644644

645645
le_target = *(cl_ulong *)(blk->work->device_target + 24);
646646
flip80(clState->cldata, blk->work->data);
647-
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
648647

649-
//clbuffer, hashes
650-
kernel = &clState->kernel;
651-
CL_SET_ARG_N(0, clState->CLbuffer0);
652-
CL_SET_ARG_N(1, clState->padbuffer8);
648+
memcpy(midblock, clState->cldata, 64);
653649

654-
CL_SET_ARG_N(2, clState->outputBuffer);
655-
CL_SET_ARG_N(3, le_target);
650+
// midblock = n, key = h
651+
for (int i = 0; i < 10; ++i) {
652+
tmp[0] = WHIRLPOOL_ROUND_CONSTANTS[i];
653+
whirlpool_round(key, tmp);
654+
tmp[0] = 0;
655+
whirlpool_round(midblock, tmp);
656+
657+
for (int x = 0; x < 8; ++x) {
658+
midblock[x] ^= key[x];
659+
}
660+
}
661+
662+
for (int i = 0; i < 8; ++i) {
663+
midblock[i] ^= ((uint64_t *)(clState->cldata))[i];
664+
}
665+
666+
status = clSetKernelArg(clState->kernel, 0, sizeof(cl_ulong8), (cl_ulong8 *)&midblock);
667+
status |= clSetKernelArg(clState->kernel, 1, sizeof(cl_ulong), (void *)(((uint64_t *)clState->cldata) + 8));
668+
status |= clSetKernelArg(clState->kernel, 2, sizeof(cl_ulong), (void *)(((uint64_t *)clState->cldata) + 9));
669+
status |= clSetKernelArg(clState->kernel, 3, sizeof(cl_mem), (void *)&clState->outputBuffer);
670+
status |= clSetKernelArg(clState->kernel, 4, sizeof(cl_ulong), (void *)&le_target);
656671

657672
return status;
658673
}
@@ -720,27 +735,6 @@ static cl_int queue_pluck_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_un
720735
return status;
721736
}
722737

723-
typedef struct _algorithm_settings_t {
724-
const char *name; /* Human-readable identifier */
725-
algorithm_type_t type; //common algorithm type
726-
const char *kernelfile; /* alternate kernel file */
727-
double diff_multiplier1;
728-
double diff_multiplier2;
729-
double share_diff_multiplier;
730-
uint32_t xintensity_shift;
731-
uint32_t intensity_shift;
732-
uint32_t found_idx;
733-
unsigned long long diff_numerator;
734-
uint32_t diff1targ;
735-
size_t n_extra_kernels;
736-
long rw_buffer_size;
737-
cl_command_queue_properties cq_properties;
738-
void(*regenhash)(struct work *);
739-
cl_int(*queue_kernel)(struct __clState *, struct _dev_blk_ctx *, cl_uint);
740-
void(*gen_hash)(const unsigned char *, unsigned int, unsigned char *);
741-
void(*set_compile_options)(build_kernel_data *, struct cgpu_info *, algorithm_t *);
742-
} algorithm_settings_t;
743-
744738
static algorithm_settings_t algos[] = {
745739
// kernels starting from this will have difficulty calculated by using litecoin algorithm
746740
#define A_SCRYPT(a) \
@@ -810,7 +804,7 @@ static algorithm_settings_t algos[] = {
810804
#undef A_FUGUE
811805

812806
{ "whirlcoin", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 3, 8 * 16 * 4194304, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, whirlcoin_regenhash, queue_whirlcoin_kernel, sha256, NULL },
813-
{ "whirlpoolx", ALGO_WHIRL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, 0, whirlpoolx_regenhash, queue_sph_kernel, gen_hash, NULL },
807+
{ "whirlpoolx", ALGO_WHIRLPOOLX, "", 1, 1, 1, 0, 0, 0xFFU, 0xFFFFULL, 0x0000FFFFUL, 0, 0, 0, whirlpoolx_regenhash, queue_whirlpoolx_kernel, gen_hash, NULL },
814808

815809
// Terminator (do not remove)
816810
{ NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
@@ -883,7 +877,6 @@ static const char *lookup_algorithm_alias(const char *lookup_alias, uint8_t *nfa
883877
ALGO_ALIAS("nist5", "talkcoin-mod");
884878
ALGO_ALIAS("keccak", "maxcoin");
885879
ALGO_ALIAS("whirlpool", "whirlcoin");
886-
ALGO_ALIAS("whirlpoolx", "whirlpoolx");
887880
ALGO_ALIAS("Lyra2RE", "lyra2re");
888881
ALGO_ALIAS("lyra2", "lyra2re");
889882

@@ -945,8 +938,7 @@ void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor)
945938
}
946939
}
947940

948-
bool cmp_algorithm(algorithm_t* algo1, algorithm_t* algo2)
941+
bool cmp_algorithm(const algorithm_t* algo1, const algorithm_t* algo2)
949942
{
950-
// return (strcmp(algo1->name, algo2->name) == 0) && (algo1->nfactor == algo2->nfactor);
951943
return (!safe_cmp(algo1->name, algo2->name) && !safe_cmp(algo1->kernelfile, algo2->kernelfile) && (algo1->nfactor == algo2->nfactor));
952944
}

algorithm.h

+25-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <inttypes.h>
1111
#include <stdbool.h>
12+
#include "ocl/build_kernel.h" // For the build_kernel_data type
1213

1314
typedef enum {
1415
ALGO_UNK,
@@ -26,6 +27,7 @@ typedef enum {
2627
ALGO_FRESH,
2728
ALGO_WHIRL,
2829
ALGO_NEOSCRYPT,
30+
ALGO_WHIRLPOOLX,
2931
ALGO_LYRA2RE,
3032
ALGO_PLUCK
3133
} algorithm_type_t;
@@ -66,13 +68,35 @@ typedef struct _algorithm_t {
6668
void(*set_compile_options)(struct _build_kernel_data *, struct cgpu_info *, struct _algorithm_t *);
6769
} algorithm_t;
6870

71+
typedef struct _algorithm_settings_t
72+
{
73+
const char *name;
74+
algorithm_type_t type;
75+
const char *kernelfile;
76+
double diff_multiplier1;
77+
double diff_multiplier2;
78+
double share_diff_multiplier;
79+
uint32_t xintensity_shift;
80+
uint32_t intensity_shift;
81+
uint32_t found_idx;
82+
unsigned long long diff_numerator;
83+
uint32_t diff1targ;
84+
size_t n_extra_kernels;
85+
long rw_buffer_size;
86+
cl_command_queue_properties cq_properties;
87+
void (*regenhash)(struct work *);
88+
cl_int (*queue_kernel)(struct __clState *, struct _dev_blk_ctx *, cl_uint);
89+
void (*gen_hash)(const unsigned char *, unsigned int, unsigned char *);
90+
void (*set_compile_options)(build_kernel_data *, struct cgpu_info *, algorithm_t *);
91+
} algorithm_settings_t;
92+
6993
/* Set default parameters based on name. */
7094
void set_algorithm(algorithm_t* algo, const char* name);
7195

7296
/* Set to specific N factor. */
7397
void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor);
7498

7599
/* Compare two algorithm parameters */
76-
bool cmp_algorithm(algorithm_t* algo1, algorithm_t* algo2);
100+
bool cmp_algorithm(const algorithm_t* algo1, const algorithm_t* algo2);
77101

78102
#endif /* ALGORITHM_H */

algorithm/whirlcoin.c

+65-65
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ Whash_context_holder base_contexts;
4949

5050
void init_whirlcoin_hash_contexts()
5151
{
52-
sph_whirlpool1_init(&base_contexts.whirlpool1);
53-
sph_whirlpool1_init(&base_contexts.whirlpool2);
54-
sph_whirlpool1_init(&base_contexts.whirlpool3);
55-
sph_whirlpool1_init(&base_contexts.whirlpool4);
52+
sph_whirlpool1_init(&base_contexts.whirlpool1);
53+
sph_whirlpool1_init(&base_contexts.whirlpool2);
54+
sph_whirlpool1_init(&base_contexts.whirlpool3);
55+
sph_whirlpool1_init(&base_contexts.whirlpool4);
5656
}
5757

5858
/*
@@ -62,10 +62,10 @@ void init_whirlcoin_hash_contexts()
6262
static inline void
6363
be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len)
6464
{
65-
uint32_t i;
65+
uint32_t i;
6666

67-
for (i = 0; i < len; i++)
68-
dst[i] = htobe32(src[i]);
67+
for (i = 0; i < len; i++)
68+
dst[i] = htobe32(src[i]);
6969
}
7070

7171

@@ -74,33 +74,32 @@ static
7474
#endif
7575
inline void whirlcoin_hash(void *state, const void *input)
7676
{
77-
init_whirlcoin_hash_contexts();
77+
init_whirlcoin_hash_contexts();
7878

79-
Whash_context_holder ctx;
80-
uint32_t hashA[16], hashB[16];
79+
Whash_context_holder ctx;
80+
uint32_t hashA[16], hashB[16];
8181

82-
memcpy(&ctx, &base_contexts, sizeof(base_contexts));
82+
memcpy(&ctx, &base_contexts, sizeof(base_contexts));
8383

84-
sph_whirlpool1 (&ctx.whirlpool1, input, 80);
85-
sph_whirlpool1_close (&ctx.whirlpool1, hashA);
84+
sph_whirlpool1(&ctx.whirlpool1, input, 80);
85+
sph_whirlpool1_close(&ctx.whirlpool1, hashA);
8686

87-
sph_whirlpool1(&ctx.whirlpool2, hashA, 64);
88-
sph_whirlpool1_close(&ctx.whirlpool2, hashB);
87+
sph_whirlpool1(&ctx.whirlpool2, hashA, 64);
88+
sph_whirlpool1_close(&ctx.whirlpool2, hashB);
8989

90-
sph_whirlpool1(&ctx.whirlpool3, hashB, 64);
91-
sph_whirlpool1_close(&ctx.whirlpool3, hashA);
90+
sph_whirlpool1(&ctx.whirlpool3, hashB, 64);
91+
sph_whirlpool1_close(&ctx.whirlpool3, hashA);
9292

93-
sph_whirlpool1(&ctx.whirlpool4, hashA, 64);
94-
sph_whirlpool1_close(&ctx.whirlpool4, hashB);
93+
sph_whirlpool1(&ctx.whirlpool4, hashA, 64);
94+
sph_whirlpool1_close(&ctx.whirlpool4, hashB);
9595

96-
memcpy(state, hashB, 32);
96+
memcpy(state, hashB, 32);
9797
}
9898

9999
static const uint32_t diff1targ = 0x0000ffff;
100100

101-
102101
/* Used externally as confirmation of correct OCL code */
103-
int whirlcoin_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
102+
int whirlcoin_test_old(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
104103
{
105104
uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
106105
uint32_t data[20], ohash[8];
@@ -124,51 +123,52 @@ int whirlcoin_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t
124123

125124
void whirlcoin_regenhash(struct work *work)
126125
{
127-
uint32_t data[20];
128-
uint32_t *nonce = (uint32_t *)(work->data + 76);
129-
uint32_t *ohash = (uint32_t *)(work->hash);
126+
uint32_t data[20];
127+
uint32_t *nonce = (uint32_t *)(work->data + 76);
128+
uint32_t *ohash = (uint32_t *)(work->hash);
130129

131-
be32enc_vect(data, (const uint32_t *)work->data, 19);
132-
data[19] = htobe32(*nonce);
133-
whirlcoin_hash(ohash, data);
130+
be32enc_vect(data, (const uint32_t *)work->data, 19);
131+
data[19] = htobe32(*nonce);
132+
whirlcoin_hash(ohash, data);
134133
}
135-
134+
/*
136135
bool scanhash_whirlcoin(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
137-
unsigned char *pdata, unsigned char __maybe_unused *phash1,
138-
unsigned char __maybe_unused *phash, const unsigned char *ptarget,
139-
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
136+
unsigned char *pdata, unsigned char __maybe_unused *phash1,
137+
unsigned char __maybe_unused *phash, const unsigned char *ptarget,
138+
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
140139
{
141-
uint32_t *nonce = (uint32_t *)(pdata + 76);
142-
uint32_t data[20];
143-
uint32_t tmp_hash7;
144-
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
145-
bool ret = false;
146-
147-
be32enc_vect(data, (const uint32_t *)pdata, 19);
148-
149-
while(1) {
150-
uint32_t ostate[8];
151-
152-
*nonce = ++n;
153-
data[19] = (n);
154-
whirlcoin_hash(ostate, data);
155-
tmp_hash7 = (ostate[7]);
156-
157-
applog(LOG_INFO, "data7 %08lx",
158-
(long unsigned int)data[7]);
159-
160-
if (unlikely(tmp_hash7 <= Htarg)) {
161-
((uint32_t *)pdata)[19] = htobe32(n);
162-
*last_nonce = n;
163-
ret = true;
164-
break;
165-
}
166-
167-
if (unlikely((n >= max_nonce) || thr->work_restart)) {
168-
*last_nonce = n;
169-
break;
170-
}
171-
}
172-
173-
return ret;
140+
uint32_t *nonce = (uint32_t *)(pdata + 76);
141+
uint32_t data[20];
142+
uint32_t tmp_hash7;
143+
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
144+
bool ret = false;
145+
146+
be32enc_vect(data, (const uint32_t *)pdata, 19);
147+
148+
while (1) {
149+
uint32_t ostate[8];
150+
151+
*nonce = ++n;
152+
data[19] = (n);
153+
whirlcoin_hash(ostate, data);
154+
tmp_hash7 = (ostate[7]);
155+
156+
applog(LOG_INFO, "data7 %08lx",
157+
(long unsigned int)data[7]);
158+
159+
if (unlikely(tmp_hash7 <= Htarg)) {
160+
((uint32_t *)pdata)[19] = htobe32(n);
161+
*last_nonce = n;
162+
ret = true;
163+
break;
164+
}
165+
166+
if (unlikely((n >= max_nonce) || thr->work_restart)) {
167+
*last_nonce = n;
168+
break;
169+
}
170+
}
171+
172+
return ret;
174173
}
174+
*/

0 commit comments

Comments
 (0)