From 55fe9b937d679b3ccff457d77424f7ae8fdfe4cc Mon Sep 17 00:00:00 2001 From: Pompolus Date: Thu, 1 Feb 2018 22:10:28 +0100 Subject: [PATCH] resultCode is now uint8_t - applyed changes suggested by bitbandi (v2) --- algorithm/evocoin.c | 46 ++++++++++++++++++--------------------------- algorithm/evocoin.h | 2 +- miner.h | 2 +- ocl.c | 3 +-- ocl/build_kernel.c | 12 +++--------- ocl/build_kernel.h | 2 +- sgminer.c | 6 +++--- 7 files changed, 28 insertions(+), 45 deletions(-) diff --git a/algorithm/evocoin.c b/algorithm/evocoin.c index f91cd66de..de6ea744b 100644 --- a/algorithm/evocoin.c +++ b/algorithm/evocoin.c @@ -121,34 +121,17 @@ int nextPerm(uint8_t n[], uint32_t count) { } -void getAlgoString(char *str, uint32_t count) -{ - uint8_t algoList[HASH_FUNC_COUNT]; - char s[100]; - char *sptr; - +void getAlgoString(uint8_t *algoList, uint32_t count) +{ initPerm(algoList, HASH_FUNC_COUNT); - - int j; - int k; for (k = 0; k < count; k++) { nextPerm(algoList, HASH_FUNC_COUNT); } - - sptr = str; - for (j = 0; j < HASH_FUNC_COUNT; j++) { - if (algoList[j] >= 10) - sprintf(sptr, "%c", 'A' + (algoList[j] - 10)); - else - sprintf(sptr, "%u", algoList[j]); - sptr++; - } - *sptr = 0; } -void evocoin_twisted_code(char *result, const char *ntime, char *code) +void evocoin_twisted_code(char *result, const char *ntime, uint8_t *code) { unsigned char bin[4]; uint32_t h32, *be32 = (uint32_t *)bin; @@ -156,7 +139,19 @@ void evocoin_twisted_code(char *result, const char *ntime, char *code) h32 = be32toh(*be32); uint32_t count = getCurrentAlgoSeq(h32, INITIAL_DATE); getAlgoString(code, count); - sprintf(result, "_%d_%s_", count, code); + char *sptr; + int j; + int n = sprintf(result, "_%d_", count); + sptr = result + n; + for (j = 0; j < HASH_FUNC_COUNT; j++) { + if (code[j] >= 10) + sprintf(sptr, "%c", 'A' + (code[j] - 10)); + else + sprintf(sptr, "%u", code[j]); + sptr++; + } + strcat(sptr, "_"); sptr++; + *sptr = 0; } @@ -179,13 +174,8 @@ static inline void xhash(void *state, const void *input , const char* ntime) void *out; - for (i = 0; i < strlen(resultCode); i++) { - char elem = resultCode[i]; - uint8_t idx; - if (elem >= 'A') - idx = elem - 'A' + 10; - else - idx = elem - '0'; + for (i = 0; i < HASH_FUNC_COUNT; i++) { + uint8_t idx = resultCode[i]; int size; diff --git a/algorithm/evocoin.h b/algorithm/evocoin.h index 22e3e79fb..47221217d 100644 --- a/algorithm/evocoin.h +++ b/algorithm/evocoin.h @@ -9,6 +9,6 @@ extern int evocoin_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce); extern void evocoin_regenhash(struct work *work); -extern void evocoin_twisted_code(char *result, const char *ntime, char *code); +extern void evocoin_twisted_code(char *result, const char *ntime, uint8_t *code); #endif /* EVOCOIN_H */ diff --git a/miner.h b/miner.h index d2a6536d8..f59784cbd 100644 --- a/miner.h +++ b/miner.h @@ -634,7 +634,7 @@ struct thr_info { int pool_no; struct timeval last; struct timeval sick; - char curSequence[12]; + uint8_t curSequence[12]; struct work *work; bool pause; diff --git a/ocl.c b/ocl.c index b0f7f6d6e..f267f3994 100644 --- a/ocl.c +++ b/ocl.c @@ -727,8 +727,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg if (clState->goffset) strcat(build_data->binary_filename, "g"); - char x11EvoCode[12]; - x11EvoCode[0] = 0; + uint8_t x11EvoCode[12] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; if (cgpu->algorithm.type == ALGO_X11EVO) { char algoSuffixCode[100]; diff --git a/ocl/build_kernel.c b/ocl/build_kernel.c index 5339c6294..95c296584 100644 --- a/ocl/build_kernel.c +++ b/ocl/build_kernel.c @@ -152,13 +152,7 @@ char *generateSource(const uint8_t *code) for (i = 0; i < HASH_FUNC_COUNT; i++) { // extract index - uint8_t elem = code[i]; - uint8_t idx; - if (elem >= 'A') - idx = elem - 'A' + 10; - else - idx = elem - '0'; - + uint8_t idx = code[i]; // calc swap requirements if (curState != algo[idx].req_inverted) { @@ -194,11 +188,11 @@ char *generateSource(const uint8_t *code) return result; } -cl_program build_opencl_kernel(build_kernel_data *data, const char *filename, const char *x11EvoCode) +cl_program build_opencl_kernel(build_kernel_data *data, const char *filename, const uint8_t *x11EvoCode) { int pl; char *source; - if (strlen(x11EvoCode) > 0) { + if (x11EvoCode[0] != 255) { source = generateSource(x11EvoCode); pl = strlen(source) + 1; } diff --git a/ocl/build_kernel.h b/ocl/build_kernel.h index b53801154..82b24a5e6 100644 --- a/ocl/build_kernel.h +++ b/ocl/build_kernel.h @@ -28,7 +28,7 @@ typedef struct _build_kernel_data { } build_kernel_data; bool needs_bfi_patch(build_kernel_data *data); -cl_program build_opencl_kernel(build_kernel_data *data, const char *filename, const char *x11EvoCode); +cl_program build_opencl_kernel(build_kernel_data *data, const char *filename, const uint8_t *x11EvoCode); bool save_opencl_kernel(build_kernel_data *data, cl_program program); void set_base_compiler_options(build_kernel_data *data); diff --git a/sgminer.c b/sgminer.c index 1f1f9caa5..4de0fc5f0 100644 --- a/sgminer.c +++ b/sgminer.c @@ -6777,14 +6777,14 @@ static bool checkIfNeedSwitch(struct thr_info *mythr, struct work *work) if (work && work->pool) { char result[100]; - char code[12]; + uint8_t code[12]; evocoin_twisted_code(result, work->pool->swork.ntime, code); - if (strcmp(code, mythr->curSequence) == 0) { + if (memcmp(code, mythr->curSequence, 12) == 0) { algoSwitch = false; } else { - strcpy(mythr->curSequence, code); + memcpy(mythr->curSequence, code, 12); } }