From 9d1db95a28702883f10622759008018b1a470206 Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Mon, 20 Jan 2014 16:04:43 +0200 Subject: [PATCH 01/15] misc: move scrypt130511.cl kernel file to kernel/ckolivas.cl Prepare for more kernels. :) Get rid of the kernel date, since this fudges up commit history. Named after Con Kolivas, the most recent committer. --- Makefile.am | 4 ++-- configure.ac | 2 +- driver-opencl.c | 8 ++++---- scrypt130511.cl => kernel/ckolivas.cl | 0 miner.h | 2 +- ocl.c | 10 +++++----- sgminer.c | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) rename scrypt130511.cl => kernel/ckolivas.cl (100%) diff --git a/Makefile.am b/Makefile.am index d670d6bb..633727c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -37,7 +37,7 @@ sgminer_SOURCES += ocl.c ocl.h sgminer_SOURCES += findnonce.c findnonce.h sgminer_SOURCES += adl.c adl.h adl_functions.h sgminer_SOURCES += scrypt.c scrypt.h -sgminer_SOURCES += *.cl +sgminer_SOURCES += kernel/*.cl -bin_SCRIPTS = $(top_srcdir)/*.cl +bin_SCRIPTS = $(top_srcdir)/kernel/*.cl diff --git a/configure.ac b/configure.ac index 4197f16c..49978c2e 100644 --- a/configure.ac +++ b/configure.ac @@ -317,7 +317,7 @@ fi AC_DEFINE_UNQUOTED([SGMINER_PREFIX], ["$prefix/bin"], [Path to sgminer install]) -AC_DEFINE_UNQUOTED([SCRYPT_KERNNAME], ["scrypt130511"], [Filename for scrypt kernel]) +AC_DEFINE_UNQUOTED([CKOLIVAS_KERNNAME], ["ckolivas"], [Filename for original scrypt kernel]) AC_SUBST(OPENCL_LIBS) diff --git a/driver-opencl.c b/driver-opencl.c index 7d1cfc15..2d29707f 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -196,8 +196,8 @@ char *set_thread_concurrency(char *arg) static enum cl_kernels select_kernel(char *arg) { - if (!strcmp(arg, "scrypt")) - return KL_SCRYPT; + if (!strcmp(arg, "ckolivas")) + return KL_CKOLIVAS; return KL_NONE; } @@ -1210,7 +1210,7 @@ static bool opencl_thread_prepare(struct thr_info *thr) if (!cgpu->kname) { switch (clStates[i]->chosen_kernel) { - case KL_SCRYPT: + case KL_CKOLIVAS: cgpu->kname = "scrypt"; break; default: @@ -1241,7 +1241,7 @@ static bool opencl_thread_init(struct thr_info *thr) } switch (clState->chosen_kernel) { - case KL_SCRYPT: + case KL_CKOLIVAS: thrdata->queue_kernel_parameters = &queue_scrypt_kernel; break; default: diff --git a/scrypt130511.cl b/kernel/ckolivas.cl similarity index 100% rename from scrypt130511.cl rename to kernel/ckolivas.cl diff --git a/miner.h b/miner.h index a74e3056..13962217 100644 --- a/miner.h +++ b/miner.h @@ -372,7 +372,7 @@ enum dev_enable { enum cl_kernels { KL_NONE, - KL_SCRYPT, + KL_CKOLIVAS, }; enum dev_reason { diff --git a/ocl.c b/ocl.c index 84446a5e..3d2dc0d8 100644 --- a/ocl.c +++ b/ocl.c @@ -400,8 +400,8 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) char numbuf[16]; if (cgpu->kernel == KL_NONE) { - applog(LOG_INFO, "Selecting scrypt kernel"); - clState->chosen_kernel = KL_SCRYPT; + applog(LOG_INFO, "Selecting kernel ckolivas"); + clState->chosen_kernel = KL_CKOLIVAS; cgpu->kernel = clState->chosen_kernel; } else { clState->chosen_kernel = cgpu->kernel; @@ -416,9 +416,9 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) preferred_vwidth = 2; switch (clState->chosen_kernel) { - case KL_SCRYPT: - strcpy(filename, SCRYPT_KERNNAME".cl"); - strcpy(binaryfilename, SCRYPT_KERNNAME); + case KL_CKOLIVAS: + strcpy(filename, CKOLIVAS_KERNNAME".cl"); + strcpy(binaryfilename, CKOLIVAS_KERNNAME); /* Scrypt only supports vector 1 */ cgpu->vwidth = 1; break; diff --git a/sgminer.c b/sgminer.c index ffe4d5c0..06913134 100644 --- a/sgminer.c +++ b/sgminer.c @@ -4121,8 +4121,8 @@ void write_config(FILE *fcfg) switch (gpus[i].kernel) { case KL_NONE: // Shouldn't happen break; - case KL_SCRYPT: - fprintf(fcfg, "scrypt"); + case KL_CKOLIVAS: + fprintf(fcfg, "ckolivas"); break; } } From afdc8b5ffb08998b4e310468883539fa3a35d1df Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Mon, 20 Jan 2014 22:26:47 +0200 Subject: [PATCH 02/15] kernel: zuikkis' vanilla kernel added. Changed encoding to UTF-8. Will not build with sgminer (fix in next commit). http://www.reddit.com/r/dogecoin/comments/1ui3bx/increase_such_hashrate_1_to_5_scrypt_tweaking/ceir5na > It is pretty much stock, except that I have removed all the #pragma > unrolls, and optimized the inner scrypt_core loop. #pragma unroll does > not give any speedup here. > The idea is to move the "if (j&1)" comparison to outside of the lookup > loops. Then, if j&1 happens to be zero, the V[z] and X[z] loops can be > combined to a single loop, which gives the speedup! > This loop and the salsa function are the most important places in the > entire source, it probably spends over 90% of time in here.. There's > very little to be gained outside of these, I think. > Donations: DQj4t2DFMQtXofhstouyZw1sYUKWUJn4wv https://github.com/veox/sgminer/issues/4#issuecomment-32753290 > Most of these optimized kernels (including mine), have fixed > lookup-gap=2. However, I have never seen anyone use any other value, for > any GPU, so I think you could just remove the configurable value. > Or with some #if LOOKUP_GAP==2 magic it is of course possible to make > such source that allows any value. > Some users have reported slightly slower hashrate with my kernel as > well, but this could be some misconfiguration also.. If scrypt kernel > becomes faster, you may need to lower the GPU engine clock to get full > speed. Same as if you increase GPU clock too high, you will get a drop > in hash rate. > My source is free to use in sgminer. And if you diff to original you > will see that the changes are not very big. > Removing of #pragma unrolls helps in any GPU, in my opinion.. Current > compilers know better when unrolling helps. --- kernel/zuikkis.cl | 841 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 841 insertions(+) create mode 100644 kernel/zuikkis.cl diff --git a/kernel/zuikkis.cl b/kernel/zuikkis.cl new file mode 100644 index 00000000..99d23321 --- /dev/null +++ b/kernel/zuikkis.cl @@ -0,0 +1,841 @@ +/*- + * Copyright 2009 Colin Percival, 2011 ArtForz, 2011 pooler, 2012 mtrlt, + * 2012-2013 Con Kolivas. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ + +__constant uint ES[2] = { 0x00FF00FF, 0xFF00FF00 }; +__constant uint K[] = { + 0x428a2f98U, + 0x71374491U, + 0xb5c0fbcfU, + 0xe9b5dba5U, + 0x3956c25bU, + 0x59f111f1U, + 0x923f82a4U, + 0xab1c5ed5U, + 0xd807aa98U, + 0x12835b01U, + 0x243185beU, // 10 + 0x550c7dc3U, + 0x72be5d74U, + 0x80deb1feU, + 0x9bdc06a7U, + 0xe49b69c1U, + 0xefbe4786U, + 0x0fc19dc6U, + 0x240ca1ccU, + 0x2de92c6fU, + 0x4a7484aaU, // 20 + 0x5cb0a9dcU, + 0x76f988daU, + 0x983e5152U, + 0xa831c66dU, + 0xb00327c8U, + 0xbf597fc7U, + 0xc6e00bf3U, + 0xd5a79147U, + 0x06ca6351U, + 0x14292967U, // 30 + 0x27b70a85U, + 0x2e1b2138U, + 0x4d2c6dfcU, + 0x53380d13U, + 0x650a7354U, + 0x766a0abbU, + 0x81c2c92eU, + 0x92722c85U, + 0xa2bfe8a1U, + 0xa81a664bU, // 40 + 0xc24b8b70U, + 0xc76c51a3U, + 0xd192e819U, + 0xd6990624U, + 0xf40e3585U, + 0x106aa070U, + 0x19a4c116U, + 0x1e376c08U, + 0x2748774cU, + 0x34b0bcb5U, // 50 + 0x391c0cb3U, + 0x4ed8aa4aU, + 0x5b9cca4fU, + 0x682e6ff3U, + 0x748f82eeU, + 0x78a5636fU, + 0x84c87814U, + 0x8cc70208U, + 0x90befffaU, + 0xa4506cebU, // 60 + 0xbef9a3f7U, + 0xc67178f2U, + 0x98c7e2a2U, + 0xfc08884dU, + 0xcd2a11aeU, + 0x510e527fU, + 0x9b05688cU, + 0xC3910C8EU, + 0xfb6feee7U, + 0x2a01a605U, // 70 + 0x0c2e12e0U, + 0x4498517BU, + 0x6a09e667U, + 0xa4ce148bU, + 0x95F61999U, + 0xc19bf174U, + 0xBB67AE85U, + 0x3C6EF372U, + 0xA54FF53AU, + 0x1F83D9ABU, // 80 + 0x5BE0CD19U, + 0x5C5C5C5CU, + 0x36363636U, + 0x80000000U, + 0x000003FFU, + 0x00000280U, + 0x000004a0U, + 0x00000300U +}; + +#define rotl(x,y) rotate(x,y) +#define Ch(x,y,z) bitselect(z,y,x) +#define Maj(x,y,z) Ch((x^z),y,z) + +#define EndianSwap(n) (rotl(n & ES[0], 24U)|rotl(n & ES[1], 8U)) + +#define Tr2(x) (rotl(x, 30U) ^ rotl(x, 19U) ^ rotl(x, 10U)) +#define Tr1(x) (rotl(x, 26U) ^ rotl(x, 21U) ^ rotl(x, 7U)) +#define Wr2(x) (rotl(x, 25U) ^ rotl(x, 14U) ^ (x>>3U)) +#define Wr1(x) (rotl(x, 15U) ^ rotl(x, 13U) ^ (x>>10U)) + +#define RND(a, b, c, d, e, f, g, h, k) \ + h += Tr1(e); \ + h += Ch(e, f, g); \ + h += k; \ + d += h; \ + h += Tr2(a); \ + h += Maj(a, b, c); + +void SHA256(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) +{ + uint4 S0 = *state0; + uint4 S1 = *state1; + +#define A S0.x +#define B S0.y +#define C S0.z +#define D S0.w +#define E S1.x +#define F S1.y +#define G S1.z +#define H S1.w + + uint4 W[4]; + + W[ 0].x = block0.x; + RND(A,B,C,D,E,F,G,H, W[0].x+ K[0]); + W[ 0].y = block0.y; + RND(H,A,B,C,D,E,F,G, W[0].y+ K[1]); + W[ 0].z = block0.z; + RND(G,H,A,B,C,D,E,F, W[0].z+ K[2]); + W[ 0].w = block0.w; + RND(F,G,H,A,B,C,D,E, W[0].w+ K[3]); + + W[ 1].x = block1.x; + RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); + W[ 1].y = block1.y; + RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); + W[ 1].z = block1.z; + RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); + W[ 1].w = block1.w; + RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); + + W[ 2].x = block2.x; + RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); + W[ 2].y = block2.y; + RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); + W[ 2].z = block2.z; + RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); + W[ 2].w = block2.w; + RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); + + W[ 3].x = block3.x; + RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); + W[ 3].y = block3.y; + RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); + W[ 3].z = block3.z; + RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); + W[ 3].w = block3.w; + RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + + *state0 += S0; + *state1 += S1; +} + +void SHA256_fresh(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) +{ +#define A (*state0).x +#define B (*state0).y +#define C (*state0).z +#define D (*state0).w +#define E (*state1).x +#define F (*state1).y +#define G (*state1).z +#define H (*state1).w + + uint4 W[4]; + + W[0].x = block0.x; + D= K[63] +W[0].x; + H= K[64] +W[0].x; + + W[0].y = block0.y; + C= K[65] +Tr1(D)+Ch(D, K[66], K[67])+W[0].y; + G= K[68] +C+Tr2(H)+Ch(H, K[69] ,K[70]); + + W[0].z = block0.z; + B= K[71] +Tr1(C)+Ch(C,D,K[66])+W[0].z; + F= K[72] +B+Tr2(G)+Maj(G,H, K[73]); + + W[0].w = block0.w; + A= K[74] +Tr1(B)+Ch(B,C,D)+W[0].w; + E= K[75] +A+Tr2(F)+Maj(F,G,H); + + W[1].x = block1.x; + RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); + W[1].y = block1.y; + RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); + W[1].z = block1.z; + RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); + W[1].w = block1.w; + RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); + + W[2].x = block2.x; + RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); + W[2].y = block2.y; + RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); + W[2].z = block2.z; + RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); + W[2].w = block2.w; + RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); + + W[3].x = block3.x; + RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); + W[3].y = block3.y; + RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); + W[3].z = block3.z; + RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); + W[3].w = block3.w; + RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + + *state0 += (uint4)(K[73], K[77], K[78], K[79]); + *state1 += (uint4)(K[66], K[67], K[80], K[81]); +} + +__constant uint fixedW[64] = +{ + 0x428a2f99,0xf1374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, + 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf794, + 0xf59b89c2,0x73924787,0x23c6886e,0xa42ca65c,0x15ed3627,0x4d6edcbf,0xe28217fc,0xef02488f, + 0xb707775c,0x0468c23f,0xe7e72b4c,0x49e1f1a2,0x4b99c816,0x926d1570,0xaa0fc072,0xadb36e2c, + 0xad87a3ea,0xbcb1d3a3,0x7b993186,0x562b9420,0xbff3ca0c,0xda4b0c23,0x6cd8711a,0x8f337caa, + 0xc91b1417,0xc359dce1,0xa83253a7,0x3b13c12d,0x9d3d725d,0xd9031a84,0xb1a03340,0x16f58012, + 0xe64fb6a2,0xe84d923a,0xe93a5730,0x09837686,0x078ff753,0x29833341,0xd5de0b7e,0x6948ccf4, + 0xe0a1adbe,0x7c728e11,0x511c78e4,0x315b45bd,0xfca71413,0xea28f96a,0x79703128,0x4e1ef848, +}; + +void SHA256_fixed(uint4*restrict state0,uint4*restrict state1) +{ + uint4 S0 = *state0; + uint4 S1 = *state1; + +#define A S0.x +#define B S0.y +#define C S0.z +#define D S0.w +#define E S1.x +#define F S1.y +#define G S1.z +#define H S1.w + + RND(A,B,C,D,E,F,G,H, fixedW[0]); + RND(H,A,B,C,D,E,F,G, fixedW[1]); + RND(G,H,A,B,C,D,E,F, fixedW[2]); + RND(F,G,H,A,B,C,D,E, fixedW[3]); + RND(E,F,G,H,A,B,C,D, fixedW[4]); + RND(D,E,F,G,H,A,B,C, fixedW[5]); + RND(C,D,E,F,G,H,A,B, fixedW[6]); + RND(B,C,D,E,F,G,H,A, fixedW[7]); + RND(A,B,C,D,E,F,G,H, fixedW[8]); + RND(H,A,B,C,D,E,F,G, fixedW[9]); + RND(G,H,A,B,C,D,E,F, fixedW[10]); + RND(F,G,H,A,B,C,D,E, fixedW[11]); + RND(E,F,G,H,A,B,C,D, fixedW[12]); + RND(D,E,F,G,H,A,B,C, fixedW[13]); + RND(C,D,E,F,G,H,A,B, fixedW[14]); + RND(B,C,D,E,F,G,H,A, fixedW[15]); + RND(A,B,C,D,E,F,G,H, fixedW[16]); + RND(H,A,B,C,D,E,F,G, fixedW[17]); + RND(G,H,A,B,C,D,E,F, fixedW[18]); + RND(F,G,H,A,B,C,D,E, fixedW[19]); + RND(E,F,G,H,A,B,C,D, fixedW[20]); + RND(D,E,F,G,H,A,B,C, fixedW[21]); + RND(C,D,E,F,G,H,A,B, fixedW[22]); + RND(B,C,D,E,F,G,H,A, fixedW[23]); + RND(A,B,C,D,E,F,G,H, fixedW[24]); + RND(H,A,B,C,D,E,F,G, fixedW[25]); + RND(G,H,A,B,C,D,E,F, fixedW[26]); + RND(F,G,H,A,B,C,D,E, fixedW[27]); + RND(E,F,G,H,A,B,C,D, fixedW[28]); + RND(D,E,F,G,H,A,B,C, fixedW[29]); + RND(C,D,E,F,G,H,A,B, fixedW[30]); + RND(B,C,D,E,F,G,H,A, fixedW[31]); + RND(A,B,C,D,E,F,G,H, fixedW[32]); + RND(H,A,B,C,D,E,F,G, fixedW[33]); + RND(G,H,A,B,C,D,E,F, fixedW[34]); + RND(F,G,H,A,B,C,D,E, fixedW[35]); + RND(E,F,G,H,A,B,C,D, fixedW[36]); + RND(D,E,F,G,H,A,B,C, fixedW[37]); + RND(C,D,E,F,G,H,A,B, fixedW[38]); + RND(B,C,D,E,F,G,H,A, fixedW[39]); + RND(A,B,C,D,E,F,G,H, fixedW[40]); + RND(H,A,B,C,D,E,F,G, fixedW[41]); + RND(G,H,A,B,C,D,E,F, fixedW[42]); + RND(F,G,H,A,B,C,D,E, fixedW[43]); + RND(E,F,G,H,A,B,C,D, fixedW[44]); + RND(D,E,F,G,H,A,B,C, fixedW[45]); + RND(C,D,E,F,G,H,A,B, fixedW[46]); + RND(B,C,D,E,F,G,H,A, fixedW[47]); + RND(A,B,C,D,E,F,G,H, fixedW[48]); + RND(H,A,B,C,D,E,F,G, fixedW[49]); + RND(G,H,A,B,C,D,E,F, fixedW[50]); + RND(F,G,H,A,B,C,D,E, fixedW[51]); + RND(E,F,G,H,A,B,C,D, fixedW[52]); + RND(D,E,F,G,H,A,B,C, fixedW[53]); + RND(C,D,E,F,G,H,A,B, fixedW[54]); + RND(B,C,D,E,F,G,H,A, fixedW[55]); + RND(A,B,C,D,E,F,G,H, fixedW[56]); + RND(H,A,B,C,D,E,F,G, fixedW[57]); + RND(G,H,A,B,C,D,E,F, fixedW[58]); + RND(F,G,H,A,B,C,D,E, fixedW[59]); + RND(E,F,G,H,A,B,C,D, fixedW[60]); + RND(D,E,F,G,H,A,B,C, fixedW[61]); + RND(C,D,E,F,G,H,A,B, fixedW[62]); + RND(B,C,D,E,F,G,H,A, fixedW[63]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + *state0 += S0; + *state1 += S1; +} + +void shittify(uint4 B[8]) +{ + uint4 tmp[4]; + tmp[0] = (uint4)(B[1].x,B[2].y,B[3].z,B[0].w); + tmp[1] = (uint4)(B[2].x,B[3].y,B[0].z,B[1].w); + tmp[2] = (uint4)(B[3].x,B[0].y,B[1].z,B[2].w); + tmp[3] = (uint4)(B[0].x,B[1].y,B[2].z,B[3].w); + +//#pragma unroll + for(uint i=0; i<4; ++i) + B[i] = EndianSwap(tmp[i]); + + tmp[0] = (uint4)(B[5].x,B[6].y,B[7].z,B[4].w); + tmp[1] = (uint4)(B[6].x,B[7].y,B[4].z,B[5].w); + tmp[2] = (uint4)(B[7].x,B[4].y,B[5].z,B[6].w); + tmp[3] = (uint4)(B[4].x,B[5].y,B[6].z,B[7].w); + +//#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] = EndianSwap(tmp[i]); +} + +void unshittify(uint4 B[8]) +{ + uint4 tmp[4]; + tmp[0] = (uint4)(B[3].x,B[2].y,B[1].z,B[0].w); + tmp[1] = (uint4)(B[0].x,B[3].y,B[2].z,B[1].w); + tmp[2] = (uint4)(B[1].x,B[0].y,B[3].z,B[2].w); + tmp[3] = (uint4)(B[2].x,B[1].y,B[0].z,B[3].w); + +//#pragma unroll + for(uint i=0; i<4; ++i) + B[i] = EndianSwap(tmp[i]); + + tmp[0] = (uint4)(B[7].x,B[6].y,B[5].z,B[4].w); + tmp[1] = (uint4)(B[4].x,B[7].y,B[6].z,B[5].w); + tmp[2] = (uint4)(B[5].x,B[4].y,B[7].z,B[6].w); + tmp[3] = (uint4)(B[6].x,B[5].y,B[4].z,B[7].w); + +//#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] = EndianSwap(tmp[i]); +} + +void salsa(uint4 B[8]) +{ + uint4 w[4]; + +//#pragma unroll + for(uint i=0; i<4; ++i) + w[i] = (B[i]^=B[i+4]); + +//#pragma unroll + for(uint i=0; i<4; ++i) + { + w[0] ^= rotl(w[3] +w[2] , 7U); + w[1] ^= rotl(w[0] +w[3] , 9U); + w[2] ^= rotl(w[1] +w[0] ,13U); + w[3] ^= rotl(w[2] +w[1] ,18U); + w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); + w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); + w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); + w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); + } + +//#pragma unroll + for(uint i=0; i<4; ++i) + w[i] = (B[i+4]^=(B[i]+=w[i])); + +//#pragma unroll + for(uint i=0; i<4; ++i) + { + w[0] ^= rotl(w[3] +w[2] , 7U); + w[1] ^= rotl(w[0] +w[3] , 9U); + w[2] ^= rotl(w[1] +w[0] ,13U); + w[3] ^= rotl(w[2] +w[1] ,18U); + w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); + w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); + w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); + w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); + } + +//#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] += w[i]; +} + +#define Coord(x,y,z) x+y*(x ## SIZE)+z*(y ## SIZE)*(x ## SIZE) +#define CO Coord(z,x,y) + +void scrypt_core(uint4 X[8], __global uint4*restrict lookup) +{ + shittify(X); + const uint zSIZE = 8; + const uint ySIZE = (1024/LOOKUP_GAP+(1024%LOOKUP_GAP>0)); + const uint xSIZE = CONCURRENT_THREADS; + uint x = get_global_id(0)%xSIZE; + + for(uint y=0; y<1024/LOOKUP_GAP; ++y) + { +//#pragma unroll + for(uint z=0; z Date: Mon, 20 Jan 2014 23:32:44 +0200 Subject: [PATCH 03/15] kernel: integrate Zuikkis' kernel, selectable with `--kernel=zuikkis`. Kernel ckolivas is still the default. Needs documentation, too. https://github.com/veox/sgminer/issues/4 --- configure.ac | 1 + driver-opencl.c | 10 +++++++++- miner.h | 1 + ocl.c | 6 ++++++ sgminer.c | 3 +++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 49978c2e..ed4441ee 100644 --- a/configure.ac +++ b/configure.ac @@ -318,6 +318,7 @@ fi AC_DEFINE_UNQUOTED([SGMINER_PREFIX], ["$prefix/bin"], [Path to sgminer install]) AC_DEFINE_UNQUOTED([CKOLIVAS_KERNNAME], ["ckolivas"], [Filename for original scrypt kernel]) +AC_DEFINE_UNQUOTED([ZUIKKIS_KERNNAME], ["zuikkis"], [Filename for Zuikkis' optimised kernel]) AC_SUBST(OPENCL_LIBS) diff --git a/driver-opencl.c b/driver-opencl.c index 2d29707f..ec8e2faf 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -198,6 +198,8 @@ static enum cl_kernels select_kernel(char *arg) { if (!strcmp(arg, "ckolivas")) return KL_CKOLIVAS; + if (!strcmp(arg, "zuikkis")) + return KL_ZUIKKIS; return KL_NONE; } @@ -1211,7 +1213,10 @@ static bool opencl_thread_prepare(struct thr_info *thr) { switch (clStates[i]->chosen_kernel) { case KL_CKOLIVAS: - cgpu->kname = "scrypt"; + cgpu->kname = "ckolivas"; + break; + case KL_ZUIKKIS: + cgpu->kname = "zuikkis"; break; default: break; @@ -1244,6 +1249,9 @@ static bool opencl_thread_init(struct thr_info *thr) case KL_CKOLIVAS: thrdata->queue_kernel_parameters = &queue_scrypt_kernel; break; + case KL_ZUIKKIS: + thrdata->queue_kernel_parameters = &queue_scrypt_kernel; + break; default: break; } diff --git a/miner.h b/miner.h index 13962217..16231b29 100644 --- a/miner.h +++ b/miner.h @@ -373,6 +373,7 @@ enum dev_enable { enum cl_kernels { KL_NONE, KL_CKOLIVAS, + KL_ZUIKKIS, }; enum dev_reason { diff --git a/ocl.c b/ocl.c index 3d2dc0d8..c3b60b64 100644 --- a/ocl.c +++ b/ocl.c @@ -422,6 +422,12 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) /* Scrypt only supports vector 1 */ cgpu->vwidth = 1; break; + case KL_ZUIKKIS: + strcpy(filename, ZUIKKIS_KERNNAME".cl"); + strcpy(binaryfilename, ZUIKKIS_KERNNAME); + /* Scrypt only supports vector 1 */ + cgpu->vwidth = 1; + break; case KL_NONE: /* Shouldn't happen */ break; } diff --git a/sgminer.c b/sgminer.c index 06913134..6b1ee9ba 100644 --- a/sgminer.c +++ b/sgminer.c @@ -4124,6 +4124,9 @@ void write_config(FILE *fcfg) case KL_CKOLIVAS: fprintf(fcfg, "ckolivas"); break; + case KL_ZUIKKIS: + fprintf(fcfg, "zuikkis"); + break; } } fputs("\",\n\"lookup-gap\" : \"", fcfg); From f796aa51cab7c0d6bc3b316a66873e457e308abc Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Mon, 20 Jan 2014 23:47:24 +0200 Subject: [PATCH 04/15] kernel/misc: change ckolivas.cl encoding to UTF-8. --- kernel/ckolivas.cl | 1706 ++++++++++++++++++++++---------------------- 1 file changed, 853 insertions(+), 853 deletions(-) diff --git a/kernel/ckolivas.cl b/kernel/ckolivas.cl index a26143f8..b1e5dfac 100644 --- a/kernel/ckolivas.cl +++ b/kernel/ckolivas.cl @@ -1,853 +1,853 @@ -/*- - * Copyright 2009 Colin Percival, 2011 ArtForz, 2011 pooler, 2012 mtrlt, - * 2012-2013 Con Kolivas. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This file was originally written by Colin Percival as part of the Tarsnap - * online backup system. - */ - -__constant uint ES[2] = { 0x00FF00FF, 0xFF00FF00 }; -__constant uint K[] = { - 0x428a2f98U, - 0x71374491U, - 0xb5c0fbcfU, - 0xe9b5dba5U, - 0x3956c25bU, - 0x59f111f1U, - 0x923f82a4U, - 0xab1c5ed5U, - 0xd807aa98U, - 0x12835b01U, - 0x243185beU, // 10 - 0x550c7dc3U, - 0x72be5d74U, - 0x80deb1feU, - 0x9bdc06a7U, - 0xe49b69c1U, - 0xefbe4786U, - 0x0fc19dc6U, - 0x240ca1ccU, - 0x2de92c6fU, - 0x4a7484aaU, // 20 - 0x5cb0a9dcU, - 0x76f988daU, - 0x983e5152U, - 0xa831c66dU, - 0xb00327c8U, - 0xbf597fc7U, - 0xc6e00bf3U, - 0xd5a79147U, - 0x06ca6351U, - 0x14292967U, // 30 - 0x27b70a85U, - 0x2e1b2138U, - 0x4d2c6dfcU, - 0x53380d13U, - 0x650a7354U, - 0x766a0abbU, - 0x81c2c92eU, - 0x92722c85U, - 0xa2bfe8a1U, - 0xa81a664bU, // 40 - 0xc24b8b70U, - 0xc76c51a3U, - 0xd192e819U, - 0xd6990624U, - 0xf40e3585U, - 0x106aa070U, - 0x19a4c116U, - 0x1e376c08U, - 0x2748774cU, - 0x34b0bcb5U, // 50 - 0x391c0cb3U, - 0x4ed8aa4aU, - 0x5b9cca4fU, - 0x682e6ff3U, - 0x748f82eeU, - 0x78a5636fU, - 0x84c87814U, - 0x8cc70208U, - 0x90befffaU, - 0xa4506cebU, // 60 - 0xbef9a3f7U, - 0xc67178f2U, - 0x98c7e2a2U, - 0xfc08884dU, - 0xcd2a11aeU, - 0x510e527fU, - 0x9b05688cU, - 0xC3910C8EU, - 0xfb6feee7U, - 0x2a01a605U, // 70 - 0x0c2e12e0U, - 0x4498517BU, - 0x6a09e667U, - 0xa4ce148bU, - 0x95F61999U, - 0xc19bf174U, - 0xBB67AE85U, - 0x3C6EF372U, - 0xA54FF53AU, - 0x1F83D9ABU, // 80 - 0x5BE0CD19U, - 0x5C5C5C5CU, - 0x36363636U, - 0x80000000U, - 0x000003FFU, - 0x00000280U, - 0x000004a0U, - 0x00000300U -}; - -#define rotl(x,y) rotate(x,y) -#define Ch(x,y,z) bitselect(z,y,x) -#define Maj(x,y,z) Ch((x^z),y,z) - -#define EndianSwap(n) (rotl(n & ES[0], 24U)|rotl(n & ES[1], 8U)) - -#define Tr2(x) (rotl(x, 30U) ^ rotl(x, 19U) ^ rotl(x, 10U)) -#define Tr1(x) (rotl(x, 26U) ^ rotl(x, 21U) ^ rotl(x, 7U)) -#define Wr2(x) (rotl(x, 25U) ^ rotl(x, 14U) ^ (x>>3U)) -#define Wr1(x) (rotl(x, 15U) ^ rotl(x, 13U) ^ (x>>10U)) - -#define RND(a, b, c, d, e, f, g, h, k) \ - h += Tr1(e); \ - h += Ch(e, f, g); \ - h += k; \ - d += h; \ - h += Tr2(a); \ - h += Maj(a, b, c); - -void SHA256(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) -{ - uint4 S0 = *state0; - uint4 S1 = *state1; - -#define A S0.x -#define B S0.y -#define C S0.z -#define D S0.w -#define E S1.x -#define F S1.y -#define G S1.z -#define H S1.w - - uint4 W[4]; - - W[ 0].x = block0.x; - RND(A,B,C,D,E,F,G,H, W[0].x+ K[0]); - W[ 0].y = block0.y; - RND(H,A,B,C,D,E,F,G, W[0].y+ K[1]); - W[ 0].z = block0.z; - RND(G,H,A,B,C,D,E,F, W[0].z+ K[2]); - W[ 0].w = block0.w; - RND(F,G,H,A,B,C,D,E, W[0].w+ K[3]); - - W[ 1].x = block1.x; - RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); - W[ 1].y = block1.y; - RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); - W[ 1].z = block1.z; - RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); - W[ 1].w = block1.w; - RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); - - W[ 2].x = block2.x; - RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); - W[ 2].y = block2.y; - RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); - W[ 2].z = block2.z; - RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); - W[ 2].w = block2.w; - RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); - - W[ 3].x = block3.x; - RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); - W[ 3].y = block3.y; - RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); - W[ 3].z = block3.z; - RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); - W[ 3].w = block3.w; - RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); - - W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); - RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); - - W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); - RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); - - W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); - RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); - - W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); - RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); - - W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); - RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); - - W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); - RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); - - W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); - RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); - - W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); - RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); - - W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); - RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); - - W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); - RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); - - W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); - RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); - - W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); - RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); - - W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); - RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); - - W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); - RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); - - W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); - RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); - - W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); - RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); - - W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); - RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); - - W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); - RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); - - W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); - RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); - - W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); - RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); - - W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); - RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); - - W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); - RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); - - W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); - RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); - - W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); - RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); - - W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); - RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); - - W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); - RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); - - W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); - RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); - - W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); - RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); - - W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); - RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); - - W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); - RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); - - W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); - RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); - - W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); - RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); - - W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); - RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); - - W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); - RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); - - W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); - RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); - - W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); - RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); - - W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); - RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); - - W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); - RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); - - W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); - RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); - - W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); - RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); - - W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); - RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); - - W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); - RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); - - W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); - RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); - - W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); - RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); - - W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); - RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); - - W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); - RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); - - W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); - RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); - - W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); - RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); - -#undef A -#undef B -#undef C -#undef D -#undef E -#undef F -#undef G -#undef H - - *state0 += S0; - *state1 += S1; -} - -void SHA256_fresh(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) -{ -#define A (*state0).x -#define B (*state0).y -#define C (*state0).z -#define D (*state0).w -#define E (*state1).x -#define F (*state1).y -#define G (*state1).z -#define H (*state1).w - - uint4 W[4]; - - W[0].x = block0.x; - D= K[63] +W[0].x; - H= K[64] +W[0].x; - - W[0].y = block0.y; - C= K[65] +Tr1(D)+Ch(D, K[66], K[67])+W[0].y; - G= K[68] +C+Tr2(H)+Ch(H, K[69] ,K[70]); - - W[0].z = block0.z; - B= K[71] +Tr1(C)+Ch(C,D,K[66])+W[0].z; - F= K[72] +B+Tr2(G)+Maj(G,H, K[73]); - - W[0].w = block0.w; - A= K[74] +Tr1(B)+Ch(B,C,D)+W[0].w; - E= K[75] +A+Tr2(F)+Maj(F,G,H); - - W[1].x = block1.x; - RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); - W[1].y = block1.y; - RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); - W[1].z = block1.z; - RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); - W[1].w = block1.w; - RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); - - W[2].x = block2.x; - RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); - W[2].y = block2.y; - RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); - W[2].z = block2.z; - RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); - W[2].w = block2.w; - RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); - - W[3].x = block3.x; - RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); - W[3].y = block3.y; - RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); - W[3].z = block3.z; - RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); - W[3].w = block3.w; - RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); - - W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); - RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); - - W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); - RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); - - W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); - RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); - - W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); - RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); - - W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); - RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); - - W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); - RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); - - W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); - RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); - - W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); - RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); - - W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); - RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); - - W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); - RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); - - W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); - RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); - - W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); - RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); - - W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); - RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); - - W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); - RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); - - W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); - RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); - - W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); - RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); - - W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); - RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); - - W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); - RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); - - W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); - RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); - - W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); - RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); - - W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); - RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); - - W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); - RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); - - W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); - RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); - - W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); - RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); - - W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); - RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); - - W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); - RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); - - W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); - RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); - - W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); - RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); - - W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); - RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); - - W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); - RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); - - W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); - RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); - - W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); - RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); - - W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); - RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); - - W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); - RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); - - W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); - RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); - - W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); - RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); - - W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); - RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); - - W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); - RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); - - W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); - RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); - - W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); - RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); - - W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); - RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); - - W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); - RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); - - W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); - RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); - - W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); - RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); - - W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); - RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); - - W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); - RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); - - W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); - RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); - - W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); - RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); - -#undef A -#undef B -#undef C -#undef D -#undef E -#undef F -#undef G -#undef H - - *state0 += (uint4)(K[73], K[77], K[78], K[79]); - *state1 += (uint4)(K[66], K[67], K[80], K[81]); -} - -__constant uint fixedW[64] = -{ - 0x428a2f99,0xf1374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, - 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf794, - 0xf59b89c2,0x73924787,0x23c6886e,0xa42ca65c,0x15ed3627,0x4d6edcbf,0xe28217fc,0xef02488f, - 0xb707775c,0x0468c23f,0xe7e72b4c,0x49e1f1a2,0x4b99c816,0x926d1570,0xaa0fc072,0xadb36e2c, - 0xad87a3ea,0xbcb1d3a3,0x7b993186,0x562b9420,0xbff3ca0c,0xda4b0c23,0x6cd8711a,0x8f337caa, - 0xc91b1417,0xc359dce1,0xa83253a7,0x3b13c12d,0x9d3d725d,0xd9031a84,0xb1a03340,0x16f58012, - 0xe64fb6a2,0xe84d923a,0xe93a5730,0x09837686,0x078ff753,0x29833341,0xd5de0b7e,0x6948ccf4, - 0xe0a1adbe,0x7c728e11,0x511c78e4,0x315b45bd,0xfca71413,0xea28f96a,0x79703128,0x4e1ef848, -}; - -void SHA256_fixed(uint4*restrict state0,uint4*restrict state1) -{ - uint4 S0 = *state0; - uint4 S1 = *state1; - -#define A S0.x -#define B S0.y -#define C S0.z -#define D S0.w -#define E S1.x -#define F S1.y -#define G S1.z -#define H S1.w - - RND(A,B,C,D,E,F,G,H, fixedW[0]); - RND(H,A,B,C,D,E,F,G, fixedW[1]); - RND(G,H,A,B,C,D,E,F, fixedW[2]); - RND(F,G,H,A,B,C,D,E, fixedW[3]); - RND(E,F,G,H,A,B,C,D, fixedW[4]); - RND(D,E,F,G,H,A,B,C, fixedW[5]); - RND(C,D,E,F,G,H,A,B, fixedW[6]); - RND(B,C,D,E,F,G,H,A, fixedW[7]); - RND(A,B,C,D,E,F,G,H, fixedW[8]); - RND(H,A,B,C,D,E,F,G, fixedW[9]); - RND(G,H,A,B,C,D,E,F, fixedW[10]); - RND(F,G,H,A,B,C,D,E, fixedW[11]); - RND(E,F,G,H,A,B,C,D, fixedW[12]); - RND(D,E,F,G,H,A,B,C, fixedW[13]); - RND(C,D,E,F,G,H,A,B, fixedW[14]); - RND(B,C,D,E,F,G,H,A, fixedW[15]); - RND(A,B,C,D,E,F,G,H, fixedW[16]); - RND(H,A,B,C,D,E,F,G, fixedW[17]); - RND(G,H,A,B,C,D,E,F, fixedW[18]); - RND(F,G,H,A,B,C,D,E, fixedW[19]); - RND(E,F,G,H,A,B,C,D, fixedW[20]); - RND(D,E,F,G,H,A,B,C, fixedW[21]); - RND(C,D,E,F,G,H,A,B, fixedW[22]); - RND(B,C,D,E,F,G,H,A, fixedW[23]); - RND(A,B,C,D,E,F,G,H, fixedW[24]); - RND(H,A,B,C,D,E,F,G, fixedW[25]); - RND(G,H,A,B,C,D,E,F, fixedW[26]); - RND(F,G,H,A,B,C,D,E, fixedW[27]); - RND(E,F,G,H,A,B,C,D, fixedW[28]); - RND(D,E,F,G,H,A,B,C, fixedW[29]); - RND(C,D,E,F,G,H,A,B, fixedW[30]); - RND(B,C,D,E,F,G,H,A, fixedW[31]); - RND(A,B,C,D,E,F,G,H, fixedW[32]); - RND(H,A,B,C,D,E,F,G, fixedW[33]); - RND(G,H,A,B,C,D,E,F, fixedW[34]); - RND(F,G,H,A,B,C,D,E, fixedW[35]); - RND(E,F,G,H,A,B,C,D, fixedW[36]); - RND(D,E,F,G,H,A,B,C, fixedW[37]); - RND(C,D,E,F,G,H,A,B, fixedW[38]); - RND(B,C,D,E,F,G,H,A, fixedW[39]); - RND(A,B,C,D,E,F,G,H, fixedW[40]); - RND(H,A,B,C,D,E,F,G, fixedW[41]); - RND(G,H,A,B,C,D,E,F, fixedW[42]); - RND(F,G,H,A,B,C,D,E, fixedW[43]); - RND(E,F,G,H,A,B,C,D, fixedW[44]); - RND(D,E,F,G,H,A,B,C, fixedW[45]); - RND(C,D,E,F,G,H,A,B, fixedW[46]); - RND(B,C,D,E,F,G,H,A, fixedW[47]); - RND(A,B,C,D,E,F,G,H, fixedW[48]); - RND(H,A,B,C,D,E,F,G, fixedW[49]); - RND(G,H,A,B,C,D,E,F, fixedW[50]); - RND(F,G,H,A,B,C,D,E, fixedW[51]); - RND(E,F,G,H,A,B,C,D, fixedW[52]); - RND(D,E,F,G,H,A,B,C, fixedW[53]); - RND(C,D,E,F,G,H,A,B, fixedW[54]); - RND(B,C,D,E,F,G,H,A, fixedW[55]); - RND(A,B,C,D,E,F,G,H, fixedW[56]); - RND(H,A,B,C,D,E,F,G, fixedW[57]); - RND(G,H,A,B,C,D,E,F, fixedW[58]); - RND(F,G,H,A,B,C,D,E, fixedW[59]); - RND(E,F,G,H,A,B,C,D, fixedW[60]); - RND(D,E,F,G,H,A,B,C, fixedW[61]); - RND(C,D,E,F,G,H,A,B, fixedW[62]); - RND(B,C,D,E,F,G,H,A, fixedW[63]); - -#undef A -#undef B -#undef C -#undef D -#undef E -#undef F -#undef G -#undef H - *state0 += S0; - *state1 += S1; -} - -void shittify(uint4 B[8]) -{ - uint4 tmp[4]; - tmp[0] = (uint4)(B[1].x,B[2].y,B[3].z,B[0].w); - tmp[1] = (uint4)(B[2].x,B[3].y,B[0].z,B[1].w); - tmp[2] = (uint4)(B[3].x,B[0].y,B[1].z,B[2].w); - tmp[3] = (uint4)(B[0].x,B[1].y,B[2].z,B[3].w); - -#pragma unroll - for(uint i=0; i<4; ++i) - B[i] = EndianSwap(tmp[i]); - - tmp[0] = (uint4)(B[5].x,B[6].y,B[7].z,B[4].w); - tmp[1] = (uint4)(B[6].x,B[7].y,B[4].z,B[5].w); - tmp[2] = (uint4)(B[7].x,B[4].y,B[5].z,B[6].w); - tmp[3] = (uint4)(B[4].x,B[5].y,B[6].z,B[7].w); - -#pragma unroll - for(uint i=0; i<4; ++i) - B[i+4] = EndianSwap(tmp[i]); -} - -void unshittify(uint4 B[8]) -{ - uint4 tmp[4]; - tmp[0] = (uint4)(B[3].x,B[2].y,B[1].z,B[0].w); - tmp[1] = (uint4)(B[0].x,B[3].y,B[2].z,B[1].w); - tmp[2] = (uint4)(B[1].x,B[0].y,B[3].z,B[2].w); - tmp[3] = (uint4)(B[2].x,B[1].y,B[0].z,B[3].w); - -#pragma unroll - for(uint i=0; i<4; ++i) - B[i] = EndianSwap(tmp[i]); - - tmp[0] = (uint4)(B[7].x,B[6].y,B[5].z,B[4].w); - tmp[1] = (uint4)(B[4].x,B[7].y,B[6].z,B[5].w); - tmp[2] = (uint4)(B[5].x,B[4].y,B[7].z,B[6].w); - tmp[3] = (uint4)(B[6].x,B[5].y,B[4].z,B[7].w); - -#pragma unroll - for(uint i=0; i<4; ++i) - B[i+4] = EndianSwap(tmp[i]); -} - -void salsa(uint4 B[8]) -{ - uint4 w[4]; - -#pragma unroll - for(uint i=0; i<4; ++i) - w[i] = (B[i]^=B[i+4]); - -#pragma unroll - for(uint i=0; i<4; ++i) - { - w[0] ^= rotl(w[3] +w[2] , 7U); - w[1] ^= rotl(w[0] +w[3] , 9U); - w[2] ^= rotl(w[1] +w[0] ,13U); - w[3] ^= rotl(w[2] +w[1] ,18U); - w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); - w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); - w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); - w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); - } - -#pragma unroll - for(uint i=0; i<4; ++i) - w[i] = (B[i+4]^=(B[i]+=w[i])); - -#pragma unroll - for(uint i=0; i<4; ++i) - { - w[0] ^= rotl(w[3] +w[2] , 7U); - w[1] ^= rotl(w[0] +w[3] , 9U); - w[2] ^= rotl(w[1] +w[0] ,13U); - w[3] ^= rotl(w[2] +w[1] ,18U); - w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); - w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); - w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); - w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); - } - -#pragma unroll - for(uint i=0; i<4; ++i) - B[i+4] += w[i]; -} - -#define Coord(x,y,z) x+y*(x ## SIZE)+z*(y ## SIZE)*(x ## SIZE) -#define CO Coord(z,x,y) - -void scrypt_core(uint4 X[8], __global uint4*restrict lookup) -{ - shittify(X); - const uint zSIZE = 8; - const uint ySIZE = (1024/LOOKUP_GAP+(1024%LOOKUP_GAP>0)); - const uint xSIZE = CONCURRENT_THREADS; - uint x = get_global_id(0)%xSIZE; - - for(uint y=0; y<1024/LOOKUP_GAP; ++y) - { -#pragma unroll - for(uint z=0; z>3U)) +#define Wr1(x) (rotl(x, 15U) ^ rotl(x, 13U) ^ (x>>10U)) + +#define RND(a, b, c, d, e, f, g, h, k) \ + h += Tr1(e); \ + h += Ch(e, f, g); \ + h += k; \ + d += h; \ + h += Tr2(a); \ + h += Maj(a, b, c); + +void SHA256(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) +{ + uint4 S0 = *state0; + uint4 S1 = *state1; + +#define A S0.x +#define B S0.y +#define C S0.z +#define D S0.w +#define E S1.x +#define F S1.y +#define G S1.z +#define H S1.w + + uint4 W[4]; + + W[ 0].x = block0.x; + RND(A,B,C,D,E,F,G,H, W[0].x+ K[0]); + W[ 0].y = block0.y; + RND(H,A,B,C,D,E,F,G, W[0].y+ K[1]); + W[ 0].z = block0.z; + RND(G,H,A,B,C,D,E,F, W[0].z+ K[2]); + W[ 0].w = block0.w; + RND(F,G,H,A,B,C,D,E, W[0].w+ K[3]); + + W[ 1].x = block1.x; + RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); + W[ 1].y = block1.y; + RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); + W[ 1].z = block1.z; + RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); + W[ 1].w = block1.w; + RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); + + W[ 2].x = block2.x; + RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); + W[ 2].y = block2.y; + RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); + W[ 2].z = block2.z; + RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); + W[ 2].w = block2.w; + RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); + + W[ 3].x = block3.x; + RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); + W[ 3].y = block3.y; + RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); + W[ 3].z = block3.z; + RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); + W[ 3].w = block3.w; + RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + + *state0 += S0; + *state1 += S1; +} + +void SHA256_fresh(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) +{ +#define A (*state0).x +#define B (*state0).y +#define C (*state0).z +#define D (*state0).w +#define E (*state1).x +#define F (*state1).y +#define G (*state1).z +#define H (*state1).w + + uint4 W[4]; + + W[0].x = block0.x; + D= K[63] +W[0].x; + H= K[64] +W[0].x; + + W[0].y = block0.y; + C= K[65] +Tr1(D)+Ch(D, K[66], K[67])+W[0].y; + G= K[68] +C+Tr2(H)+Ch(H, K[69] ,K[70]); + + W[0].z = block0.z; + B= K[71] +Tr1(C)+Ch(C,D,K[66])+W[0].z; + F= K[72] +B+Tr2(G)+Maj(G,H, K[73]); + + W[0].w = block0.w; + A= K[74] +Tr1(B)+Ch(B,C,D)+W[0].w; + E= K[75] +A+Tr2(F)+Maj(F,G,H); + + W[1].x = block1.x; + RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); + W[1].y = block1.y; + RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); + W[1].z = block1.z; + RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); + W[1].w = block1.w; + RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); + + W[2].x = block2.x; + RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); + W[2].y = block2.y; + RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); + W[2].z = block2.z; + RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); + W[2].w = block2.w; + RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); + + W[3].x = block3.x; + RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); + W[3].y = block3.y; + RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); + W[3].z = block3.z; + RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); + W[3].w = block3.w; + RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + + *state0 += (uint4)(K[73], K[77], K[78], K[79]); + *state1 += (uint4)(K[66], K[67], K[80], K[81]); +} + +__constant uint fixedW[64] = +{ + 0x428a2f99,0xf1374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, + 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf794, + 0xf59b89c2,0x73924787,0x23c6886e,0xa42ca65c,0x15ed3627,0x4d6edcbf,0xe28217fc,0xef02488f, + 0xb707775c,0x0468c23f,0xe7e72b4c,0x49e1f1a2,0x4b99c816,0x926d1570,0xaa0fc072,0xadb36e2c, + 0xad87a3ea,0xbcb1d3a3,0x7b993186,0x562b9420,0xbff3ca0c,0xda4b0c23,0x6cd8711a,0x8f337caa, + 0xc91b1417,0xc359dce1,0xa83253a7,0x3b13c12d,0x9d3d725d,0xd9031a84,0xb1a03340,0x16f58012, + 0xe64fb6a2,0xe84d923a,0xe93a5730,0x09837686,0x078ff753,0x29833341,0xd5de0b7e,0x6948ccf4, + 0xe0a1adbe,0x7c728e11,0x511c78e4,0x315b45bd,0xfca71413,0xea28f96a,0x79703128,0x4e1ef848, +}; + +void SHA256_fixed(uint4*restrict state0,uint4*restrict state1) +{ + uint4 S0 = *state0; + uint4 S1 = *state1; + +#define A S0.x +#define B S0.y +#define C S0.z +#define D S0.w +#define E S1.x +#define F S1.y +#define G S1.z +#define H S1.w + + RND(A,B,C,D,E,F,G,H, fixedW[0]); + RND(H,A,B,C,D,E,F,G, fixedW[1]); + RND(G,H,A,B,C,D,E,F, fixedW[2]); + RND(F,G,H,A,B,C,D,E, fixedW[3]); + RND(E,F,G,H,A,B,C,D, fixedW[4]); + RND(D,E,F,G,H,A,B,C, fixedW[5]); + RND(C,D,E,F,G,H,A,B, fixedW[6]); + RND(B,C,D,E,F,G,H,A, fixedW[7]); + RND(A,B,C,D,E,F,G,H, fixedW[8]); + RND(H,A,B,C,D,E,F,G, fixedW[9]); + RND(G,H,A,B,C,D,E,F, fixedW[10]); + RND(F,G,H,A,B,C,D,E, fixedW[11]); + RND(E,F,G,H,A,B,C,D, fixedW[12]); + RND(D,E,F,G,H,A,B,C, fixedW[13]); + RND(C,D,E,F,G,H,A,B, fixedW[14]); + RND(B,C,D,E,F,G,H,A, fixedW[15]); + RND(A,B,C,D,E,F,G,H, fixedW[16]); + RND(H,A,B,C,D,E,F,G, fixedW[17]); + RND(G,H,A,B,C,D,E,F, fixedW[18]); + RND(F,G,H,A,B,C,D,E, fixedW[19]); + RND(E,F,G,H,A,B,C,D, fixedW[20]); + RND(D,E,F,G,H,A,B,C, fixedW[21]); + RND(C,D,E,F,G,H,A,B, fixedW[22]); + RND(B,C,D,E,F,G,H,A, fixedW[23]); + RND(A,B,C,D,E,F,G,H, fixedW[24]); + RND(H,A,B,C,D,E,F,G, fixedW[25]); + RND(G,H,A,B,C,D,E,F, fixedW[26]); + RND(F,G,H,A,B,C,D,E, fixedW[27]); + RND(E,F,G,H,A,B,C,D, fixedW[28]); + RND(D,E,F,G,H,A,B,C, fixedW[29]); + RND(C,D,E,F,G,H,A,B, fixedW[30]); + RND(B,C,D,E,F,G,H,A, fixedW[31]); + RND(A,B,C,D,E,F,G,H, fixedW[32]); + RND(H,A,B,C,D,E,F,G, fixedW[33]); + RND(G,H,A,B,C,D,E,F, fixedW[34]); + RND(F,G,H,A,B,C,D,E, fixedW[35]); + RND(E,F,G,H,A,B,C,D, fixedW[36]); + RND(D,E,F,G,H,A,B,C, fixedW[37]); + RND(C,D,E,F,G,H,A,B, fixedW[38]); + RND(B,C,D,E,F,G,H,A, fixedW[39]); + RND(A,B,C,D,E,F,G,H, fixedW[40]); + RND(H,A,B,C,D,E,F,G, fixedW[41]); + RND(G,H,A,B,C,D,E,F, fixedW[42]); + RND(F,G,H,A,B,C,D,E, fixedW[43]); + RND(E,F,G,H,A,B,C,D, fixedW[44]); + RND(D,E,F,G,H,A,B,C, fixedW[45]); + RND(C,D,E,F,G,H,A,B, fixedW[46]); + RND(B,C,D,E,F,G,H,A, fixedW[47]); + RND(A,B,C,D,E,F,G,H, fixedW[48]); + RND(H,A,B,C,D,E,F,G, fixedW[49]); + RND(G,H,A,B,C,D,E,F, fixedW[50]); + RND(F,G,H,A,B,C,D,E, fixedW[51]); + RND(E,F,G,H,A,B,C,D, fixedW[52]); + RND(D,E,F,G,H,A,B,C, fixedW[53]); + RND(C,D,E,F,G,H,A,B, fixedW[54]); + RND(B,C,D,E,F,G,H,A, fixedW[55]); + RND(A,B,C,D,E,F,G,H, fixedW[56]); + RND(H,A,B,C,D,E,F,G, fixedW[57]); + RND(G,H,A,B,C,D,E,F, fixedW[58]); + RND(F,G,H,A,B,C,D,E, fixedW[59]); + RND(E,F,G,H,A,B,C,D, fixedW[60]); + RND(D,E,F,G,H,A,B,C, fixedW[61]); + RND(C,D,E,F,G,H,A,B, fixedW[62]); + RND(B,C,D,E,F,G,H,A, fixedW[63]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + *state0 += S0; + *state1 += S1; +} + +void shittify(uint4 B[8]) +{ + uint4 tmp[4]; + tmp[0] = (uint4)(B[1].x,B[2].y,B[3].z,B[0].w); + tmp[1] = (uint4)(B[2].x,B[3].y,B[0].z,B[1].w); + tmp[2] = (uint4)(B[3].x,B[0].y,B[1].z,B[2].w); + tmp[3] = (uint4)(B[0].x,B[1].y,B[2].z,B[3].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i] = EndianSwap(tmp[i]); + + tmp[0] = (uint4)(B[5].x,B[6].y,B[7].z,B[4].w); + tmp[1] = (uint4)(B[6].x,B[7].y,B[4].z,B[5].w); + tmp[2] = (uint4)(B[7].x,B[4].y,B[5].z,B[6].w); + tmp[3] = (uint4)(B[4].x,B[5].y,B[6].z,B[7].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] = EndianSwap(tmp[i]); +} + +void unshittify(uint4 B[8]) +{ + uint4 tmp[4]; + tmp[0] = (uint4)(B[3].x,B[2].y,B[1].z,B[0].w); + tmp[1] = (uint4)(B[0].x,B[3].y,B[2].z,B[1].w); + tmp[2] = (uint4)(B[1].x,B[0].y,B[3].z,B[2].w); + tmp[3] = (uint4)(B[2].x,B[1].y,B[0].z,B[3].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i] = EndianSwap(tmp[i]); + + tmp[0] = (uint4)(B[7].x,B[6].y,B[5].z,B[4].w); + tmp[1] = (uint4)(B[4].x,B[7].y,B[6].z,B[5].w); + tmp[2] = (uint4)(B[5].x,B[4].y,B[7].z,B[6].w); + tmp[3] = (uint4)(B[6].x,B[5].y,B[4].z,B[7].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] = EndianSwap(tmp[i]); +} + +void salsa(uint4 B[8]) +{ + uint4 w[4]; + +#pragma unroll + for(uint i=0; i<4; ++i) + w[i] = (B[i]^=B[i+4]); + +#pragma unroll + for(uint i=0; i<4; ++i) + { + w[0] ^= rotl(w[3] +w[2] , 7U); + w[1] ^= rotl(w[0] +w[3] , 9U); + w[2] ^= rotl(w[1] +w[0] ,13U); + w[3] ^= rotl(w[2] +w[1] ,18U); + w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); + w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); + w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); + w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); + } + +#pragma unroll + for(uint i=0; i<4; ++i) + w[i] = (B[i+4]^=(B[i]+=w[i])); + +#pragma unroll + for(uint i=0; i<4; ++i) + { + w[0] ^= rotl(w[3] +w[2] , 7U); + w[1] ^= rotl(w[0] +w[3] , 9U); + w[2] ^= rotl(w[1] +w[0] ,13U); + w[3] ^= rotl(w[2] +w[1] ,18U); + w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); + w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); + w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); + w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); + } + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] += w[i]; +} + +#define Coord(x,y,z) x+y*(x ## SIZE)+z*(y ## SIZE)*(x ## SIZE) +#define CO Coord(z,x,y) + +void scrypt_core(uint4 X[8], __global uint4*restrict lookup) +{ + shittify(X); + const uint zSIZE = 8; + const uint ySIZE = (1024/LOOKUP_GAP+(1024%LOOKUP_GAP>0)); + const uint xSIZE = CONCURRENT_THREADS; + uint x = get_global_id(0)%xSIZE; + + for(uint y=0; y<1024/LOOKUP_GAP; ++y) + { +#pragma unroll + for(uint z=0; z Date: Mon, 20 Jan 2014 17:13:18 -0500 Subject: [PATCH 05/15] Replace multiply by 2 (i*2) with left shift. This should be slightly faster. Can't use OpenCL rotate becase of bit carry overs --- kernel/ckolivas.cl | 6 +++--- kernel/zuikkis.cl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/ckolivas.cl b/kernel/ckolivas.cl index b1e5dfac..6b264bc7 100644 --- a/kernel/ckolivas.cl +++ b/kernel/ckolivas.cl @@ -835,11 +835,11 @@ const uint4 midstate0, const uint4 midstate16, const uint target) { pad0 = tstate0; pad1 = tstate1; - X[i*2 ] = ostate0; - X[i*2+1] = ostate1; + X[i<<1 ] = ostate0; + X[(i<<1)+1] = ostate1; SHA256(&pad0,&pad1, data, (uint4)(i+1,K[84],0,0), (uint4)(0,0,0,0), (uint4)(0,0,0, K[87])); - SHA256(X+i*2,X+i*2+1, pad0, pad1, (uint4)(K[84], 0U, 0U, 0U), (uint4)(0U, 0U, 0U, K[88])); + SHA256(X+(i<<1),X+(i<<1)+1, pad0, pad1, (uint4)(K[84], 0U, 0U, 0U), (uint4)(0U, 0U, 0U, K[88])); } scrypt_core(X,padcache); SHA256(&tmp0,&tmp1, X[0], X[1], X[2], X[3]); diff --git a/kernel/zuikkis.cl b/kernel/zuikkis.cl index 99d23321..3b42574f 100644 --- a/kernel/zuikkis.cl +++ b/kernel/zuikkis.cl @@ -823,11 +823,11 @@ const uint4 midstate0, const uint4 midstate16, const uint target) { pad0 = tstate0; pad1 = tstate1; - X[i*2 ] = ostate0; - X[i*2+1] = ostate1; + X[i<<1 ] = ostate0; + X[(i<<1)+1] = ostate1; SHA256(&pad0,&pad1, data, (uint4)(i+1,K[84],0,0), (uint4)(0,0,0,0), (uint4)(0,0,0, K[87])); - SHA256(X+i*2,X+i*2+1, pad0, pad1, (uint4)(K[84], 0U, 0U, 0U), (uint4)(0U, 0U, 0U, K[88])); + SHA256(X+(i<<1),X+(i<<1)+1, pad0, pad1, (uint4)(K[84], 0U, 0U, 0U), (uint4)(0U, 0U, 0U, K[88])); } scrypt_core(X,padcache); SHA256(&tmp0,&tmp1, X[0], X[1], X[2], X[3]); From 81337e006484a76391eff9f932f4857c262f741d Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Tue, 21 Jan 2014 09:45:10 +0200 Subject: [PATCH 06/15] kernel: vanilla Alexey Karimov kernels (alexkarnew and alexkarold). alexkarnew: (for driver 13.4 and newer, and cgminer 3.3.1) alexkarold: (for older drivers than 13.4, and cgminer 3.3.1) https://litecointalk.org/index.php?topic=4082.0 > I was able to optimize the code of cgminer's scrypt.cl. > It gives 0-3% increase, depending on the drivers and hardware. > 1. Without optimization, when "CO" is used, every time > z+x*zSIZE+y*xSIZE*zSIZE is calculated. > I have created "CO" variable, and made so that x*SIZE is calculated only > once. Now, when "CO" is used, every time z+y*xSIZE*zSIZE is calculated. > In one case, variable y is incremented by 1 after 8 "CO" calculations. > I have created "CO_tmp" variable, where contains result of xSIZE*zSIZE. > And after 8 "CO" calculations I add "CO_tmp" to "CO". > Now, when "CO" is used, every time only z is calculated. It is faster as > z+x*zSIZE+y*xSIZE*zSIZE :) > In other case when "CO" is used, every time z+y*xSIZE*zSIZE is > calculated, but it faster than z+x*zSIZE+y*xSIZE*zSIZE too. > 2. I have replaced multiplication by 2 with bit rotation - it is faster. > For 7xxx cards you can try to set --thread-concurrency equal to (2^n + 1). > It may give a little more mining speed. > For example: 16385 (it is 2^14 + 1), 8193 (2^13 + 1), or 4097 (2^12 + 1). > I have almost no information, how it works on other series. > LMqRcHdwnZtTMH6c2kWoxSoKM5KySfaP5C --- kernel/alexkarnew.cl | 858 +++++++++++++++++++++++++++++++++++++++++++ kernel/alexkarold.cl | 855 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1713 insertions(+) create mode 100644 kernel/alexkarnew.cl create mode 100644 kernel/alexkarold.cl diff --git a/kernel/alexkarnew.cl b/kernel/alexkarnew.cl new file mode 100644 index 00000000..e936fdd1 --- /dev/null +++ b/kernel/alexkarnew.cl @@ -0,0 +1,858 @@ +/*- + * Copyright 2009 Colin Percival, 2011 ArtForz, 2011 pooler, 2012 mtrlt, + * 2012-2013 Con Kolivas, 2013 Alexey Karimov. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file was originally written by Colin Percival as part of the Tarsnap + * online backup system. + */ + +__constant uint ES[2] = { 0x00FF00FF, 0xFF00FF00 }; +__constant uint K[] = { + 0x428a2f98U, + 0x71374491U, + 0xb5c0fbcfU, + 0xe9b5dba5U, + 0x3956c25bU, + 0x59f111f1U, + 0x923f82a4U, + 0xab1c5ed5U, + 0xd807aa98U, + 0x12835b01U, + 0x243185beU, // 10 + 0x550c7dc3U, + 0x72be5d74U, + 0x80deb1feU, + 0x9bdc06a7U, + 0xe49b69c1U, + 0xefbe4786U, + 0x0fc19dc6U, + 0x240ca1ccU, + 0x2de92c6fU, + 0x4a7484aaU, // 20 + 0x5cb0a9dcU, + 0x76f988daU, + 0x983e5152U, + 0xa831c66dU, + 0xb00327c8U, + 0xbf597fc7U, + 0xc6e00bf3U, + 0xd5a79147U, + 0x06ca6351U, + 0x14292967U, // 30 + 0x27b70a85U, + 0x2e1b2138U, + 0x4d2c6dfcU, + 0x53380d13U, + 0x650a7354U, + 0x766a0abbU, + 0x81c2c92eU, + 0x92722c85U, + 0xa2bfe8a1U, + 0xa81a664bU, // 40 + 0xc24b8b70U, + 0xc76c51a3U, + 0xd192e819U, + 0xd6990624U, + 0xf40e3585U, + 0x106aa070U, + 0x19a4c116U, + 0x1e376c08U, + 0x2748774cU, + 0x34b0bcb5U, // 50 + 0x391c0cb3U, + 0x4ed8aa4aU, + 0x5b9cca4fU, + 0x682e6ff3U, + 0x748f82eeU, + 0x78a5636fU, + 0x84c87814U, + 0x8cc70208U, + 0x90befffaU, + 0xa4506cebU, // 60 + 0xbef9a3f7U, + 0xc67178f2U, + 0x98c7e2a2U, + 0xfc08884dU, + 0xcd2a11aeU, + 0x510e527fU, + 0x9b05688cU, + 0xC3910C8EU, + 0xfb6feee7U, + 0x2a01a605U, // 70 + 0x0c2e12e0U, + 0x4498517BU, + 0x6a09e667U, + 0xa4ce148bU, + 0x95F61999U, + 0xc19bf174U, + 0xBB67AE85U, + 0x3C6EF372U, + 0xA54FF53AU, + 0x1F83D9ABU, // 80 + 0x5BE0CD19U, + 0x5C5C5C5CU, + 0x36363636U, + 0x80000000U, + 0x000003FFU, + 0x00000280U, + 0x000004a0U, + 0x00000300U +}; + +#define rotl(x,y) rotate(x,y) +#define Ch(x,y,z) bitselect(z,y,x) +#define Maj(x,y,z) Ch((x^z),y,z) + +#define EndianSwap(n) (rotl(n & ES[0], 24U)|rotl(n & ES[1], 8U)) + +#define Tr2(x) (rotl(x, 30U) ^ rotl(x, 19U) ^ rotl(x, 10U)) +#define Tr1(x) (rotl(x, 26U) ^ rotl(x, 21U) ^ rotl(x, 7U)) +#define Wr2(x) (rotl(x, 25U) ^ rotl(x, 14U) ^ (x>>3U)) +#define Wr1(x) (rotl(x, 15U) ^ rotl(x, 13U) ^ (x>>10U)) + +#define RND(a, b, c, d, e, f, g, h, k) \ + h += Tr1(e); \ + h += Ch(e, f, g); \ + h += k; \ + d += h; \ + h += Tr2(a); \ + h += Maj(a, b, c); + +void SHA256(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) +{ + uint4 S0 = *state0; + uint4 S1 = *state1; + +#define A S0.x +#define B S0.y +#define C S0.z +#define D S0.w +#define E S1.x +#define F S1.y +#define G S1.z +#define H S1.w + + uint4 W[4]; + + W[ 0].x = block0.x; + RND(A,B,C,D,E,F,G,H, W[0].x+ K[0]); + W[ 0].y = block0.y; + RND(H,A,B,C,D,E,F,G, W[0].y+ K[1]); + W[ 0].z = block0.z; + RND(G,H,A,B,C,D,E,F, W[0].z+ K[2]); + W[ 0].w = block0.w; + RND(F,G,H,A,B,C,D,E, W[0].w+ K[3]); + + W[ 1].x = block1.x; + RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); + W[ 1].y = block1.y; + RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); + W[ 1].z = block1.z; + RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); + W[ 1].w = block1.w; + RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); + + W[ 2].x = block2.x; + RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); + W[ 2].y = block2.y; + RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); + W[ 2].z = block2.z; + RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); + W[ 2].w = block2.w; + RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); + + W[ 3].x = block3.x; + RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); + W[ 3].y = block3.y; + RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); + W[ 3].z = block3.z; + RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); + W[ 3].w = block3.w; + RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + + *state0 += S0; + *state1 += S1; +} + +void SHA256_fresh(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) +{ +#define A (*state0).x +#define B (*state0).y +#define C (*state0).z +#define D (*state0).w +#define E (*state1).x +#define F (*state1).y +#define G (*state1).z +#define H (*state1).w + + uint4 W[4]; + + W[0].x = block0.x; + D= K[63] +W[0].x; + H= K[64] +W[0].x; + + W[0].y = block0.y; + C= K[65] +Tr1(D)+Ch(D, K[66], K[67])+W[0].y; + G= K[68] +C+Tr2(H)+Ch(H, K[69] ,K[70]); + + W[0].z = block0.z; + B= K[71] +Tr1(C)+Ch(C,D,K[66])+W[0].z; + F= K[72] +B+Tr2(G)+Maj(G,H, K[73]); + + W[0].w = block0.w; + A= K[74] +Tr1(B)+Ch(B,C,D)+W[0].w; + E= K[75] +A+Tr2(F)+Maj(F,G,H); + + W[1].x = block1.x; + RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); + W[1].y = block1.y; + RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); + W[1].z = block1.z; + RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); + W[1].w = block1.w; + RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); + + W[2].x = block2.x; + RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); + W[2].y = block2.y; + RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); + W[2].z = block2.z; + RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); + W[2].w = block2.w; + RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); + + W[3].x = block3.x; + RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); + W[3].y = block3.y; + RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); + W[3].z = block3.z; + RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); + W[3].w = block3.w; + RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + + *state0 += (uint4)(K[73], K[77], K[78], K[79]); + *state1 += (uint4)(K[66], K[67], K[80], K[81]); +} + +__constant uint fixedW[64] = +{ + 0x428a2f99,0xf1374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, + 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf794, + 0xf59b89c2,0x73924787,0x23c6886e,0xa42ca65c,0x15ed3627,0x4d6edcbf,0xe28217fc,0xef02488f, + 0xb707775c,0x0468c23f,0xe7e72b4c,0x49e1f1a2,0x4b99c816,0x926d1570,0xaa0fc072,0xadb36e2c, + 0xad87a3ea,0xbcb1d3a3,0x7b993186,0x562b9420,0xbff3ca0c,0xda4b0c23,0x6cd8711a,0x8f337caa, + 0xc91b1417,0xc359dce1,0xa83253a7,0x3b13c12d,0x9d3d725d,0xd9031a84,0xb1a03340,0x16f58012, + 0xe64fb6a2,0xe84d923a,0xe93a5730,0x09837686,0x078ff753,0x29833341,0xd5de0b7e,0x6948ccf4, + 0xe0a1adbe,0x7c728e11,0x511c78e4,0x315b45bd,0xfca71413,0xea28f96a,0x79703128,0x4e1ef848, +}; + +void SHA256_fixed(uint4*restrict state0,uint4*restrict state1) +{ + uint4 S0 = *state0; + uint4 S1 = *state1; + +#define A S0.x +#define B S0.y +#define C S0.z +#define D S0.w +#define E S1.x +#define F S1.y +#define G S1.z +#define H S1.w + + RND(A,B,C,D,E,F,G,H, fixedW[0]); + RND(H,A,B,C,D,E,F,G, fixedW[1]); + RND(G,H,A,B,C,D,E,F, fixedW[2]); + RND(F,G,H,A,B,C,D,E, fixedW[3]); + RND(E,F,G,H,A,B,C,D, fixedW[4]); + RND(D,E,F,G,H,A,B,C, fixedW[5]); + RND(C,D,E,F,G,H,A,B, fixedW[6]); + RND(B,C,D,E,F,G,H,A, fixedW[7]); + RND(A,B,C,D,E,F,G,H, fixedW[8]); + RND(H,A,B,C,D,E,F,G, fixedW[9]); + RND(G,H,A,B,C,D,E,F, fixedW[10]); + RND(F,G,H,A,B,C,D,E, fixedW[11]); + RND(E,F,G,H,A,B,C,D, fixedW[12]); + RND(D,E,F,G,H,A,B,C, fixedW[13]); + RND(C,D,E,F,G,H,A,B, fixedW[14]); + RND(B,C,D,E,F,G,H,A, fixedW[15]); + RND(A,B,C,D,E,F,G,H, fixedW[16]); + RND(H,A,B,C,D,E,F,G, fixedW[17]); + RND(G,H,A,B,C,D,E,F, fixedW[18]); + RND(F,G,H,A,B,C,D,E, fixedW[19]); + RND(E,F,G,H,A,B,C,D, fixedW[20]); + RND(D,E,F,G,H,A,B,C, fixedW[21]); + RND(C,D,E,F,G,H,A,B, fixedW[22]); + RND(B,C,D,E,F,G,H,A, fixedW[23]); + RND(A,B,C,D,E,F,G,H, fixedW[24]); + RND(H,A,B,C,D,E,F,G, fixedW[25]); + RND(G,H,A,B,C,D,E,F, fixedW[26]); + RND(F,G,H,A,B,C,D,E, fixedW[27]); + RND(E,F,G,H,A,B,C,D, fixedW[28]); + RND(D,E,F,G,H,A,B,C, fixedW[29]); + RND(C,D,E,F,G,H,A,B, fixedW[30]); + RND(B,C,D,E,F,G,H,A, fixedW[31]); + RND(A,B,C,D,E,F,G,H, fixedW[32]); + RND(H,A,B,C,D,E,F,G, fixedW[33]); + RND(G,H,A,B,C,D,E,F, fixedW[34]); + RND(F,G,H,A,B,C,D,E, fixedW[35]); + RND(E,F,G,H,A,B,C,D, fixedW[36]); + RND(D,E,F,G,H,A,B,C, fixedW[37]); + RND(C,D,E,F,G,H,A,B, fixedW[38]); + RND(B,C,D,E,F,G,H,A, fixedW[39]); + RND(A,B,C,D,E,F,G,H, fixedW[40]); + RND(H,A,B,C,D,E,F,G, fixedW[41]); + RND(G,H,A,B,C,D,E,F, fixedW[42]); + RND(F,G,H,A,B,C,D,E, fixedW[43]); + RND(E,F,G,H,A,B,C,D, fixedW[44]); + RND(D,E,F,G,H,A,B,C, fixedW[45]); + RND(C,D,E,F,G,H,A,B, fixedW[46]); + RND(B,C,D,E,F,G,H,A, fixedW[47]); + RND(A,B,C,D,E,F,G,H, fixedW[48]); + RND(H,A,B,C,D,E,F,G, fixedW[49]); + RND(G,H,A,B,C,D,E,F, fixedW[50]); + RND(F,G,H,A,B,C,D,E, fixedW[51]); + RND(E,F,G,H,A,B,C,D, fixedW[52]); + RND(D,E,F,G,H,A,B,C, fixedW[53]); + RND(C,D,E,F,G,H,A,B, fixedW[54]); + RND(B,C,D,E,F,G,H,A, fixedW[55]); + RND(A,B,C,D,E,F,G,H, fixedW[56]); + RND(H,A,B,C,D,E,F,G, fixedW[57]); + RND(G,H,A,B,C,D,E,F, fixedW[58]); + RND(F,G,H,A,B,C,D,E, fixedW[59]); + RND(E,F,G,H,A,B,C,D, fixedW[60]); + RND(D,E,F,G,H,A,B,C, fixedW[61]); + RND(C,D,E,F,G,H,A,B, fixedW[62]); + RND(B,C,D,E,F,G,H,A, fixedW[63]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + *state0 += S0; + *state1 += S1; +} + +void shittify(uint4 B[8]) +{ + uint4 tmp[4]; + tmp[0] = (uint4)(B[1].x,B[2].y,B[3].z,B[0].w); + tmp[1] = (uint4)(B[2].x,B[3].y,B[0].z,B[1].w); + tmp[2] = (uint4)(B[3].x,B[0].y,B[1].z,B[2].w); + tmp[3] = (uint4)(B[0].x,B[1].y,B[2].z,B[3].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i] = EndianSwap(tmp[i]); + + tmp[0] = (uint4)(B[5].x,B[6].y,B[7].z,B[4].w); + tmp[1] = (uint4)(B[6].x,B[7].y,B[4].z,B[5].w); + tmp[2] = (uint4)(B[7].x,B[4].y,B[5].z,B[6].w); + tmp[3] = (uint4)(B[4].x,B[5].y,B[6].z,B[7].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] = EndianSwap(tmp[i]); +} + +void unshittify(uint4 B[8]) +{ + uint4 tmp[4]; + tmp[0] = (uint4)(B[3].x,B[2].y,B[1].z,B[0].w); + tmp[1] = (uint4)(B[0].x,B[3].y,B[2].z,B[1].w); + tmp[2] = (uint4)(B[1].x,B[0].y,B[3].z,B[2].w); + tmp[3] = (uint4)(B[2].x,B[1].y,B[0].z,B[3].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i] = EndianSwap(tmp[i]); + + tmp[0] = (uint4)(B[7].x,B[6].y,B[5].z,B[4].w); + tmp[1] = (uint4)(B[4].x,B[7].y,B[6].z,B[5].w); + tmp[2] = (uint4)(B[5].x,B[4].y,B[7].z,B[6].w); + tmp[3] = (uint4)(B[6].x,B[5].y,B[4].z,B[7].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] = EndianSwap(tmp[i]); +} + +void salsa(uint4 B[8]) +{ + uint4 w[4]; + +#pragma unroll + for(uint i=0; i<4; ++i) + w[i] = (B[i]^=B[i+4]); + +#pragma unroll + for(uint i=0; i<4; ++i) + { + w[0] ^= rotl(w[3] +w[2] , 7U); + w[1] ^= rotl(w[0] +w[3] , 9U); + w[2] ^= rotl(w[1] +w[0] ,13U); + w[3] ^= rotl(w[2] +w[1] ,18U); + w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); + w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); + w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); + w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); + } + +#pragma unroll + for(uint i=0; i<4; ++i) + w[i] = (B[i+4]^=(B[i]+=w[i])); + +#pragma unroll + for(uint i=0; i<4; ++i) + { + w[0] ^= rotl(w[3] +w[2] , 7U); + w[1] ^= rotl(w[0] +w[3] , 9U); + w[2] ^= rotl(w[1] +w[0] ,13U); + w[3] ^= rotl(w[2] +w[1] ,18U); + w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); + w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); + w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); + w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); + } + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] += w[i]; +} + +void scrypt_core(uint4 X[8], __global uint4*restrict lookup) +{ + shittify(X); + const uint zSIZE = 8; + const uint xSIZE = CONCURRENT_THREADS; + uint x = get_global_id(0)%xSIZE; + uint CO=rotl(x,3U); + uint CO_tmp=rotl(xSIZE,3U); + + for(uint y=0; y<1024/LOOKUP_GAP; ++y, CO+=CO_tmp) + { + uint CO_reg=CO; +#pragma unroll + for(uint z=0; z>3U)) +#define Wr1(x) (rotl(x, 15U) ^ rotl(x, 13U) ^ (x>>10U)) + +#define RND(a, b, c, d, e, f, g, h, k) \ + h += Tr1(e); \ + h += Ch(e, f, g); \ + h += k; \ + d += h; \ + h += Tr2(a); \ + h += Maj(a, b, c); + +void SHA256(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) +{ + uint4 S0 = *state0; + uint4 S1 = *state1; + +#define A S0.x +#define B S0.y +#define C S0.z +#define D S0.w +#define E S1.x +#define F S1.y +#define G S1.z +#define H S1.w + + uint4 W[4]; + + W[ 0].x = block0.x; + RND(A,B,C,D,E,F,G,H, W[0].x+ K[0]); + W[ 0].y = block0.y; + RND(H,A,B,C,D,E,F,G, W[0].y+ K[1]); + W[ 0].z = block0.z; + RND(G,H,A,B,C,D,E,F, W[0].z+ K[2]); + W[ 0].w = block0.w; + RND(F,G,H,A,B,C,D,E, W[0].w+ K[3]); + + W[ 1].x = block1.x; + RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); + W[ 1].y = block1.y; + RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); + W[ 1].z = block1.z; + RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); + W[ 1].w = block1.w; + RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); + + W[ 2].x = block2.x; + RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); + W[ 2].y = block2.y; + RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); + W[ 2].z = block2.z; + RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); + W[ 2].w = block2.w; + RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); + + W[ 3].x = block3.x; + RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); + W[ 3].y = block3.y; + RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); + W[ 3].z = block3.z; + RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); + W[ 3].w = block3.w; + RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); + + W[ 0].x += Wr1(W[ 3].z) + W[ 2].y + Wr2(W[ 0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); + + W[ 0].y += Wr1(W[ 3].w) + W[ 2].z + Wr2(W[ 0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); + + W[ 0].z += Wr1(W[ 0].x) + W[ 2].w + Wr2(W[ 0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); + + W[ 0].w += Wr1(W[ 0].y) + W[ 3].x + Wr2(W[ 1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); + + W[ 1].x += Wr1(W[ 0].z) + W[ 3].y + Wr2(W[ 1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); + + W[ 1].y += Wr1(W[ 0].w) + W[ 3].z + Wr2(W[ 1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); + + W[ 1].z += Wr1(W[ 1].x) + W[ 3].w + Wr2(W[ 1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); + + W[ 1].w += Wr1(W[ 1].y) + W[ 0].x + Wr2(W[ 2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); + + W[ 2].x += Wr1(W[ 1].z) + W[ 0].y + Wr2(W[ 2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); + + W[ 2].y += Wr1(W[ 1].w) + W[ 0].z + Wr2(W[ 2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); + + W[ 2].z += Wr1(W[ 2].x) + W[ 0].w + Wr2(W[ 2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); + + W[ 2].w += Wr1(W[ 2].y) + W[ 1].x + Wr2(W[ 3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); + + W[ 3].x += Wr1(W[ 2].z) + W[ 1].y + Wr2(W[ 3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); + + W[ 3].y += Wr1(W[ 2].w) + W[ 1].z + Wr2(W[ 3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); + + W[ 3].z += Wr1(W[ 3].x) + W[ 1].w + Wr2(W[ 3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); + + W[ 3].w += Wr1(W[ 3].y) + W[ 2].x + Wr2(W[ 0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + + *state0 += S0; + *state1 += S1; +} + +void SHA256_fresh(uint4*restrict state0,uint4*restrict state1, const uint4 block0, const uint4 block1, const uint4 block2, const uint4 block3) +{ +#define A (*state0).x +#define B (*state0).y +#define C (*state0).z +#define D (*state0).w +#define E (*state1).x +#define F (*state1).y +#define G (*state1).z +#define H (*state1).w + + uint4 W[4]; + + W[0].x = block0.x; + D= K[63] +W[0].x; + H= K[64] +W[0].x; + + W[0].y = block0.y; + C= K[65] +Tr1(D)+Ch(D, K[66], K[67])+W[0].y; + G= K[68] +C+Tr2(H)+Ch(H, K[69] ,K[70]); + + W[0].z = block0.z; + B= K[71] +Tr1(C)+Ch(C,D,K[66])+W[0].z; + F= K[72] +B+Tr2(G)+Maj(G,H, K[73]); + + W[0].w = block0.w; + A= K[74] +Tr1(B)+Ch(B,C,D)+W[0].w; + E= K[75] +A+Tr2(F)+Maj(F,G,H); + + W[1].x = block1.x; + RND(E,F,G,H,A,B,C,D, W[1].x+ K[4]); + W[1].y = block1.y; + RND(D,E,F,G,H,A,B,C, W[1].y+ K[5]); + W[1].z = block1.z; + RND(C,D,E,F,G,H,A,B, W[1].z+ K[6]); + W[1].w = block1.w; + RND(B,C,D,E,F,G,H,A, W[1].w+ K[7]); + + W[2].x = block2.x; + RND(A,B,C,D,E,F,G,H, W[2].x+ K[8]); + W[2].y = block2.y; + RND(H,A,B,C,D,E,F,G, W[2].y+ K[9]); + W[2].z = block2.z; + RND(G,H,A,B,C,D,E,F, W[2].z+ K[10]); + W[2].w = block2.w; + RND(F,G,H,A,B,C,D,E, W[2].w+ K[11]); + + W[3].x = block3.x; + RND(E,F,G,H,A,B,C,D, W[3].x+ K[12]); + W[3].y = block3.y; + RND(D,E,F,G,H,A,B,C, W[3].y+ K[13]); + W[3].z = block3.z; + RND(C,D,E,F,G,H,A,B, W[3].z+ K[14]); + W[3].w = block3.w; + RND(B,C,D,E,F,G,H,A, W[3].w+ K[76]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[15]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[16]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[17]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[18]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[19]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[20]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[21]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[22]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[23]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[24]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[25]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[26]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[27]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[28]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[29]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[30]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[31]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[32]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[33]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[34]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[35]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[36]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[37]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[38]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[39]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[40]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[41]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[42]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[43]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[44]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[45]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[46]); + + W[0].x += Wr1(W[3].z) + W[2].y + Wr2(W[0].y); + RND(A,B,C,D,E,F,G,H, W[0].x+ K[47]); + + W[0].y += Wr1(W[3].w) + W[2].z + Wr2(W[0].z); + RND(H,A,B,C,D,E,F,G, W[0].y+ K[48]); + + W[0].z += Wr1(W[0].x) + W[2].w + Wr2(W[0].w); + RND(G,H,A,B,C,D,E,F, W[0].z+ K[49]); + + W[0].w += Wr1(W[0].y) + W[3].x + Wr2(W[1].x); + RND(F,G,H,A,B,C,D,E, W[0].w+ K[50]); + + W[1].x += Wr1(W[0].z) + W[3].y + Wr2(W[1].y); + RND(E,F,G,H,A,B,C,D, W[1].x+ K[51]); + + W[1].y += Wr1(W[0].w) + W[3].z + Wr2(W[1].z); + RND(D,E,F,G,H,A,B,C, W[1].y+ K[52]); + + W[1].z += Wr1(W[1].x) + W[3].w + Wr2(W[1].w); + RND(C,D,E,F,G,H,A,B, W[1].z+ K[53]); + + W[1].w += Wr1(W[1].y) + W[0].x + Wr2(W[2].x); + RND(B,C,D,E,F,G,H,A, W[1].w+ K[54]); + + W[2].x += Wr1(W[1].z) + W[0].y + Wr2(W[2].y); + RND(A,B,C,D,E,F,G,H, W[2].x+ K[55]); + + W[2].y += Wr1(W[1].w) + W[0].z + Wr2(W[2].z); + RND(H,A,B,C,D,E,F,G, W[2].y+ K[56]); + + W[2].z += Wr1(W[2].x) + W[0].w + Wr2(W[2].w); + RND(G,H,A,B,C,D,E,F, W[2].z+ K[57]); + + W[2].w += Wr1(W[2].y) + W[1].x + Wr2(W[3].x); + RND(F,G,H,A,B,C,D,E, W[2].w+ K[58]); + + W[3].x += Wr1(W[2].z) + W[1].y + Wr2(W[3].y); + RND(E,F,G,H,A,B,C,D, W[3].x+ K[59]); + + W[3].y += Wr1(W[2].w) + W[1].z + Wr2(W[3].z); + RND(D,E,F,G,H,A,B,C, W[3].y+ K[60]); + + W[3].z += Wr1(W[3].x) + W[1].w + Wr2(W[3].w); + RND(C,D,E,F,G,H,A,B, W[3].z+ K[61]); + + W[3].w += Wr1(W[3].y) + W[2].x + Wr2(W[0].x); + RND(B,C,D,E,F,G,H,A, W[3].w+ K[62]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + + *state0 += (uint4)(K[73], K[77], K[78], K[79]); + *state1 += (uint4)(K[66], K[67], K[80], K[81]); +} + +__constant uint fixedW[64] = +{ + 0x428a2f99,0xf1374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5, + 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3,0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf794, + 0xf59b89c2,0x73924787,0x23c6886e,0xa42ca65c,0x15ed3627,0x4d6edcbf,0xe28217fc,0xef02488f, + 0xb707775c,0x0468c23f,0xe7e72b4c,0x49e1f1a2,0x4b99c816,0x926d1570,0xaa0fc072,0xadb36e2c, + 0xad87a3ea,0xbcb1d3a3,0x7b993186,0x562b9420,0xbff3ca0c,0xda4b0c23,0x6cd8711a,0x8f337caa, + 0xc91b1417,0xc359dce1,0xa83253a7,0x3b13c12d,0x9d3d725d,0xd9031a84,0xb1a03340,0x16f58012, + 0xe64fb6a2,0xe84d923a,0xe93a5730,0x09837686,0x078ff753,0x29833341,0xd5de0b7e,0x6948ccf4, + 0xe0a1adbe,0x7c728e11,0x511c78e4,0x315b45bd,0xfca71413,0xea28f96a,0x79703128,0x4e1ef848, +}; + +void SHA256_fixed(uint4*restrict state0,uint4*restrict state1) +{ + uint4 S0 = *state0; + uint4 S1 = *state1; + +#define A S0.x +#define B S0.y +#define C S0.z +#define D S0.w +#define E S1.x +#define F S1.y +#define G S1.z +#define H S1.w + + RND(A,B,C,D,E,F,G,H, fixedW[0]); + RND(H,A,B,C,D,E,F,G, fixedW[1]); + RND(G,H,A,B,C,D,E,F, fixedW[2]); + RND(F,G,H,A,B,C,D,E, fixedW[3]); + RND(E,F,G,H,A,B,C,D, fixedW[4]); + RND(D,E,F,G,H,A,B,C, fixedW[5]); + RND(C,D,E,F,G,H,A,B, fixedW[6]); + RND(B,C,D,E,F,G,H,A, fixedW[7]); + RND(A,B,C,D,E,F,G,H, fixedW[8]); + RND(H,A,B,C,D,E,F,G, fixedW[9]); + RND(G,H,A,B,C,D,E,F, fixedW[10]); + RND(F,G,H,A,B,C,D,E, fixedW[11]); + RND(E,F,G,H,A,B,C,D, fixedW[12]); + RND(D,E,F,G,H,A,B,C, fixedW[13]); + RND(C,D,E,F,G,H,A,B, fixedW[14]); + RND(B,C,D,E,F,G,H,A, fixedW[15]); + RND(A,B,C,D,E,F,G,H, fixedW[16]); + RND(H,A,B,C,D,E,F,G, fixedW[17]); + RND(G,H,A,B,C,D,E,F, fixedW[18]); + RND(F,G,H,A,B,C,D,E, fixedW[19]); + RND(E,F,G,H,A,B,C,D, fixedW[20]); + RND(D,E,F,G,H,A,B,C, fixedW[21]); + RND(C,D,E,F,G,H,A,B, fixedW[22]); + RND(B,C,D,E,F,G,H,A, fixedW[23]); + RND(A,B,C,D,E,F,G,H, fixedW[24]); + RND(H,A,B,C,D,E,F,G, fixedW[25]); + RND(G,H,A,B,C,D,E,F, fixedW[26]); + RND(F,G,H,A,B,C,D,E, fixedW[27]); + RND(E,F,G,H,A,B,C,D, fixedW[28]); + RND(D,E,F,G,H,A,B,C, fixedW[29]); + RND(C,D,E,F,G,H,A,B, fixedW[30]); + RND(B,C,D,E,F,G,H,A, fixedW[31]); + RND(A,B,C,D,E,F,G,H, fixedW[32]); + RND(H,A,B,C,D,E,F,G, fixedW[33]); + RND(G,H,A,B,C,D,E,F, fixedW[34]); + RND(F,G,H,A,B,C,D,E, fixedW[35]); + RND(E,F,G,H,A,B,C,D, fixedW[36]); + RND(D,E,F,G,H,A,B,C, fixedW[37]); + RND(C,D,E,F,G,H,A,B, fixedW[38]); + RND(B,C,D,E,F,G,H,A, fixedW[39]); + RND(A,B,C,D,E,F,G,H, fixedW[40]); + RND(H,A,B,C,D,E,F,G, fixedW[41]); + RND(G,H,A,B,C,D,E,F, fixedW[42]); + RND(F,G,H,A,B,C,D,E, fixedW[43]); + RND(E,F,G,H,A,B,C,D, fixedW[44]); + RND(D,E,F,G,H,A,B,C, fixedW[45]); + RND(C,D,E,F,G,H,A,B, fixedW[46]); + RND(B,C,D,E,F,G,H,A, fixedW[47]); + RND(A,B,C,D,E,F,G,H, fixedW[48]); + RND(H,A,B,C,D,E,F,G, fixedW[49]); + RND(G,H,A,B,C,D,E,F, fixedW[50]); + RND(F,G,H,A,B,C,D,E, fixedW[51]); + RND(E,F,G,H,A,B,C,D, fixedW[52]); + RND(D,E,F,G,H,A,B,C, fixedW[53]); + RND(C,D,E,F,G,H,A,B, fixedW[54]); + RND(B,C,D,E,F,G,H,A, fixedW[55]); + RND(A,B,C,D,E,F,G,H, fixedW[56]); + RND(H,A,B,C,D,E,F,G, fixedW[57]); + RND(G,H,A,B,C,D,E,F, fixedW[58]); + RND(F,G,H,A,B,C,D,E, fixedW[59]); + RND(E,F,G,H,A,B,C,D, fixedW[60]); + RND(D,E,F,G,H,A,B,C, fixedW[61]); + RND(C,D,E,F,G,H,A,B, fixedW[62]); + RND(B,C,D,E,F,G,H,A, fixedW[63]); + +#undef A +#undef B +#undef C +#undef D +#undef E +#undef F +#undef G +#undef H + *state0 += S0; + *state1 += S1; +} + +void shittify(uint4 B[8]) +{ + uint4 tmp[4]; + tmp[0] = (uint4)(B[1].x,B[2].y,B[3].z,B[0].w); + tmp[1] = (uint4)(B[2].x,B[3].y,B[0].z,B[1].w); + tmp[2] = (uint4)(B[3].x,B[0].y,B[1].z,B[2].w); + tmp[3] = (uint4)(B[0].x,B[1].y,B[2].z,B[3].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i] = EndianSwap(tmp[i]); + + tmp[0] = (uint4)(B[5].x,B[6].y,B[7].z,B[4].w); + tmp[1] = (uint4)(B[6].x,B[7].y,B[4].z,B[5].w); + tmp[2] = (uint4)(B[7].x,B[4].y,B[5].z,B[6].w); + tmp[3] = (uint4)(B[4].x,B[5].y,B[6].z,B[7].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] = EndianSwap(tmp[i]); +} + +void unshittify(uint4 B[8]) +{ + uint4 tmp[4]; + tmp[0] = (uint4)(B[3].x,B[2].y,B[1].z,B[0].w); + tmp[1] = (uint4)(B[0].x,B[3].y,B[2].z,B[1].w); + tmp[2] = (uint4)(B[1].x,B[0].y,B[3].z,B[2].w); + tmp[3] = (uint4)(B[2].x,B[1].y,B[0].z,B[3].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i] = EndianSwap(tmp[i]); + + tmp[0] = (uint4)(B[7].x,B[6].y,B[5].z,B[4].w); + tmp[1] = (uint4)(B[4].x,B[7].y,B[6].z,B[5].w); + tmp[2] = (uint4)(B[5].x,B[4].y,B[7].z,B[6].w); + tmp[3] = (uint4)(B[6].x,B[5].y,B[4].z,B[7].w); + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] = EndianSwap(tmp[i]); +} + +void salsa(uint4 B[8]) +{ + uint4 w[4]; + +#pragma unroll + for(uint i=0; i<4; ++i) + w[i] = (B[i]^=B[i+4]); + +#pragma unroll + for(uint i=0; i<4; ++i) + { + w[0] ^= rotl(w[3] +w[2] , 7U); + w[1] ^= rotl(w[0] +w[3] , 9U); + w[2] ^= rotl(w[1] +w[0] ,13U); + w[3] ^= rotl(w[2] +w[1] ,18U); + w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); + w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); + w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); + w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); + } + +#pragma unroll + for(uint i=0; i<4; ++i) + w[i] = (B[i+4]^=(B[i]+=w[i])); + +#pragma unroll + for(uint i=0; i<4; ++i) + { + w[0] ^= rotl(w[3] +w[2] , 7U); + w[1] ^= rotl(w[0] +w[3] , 9U); + w[2] ^= rotl(w[1] +w[0] ,13U); + w[3] ^= rotl(w[2] +w[1] ,18U); + w[2] ^= rotl(w[3].wxyz+w[0].zwxy, 7U); + w[1] ^= rotl(w[2].wxyz+w[3].zwxy, 9U); + w[0] ^= rotl(w[1].wxyz+w[2].zwxy,13U); + w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); + } + +#pragma unroll + for(uint i=0; i<4; ++i) + B[i+4] += w[i]; +} + +void scrypt_core(uint4 X[8], __global uint4*restrict lookup) +{ + shittify(X); + const uint zSIZE = 8; + const uint xSIZE = CONCURRENT_THREADS; + uint x = get_global_id(0)%xSIZE; + uint CO_tmp=xSIZE<<3U; + uint CO_tmp2=x<<3U; + + for(uint y=0; y<1024/LOOKUP_GAP; ++y) + { + uint CO=y*CO_tmp+CO_tmp2; +#pragma unroll + for(uint z=0; z Date: Tue, 21 Jan 2014 10:36:55 +0200 Subject: [PATCH 07/15] kernel: allow choosing Alexey Karimov's kernels. Am I the only one who gets a segfault?.. --- configure.ac | 3 ++- driver-opencl.c | 10 ++++++++++ kernel/alexkarnew.cl | 4 ++-- kernel/alexkarold.cl | 4 ++-- miner.h | 2 ++ ocl.c | 16 ++++++++++++++-- sgminer.c | 6 ++++++ 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index ed4441ee..0ffacfc5 100644 --- a/configure.ac +++ b/configure.ac @@ -317,10 +317,11 @@ fi AC_DEFINE_UNQUOTED([SGMINER_PREFIX], ["$prefix/bin"], [Path to sgminer install]) +AC_DEFINE_UNQUOTED([ALEXKARNEW_KERNNAME], ["alexkarnew"], [Filename for Alexey Karimov's optimised kernel for Catalyst >=13.4]) +AC_DEFINE_UNQUOTED([ALEXKAROLD_KERNNAME], ["alexkarold"], [Filename for Alexey Karimov's optimised kernel for Catalyst <13.4]) AC_DEFINE_UNQUOTED([CKOLIVAS_KERNNAME], ["ckolivas"], [Filename for original scrypt kernel]) AC_DEFINE_UNQUOTED([ZUIKKIS_KERNNAME], ["zuikkis"], [Filename for Zuikkis' optimised kernel]) - AC_SUBST(OPENCL_LIBS) AC_SUBST(OPENCL_FLAGS) AC_SUBST(JANSSON_LIBS) diff --git a/driver-opencl.c b/driver-opencl.c index ec8e2faf..cfef0c81 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -196,6 +196,10 @@ char *set_thread_concurrency(char *arg) static enum cl_kernels select_kernel(char *arg) { + if (!strcmp(arg, "alexkarnew")) + return KL_ALEXKARNEW; + if (!strcmp(arg, "alexkarold")) + return KL_ALEXKAROLD; if (!strcmp(arg, "ckolivas")) return KL_CKOLIVAS; if (!strcmp(arg, "zuikkis")) @@ -1212,6 +1216,12 @@ static bool opencl_thread_prepare(struct thr_info *thr) if (!cgpu->kname) { switch (clStates[i]->chosen_kernel) { + case KL_ALEXKARNEW: + cgpu->kname = "alexkarnew"; + break; + case KL_ALEXKAROLD: + cgpu->kname = "alexkarold"; + break; case KL_CKOLIVAS: cgpu->kname = "ckolivas"; break; diff --git a/kernel/alexkarnew.cl b/kernel/alexkarnew.cl index e936fdd1..757e8114 100644 --- a/kernel/alexkarnew.cl +++ b/kernel/alexkarnew.cl @@ -813,8 +813,8 @@ void scrypt_core(uint4 X[8], __global uint4*restrict lookup) unshittify(X); } -#define SCRYPT_FOUND (0xFF) -#define SETFOUND(Xnonce) output[output[SCRYPT_FOUND]++] = Xnonce +#define FOUND (0xFF) +#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce __attribute__((reqd_work_group_size(WORKSIZE, 1, 1))) __kernel void search(__global const uint4 * restrict input, diff --git a/kernel/alexkarold.cl b/kernel/alexkarold.cl index ce555fe7..9c3c1b7b 100644 --- a/kernel/alexkarold.cl +++ b/kernel/alexkarold.cl @@ -810,8 +810,8 @@ void scrypt_core(uint4 X[8], __global uint4*restrict lookup) unshittify(X); } -#define SCRYPT_FOUND (0xFF) -#define SETFOUND(Xnonce) output[output[SCRYPT_FOUND]++] = Xnonce +#define FOUND (0xFF) +#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce __attribute__((reqd_work_group_size(WORKSIZE, 1, 1))) __kernel void search(__global const uint4 * restrict input, diff --git a/miner.h b/miner.h index 16231b29..ea08fb23 100644 --- a/miner.h +++ b/miner.h @@ -372,6 +372,8 @@ enum dev_enable { enum cl_kernels { KL_NONE, + KL_ALEXKARNEW, + KL_ALEXKAROLD, KL_CKOLIVAS, KL_ZUIKKIS, }; diff --git a/ocl.c b/ocl.c index c3b60b64..159f25fc 100644 --- a/ocl.c +++ b/ocl.c @@ -416,16 +416,28 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) preferred_vwidth = 2; switch (clState->chosen_kernel) { + case KL_ALEXKARNEW: + strcpy(filename, ALEXKARNEW_KERNNAME".cl"); + strcpy(binaryfilename, ALEXKARNEW_KERNNAME); + /* Kernel only supports vector 1 */ + cgpu->vwidth = 1; + break; + case KL_ALEXKAROLD: + strcpy(filename, ALEXKAROLD_KERNNAME".cl"); + strcpy(binaryfilename, ALEXKAROLD_KERNNAME); + /* Kernel only supports vector 1 */ + cgpu->vwidth = 1; + break; case KL_CKOLIVAS: strcpy(filename, CKOLIVAS_KERNNAME".cl"); strcpy(binaryfilename, CKOLIVAS_KERNNAME); - /* Scrypt only supports vector 1 */ + /* Kernel only supports vector 1 */ cgpu->vwidth = 1; break; case KL_ZUIKKIS: strcpy(filename, ZUIKKIS_KERNNAME".cl"); strcpy(binaryfilename, ZUIKKIS_KERNNAME); - /* Scrypt only supports vector 1 */ + /* Kernel only supports vector 1 */ cgpu->vwidth = 1; break; case KL_NONE: /* Shouldn't happen */ diff --git a/sgminer.c b/sgminer.c index 6b1ee9ba..8e8252ba 100644 --- a/sgminer.c +++ b/sgminer.c @@ -4121,6 +4121,12 @@ void write_config(FILE *fcfg) switch (gpus[i].kernel) { case KL_NONE: // Shouldn't happen break; + case KL_ALEXKARNEW: + fprintf(fcfg, "alexkarnew"); + break; + case KL_ALEXKAROLD: + fprintf(fcfg, "alexkarold"); + break; case KL_CKOLIVAS: fprintf(fcfg, "ckolivas"); break; From 4ac17b03f6ef8f580ae3bce0c1809eb9e860b990 Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Tue, 21 Jan 2014 15:04:08 +0200 Subject: [PATCH 08/15] misc: Add Zuikkis and Alex Karimov to authors. --- AUTHORS.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index 963f0a6a..b1dd54c1 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,6 +1,6 @@ # Authors -## Current +## Core * Scrypt-only refactor and maintenance: Noel Maersk LfxRFgXzA13TSTxgFGUFEtumv5ShGzAmLw * Core: Martin Danielsen @@ -9,6 +9,13 @@ * API: Andrew Smith 1Jjk2LmktEQKnv8r2cZ9MvLiZwZ9gxabKm +## OpenCL kernels + +* scrypt: Colin Percival +* zuikkis: Zuikkis LeXck7EYgxyjw13zNDxZFmmgmWffFvhmSh +* alexkarnew/alexkarold: Alexey Karimov LMqRcHdwnZtTMH6c2kWoxSoKM5KySfaP5C + + ## Bug fixes Too many to list. See: From 629f7b15e2e49f822a2edab5a826bcfe6ef680de Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Tue, 21 Jan 2014 16:04:47 +0200 Subject: [PATCH 09/15] kernel/zuikkis: remove unneeded comments and change defines. I thought I've already fixed and committed this before. It probably got merged back in when I wasn't looking. --- kernel/zuikkis.cl | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/kernel/zuikkis.cl b/kernel/zuikkis.cl index 3b42574f..fb06f722 100644 --- a/kernel/zuikkis.cl +++ b/kernel/zuikkis.cl @@ -673,7 +673,7 @@ void shittify(uint4 B[8]) tmp[2] = (uint4)(B[3].x,B[0].y,B[1].z,B[2].w); tmp[3] = (uint4)(B[0].x,B[1].y,B[2].z,B[3].w); -//#pragma unroll + for(uint i=0; i<4; ++i) B[i] = EndianSwap(tmp[i]); @@ -682,7 +682,7 @@ void shittify(uint4 B[8]) tmp[2] = (uint4)(B[7].x,B[4].y,B[5].z,B[6].w); tmp[3] = (uint4)(B[4].x,B[5].y,B[6].z,B[7].w); -//#pragma unroll + for(uint i=0; i<4; ++i) B[i+4] = EndianSwap(tmp[i]); } @@ -695,7 +695,7 @@ void unshittify(uint4 B[8]) tmp[2] = (uint4)(B[1].x,B[0].y,B[3].z,B[2].w); tmp[3] = (uint4)(B[2].x,B[1].y,B[0].z,B[3].w); -//#pragma unroll + for(uint i=0; i<4; ++i) B[i] = EndianSwap(tmp[i]); @@ -704,7 +704,7 @@ void unshittify(uint4 B[8]) tmp[2] = (uint4)(B[5].x,B[4].y,B[7].z,B[6].w); tmp[3] = (uint4)(B[6].x,B[5].y,B[4].z,B[7].w); -//#pragma unroll + for(uint i=0; i<4; ++i) B[i+4] = EndianSwap(tmp[i]); } @@ -713,11 +713,11 @@ void salsa(uint4 B[8]) { uint4 w[4]; -//#pragma unroll + for(uint i=0; i<4; ++i) w[i] = (B[i]^=B[i+4]); -//#pragma unroll + for(uint i=0; i<4; ++i) { w[0] ^= rotl(w[3] +w[2] , 7U); @@ -730,11 +730,11 @@ void salsa(uint4 B[8]) w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); } -//#pragma unroll + for(uint i=0; i<4; ++i) w[i] = (B[i+4]^=(B[i]+=w[i])); -//#pragma unroll + for(uint i=0; i<4; ++i) { w[0] ^= rotl(w[3] +w[2] , 7U); @@ -747,7 +747,7 @@ void salsa(uint4 B[8]) w[3] ^= rotl(w[0].wxyz+w[1].zwxy,18U); } -//#pragma unroll + for(uint i=0; i<4; ++i) B[i+4] += w[i]; } @@ -765,7 +765,7 @@ void scrypt_core(uint4 X[8], __global uint4*restrict lookup) for(uint y=0; y<1024/LOOKUP_GAP; ++y) { -//#pragma unroll + for(uint z=0; z Date: Tue, 21 Jan 2014 16:28:43 +0200 Subject: [PATCH 10/15] doc: skeleton KERNEL documentation. On how to submit new kernels. This should allow a broad community review. --- doc/KERNEL.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 doc/KERNEL.md diff --git a/doc/KERNEL.md b/doc/KERNEL.md new file mode 100644 index 00000000..091f549d --- /dev/null +++ b/doc/KERNEL.md @@ -0,0 +1,37 @@ +# Kernels + +## Available OpenCL kernels + +See directory `kernel`. + + +## Submitting new kernels + +### Requirements + +TODO + + +### Procedure + +1. Copy the kernel you wish to modify and commit it verbatim. + +This way, it is easy to verify that there are no hidden changes. Note in +the commit message which kernel is used as a base. + +2. Make changes to the kernel. Commit them. + +This way, it can be easily shown what was changed. + +3. Search for KL_CKOLIVAS and CKOLIVAS_KERNNAME in the top-level source +directory and make additions to the listed files in order to integrate +the new kernel. + +Now it can be selected when starting via the `--kernel` argument or +`kernel` configuration option. + +4. Add yourself to the "kernels" section in `AUTHORS.md`. Keep it short. + +5. Submit a pull request on GitHub, or file it at the issue tracker, +listing your git repository and branch name. The current repository and +issue tracker links should be in `README.md`. From 35a23942b16bcf14416bbcd19eef7de183b25b2e Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Tue, 21 Jan 2014 21:16:49 +0200 Subject: [PATCH 11/15] kernel: fix alexkar* kernel crashes due to missing case in switch. Fixes https://github.com/veox/sgminer/issues/27 --- driver-opencl.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/driver-opencl.c b/driver-opencl.c index cfef0c81..f45ec3ce 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -1256,14 +1256,15 @@ static bool opencl_thread_init(struct thr_info *thr) } switch (clState->chosen_kernel) { - case KL_CKOLIVAS: - thrdata->queue_kernel_parameters = &queue_scrypt_kernel; - break; - case KL_ZUIKKIS: - thrdata->queue_kernel_parameters = &queue_scrypt_kernel; - break; - default: - break; + case KL_ALEXKARNEW: + case KL_ALEXKAROLD: + case KL_CKOLIVAS: + case KL_ZUIKKIS: + thrdata->queue_kernel_parameters = &queue_scrypt_kernel; + break; + default: + applog(LOG_ERR, "Failed to choose kernel in opencl_thread_init"); + break; } thrdata->res = calloc(buffersize, 1); From 5f795be64a1e04dbd8b4673b77cd0419f0cb57ea Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Thu, 23 Jan 2014 11:46:47 +0200 Subject: [PATCH 12/15] core: use kernel name defines now that version date is not in the filenames. Ideally, even this should not be needed, and specifying a kernel name string should search for the appropriate file in kernel-path. --- driver-opencl.c | 16 ++++++++-------- sgminer.c | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/driver-opencl.c b/driver-opencl.c index f45ec3ce..02fc34e9 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -196,13 +196,13 @@ char *set_thread_concurrency(char *arg) static enum cl_kernels select_kernel(char *arg) { - if (!strcmp(arg, "alexkarnew")) + if (!strcmp(arg, ALEXKARNEW_KERNNAME)) return KL_ALEXKARNEW; - if (!strcmp(arg, "alexkarold")) + if (!strcmp(arg, ALEXKAROLD_KERNNAME)) return KL_ALEXKAROLD; - if (!strcmp(arg, "ckolivas")) + if (!strcmp(arg, CKOLIVAS_KERNNAME)) return KL_CKOLIVAS; - if (!strcmp(arg, "zuikkis")) + if (!strcmp(arg, ZUIKKIS_KERNNAME)) return KL_ZUIKKIS; return KL_NONE; @@ -1217,16 +1217,16 @@ static bool opencl_thread_prepare(struct thr_info *thr) { switch (clStates[i]->chosen_kernel) { case KL_ALEXKARNEW: - cgpu->kname = "alexkarnew"; + cgpu->kname = ALEXKARNEW_KERNNAME; break; case KL_ALEXKAROLD: - cgpu->kname = "alexkarold"; + cgpu->kname = ALEXKAROLD_KERNNAME; break; case KL_CKOLIVAS: - cgpu->kname = "ckolivas"; + cgpu->kname = CKOLIVAS_KERNNAME; break; case KL_ZUIKKIS: - cgpu->kname = "zuikkis"; + cgpu->kname = ZUIKKIS_KERNNAME; break; default: break; diff --git a/sgminer.c b/sgminer.c index 8e8252ba..be02d1b4 100644 --- a/sgminer.c +++ b/sgminer.c @@ -4122,16 +4122,16 @@ void write_config(FILE *fcfg) case KL_NONE: // Shouldn't happen break; case KL_ALEXKARNEW: - fprintf(fcfg, "alexkarnew"); + fprintf(fcfg, ALEXKARNEW_KERNNAME); break; case KL_ALEXKAROLD: - fprintf(fcfg, "alexkarold"); + fprintf(fcfg, ALEXKAROLD_KERNNAME); break; case KL_CKOLIVAS: - fprintf(fcfg, "ckolivas"); + fprintf(fcfg, CKOLIVAS_KERNNAME); break; case KL_ZUIKKIS: - fprintf(fcfg, "zuikkis"); + fprintf(fcfg, ZUIKKIS_KERNNAME); break; } } From abf1b940b570bf4d666b48284b5440261a97d526 Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Thu, 23 Jan 2014 12:05:49 +0200 Subject: [PATCH 13/15] doc: update README.md to point to KERNEL.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7a3fdb2a..1f82b2ba 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Documentation is available in directory `doc`. For details on several topics, se * `SCRYPT` for how to find the right balance in GPU configuration to mine Scrypt-based coins effectively; * `FAQ` for frequently asked questions; * `GPU` for semi-obsolete information on GPU configuration options and mining SHA256d-based coins; +* `KERNEL.md` for OpenCL kernel-related information; * `windows-build.txt` for information on how to build on Windows. Note that **most of the documentation is outdated**. If you want to contribute, fork this repository, update as needed, and submit a pull request. From 7a69044cff11e0f1c1d920c63a6d09895d3b4030 Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Thu, 23 Jan 2014 18:25:12 +0200 Subject: [PATCH 14/15] doc: update KERNEL.md --- README.md | 2 +- doc/KERNEL.md | 57 +++++++++++++++++++++++++++++++++++++++--- doc/{SCRYPT => MINING} | 0 3 files changed, 54 insertions(+), 5 deletions(-) rename doc/{SCRYPT => MINING} (100%) diff --git a/README.md b/README.md index 1f82b2ba..ca41d639 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,10 @@ License: GPLv3. See `COPYING` for details. Documentation is available in directory `doc`. For details on several topics, see: * `API` for the RPC API specification; -* `SCRYPT` for how to find the right balance in GPU configuration to mine Scrypt-based coins effectively; * `FAQ` for frequently asked questions; * `GPU` for semi-obsolete information on GPU configuration options and mining SHA256d-based coins; * `KERNEL.md` for OpenCL kernel-related information; +* `MINING` for how to find the right balance in GPU configuration to mine Scrypt-based coins effectively; * `windows-build.txt` for information on how to build on Windows. Note that **most of the documentation is outdated**. If you want to contribute, fork this repository, update as needed, and submit a pull request. diff --git a/doc/KERNEL.md b/doc/KERNEL.md index 091f549d..aeeb948f 100644 --- a/doc/KERNEL.md +++ b/doc/KERNEL.md @@ -5,11 +5,59 @@ See directory `kernel`. +## Parameter configuration + +### Common + +In general, switching kernels requires reconfiguring mining parameters, +such as (but not necessarily limited to) `thread-concurrency`, `intensity`, +`gpu-engine` and `gpu-memclock`. + +A description of how to do this is available in `doc/MINING`. + + +### alexkarnew + +Alaxey Karimov's optimised kernel, based on `ckolivas`. For Catalyst >=13.4. + +Only supports `vectors=1`. + +[Announcement](https://litecointalk.org/index.php?topic=4082.0). + + +### alexkarold + +Alaxey Karimov's optimised kernel, based on `ckolivas`. For Catalyst <13.4. + +Only supports `vectors=1`. + +[Announcement](https://litecointalk.org/index.php?topic=4082.0). + + +### ckolivas + +The original Colin Percival `scrypt` kernel, maintained for a long time by +Con Kolivas in `cgminer` and renamed to reflect the fact. + +Only supports `vectors=1`. + + +### zuikkis + +Zuikkis' optimised kernel, based on `ckolivas`. + +Only supports `vectors=1`, `lookup-gap=2` and `worksize=256`. + +[Announcement](https://litecointalk.org/index.php?topic=6058.msg90873#msg90873). + + ## Submitting new kernels ### Requirements -TODO +* OpenCL source code only, licenced under GPLv3 (or later). +* Not hard-coded for a specific GPU model or manufacturer. +* Known limitations and any specific configuration quirks must be mentioned. ### Procedure @@ -21,7 +69,7 @@ the commit message which kernel is used as a base. 2. Make changes to the kernel. Commit them. -This way, it can be easily shown what was changed. +This allows to produce a diff that makes sense. 3. Search for KL_CKOLIVAS and CKOLIVAS_KERNNAME in the top-level source directory and make additions to the listed files in order to integrate @@ -33,5 +81,6 @@ Now it can be selected when starting via the `--kernel` argument or 4. Add yourself to the "kernels" section in `AUTHORS.md`. Keep it short. 5. Submit a pull request on GitHub, or file it at the issue tracker, -listing your git repository and branch name. The current repository and -issue tracker links should be in `README.md`. +outlining the changes made, known limitations, and tested GPUs. List +your git repository and branch name. The current repository and issue +tracker links should be in `README.md`. diff --git a/doc/SCRYPT b/doc/MINING similarity index 100% rename from doc/SCRYPT rename to doc/MINING From e8978db55f26dd6ff789e6c6b757d5dd4dbfc367 Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Thu, 23 Jan 2014 20:05:57 +0200 Subject: [PATCH 15/15] kernel: slight refactor, add warnings about new kernels, and known limitations of zuikkis. Limitations of alexkar* kernels are not known to me. Closes https://github.com/veox/sgminer/issues/28 --- ocl.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ocl.c b/ocl.c index 159f25fc..3fb6c98f 100644 --- a/ocl.c +++ b/ocl.c @@ -415,30 +415,32 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize) else if (preferred_vwidth > 2) preferred_vwidth = 2; + /* All available kernels only support vector 1 */ + cgpu->vwidth = 1; + switch (clState->chosen_kernel) { case KL_ALEXKARNEW: + applog(LOG_WARNING, "Kernel alexkarnew is experimental."); strcpy(filename, ALEXKARNEW_KERNNAME".cl"); strcpy(binaryfilename, ALEXKARNEW_KERNNAME); - /* Kernel only supports vector 1 */ - cgpu->vwidth = 1; break; case KL_ALEXKAROLD: + applog(LOG_WARNING, "Kernel alexkarold is experimental."); strcpy(filename, ALEXKAROLD_KERNNAME".cl"); strcpy(binaryfilename, ALEXKAROLD_KERNNAME); - /* Kernel only supports vector 1 */ - cgpu->vwidth = 1; break; case KL_CKOLIVAS: strcpy(filename, CKOLIVAS_KERNNAME".cl"); strcpy(binaryfilename, CKOLIVAS_KERNNAME); - /* Kernel only supports vector 1 */ - cgpu->vwidth = 1; break; case KL_ZUIKKIS: + applog(LOG_WARNING, "Kernel zuikkis is experimental."); strcpy(filename, ZUIKKIS_KERNNAME".cl"); strcpy(binaryfilename, ZUIKKIS_KERNNAME); - /* Kernel only supports vector 1 */ - cgpu->vwidth = 1; + /* Kernel only supports lookup-gap 2 */ + cgpu->lookup_gap = 2; + /* Kernel only supports worksize 256 */ + cgpu->work_size = 256; break; case KL_NONE: /* Shouldn't happen */ break;