Advertisement
Guest User

Untitled

a guest
Mar 27th, 2018
1,090
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 59.54 KB | None | 0 0
  1. /*
  2. * Copyright 2014 sgminer developers
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or (at
  7. * your option) any later version. See COPYING for more details.
  8. */
  9.  
  10. #include "algorithm.h"
  11. #include "driver-baikal.h"
  12. #include "sph/sph_sha2.h"
  13.  
  14. #ifdef USE_GPU
  15. #include "ocl.h"
  16. #include "ocl/build_kernel.h"
  17. #endif
  18.  
  19. #include "algorithm/scrypt.h"
  20. #include "algorithm/animecoin.h"
  21. #include "algorithm/inkcoin.h"
  22. #include "algorithm/quarkcoin.h"
  23. #include "algorithm/qubitcoin.h"
  24. #include "algorithm/sifcoin.h"
  25. #include "algorithm/darkcoin.h"
  26. #include "algorithm/myriadcoin-groestl.h"
  27. #include "algorithm/fuguecoin.h"
  28. #include "algorithm/groestlcoin.h"
  29. #include "algorithm/twecoin.h"
  30. #include "algorithm/marucoin.h"
  31. #include "algorithm/maxcoin.h"
  32. #include "algorithm/talkcoin.h"
  33. #include "algorithm/bitblock.h"
  34. #include "algorithm/x14.h"
  35. #include "algorithm/fresh.h"
  36. #include "algorithm/whirlcoin.h"
  37. #include "algorithm/neoscrypt.h"
  38. #include "algorithm/whirlpoolx.h"
  39. #include "algorithm/lyra2re.h"
  40. #include "algorithm/lyra2rev2.h"
  41. #include "algorithm/pluck.h"
  42. #include "algorithm/yescrypt.h"
  43. #include "algorithm/credits.h"
  44. #include "algorithm/blake256.h"
  45. #include "algorithm/blakecoin.h"
  46. #include "algorithm/sia.h"
  47. #include "algorithm/decred.h"
  48. #include "algorithm/pascal.h"
  49. #include "algorithm/lbry.h"
  50. #include "algorithm/sibcoin.h"
  51. #include "algorithm/cryptonight.h"
  52. #include "algorithm/skeincoin.h"
  53. #include "algorithm/veltor.h"
  54. #include "compat.h"
  55.  
  56. #include <inttypes.h>
  57. #include <string.h>
  58.  
  59. const char *algorithm_type_str[] = {
  60. "Unknown",
  61. "Credits",
  62. "Scrypt",
  63. "NScrypt",
  64. "Pascal",
  65. "X11",
  66. "X11Gost",
  67. "X13",
  68. "X14",
  69. "X15",
  70. "Keccak",
  71. "Quarkcoin",
  72. "Twecoin",
  73. "Fugue256",
  74. "NIST",
  75. "Fresh",
  76. "Whirlcoin",
  77. "Neoscrypt",
  78. "WhirlpoolX",
  79. "Lyra2RE",
  80. "Lyra2REV2",
  81. "Pluck",
  82. "Yescrypt",
  83. "Yescrypt-multi",
  84. "Blakecoin",
  85. "Blake",
  86. "Sia",
  87. "Decred",
  88. "Vanilla",
  89. "Lbry",
  90. "Cryptonight",
  91. "Cryptonight-lite",
  92. "Skeincoin",
  93. "Skein2",
  94. "Qubit",
  95. "MGroestl",
  96. "Groestl",
  97. "Nevacoin",
  98. "Diamond",
  99. "Veltor"
  100. };
  101.  
  102. void sha256(const unsigned char *message, unsigned int len, unsigned char *digest)
  103. {
  104. sph_sha256_context ctx_sha2;
  105.  
  106. sph_sha256_init(&ctx_sha2);
  107. sph_sha256(&ctx_sha2, message, len);
  108. sph_sha256_close(&ctx_sha2, (void*)digest);
  109. }
  110.  
  111. void gen_hash(const unsigned char *data, unsigned int len, unsigned char *hash)
  112. {
  113. unsigned char hash1[32];
  114. sph_sha256_context ctx_sha2;
  115.  
  116. sph_sha256_init(&ctx_sha2);
  117. sph_sha256(&ctx_sha2, data, len);
  118. sph_sha256_close(&ctx_sha2, hash1);
  119. sph_sha256(&ctx_sha2, hash1, 32);
  120. sph_sha256_close(&ctx_sha2, hash);
  121. }
  122.  
  123. void sha256d_midstate(struct work *work)
  124. {
  125. unsigned char data[64];
  126. uint32_t *data32 = (uint32_t *)data;
  127. sph_sha256_context ctx;
  128.  
  129. flip64(data32, work->data);
  130. sph_sha256_init(&ctx);
  131. sph_sha256(&ctx, data, 64);
  132. memcpy(work->midstate, ctx.val, 32);
  133. endian_flip32(work->midstate, work->midstate);
  134. }
  135.  
  136. #ifdef USE_GPU
  137. #define CL_SET_BLKARG(blkvar) status |= clSetKernelArg(*kernel, num++, sizeof(uint), (void *)&blk->blkvar)
  138. #define CL_SET_VARG(args, var) status |= clSetKernelArg(*kernel, num++, args * sizeof(uint), (void *)var)
  139. #define CL_SET_ARG_N(n, var) do { status |= clSetKernelArg(*kernel, n, sizeof(var), (void *)&var); } while (0)
  140. #define CL_SET_ARG_0(var) CL_SET_ARG_N(0, var)
  141. #define CL_SET_ARG(var) CL_SET_ARG_N(num++, var)
  142. #define CL_NEXTKERNEL_SET_ARG_N(n, var) do { kernel++; CL_SET_ARG_N(n, var); } while (0)
  143. #define CL_NEXTKERNEL_SET_ARG_0(var) CL_NEXTKERNEL_SET_ARG_N(0, var)
  144. #define CL_NEXTKERNEL_SET_ARG(var) CL_NEXTKERNEL_SET_ARG_N(num++, var)
  145.  
  146. static void append_scrypt_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
  147. {
  148. char buf[255];
  149. sprintf(buf, " -D LOOKUP_GAP=%d -D CONCURRENT_THREADS=%u -D NFACTOR=%d",
  150. cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency, algorithm->nfactor);
  151. strcat(data->compiler_options, buf);
  152.  
  153. sprintf(buf, "lg%utc%unf%u", cgpu->lookup_gap, (unsigned int)cgpu->thread_concurrency, algorithm->nfactor);
  154. strcat(data->binary_filename, buf);
  155. }
  156.  
  157. static void append_neoscrypt_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
  158. {
  159. char buf[255];
  160. sprintf(buf, " %s-D MAX_GLOBAL_THREADS=%lu ",
  161. ((cgpu->lookup_gap > 0) ? " -D LOOKUP_GAP=2 " : ""), (unsigned long)cgpu->thread_concurrency);
  162. strcat(data->compiler_options, buf);
  163.  
  164. sprintf(buf, "%stc%lu", ((cgpu->lookup_gap > 0) ? "lg" : ""), (unsigned long)cgpu->thread_concurrency);
  165. strcat(data->binary_filename, buf);
  166. }
  167.  
  168. static void append_blake256_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
  169. {
  170. char buf[255];
  171. sprintf(buf, " -D LOOKUP_GAP=%d -D MAX_GLOBAL_THREADS=%lu ",
  172. cgpu->lookup_gap, (unsigned long)cgpu->thread_concurrency);
  173. strcat(data->compiler_options, buf);
  174.  
  175. sprintf(buf, "tc%lu", (unsigned long)cgpu->thread_concurrency);
  176. strcat(data->binary_filename, buf);
  177. }
  178.  
  179. static void append_x11_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
  180. {
  181. char buf[255];
  182. sprintf(buf, " -D SPH_COMPACT_BLAKE_64=%d -D SPH_LUFFA_PARALLEL=%d -D SPH_KECCAK_UNROLL=%u ",
  183. ((opt_blake_compact) ? 1 : 0), ((opt_luffa_parallel) ? 1 : 0), (unsigned int)opt_keccak_unroll);
  184. strcat(data->compiler_options, buf);
  185.  
  186. sprintf(buf, "ku%u%s%s", (unsigned int)opt_keccak_unroll, ((opt_blake_compact) ? "bc" : ""), ((opt_luffa_parallel) ? "lp" : ""));
  187. strcat(data->binary_filename, buf);
  188. }
  189.  
  190.  
  191. static void append_x13_compiler_options(struct _build_kernel_data *data, struct cgpu_info *cgpu, struct _algorithm_t *algorithm)
  192. {
  193. char buf[255];
  194.  
  195. append_x11_compiler_options(data, cgpu, algorithm);
  196.  
  197. sprintf(buf, " -D SPH_HAMSI_EXPAND_BIG=%d -D SPH_HAMSI_SHORT=%d ",
  198. (unsigned int)opt_hamsi_expand_big, ((opt_hamsi_short) ? 1 : 0));
  199. strcat(data->compiler_options, buf);
  200.  
  201. sprintf(buf, "big%u%s", (unsigned int)opt_hamsi_expand_big, ((opt_hamsi_short) ? "hs" : ""));
  202. strcat(data->binary_filename, buf);
  203. }
  204.  
  205. static cl_int queue_scrypt_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  206. {
  207. unsigned char *midstate = blk->work->midstate;
  208. cl_kernel *kernel = &clState->kernel;
  209. unsigned int num = 0;
  210. cl_uint le_target;
  211. cl_int status = 0;
  212.  
  213. le_target = *(cl_uint *)(blk->work->device_target + 28);
  214. memcpy(clState->cldata, blk->work->data, 80);
  215. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  216.  
  217. CL_SET_ARG(clState->CLbuffer0);
  218. CL_SET_ARG(clState->outputBuffer);
  219. CL_SET_ARG(clState->padbuffer8);
  220. CL_SET_VARG(4, &midstate[0]);
  221. CL_SET_VARG(4, &midstate[16]);
  222. CL_SET_ARG(le_target);
  223.  
  224. return status;
  225. }
  226.  
  227. static cl_int queue_pascal_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  228. {
  229. cl_kernel *kernel = &clState->kernel;
  230. unsigned int num = 0;
  231. cl_ulong le_target;
  232. cl_int status = 0;
  233.  
  234. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  235. flip196(clState->cldata, blk->work->data);
  236. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 196, clState->cldata, 0, NULL, NULL);
  237.  
  238. CL_SET_ARG(clState->CLbuffer0);
  239. CL_SET_ARG(clState->outputBuffer);
  240. CL_SET_ARG(le_target);
  241. CL_SET_ARG(blk->work->midstate);
  242.  
  243. return status;
  244. }
  245.  
  246. static cl_int queue_neoscrypt_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  247. {
  248. cl_kernel *kernel = &clState->kernel;
  249. unsigned int num = 0;
  250. cl_uint le_target;
  251. cl_int status = 0;
  252.  
  253. /* This looks like a unnecessary double cast, but to make sure, that
  254. * the target's most significant entry is adressed as a 32-bit value
  255. * and not accidently by something else the double cast seems wise.
  256. * The compiler will get rid of it anyway. */
  257. le_target = (cl_uint)le32toh(((uint32_t *)blk->work->/*device_*/target)[7]);
  258. memcpy(clState->cldata, blk->work->data, 80);
  259. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  260.  
  261. CL_SET_ARG(clState->CLbuffer0);
  262. CL_SET_ARG(clState->outputBuffer);
  263. CL_SET_ARG(clState->padbuffer8);
  264. CL_SET_ARG(le_target);
  265.  
  266. return status;
  267. }
  268.  
  269. static cl_int queue_credits_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  270. {
  271. cl_kernel *kernel = &clState->kernel;
  272. unsigned int num = 0;
  273. cl_ulong le_target;
  274. cl_int status = 0;
  275.  
  276.  
  277. // le_target = (*(cl_uint *)(blk->work->device_target + 24));
  278. le_target = (cl_ulong)le64toh(((uint64_t *)blk->work->/*device_*/target)[3]);
  279. // le_target = (cl_uint)((uint32_t *)blk->work->target)[6];
  280.  
  281.  
  282. memcpy(clState->cldata, blk->work->data, 168);
  283. // flip168(clState->cldata, blk->work->data);
  284. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 168, clState->cldata, 0, NULL, NULL);
  285.  
  286. CL_SET_ARG(clState->CLbuffer0);
  287. CL_SET_ARG(clState->outputBuffer);
  288. CL_SET_ARG(le_target);
  289. CL_SET_ARG(blk->work->midstate);
  290.  
  291. return status;
  292. }
  293.  
  294. static cl_int queue_yescrypt_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  295. {
  296. cl_kernel *kernel = &clState->kernel;
  297. unsigned int num = 0;
  298. cl_uint le_target;
  299. cl_int status = 0;
  300.  
  301.  
  302. // le_target = (*(cl_uint *)(blk->work->device_target + 28));
  303. le_target = (cl_uint)le32toh(((uint32_t *)blk->work->/*device_*/target)[7]);
  304. // le_target = (cl_uint)((uint32_t *)blk->work->target)[7];
  305.  
  306.  
  307. // memcpy(clState->cldata, blk->work->data, 80);
  308. flip80(clState->cldata, blk->work->data);
  309. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  310.  
  311. CL_SET_ARG(clState->CLbuffer0);
  312. CL_SET_ARG(clState->outputBuffer);
  313. CL_SET_ARG(clState->padbuffer8);
  314. CL_SET_ARG(clState->buffer1);
  315. CL_SET_ARG(clState->buffer2);
  316. CL_SET_ARG(le_target);
  317.  
  318. return status;
  319. }
  320.  
  321. static cl_int queue_yescrypt_multikernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  322. {
  323. // cl_kernel *kernel = &clState->kernel;
  324. cl_kernel *kernel;
  325. unsigned int num = 0;
  326. cl_uint le_target;
  327. cl_int status = 0;
  328.  
  329.  
  330. // le_target = (*(cl_uint *)(blk->work->device_target + 28));
  331. le_target = (cl_uint)le32toh(((uint32_t *)blk->work->/*device_*/target)[7]);
  332. memcpy(clState->cldata, blk->work->data, 80);
  333. // flip80(clState->cldata, blk->work->data);
  334. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  335. //pbkdf and initial sha
  336. kernel = &clState->kernel;
  337.  
  338. CL_SET_ARG(clState->CLbuffer0);
  339. CL_SET_ARG(clState->outputBuffer);
  340. CL_SET_ARG(clState->padbuffer8);
  341. CL_SET_ARG(clState->buffer1);
  342. CL_SET_ARG(clState->buffer2);
  343. CL_SET_ARG(clState->buffer3);
  344. CL_SET_ARG(le_target);
  345.  
  346. //inactive kernel
  347. num = 0;
  348. kernel = clState->extra_kernels;
  349. CL_SET_ARG_N(0,clState->buffer1);
  350. CL_SET_ARG_N(1,clState->buffer2);
  351. // CL_SET_ARG_N(3, clState->buffer3);
  352.  
  353. //mix2_2
  354. num = 0;
  355. CL_NEXTKERNEL_SET_ARG_N(0, clState->padbuffer8);
  356. CL_SET_ARG_N(1,clState->buffer1);
  357. CL_SET_ARG_N(2,clState->buffer2);
  358. //mix2_2
  359. //inactive kernel
  360. num = 0;
  361. CL_NEXTKERNEL_SET_ARG_N(0, clState->buffer1);
  362. CL_SET_ARG_N(1, clState->buffer2);
  363. //mix2_2
  364.  
  365. num = 0;
  366. CL_NEXTKERNEL_SET_ARG_N(0, clState->padbuffer8);
  367. CL_SET_ARG_N(1, clState->buffer1);
  368. CL_SET_ARG_N(2, clState->buffer2);
  369.  
  370. //inactive kernel
  371. num = 0;
  372. CL_NEXTKERNEL_SET_ARG_N(0, clState->buffer1);
  373. CL_SET_ARG_N(1, clState->buffer2);
  374. //mix2_2
  375.  
  376.  
  377. //pbkdf and finalization
  378. num=0;
  379. CL_NEXTKERNEL_SET_ARG(clState->CLbuffer0);
  380. CL_SET_ARG(clState->outputBuffer);
  381. CL_SET_ARG(clState->buffer2);
  382. CL_SET_ARG(clState->buffer3);
  383. CL_SET_ARG(le_target);
  384.  
  385. return status;
  386. }
  387.  
  388. static cl_int queue_maxcoin_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  389. {
  390. cl_kernel *kernel = &clState->kernel;
  391. unsigned int num = 0;
  392. cl_int status = 0;
  393.  
  394. flip80(clState->cldata, blk->work->data);
  395. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  396.  
  397. CL_SET_ARG(clState->CLbuffer0);
  398. CL_SET_ARG(clState->outputBuffer);
  399.  
  400. return status;
  401. }
  402.  
  403. static cl_int queue_sph_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  404. {
  405. cl_kernel *kernel = &clState->kernel;
  406. unsigned int num = 0;
  407. cl_ulong le_target;
  408. cl_int status = 0;
  409.  
  410. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  411. flip80(clState->cldata, blk->work->data);
  412. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  413.  
  414. CL_SET_ARG(clState->CLbuffer0);
  415. CL_SET_ARG(clState->outputBuffer);
  416. CL_SET_ARG(le_target);
  417.  
  418. return status;
  419. }
  420.  
  421. static cl_int queue_darkcoin_mod_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  422. {
  423. cl_kernel *kernel;
  424. unsigned int num;
  425. cl_ulong le_target;
  426. cl_int status = 0;
  427.  
  428. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  429. flip80(clState->cldata, blk->work->data);
  430. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  431.  
  432. // blake - search
  433. kernel = &clState->kernel;
  434. num = 0;
  435. CL_SET_ARG(clState->CLbuffer0);
  436. CL_SET_ARG(clState->padbuffer8);
  437. // bmw - search1
  438. kernel = clState->extra_kernels;
  439. CL_SET_ARG_0(clState->padbuffer8);
  440. // groestl - search2
  441. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  442. // skein - search3
  443. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  444. // jh - search4
  445. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  446. // keccak - search5
  447. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  448. // luffa - search6
  449. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  450. // cubehash - search7
  451. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  452. // shavite - search8
  453. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  454. // simd - search9
  455. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  456. // echo - search10
  457. num = 0;
  458. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  459. CL_SET_ARG(clState->outputBuffer);
  460. CL_SET_ARG(le_target);
  461.  
  462. return status;
  463. }
  464.  
  465.  
  466. static cl_int queue_sibcoin_mod_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  467. {
  468. cl_kernel *kernel;
  469. unsigned int num;
  470. cl_ulong le_target;
  471. cl_int status = 0;
  472.  
  473. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  474. flip80(clState->cldata, blk->work->data);
  475. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  476.  
  477. // blake - search
  478. kernel = &clState->kernel;
  479. num = 0;
  480. CL_SET_ARG(clState->CLbuffer0);
  481. CL_SET_ARG(clState->padbuffer8);
  482. // bmw - search1
  483. kernel = clState->extra_kernels;
  484. CL_SET_ARG_0(clState->padbuffer8);
  485. // groestl - search2
  486. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  487. // skein - search3
  488. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  489. // jh - search4
  490. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  491. // keccak - search5
  492. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  493. // gost - search6
  494. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  495. // luffa - search7
  496. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  497. // cubehash - search8
  498. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  499. // shavite - search9
  500. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  501. // simd - search10
  502. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  503. // echo - search11
  504. num = 0;
  505. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  506. CL_SET_ARG(clState->outputBuffer);
  507. CL_SET_ARG(le_target);
  508.  
  509. return status;
  510. }
  511.  
  512. static cl_int queue_veltor_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  513. {
  514. cl_kernel *kernel;
  515. unsigned int num;
  516. cl_ulong le_target;
  517. cl_int status = 0;
  518.  
  519. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  520. flip80(clState->cldata, blk->work->data);
  521. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  522. // skein80 search()
  523. kernel = &clState->kernel;
  524. num = 0;
  525. CL_SET_ARG(clState->CLbuffer0);
  526. CL_SET_ARG(clState->padbuffer8);
  527. // shavite search1()
  528. kernel = clState->extra_kernels;
  529. CL_SET_ARG_0(clState->padbuffer8);
  530. // shabal search2()
  531. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  532. // streebog search3()
  533. num = 0;
  534. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  535. CL_SET_ARG(clState->outputBuffer);
  536. CL_SET_ARG(le_target);
  537.  
  538. return status;
  539. }
  540.  
  541. static cl_int queue_bitblock_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  542. {
  543. cl_kernel *kernel;
  544. unsigned int num;
  545. cl_ulong le_target;
  546. cl_int status = 0;
  547.  
  548. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  549. flip80(clState->cldata, blk->work->data);
  550. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  551.  
  552. // blake - search
  553. kernel = &clState->kernel;
  554. num = 0;
  555. CL_SET_ARG(clState->CLbuffer0);
  556. CL_SET_ARG(clState->padbuffer8);
  557. // bmw - search1
  558. kernel = clState->extra_kernels;
  559. CL_SET_ARG_0(clState->padbuffer8);
  560. // groestl - search2
  561. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  562. // skein - search3
  563. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  564. // jh - search4
  565. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  566. // keccak - search5
  567. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  568. // luffa - search6
  569. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  570. // cubehash - search7
  571. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  572. // shavite - search8
  573. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  574. // simd - search9
  575. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  576. // echo - search10
  577. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  578. // hamsi - search11
  579. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  580. // fugue - search12
  581. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  582. // hamsi - search11
  583. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  584. // fugue - search12
  585. num = 0;
  586. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  587. CL_SET_ARG(clState->outputBuffer);
  588. CL_SET_ARG(le_target);
  589.  
  590. return status;
  591. }
  592.  
  593. static cl_int queue_bitblockold_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  594. {
  595. cl_kernel *kernel;
  596. unsigned int num;
  597. cl_ulong le_target;
  598. cl_int status = 0;
  599.  
  600. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  601. flip80(clState->cldata, blk->work->data);
  602. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  603.  
  604. // blake - search
  605. kernel = &clState->kernel;
  606. num = 0;
  607. CL_SET_ARG(clState->CLbuffer0);
  608. CL_SET_ARG(clState->padbuffer8);
  609. // bmw - search1
  610. kernel = clState->extra_kernels;
  611. CL_SET_ARG_0(clState->padbuffer8);
  612. // groestl - search2
  613. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  614. // skein - search3
  615. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  616. // jh - search4
  617. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  618. // keccak - search5
  619. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  620. // luffa - search6
  621. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  622. // cubehash - search7
  623. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  624. // shavite - search8
  625. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  626. // simd - search9
  627. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  628. // combined echo, hamsi, fugue - shabal - whirlpool - search10
  629. num = 0;
  630. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  631. CL_SET_ARG(clState->outputBuffer);
  632. CL_SET_ARG(le_target);
  633.  
  634. return status;
  635. }
  636.  
  637.  
  638. static cl_int queue_marucoin_mod_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  639. {
  640. cl_kernel *kernel;
  641. unsigned int num;
  642. cl_ulong le_target;
  643. cl_int status = 0;
  644.  
  645. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  646. flip80(clState->cldata, blk->work->data);
  647. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  648.  
  649. // blake - search
  650. kernel = &clState->kernel;
  651. num = 0;
  652. CL_SET_ARG(clState->CLbuffer0);
  653. CL_SET_ARG(clState->padbuffer8);
  654. // bmw - search1
  655. kernel = clState->extra_kernels;
  656. CL_SET_ARG_0(clState->padbuffer8);
  657. // groestl - search2
  658. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  659. // skein - search3
  660. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  661. // jh - search4
  662. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  663. // keccak - search5
  664. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  665. // luffa - search6
  666. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  667. // cubehash - search7
  668. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  669. // shavite - search8
  670. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  671. // simd - search9
  672. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  673. // echo - search10
  674. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  675. // hamsi - search11
  676. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  677. // fugue - search12
  678. num = 0;
  679. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  680. CL_SET_ARG(clState->outputBuffer);
  681. CL_SET_ARG(le_target);
  682.  
  683. return status;
  684. }
  685.  
  686. static cl_int queue_marucoin_mod_old_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  687. {
  688. cl_kernel *kernel;
  689. unsigned int num;
  690. cl_ulong le_target;
  691. cl_int status = 0;
  692.  
  693. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  694. flip80(clState->cldata, blk->work->data);
  695. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  696.  
  697. // blake - search
  698. kernel = &clState->kernel;
  699. num = 0;
  700. CL_SET_ARG(clState->CLbuffer0);
  701. CL_SET_ARG(clState->padbuffer8);
  702. // bmw - search1
  703. kernel = clState->extra_kernels;
  704. CL_SET_ARG_0(clState->padbuffer8);
  705. // groestl - search2
  706. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  707. // skein - search3
  708. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  709. // jh - search4
  710. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  711. // keccak - search5
  712. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  713. // luffa - search6
  714. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  715. // cubehash - search7
  716. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  717. // shavite - search8
  718. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  719. // simd - search9
  720. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  721. // combined echo, hamsi, fugue - search10
  722. num = 0;
  723. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  724. CL_SET_ARG(clState->outputBuffer);
  725. CL_SET_ARG(le_target);
  726.  
  727. return status;
  728. }
  729.  
  730. static cl_int queue_talkcoin_mod_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  731. {
  732. cl_kernel *kernel;
  733. unsigned int num;
  734. cl_ulong le_target;
  735. cl_int status = 0;
  736.  
  737. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  738. flip80(clState->cldata, blk->work->data);
  739. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  740.  
  741. // blake - search
  742. kernel = &clState->kernel;
  743. num = 0;
  744. CL_SET_ARG(clState->CLbuffer0);
  745. CL_SET_ARG(clState->padbuffer8);
  746. // groestl - search1
  747. kernel = clState->extra_kernels;
  748. CL_SET_ARG_0(clState->padbuffer8);
  749. // jh - search2
  750. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  751. // keccak - search3
  752. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  753. // skein - search4
  754. num = 0;
  755. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  756. CL_SET_ARG(clState->outputBuffer);
  757. CL_SET_ARG(le_target);
  758.  
  759. return status;
  760. }
  761.  
  762. static cl_int queue_x14_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  763. {
  764. cl_kernel *kernel;
  765. unsigned int num;
  766. cl_ulong le_target;
  767. cl_int status = 0;
  768.  
  769. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  770. flip80(clState->cldata, blk->work->data);
  771. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  772.  
  773. // blake - search
  774. kernel = &clState->kernel;
  775. num = 0;
  776. CL_SET_ARG(clState->CLbuffer0);
  777. CL_SET_ARG(clState->padbuffer8);
  778. // bmw - search1
  779. kernel = clState->extra_kernels;
  780. CL_SET_ARG_0(clState->padbuffer8);
  781. // groestl - search2
  782. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  783. // skein - search3
  784. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  785. // jh - search4
  786. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  787. // keccak - search5
  788. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  789. // luffa - search6
  790. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  791. // cubehash - search7
  792. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  793. // shavite - search8
  794. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  795. // simd - search9
  796. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  797. // echo - search10
  798. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  799. // hamsi - search11
  800. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  801. // fugue - search12
  802. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  803. // shabal - search13
  804. num = 0;
  805. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  806. CL_SET_ARG(clState->outputBuffer);
  807. CL_SET_ARG(le_target);
  808.  
  809. return status;
  810. }
  811.  
  812. static cl_int queue_x14_old_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  813. {
  814. cl_kernel *kernel;
  815. unsigned int num;
  816. cl_ulong le_target;
  817. cl_int status = 0;
  818.  
  819. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  820. flip80(clState->cldata, blk->work->data);
  821. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  822.  
  823. // blake - search
  824. kernel = &clState->kernel;
  825. num = 0;
  826. CL_SET_ARG(clState->CLbuffer0);
  827. CL_SET_ARG(clState->padbuffer8);
  828. // bmw - search1
  829. kernel = clState->extra_kernels;
  830. CL_SET_ARG_0(clState->padbuffer8);
  831. // groestl - search2
  832. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  833. // skein - search3
  834. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  835. // jh - search4
  836. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  837. // keccak - search5
  838. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  839. // luffa - search6
  840. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  841. // cubehash - search7
  842. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  843. // shavite - search8
  844. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  845. // simd - search9
  846. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  847. // combined echo, hamsi, fugue - shabal - search10
  848. num = 0;
  849. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  850. CL_SET_ARG(clState->outputBuffer);
  851. CL_SET_ARG(le_target);
  852.  
  853. return status;
  854. }
  855.  
  856. static cl_int queue_fresh_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  857. {
  858. cl_kernel *kernel;
  859. unsigned int num;
  860. cl_ulong le_target;
  861. cl_int status = 0;
  862.  
  863. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  864. flip80(clState->cldata, blk->work->data);
  865. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  866.  
  867. // shavite 1 - search
  868. kernel = &clState->kernel;
  869. num = 0;
  870. CL_SET_ARG(clState->CLbuffer0);
  871. CL_SET_ARG(clState->padbuffer8);
  872. // smid 1 - search1
  873. kernel = clState->extra_kernels;
  874. CL_SET_ARG_0(clState->padbuffer8);
  875. // shavite 2 - search2
  876. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  877. // smid 2 - search3
  878. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  879. // echo - search4
  880. num = 0;
  881. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  882. CL_SET_ARG(clState->outputBuffer);
  883. CL_SET_ARG(le_target);
  884.  
  885. return status;
  886. }
  887.  
  888. static cl_int queue_whirlcoin_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  889. {
  890. cl_kernel *kernel;
  891. cl_ulong le_target;
  892. cl_int status = 0;
  893.  
  894. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  895. flip80(clState->cldata, blk->work->data);
  896. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  897.  
  898. //clbuffer, hashes
  899. kernel = &clState->kernel;
  900. CL_SET_ARG_N(0, clState->CLbuffer0);
  901. CL_SET_ARG_N(1, clState->padbuffer8);
  902.  
  903. kernel = clState->extra_kernels;
  904. CL_SET_ARG_N(0, clState->padbuffer8);
  905.  
  906. CL_NEXTKERNEL_SET_ARG_N(0, clState->padbuffer8);
  907.  
  908. //hashes, output, target
  909. CL_NEXTKERNEL_SET_ARG_N(0, clState->padbuffer8);
  910. CL_SET_ARG_N(1, clState->outputBuffer);
  911. CL_SET_ARG_N(2, le_target);
  912.  
  913. return status;
  914. }
  915.  
  916. static cl_int queue_whirlpoolx_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  917. {
  918. uint64_t midblock[8], key[8] = { 0 }, tmp[8] = { 0 };
  919. cl_ulong le_target;
  920. cl_int status;
  921.  
  922. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  923. flip80(clState->cldata, blk->work->data);
  924.  
  925. memcpy(midblock, clState->cldata, 64);
  926.  
  927. // midblock = n, key = h
  928. for (int i = 0; i < 10; ++i) {
  929. tmp[0] = WHIRLPOOL_ROUND_CONSTANTS[i];
  930. whirlpool_round(key, tmp);
  931. tmp[0] = 0;
  932. whirlpool_round(midblock, tmp);
  933.  
  934. for (int x = 0; x < 8; ++x) {
  935. midblock[x] ^= key[x];
  936. }
  937. }
  938.  
  939. for (int i = 0; i < 8; ++i) {
  940. midblock[i] ^= ((uint64_t *)(clState->cldata))[i];
  941. }
  942.  
  943. status = clSetKernelArg(clState->kernel, 0, sizeof(cl_ulong8), (cl_ulong8 *)&midblock);
  944. status |= clSetKernelArg(clState->kernel, 1, sizeof(cl_ulong), (void *)(((uint64_t *)clState->cldata) + 8));
  945. status |= clSetKernelArg(clState->kernel, 2, sizeof(cl_ulong), (void *)(((uint64_t *)clState->cldata) + 9));
  946. status |= clSetKernelArg(clState->kernel, 3, sizeof(cl_mem), (void *)&clState->outputBuffer);
  947. status |= clSetKernelArg(clState->kernel, 4, sizeof(cl_ulong), (void *)&le_target);
  948.  
  949. return status;
  950. }
  951.  
  952. static cl_int queue_lyra2re_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  953. {
  954. cl_kernel *kernel;
  955. unsigned int num;
  956. cl_int status = 0;
  957. cl_ulong le_target;
  958.  
  959. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  960. flip80(clState->cldata, blk->work->data);
  961. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  962.  
  963. // blake - search
  964. kernel = &clState->kernel;
  965. num = 0;
  966.  
  967. CL_SET_ARG(clState->padbuffer8);
  968. CL_SET_ARG(blk->work->blk.ctx_a);
  969. CL_SET_ARG(blk->work->blk.ctx_b);
  970. CL_SET_ARG(blk->work->blk.ctx_c);
  971. CL_SET_ARG(blk->work->blk.ctx_d);
  972. CL_SET_ARG(blk->work->blk.ctx_e);
  973. CL_SET_ARG(blk->work->blk.ctx_f);
  974. CL_SET_ARG(blk->work->blk.ctx_g);
  975. CL_SET_ARG(blk->work->blk.ctx_h);
  976. CL_SET_ARG(blk->work->blk.cty_a);
  977. CL_SET_ARG(blk->work->blk.cty_b);
  978. CL_SET_ARG(blk->work->blk.cty_c);
  979.  
  980. // bmw - search1
  981. kernel = clState->extra_kernels;
  982. CL_SET_ARG_0(clState->padbuffer8);
  983. // groestl - search2
  984. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  985. // skein - search3
  986. CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
  987. // jh - search4
  988. num = 0;
  989. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  990. CL_SET_ARG(clState->outputBuffer);
  991. CL_SET_ARG(le_target);
  992.  
  993. return status;
  994. }
  995.  
  996. static cl_int queue_lyra2rev2_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  997. {
  998. cl_kernel *kernel;
  999. unsigned int num;
  1000. cl_int status = 0;
  1001. cl_ulong le_target;
  1002.  
  1003. // le_target = *(cl_uint *)(blk->work->device_target + 28);
  1004. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  1005. flip80(clState->cldata, blk->work->data);
  1006. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  1007.  
  1008. // blake - search
  1009. kernel = &clState->kernel;
  1010. num = 0;
  1011. // CL_SET_ARG(clState->CLbuffer0);
  1012. CL_SET_ARG(clState->buffer1);
  1013. CL_SET_ARG(blk->work->blk.ctx_a);
  1014. CL_SET_ARG(blk->work->blk.ctx_b);
  1015. CL_SET_ARG(blk->work->blk.ctx_c);
  1016. CL_SET_ARG(blk->work->blk.ctx_d);
  1017. CL_SET_ARG(blk->work->blk.ctx_e);
  1018. CL_SET_ARG(blk->work->blk.ctx_f);
  1019. CL_SET_ARG(blk->work->blk.ctx_g);
  1020. CL_SET_ARG(blk->work->blk.ctx_h);
  1021. CL_SET_ARG(blk->work->blk.cty_a);
  1022. CL_SET_ARG(blk->work->blk.cty_b);
  1023. CL_SET_ARG(blk->work->blk.cty_c);
  1024.  
  1025. // keccak - search1
  1026. kernel = clState->extra_kernels;
  1027. CL_SET_ARG_0(clState->buffer1);
  1028. // cubehash - search2
  1029. num = 0;
  1030. CL_NEXTKERNEL_SET_ARG_0(clState->buffer1);
  1031. // lyra - search3
  1032. num = 0;
  1033. CL_NEXTKERNEL_SET_ARG_N(0, clState->buffer1);
  1034. CL_SET_ARG_N(1, clState->padbuffer8);
  1035. // skein -search4
  1036. num = 0;
  1037. CL_NEXTKERNEL_SET_ARG_0(clState->buffer1);
  1038. // cubehash - search5
  1039. num = 0;
  1040. CL_NEXTKERNEL_SET_ARG_0(clState->buffer1);
  1041. // bmw - search6
  1042. num = 0;
  1043. CL_NEXTKERNEL_SET_ARG(clState->buffer1);
  1044. CL_SET_ARG(clState->outputBuffer);
  1045. CL_SET_ARG(le_target);
  1046.  
  1047. return status;
  1048. }
  1049.  
  1050. static cl_int queue_pluck_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  1051. {
  1052. cl_kernel *kernel = &clState->kernel;
  1053. unsigned int num = 0;
  1054. cl_uint le_target;
  1055. cl_int status = 0;
  1056.  
  1057. le_target = (cl_uint)le32toh(((uint32_t *)blk->work->/*device_*/target)[7]);
  1058. flip80(clState->cldata, blk->work->data);
  1059. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  1060.  
  1061. CL_SET_ARG(clState->CLbuffer0);
  1062. CL_SET_ARG(clState->outputBuffer);
  1063. CL_SET_ARG(clState->padbuffer8);
  1064. CL_SET_ARG(le_target);
  1065.  
  1066. return status;
  1067. }
  1068.  
  1069. static cl_int queue_blake_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  1070. {
  1071. cl_kernel *kernel = &clState->kernel;
  1072. unsigned int num = 0;
  1073. cl_int status = 0;
  1074. cl_ulong le_target;
  1075.  
  1076. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  1077. flip80(clState->cldata, blk->work->data);
  1078. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  1079.  
  1080. CL_SET_ARG(clState->outputBuffer);
  1081. CL_SET_ARG(blk->work->blk.ctx_a);
  1082. CL_SET_ARG(blk->work->blk.ctx_b);
  1083. CL_SET_ARG(blk->work->blk.ctx_c);
  1084. CL_SET_ARG(blk->work->blk.ctx_d);
  1085. CL_SET_ARG(blk->work->blk.ctx_e);
  1086. CL_SET_ARG(blk->work->blk.ctx_f);
  1087. CL_SET_ARG(blk->work->blk.ctx_g);
  1088. CL_SET_ARG(blk->work->blk.ctx_h);
  1089.  
  1090. CL_SET_ARG(blk->work->blk.cty_a);
  1091. CL_SET_ARG(blk->work->blk.cty_b);
  1092. CL_SET_ARG(blk->work->blk.cty_c);
  1093.  
  1094. return status;
  1095. }
  1096.  
  1097. static cl_int queue_sia_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  1098. {
  1099. cl_kernel *kernel = &clState->kernel;
  1100. unsigned int num = 0;
  1101. cl_ulong le_target;
  1102. cl_int status = 0;
  1103.  
  1104. le_target = *(cl_ulong *)(blk->work->device_target + 24);
  1105. flip80(clState->cldata, blk->work->data);
  1106. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL, NULL);
  1107.  
  1108. CL_SET_ARG(clState->CLbuffer0);
  1109. CL_SET_ARG(clState->outputBuffer);
  1110. CL_SET_ARG(le_target);
  1111.  
  1112. return status;
  1113. }
  1114.  
  1115. static cl_int queue_decred_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  1116. {
  1117. cl_kernel *kernel = &clState->kernel;
  1118. unsigned int num = 0;
  1119. cl_int status = 0;
  1120.  
  1121. CL_SET_ARG(clState->outputBuffer);
  1122. /* Midstate */
  1123. CL_SET_BLKARG(ctx_a);
  1124. CL_SET_BLKARG(ctx_b);
  1125. CL_SET_BLKARG(ctx_c);
  1126. CL_SET_BLKARG(ctx_d);
  1127. CL_SET_BLKARG(ctx_e);
  1128. CL_SET_BLKARG(ctx_f);
  1129. CL_SET_BLKARG(ctx_g);
  1130. CL_SET_BLKARG(ctx_h);
  1131. /* Last 52 bytes of data (without nonce) */
  1132. CL_SET_BLKARG(cty_a);
  1133. CL_SET_BLKARG(cty_b);
  1134. CL_SET_BLKARG(cty_c);
  1135. CL_SET_BLKARG(cty_d);
  1136. CL_SET_BLKARG(cty_e);
  1137. CL_SET_BLKARG(cty_f);
  1138. CL_SET_BLKARG(cty_g);
  1139. CL_SET_BLKARG(cty_h);
  1140. CL_SET_BLKARG(cty_i);
  1141. CL_SET_BLKARG(cty_j);
  1142. CL_SET_BLKARG(cty_k);
  1143. CL_SET_BLKARG(cty_l);
  1144.  
  1145. return status;
  1146. }
  1147.  
  1148. static cl_int queue_cryptonight_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  1149. {
  1150. cl_kernel *kernel = &clState->kernel;
  1151. unsigned int num = 0;
  1152. cl_int status = 0, tgt32 = (blk->work->XMRTarget);
  1153. cl_ulong le_target = ((cl_ulong)(blk->work->XMRTarget));
  1154.  
  1155. //le_target = *(cl_ulong *)(blk->work->device_target + 24);
  1156. memcpy(clState->cldata, blk->work->data, 76);
  1157.  
  1158. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 76, clState->cldata , 0, NULL, NULL);
  1159.  
  1160. CL_SET_ARG(clState->CLbuffer0);
  1161. CL_SET_ARG(clState->Scratchpads);
  1162. CL_SET_ARG(clState->States);
  1163.  
  1164. num = 0;
  1165. kernel = clState->extra_kernels;
  1166. CL_SET_ARG(clState->Scratchpads);
  1167. CL_SET_ARG(clState->States);
  1168.  
  1169. num = 0;
  1170. CL_NEXTKERNEL_SET_ARG(clState->Scratchpads);
  1171. CL_SET_ARG(clState->States);
  1172. CL_SET_ARG(clState->BranchBuffer[0]);
  1173. CL_SET_ARG(clState->BranchBuffer[1]);
  1174. CL_SET_ARG(clState->BranchBuffer[2]);
  1175. CL_SET_ARG(clState->BranchBuffer[3]);
  1176.  
  1177. num = 0;
  1178. CL_NEXTKERNEL_SET_ARG(clState->States);
  1179. CL_SET_ARG(clState->BranchBuffer[0]);
  1180. CL_SET_ARG(clState->outputBuffer);
  1181. CL_SET_ARG(tgt32);
  1182.  
  1183. // last to be set in driver-opencl.c
  1184.  
  1185. num = 0;
  1186. CL_NEXTKERNEL_SET_ARG(clState->States);
  1187. CL_SET_ARG(clState->BranchBuffer[1]);
  1188. CL_SET_ARG(clState->outputBuffer);
  1189. CL_SET_ARG(tgt32);
  1190.  
  1191.  
  1192. num = 0;
  1193. CL_NEXTKERNEL_SET_ARG(clState->States);
  1194. CL_SET_ARG(clState->BranchBuffer[2]);
  1195. CL_SET_ARG(clState->outputBuffer);
  1196. CL_SET_ARG(tgt32);
  1197.  
  1198.  
  1199. num = 0;
  1200. CL_NEXTKERNEL_SET_ARG(clState->States);
  1201. CL_SET_ARG(clState->BranchBuffer[3]);
  1202. CL_SET_ARG(clState->outputBuffer);
  1203. CL_SET_ARG(tgt32);
  1204.  
  1205. return(status);
  1206. }
  1207.  
  1208. static cl_int queue_lbry_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  1209. {
  1210. cl_kernel *kernel = &clState->kernel;
  1211. unsigned int num = 0;
  1212. cl_ulong le_target;
  1213. cl_int status = 0;
  1214.  
  1215. le_target = *(cl_ulong *)(blk->work->target + 24);
  1216. flip112(clState->cldata, blk->work->data);
  1217. status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 112, clState->cldata, 0, NULL, NULL);
  1218.  
  1219. CL_SET_ARG(clState->CLbuffer0);
  1220. CL_SET_ARG(clState->padbuffer8);
  1221. num = 0;
  1222. kernel = clState->extra_kernels;
  1223. CL_SET_ARG_0(clState->padbuffer8);
  1224. num = 0;
  1225.  
  1226. CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
  1227. CL_SET_ARG(clState->outputBuffer);
  1228. CL_SET_ARG(le_target);
  1229.  
  1230. return status;
  1231. }
  1232.  
  1233.  
  1234. static cl_int queue_skeincoin_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads)
  1235. {
  1236. cl_kernel *kernel = &clState->kernel;
  1237. unsigned int num = 0;
  1238. cl_int status = 0;
  1239. int i;
  1240. for (i = 0; i < 8; i++) {
  1241. status |= clSetKernelArg(*kernel, num++, sizeof(cl_ulong), blk->ulongMidstate + i);
  1242. }
  1243. for (i = 0; i < 3; i++) {
  1244. status |= clSetKernelArg(*kernel, num++, sizeof(cl_uint), blk->ulongData + i);
  1245. }
  1246. CL_SET_ARG(clState->outputBuffer);
  1247.  
  1248. return status;
  1249. }
  1250.  
  1251. static algorithm_settings_t algos[] = {
  1252. // kernels starting from this will have difficulty calculated by using litecoin algorithm
  1253. #define A_SCRYPT(a) \
  1254. { a, ALGO_SCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFFFFFFULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, scrypt_regenhash, NULL, NULL, queue_scrypt_kernel, gen_hash, append_scrypt_compiler_options }
  1255. A_SCRYPT("ckolivas"),
  1256. A_SCRYPT("alexkarnew"),
  1257. A_SCRYPT("alexkarnold"),
  1258. A_SCRYPT("bufius"),
  1259. A_SCRYPT("psw"),
  1260. A_SCRYPT("zuikkis"),
  1261. A_SCRYPT("arebyp"),
  1262. #undef A_SCRYPT
  1263.  
  1264. #define A_NEOSCRYPT(a) \
  1265. { a, ALGO_NEOSCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, neoscrypt_regenhash, NULL, NULL, queue_neoscrypt_kernel, gen_hash, append_neoscrypt_compiler_options }
  1266. A_NEOSCRYPT("neoscrypt"),
  1267. #undef A_NEOSCRYPT
  1268.  
  1269. #define A_PLUCK(a) \
  1270. { a, ALGO_PLUCK, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, pluck_regenhash, NULL, NULL, queue_pluck_kernel, gen_hash, append_neoscrypt_compiler_options }
  1271. A_PLUCK("pluck"),
  1272. #undef A_PLUCK
  1273.  
  1274. #define A_CREDITS(a) \
  1275. { a, ALGO_CRE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, credits_regenhash, NULL, NULL, queue_credits_kernel, gen_hash, NULL}
  1276. A_CREDITS("credits"),
  1277. #undef A_CREDITS
  1278.  
  1279. #define A_DECRED(a) \
  1280. { a, ALGO_DECRED, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, decred_regenhash, decred_midstate, decred_prepare_work, queue_decred_kernel, gen_hash, append_blake256_compiler_options }
  1281. A_DECRED("decred"),
  1282. #undef A_DECRED
  1283.  
  1284. #define A_YESCRYPT(a) \
  1285. { a, ALGO_YESCRYPT, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 0, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, yescrypt_regenhash, NULL, NULL, queue_yescrypt_kernel, gen_hash, append_neoscrypt_compiler_options}
  1286. A_YESCRYPT("yescrypt"),
  1287. #undef A_YESCRYPT
  1288.  
  1289. #define A_YESCRYPT_MULTI(a) \
  1290. { a, ALGO_YESCRYPT_MULTI, "", 1, 65536, 65536, 0, 0, 0xFF, 0xFFFF000000000000ULL, 0x0000ffffUL, 6,-1,CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE , yescrypt_regenhash, NULL, NULL, queue_yescrypt_multikernel, gen_hash, append_neoscrypt_compiler_options}
  1291. A_YESCRYPT_MULTI("yescrypt-multi"),
  1292. #undef A_YESCRYPT_MULTI
  1293.  
  1294. // kernels starting from this will have difficulty calculated by using quarkcoin algorithm
  1295. #define A_QUARK(a, b) \
  1296. { a, ALGO_QUARK, "", 256, 256, 256, 0, 0, 0xFF, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, NULL, NULL, queue_sph_kernel, gen_hash, append_x11_compiler_options }
  1297. A_QUARK("quarkcoin", quarkcoin_regenhash),
  1298. A_QUARK("qubitcoin", qubitcoin_regenhash),
  1299. A_QUARK("animecoin", animecoin_regenhash),
  1300. A_QUARK("sifcoin", sifcoin_regenhash),
  1301. #undef A_QUARK
  1302.  
  1303. // kernels starting from this will have difficulty calculated by using bitcoin algorithm
  1304. #define A_DARK(a, b) \
  1305. { a, ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, NULL, NULL, queue_sph_kernel, gen_hash, append_x11_compiler_options }
  1306. A_DARK("darkcoin", darkcoin_regenhash),
  1307. A_DARK("inkcoin", inkcoin_regenhash),
  1308. #undef A_DARK
  1309.  
  1310. { "twecoin", ALGO_TWE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, twecoin_regenhash, NULL, NULL, queue_sph_kernel, sha256, NULL },
  1311. { "maxcoin", ALGO_KECCAK, "", 1, 256, 1, 4, 15, 0x0F, 0xFFFFULL, 0x000000ffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, maxcoin_regenhash, NULL, NULL, queue_maxcoin_kernel, sha256, NULL },
  1312.  
  1313. { "darkcoin-mod", ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, darkcoin_regenhash, NULL, NULL, queue_darkcoin_mod_kernel, gen_hash, append_x11_compiler_options },
  1314.  
  1315. { "sibcoin", ALGO_X11GOST, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, sibcoin_regenhash, NULL, NULL, queue_sph_kernel, gen_hash, append_x11_compiler_options },
  1316. { "sibcoin-mod", ALGO_X11GOST, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 11, 2 * 16 * 4194304, 0, sibcoin_regenhash, NULL, NULL, queue_sibcoin_mod_kernel, gen_hash, append_x11_compiler_options },
  1317.  
  1318. { "marucoin", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, marucoin_regenhash, NULL, NULL, queue_sph_kernel, gen_hash, append_x13_compiler_options },
  1319. { "marucoin-mod", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 12, 8 * 16 * 4194304, 0, marucoin_regenhash, NULL, NULL, queue_marucoin_mod_kernel, gen_hash, append_x13_compiler_options },
  1320. { "marucoin-modold", ALGO_X13, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, marucoin_regenhash, NULL, NULL, queue_marucoin_mod_old_kernel, gen_hash, append_x13_compiler_options },
  1321.  
  1322. { "x14", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 13, 8 * 16 * 4194304, 0, x14_regenhash, NULL, NULL, queue_x14_kernel, gen_hash, append_x13_compiler_options },
  1323. { "x14old", ALGO_X14, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 8 * 16 * 4194304, 0, x14_regenhash, NULL, NULL, queue_x14_old_kernel, gen_hash, append_x13_compiler_options },
  1324.  
  1325. { "bitblock", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 14, 4 * 16 * 4194304, 0, bitblock_regenhash, NULL, NULL, queue_bitblock_kernel, gen_hash, append_x13_compiler_options },
  1326. { "bitblockold", ALGO_X15, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 4 * 16 * 4194304, 0, bitblock_regenhash, NULL, NULL, queue_bitblockold_kernel, gen_hash, append_x13_compiler_options },
  1327.  
  1328. { "talkcoin-mod", ALGO_NIST, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 8 * 16 * 4194304, 0, talkcoin_regenhash, NULL, NULL, queue_talkcoin_mod_kernel, gen_hash, append_x11_compiler_options },
  1329.  
  1330. { "fresh", ALGO_FRESH, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 4 * 16 * 4194304, 0, fresh_regenhash, NULL, NULL, queue_fresh_kernel, gen_hash, NULL },
  1331.  
  1332. { "lyra2re", ALGO_LYRA2RE, "", 1, 128, 128, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 2 * 8 * 4194304, 0, lyra2re_regenhash, blake256_midstate, blake256_prepare_work, queue_lyra2re_kernel, gen_hash, NULL },
  1333. { "lyra2rev2", ALGO_LYRA2REV2, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, -1, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, lyra2rev2_regenhash, blake256_midstate, blake256_prepare_work, queue_lyra2rev2_kernel, gen_hash, append_neoscrypt_compiler_options },
  1334.  
  1335. { "myriadcoin-groestl", ALGO_MYRIAD_GROESTL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, myriadcoin_groestl_regenhash, NULL, NULL, queue_sph_kernel, gen_hash, append_x11_compiler_options },
  1336.  
  1337. // kernels starting from this will have difficulty calculated by using fuguecoin algorithm
  1338. #define A_FUGUE(a, b, c) \
  1339. { a, ALGO_FUGUE, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, NULL, NULL, queue_sph_kernel, c, NULL }
  1340. A_FUGUE("fuguecoin", fuguecoin_regenhash, sha256),
  1341. A_FUGUE("diamond", groestlcoin_regenhash, gen_hash),
  1342. #undef A_FUGUE
  1343. { "groestlcoin", ALGO_GROESTL, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, groestlcoin_regenhash, NULL, NULL, queue_sph_kernel, sha256, NULL },
  1344.  
  1345. { "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, NULL, NULL, queue_whirlcoin_kernel, sha256, NULL },
  1346. { "whirlpoolx", ALGO_WHIRLPOOLX, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000FFFFUL, 0, 0, 0, whirlpoolx_regenhash, NULL, NULL, queue_whirlpoolx_kernel, gen_hash, NULL },
  1347.  
  1348. { "blake256r8", ALGO_BLAKECOIN, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, 0, blakecoin_regenhash, blakecoin_midstate, blakecoin_prepare_work, queue_blake_kernel, sha256, NULL },
  1349. { "blake256r14", ALGO_BLAKE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x00000000UL, 0, 128, 0, blake256_regenhash, blake256_midstate, blake256_prepare_work, queue_blake_kernel, gen_hash, NULL },
  1350. #if SUPPORT_SIAPOOL
  1351. { "sia", ALGO_SIA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000FFFFUL, 0, 0, 0, sia_regenhash, NULL, NULL, queue_sia_kernel, sia_gen_hash, NULL },
  1352. #else
  1353. { "sia", ALGO_SIA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000FFFFUL, 0, 128, 0, sia_regenhash, NULL, NULL, queue_sia_kernel, NULL, NULL },
  1354. #endif
  1355. { "vanilla", ALGO_VANILLA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, 0, blakecoin_regenhash, blakecoin_midstate, blakecoin_prepare_work, queue_blake_kernel, gen_hash, NULL },
  1356.  
  1357. { "lbry", ALGO_LBRY, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 2, 4 * 8 * 4194304, 0, lbry_regenhash, NULL, NULL, queue_lbry_kernel, gen_hash, NULL },
  1358.  
  1359. { "pascal", ALGO_PASCAL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, pascal_regenhash, pascal_midstate, NULL, queue_pascal_kernel, NULL, NULL },
  1360. { "cryptonight", ALGO_CRYPTONIGHT, "", (1ULL << 32), (1ULL << 32), (1ULL << 32), 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, 0, 0, cryptonight_regenhash, NULL, NULL, queue_cryptonight_kernel, gen_hash, NULL },
  1361. { "cryptonight-lite", ALGO_CRYPTONIGHT_LITE, "", (1ULL << 32), (1ULL << 32), (1ULL << 32), 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, 0, 0, cryptonightlite_regenhash, NULL, NULL, queue_cryptonight_kernel, gen_hash, NULL },
  1362. { "skeincoin", ALGO_SKEINCOIN, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, skeincoin_regenhash, NULL, skeincoin_prepare_work, queue_skeincoin_kernel, gen_hash, NULL },
  1363. { "veltor", ALGO_VELTOR, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 3, 8 * 16 * 4194304, 0, veltor_regenhash, NULL, NULL, queue_veltor_kernel, gen_hash, append_x11_compiler_options },
  1364. // Terminator (do not remove)
  1365. { NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL }
  1366. };
  1367. #endif // USE_GPU
  1368.  
  1369.  
  1370. #ifdef USE_BAIKAL
  1371. static algorithm_settings_t algos[] = {
  1372. #if BAIKAL_TYPE & BAIKAL_1772
  1373. { "quark", ALGO_QUARK, "", 256, 256, 256, 0, 0, 0xFF, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, quarkcoin_regenhash, NULL, NULL, gen_hash },
  1374. { "qubit", ALGO_QUBIT, "", 256, 256, 256, 0, 0, 0xFF, 0xFFFFFFULL, 0x0000ffffUL, 0, 0, qubitcoin_regenhash, NULL, NULL, gen_hash },
  1375. { "x11", ALGO_X11, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, darkcoin_regenhash, NULL, NULL, gen_hash },
  1376. { "skein-sha256", ALGO_SKEINCOIN, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, skeincoin_regenhash, NULL, skeincoin_prepare_work, gen_hash },
  1377. { "myriadcoin-groestl", ALGO_MYRIAD_GROESTL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, myriadcoin_groestl_regenhash, NULL, NULL, gen_hash },
  1378. #if 0
  1379. { "groestl", ALGO_GROESTL, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, groestlcoin_regenhash, NULL, NULL, sha256 },
  1380. { "nist5", ALGO_NIST, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 8*16*4194304, talkcoin_regenhash, NULL, NULL, gen_hash },
  1381. { "x11-gost", ALGO_X11GOST, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, sibcoin_regenhash, NULL, NULL, gen_hash },
  1382. { "veltor", ALGO_VELTOR, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 3, 8*16*4194304, veltor_regenhash, NULL, NULL, gen_hash },
  1383. #endif
  1384. #endif
  1385.  
  1386. #if BAIKAL_TYPE & BAIKAL_1751
  1387. { "cryptonight", ALGO_CRYPTONIGHT, "", (1ULL << 32), (1ULL << 32), (1ULL << 32), 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, 0, cryptonight_regenhash, NULL, NULL, gen_hash },
  1388. { "cryptonight-lite", ALGO_CRYPTONIGHT_LITE, "", (1ULL << 32), (1ULL << 32), (1ULL << 32), 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 6, 0, cryptonightlite_regenhash, NULL, NULL, gen_hash },
  1389. #endif
  1390.  
  1391. #if BAIKAL_TYPE & BAIKAL_1791
  1392. { "blake256r8", ALGO_BLAKECOIN, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, blakecoin_regenhash, blakecoin_midstate, blakecoin_prepare_work, sha256 },
  1393. { "blake256r14", ALGO_BLAKE, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x00000000UL, 0, 128, blake256_regenhash, blake256_midstate, blake256_prepare_work, gen_hash },
  1394. { "decred", ALGO_DECRED, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x00000000UL, 0, 0, decred_regenhash, decred_midstate, decred_prepare_work, gen_hash },
  1395. { "vanilla", ALGO_VANILLA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x000000ffUL, 0, 128, blakecoin_regenhash, blakecoin_midstate, blakecoin_prepare_work, gen_hash },
  1396. #if SUPPORT_SIAPOOL
  1397. { "sia", ALGO_SIA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000FFFFUL, 0, 0, sia_regenhash, NULL, NULL, sia_gen_hash },
  1398. #else
  1399. { "sia", ALGO_SIA, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 128, sia_regenhash, NULL, NULL, NULL },
  1400. #endif
  1401. { "lbry", ALGO_LBRY, "", 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 2, 4*8*4194304, lbry_regenhash, NULL, NULL, gen_hash },
  1402. { "pascal", ALGO_PASCAL, "", 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, pascal_regenhash, pascal_midstate, NULL, NULL },
  1403. #endif
  1404.  
  1405. // Terminator (do not remove)
  1406. { NULL, ALGO_UNK, "", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL }
  1407. };
  1408. #endif
  1409.  
  1410. void copy_algorithm_settings(algorithm_t* dest, const char* algo)
  1411. {
  1412. algorithm_settings_t* src;
  1413.  
  1414. // Find algorithm settings and copy
  1415. for (src = algos; src->name; src++)
  1416. {
  1417. if (strcasecmp(src->name, algo) == 0)
  1418. {
  1419. strcpy(dest->name, src->name);
  1420. dest->kernelfile = src->kernelfile;
  1421. dest->type = src->type;
  1422.  
  1423. dest->diff_multiplier1 = src->diff_multiplier1;
  1424. dest->diff_multiplier2 = src->diff_multiplier2;
  1425. dest->share_diff_multiplier = src->share_diff_multiplier;
  1426. dest->xintensity_shift = src->xintensity_shift;
  1427. dest->intensity_shift = src->intensity_shift;
  1428. dest->found_idx = src->found_idx;
  1429. dest->diff_numerator = src->diff_numerator;
  1430. dest->diff1targ = src->diff1targ;
  1431. dest->n_extra_kernels = src->n_extra_kernels;
  1432. dest->rw_buffer_size = src->rw_buffer_size;
  1433. #ifdef USE_GPU
  1434. dest->cq_properties = src->cq_properties;
  1435. #endif
  1436. dest->regenhash = src->regenhash;
  1437. dest->calc_midstate = src->calc_midstate;
  1438. dest->prepare_work = src->prepare_work;
  1439. #ifdef USE_GPU
  1440. dest->queue_kernel = src->queue_kernel;
  1441. #endif
  1442. dest->gen_hash = src->gen_hash;
  1443. #ifdef USE_GPU
  1444. dest->set_compile_options = src->set_compile_options;
  1445. #endif
  1446. break;
  1447. }
  1448. }
  1449.  
  1450. // if not found
  1451. if (src->name == NULL)
  1452. {
  1453. applog(LOG_WARNING, "Algorithm %s not found, using %s.", algo, algos->name);
  1454. copy_algorithm_settings(dest, algos->name);
  1455. }
  1456. }
  1457.  
  1458. static const char *lookup_algorithm_alias(const char *lookup_alias, uint8_t *nfactor)
  1459. {
  1460. #define ALGO_ALIAS_NF(alias, name, nf) \
  1461. if (strcasecmp(alias, lookup_alias) == 0) { *nfactor = nf; return name; }
  1462. #define ALGO_ALIAS(alias, name) \
  1463. if (strcasecmp(alias, lookup_alias) == 0) return name;
  1464.  
  1465. ALGO_ALIAS_NF("scrypt", "ckolivas", 10);
  1466. ALGO_ALIAS_NF("scrypt", "ckolivas", 10);
  1467. ALGO_ALIAS_NF("adaptive-n-factor", "ckolivas", 11);
  1468. ALGO_ALIAS_NF("adaptive-nfactor", "ckolivas", 11);
  1469. ALGO_ALIAS_NF("nscrypt", "ckolivas", 11);
  1470. ALGO_ALIAS_NF("adaptive-nscrypt", "ckolivas", 11);
  1471. ALGO_ALIAS_NF("adaptive-n-scrypt", "ckolivas", 11);
  1472. #ifdef USE_BAIKAL
  1473. #if BAIKAL_TYPE & BAIKAL_1772
  1474. ALGO_ALIAS("darkcoin", "x11");
  1475. ALGO_ALIAS("darkcoin-mod", "x11");
  1476. ALGO_ALIAS("quarkcoin", "quark");
  1477. ALGO_ALIAS("qubitcoin", "qubit");
  1478. ALGO_ALIAS("skein", "skein-sha256");
  1479. ALGO_ALIAS("skeincoin", "skein-sha256");
  1480. ALGO_ALIAS("myr-gr", "myriadcoin-groestl");
  1481. #if 0
  1482. ALGO_ALIAS("groestlcoin", "groestl");
  1483. ALGO_ALIAS("talkcoin", "nist5");
  1484. ALGO_ALIAS("talkcoin-mod", "nist5");
  1485. ALGO_ALIAS("x11gost", "x11-gost");
  1486. ALGO_ALIAS("sibcoin", "x11-gost");
  1487. ALGO_ALIAS("sibcoin-mod", "x11-gost");
  1488. #endif
  1489. #endif
  1490.  
  1491. #if BAIKAL_TYPE & BAIKAL_1791
  1492. ALGO_ALIAS("vcash", "vanilla");
  1493. ALGO_ALIAS("blakecoin", "blake256r8");
  1494. ALGO_ALIAS("blake2b", "sia");
  1495. ALGO_ALIAS("lbry-sha", "pascal");
  1496. #endif
  1497.  
  1498. #else
  1499. ALGO_ALIAS("x11mod", "darkcoin");
  1500. ALGO_ALIAS("x11", "darkcoin");
  1501. ALGO_ALIAS("x11-gost", "sibcoin");
  1502. ALGO_ALIAS("x13mod", "marucoin");
  1503. ALGO_ALIAS("x13", "marucoin");
  1504. ALGO_ALIAS("x15", "bitblock");
  1505. ALGO_ALIAS("nist5", "talkcoin");
  1506. ALGO_ALIAS("blakecoin", "blake256r8");
  1507. ALGO_ALIAS("blake", "blake256r14");
  1508. ALGO_ALIAS("qubitcoin", "qubit");
  1509. ALGO_ALIAS("skein-sha256", "skeincoin");
  1510. #endif
  1511.  
  1512. #undef ALGO_ALIAS
  1513. #undef ALGO_ALIAS_NF
  1514.  
  1515. return NULL;
  1516. }
  1517.  
  1518. void set_algorithm(algorithm_t* algo, const char* newname_alias)
  1519. {
  1520. const char *newname;
  1521.  
  1522. //load previous algorithm nfactor in case nfactor was applied before algorithm... or default to 10
  1523. uint8_t old_nfactor = ((algo->nfactor) ? algo->nfactor : 0);
  1524. //load previous kernel file name if was applied before algorithm...
  1525. const char *kernelfile = algo->kernelfile;
  1526. uint8_t nfactor = 10;
  1527.  
  1528. if (!(newname = lookup_algorithm_alias(newname_alias, &nfactor)))
  1529. newname = newname_alias;
  1530.  
  1531. copy_algorithm_settings(algo, newname);
  1532.  
  1533. // use old nfactor if it was previously set and is different than the one set by alias
  1534. if ((old_nfactor > 0) && (old_nfactor != nfactor))
  1535. nfactor = old_nfactor;
  1536.  
  1537. set_algorithm_nfactor(algo, nfactor);
  1538.  
  1539. //reapply kernelfile if was set
  1540. if (!empty_string(kernelfile)) {
  1541. algo->kernelfile = kernelfile;
  1542. }
  1543. }
  1544.  
  1545. void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor)
  1546. {
  1547. algo->nfactor = nfactor;
  1548. algo->n = (1 << nfactor);
  1549.  
  1550. //adjust algo type accordingly
  1551. switch (algo->type)
  1552. {
  1553. case ALGO_SCRYPT:
  1554. //if nfactor isnt 10, switch to NSCRYPT
  1555. if (algo->nfactor != 10)
  1556. algo->type = ALGO_NSCRYPT;
  1557. break;
  1558. //nscrypt
  1559. case ALGO_NSCRYPT:
  1560. //if nfactor is 10, switch to SCRYPT
  1561. if (algo->nfactor == 10)
  1562. algo->type = ALGO_SCRYPT;
  1563. break;
  1564. //ignore rest
  1565. default:
  1566. break;
  1567. }
  1568. }
  1569.  
  1570. bool cmp_algorithm(const algorithm_t* algo1, const algorithm_t* algo2)
  1571. {
  1572. return (!safe_cmp(algo1->name, algo2->name) && !safe_cmp(algo1->kernelfile, algo2->kernelfile) && (algo1->nfactor == algo2->nfactor));
  1573. }
  1574.  
  1575. #ifdef USE_BAIKAL
  1576. int to_baikal_algorithm(algorithm_type_t type)
  1577. {
  1578. switch (type) {
  1579. #if BAIKAL_TYPE & BAIKAL_1772
  1580. case ALGO_X11:
  1581. return 0x01;
  1582. case ALGO_QUARK:
  1583. return 0x05;
  1584. case ALGO_QUBIT:
  1585. return 0x06;
  1586. case ALGO_SKEINCOIN:
  1587. return 0x08;
  1588. case ALGO_MYRIAD_GROESTL:
  1589. return 0x09;
  1590. #if 0
  1591. case ALGO_GROESTL:
  1592. return 0x0A;
  1593. case ALGO_NIST:
  1594. return 0x0C;
  1595. case ALGO_X11GOST:
  1596. return 0x07;
  1597. case ALGO_VELTOR:
  1598. return 0x0D;
  1599. #endif
  1600. #endif
  1601.  
  1602. #if BAIKAL_TYPE & BAIKAL_1751
  1603. case ALGO_CRYPTONIGHT:
  1604. return 0x20;
  1605. case ALGO_CRYPTONIGHT_LITE:
  1606. return 0x22;
  1607. #endif
  1608.  
  1609. #if BAIKAL_TYPE & BAIKAL_1791
  1610. case ALGO_BLAKECOIN:
  1611. case ALGO_VANILLA:
  1612. return 0x30;
  1613. case ALGO_DECRED: // input data 180byte
  1614. return 0x32;
  1615. case ALGO_SIA:
  1616. return 0x34;
  1617. case ALGO_LBRY:
  1618. return 0x36;
  1619. case ALGO_PASCAL:
  1620. return 0x37;
  1621. case ALGO_BLAKE: // input data 80byte
  1622. #endif
  1623. default:
  1624. return 0;
  1625. }
  1626. }
  1627. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement