diff --git a/algorithm.c b/algorithm.c index e58aea7f..14be6656 100644 --- a/algorithm.c +++ b/algorithm.c @@ -52,8 +52,13 @@ void gen_hash(const unsigned char *data, unsigned int len, unsigned char *hash) } #define CL_SET_BLKARG(blkvar) status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->blkvar) -#define CL_SET_ARG(var) status |= clSetKernelArg(*kernel, num++, sizeof(var), (void *)&var) #define CL_SET_VARG(args, var) status |= clSetKernelArg(*kernel, num++, args * sizeof(uint), (void *)var) +#define CL_SET_ARG_N(n, var) do { status |= clSetKernelArg(*kernel, n, sizeof(var), (void *)&var); } while (0) +#define CL_SET_ARG_0(var) CL_SET_ARG_N(0, var) +#define CL_SET_ARG(var) CL_SET_ARG_N(num++, var) +#define CL_NEXTKERNEL_SET_ARG_N(n, var) do { kernel++; CL_SET_ARG_N(n, var); } while (0) +#define CL_NEXTKERNEL_SET_ARG_0(var) CL_NEXTKERNEL_SET_ARG_N(0, var) +#define CL_NEXTKERNEL_SET_ARG(var) CL_NEXTKERNEL_SET_ARG_N(num++, var) static void append_scrypt_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm) { @@ -150,44 +155,26 @@ static cl_int queue_darkcoin_mod_kernel(struct __clState *clState, struct _dev_b CL_SET_ARG(clState->padbuffer8); // bmw - search1 kernel = clState->extra_kernels; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_SET_ARG_0(clState->padbuffer8); // groestl - search2 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // skein - search3 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // jh - search4 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // keccak - search5 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // luffa - search6 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // cubehash - search7 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // shavite - search8 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // simd - search9 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // echo - search10 - kernel++; num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG(clState->padbuffer8); CL_SET_ARG(clState->outputBuffer); CL_SET_ARG(le_target); @@ -212,52 +199,30 @@ static cl_int queue_marucoin_mod_kernel(struct __clState *clState, struct _dev_b CL_SET_ARG(clState->padbuffer8); // bmw - search1 kernel = clState->extra_kernels; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_SET_ARG_0(clState->padbuffer8); // groestl - search2 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // skein - search3 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // jh - search4 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // keccak - search5 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // luffa - search6 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // cubehash - search7 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // shavite - search8 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // simd - search9 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // echo - search10 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // hamsi - search11 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // fugue - search12 - kernel++; num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG(clState->padbuffer8); CL_SET_ARG(clState->outputBuffer); CL_SET_ARG(le_target); @@ -282,44 +247,26 @@ static cl_int queue_marucoin_mod_old_kernel(struct __clState *clState, struct _d CL_SET_ARG(clState->padbuffer8); // bmw - search1 kernel = clState->extra_kernels; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_SET_ARG_0(clState->padbuffer8); // groestl - search2 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // skein - search3 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // jh - search4 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // keccak - search5 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // luffa - search6 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // cubehash - search7 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // shavite - search8 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // simd - search9 - kernel++; - num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8); // combined echo, hamsi, fugue - search10 - kernel++; num = 0; - CL_SET_ARG(clState->padbuffer8); + CL_NEXTKERNEL_SET_ARG(clState->padbuffer8); CL_SET_ARG(clState->outputBuffer); CL_SET_ARG(le_target); diff --git a/driver-opencl.c b/driver-opencl.c index 8b28bb7a..4dea389f 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -1157,7 +1157,7 @@ static void opencl_detect(bool hotplug) cgpu->threads = 1; #endif cgpu->virtual_gpu = i; - cgpu->algorithm = *opt_algorithm; + cgpu->algorithm = opt_algorithm; add_cgpu(cgpu); } diff --git a/miner.h b/miner.h index 6568e92d..fcf419ef 100644 --- a/miner.h +++ b/miner.h @@ -990,7 +990,7 @@ extern int opt_queue; extern int opt_scantime; extern int opt_expiry; -extern algorithm_t *opt_algorithm; +extern algorithm_t opt_algorithm; extern cglock_t control_lock; extern pthread_mutex_t hash_lock; @@ -1463,10 +1463,4 @@ extern struct api_data *api_add_diff(struct api_data *root, char *name, double * extern struct api_data *api_add_percent(struct api_data *root, char *name, double *data, bool copy_data); extern struct api_data *api_add_avg(struct api_data *root, char *name, float *data, bool copy_data); -enum diff_calc_mode { - DM_BITCOIN, - DM_QUARKCOIN, - DM_LITECOIN, -}; - #endif /* MINER_H */ diff --git a/sgminer.c b/sgminer.c index 2f2a2605..009d6110 100644 --- a/sgminer.c +++ b/sgminer.c @@ -98,7 +98,7 @@ int opt_queue = 1; int opt_scantime = 7; int opt_expiry = 28; -algorithm_t *opt_algorithm; +algorithm_t opt_algorithm; unsigned long long global_hashrate; unsigned long global_quota_gcd = 1; @@ -528,7 +528,7 @@ struct pool *add_pool(void) pool->name = strdup(buf); /* Algorithm */ - pool->algorithm = *opt_algorithm; + pool->algorithm = opt_algorithm; pools = (struct pool **)realloc(pools, sizeof(struct pool *) * (total_pools + 2)); pools[total_pools++] = pool; @@ -1117,8 +1117,8 @@ static void load_temp_cutoffs() static char *set_algo(const char *arg) { if ((json_array_index < 0) || (total_pools == 0)) { - set_algorithm(opt_algorithm, arg); - applog(LOG_INFO, "Set default algorithm to %s", opt_algorithm->name); + set_algorithm(&opt_algorithm, arg); + applog(LOG_INFO, "Set default algorithm to %s", opt_algorithm.name); } else { set_pool_algorithm(arg); } @@ -1129,9 +1129,9 @@ static char *set_algo(const char *arg) static char *set_nfactor(const char *arg) { if ((json_array_index < 0) || (total_pools == 0)) { - set_algorithm_nfactor(opt_algorithm, (const uint8_t) atoi(arg)); + set_algorithm_nfactor(&opt_algorithm, (const uint8_t) atoi(arg)); applog(LOG_INFO, "Set algorithm N-factor to %d (N to %d)", - opt_algorithm->nfactor, opt_algorithm->n); + opt_algorithm.nfactor, opt_algorithm.n); } else { set_pool_nfactor(arg); } @@ -4414,7 +4414,7 @@ void write_config(FILE *fcfg) if (strcmp(pool->description, "") != 0) { fprintf(fcfg, ",\n\t\t\"description\" : \"%s\"", json_escape(pool->description)); } - if (!cmp_algorithm(&pool->algorithm, opt_algorithm)) { + if (!cmp_algorithm(&pool->algorithm, &opt_algorithm)) { fprintf(fcfg, ",\n\t\t\"algorithm\" : \"%s\"", json_escape(pool->algorithm.name)); } if (pool->prio != i) { @@ -4591,8 +4591,8 @@ void write_config(FILE *fcfg) } if (opt_removedisabled) fprintf(fcfg, ",\n\"remove-disabled\" : true"); - if (strcmp(opt_algorithm->name, "scrypt") != 0) - fprintf(fcfg, ",\n\"algorithm\" : \"%s\"", json_escape(opt_algorithm->name)); + if (strcmp(opt_algorithm.name, "scrypt") != 0) + fprintf(fcfg, ",\n\"algorithm\" : \"%s\"", json_escape(opt_algorithm.name)); if (opt_api_allow) fprintf(fcfg, ",\n\"api-allow\" : \"%s\"", json_escape(opt_api_allow)); if (strcmp(opt_api_mcast_addr, API_MCAST_ADDR) != 0) @@ -7409,7 +7409,7 @@ static bool input_pool(bool live) desc = curses_input("Description (optional)"); if (strcmp(desc, "-1") == 0) strcpy(desc, ""); algo = curses_input("Algorithm (optional)"); - if (strcmp(algo, "-1") == 0) strcpy(algo, opt_algorithm->name); + if (strcmp(algo, "-1") == 0) strcpy(algo, opt_algorithm.name); pool = add_pool(); @@ -7919,8 +7919,7 @@ int main(int argc, char *argv[]) #endif /* Default algorithm specified in algorithm.c ATM */ - opt_algorithm = (algorithm_t *)alloca(sizeof(algorithm_t)); - set_algorithm(opt_algorithm, "scrypt"); + set_algorithm(&opt_algorithm, "scrypt"); devcursor = 8; logstart = devcursor + 1;