Browse Source

Added "Fresh" Algorithm and optimized it for a slight speed increase using extra kernels.

djm34
ystarnaud 10 years ago committed by troky
parent
commit
a90bbf7dd2
  1. 1
      Makefile.am
  2. 56
      algorithm.c
  3. 5
      algorithm.h
  4. 189
      algorithm/fresh.c
  5. 9
      algorithm/fresh.h
  6. 596
      kernel/fresh.cl
  7. 2
      winbuild/sgminer.vcxproj
  8. 34
      winbuild/sgminer.vcxproj.filters

1
Makefile.am

@ -64,6 +64,7 @@ sgminer_SOURCES += algorithm/maxcoin.c algorithm/maxcoin.h @@ -64,6 +64,7 @@ sgminer_SOURCES += algorithm/maxcoin.c algorithm/maxcoin.h
sgminer_SOURCES += algorithm/talkcoin.c algorithm/talkcoin.h
sgminer_SOURCES += algorithm/bitblock.c algorithm/bitblock.h
sgminer_SOURCES += algorithm/x14.c algorithm/x14.h
sgminer_SOURCES += algorithm/fresh.c algorithm/fresh.h
bin_SCRIPTS = $(top_srcdir)/kernel/*.cl

56
algorithm.c

@ -28,6 +28,7 @@ @@ -28,6 +28,7 @@
#include "algorithm/talkcoin.h"
#include "algorithm/bitblock.h"
#include "algorithm/x14.h"
#include "algorithm/fresh.h"
#include "compat.h"
@ -46,7 +47,8 @@ const char *algorithm_type_str[] = { @@ -46,7 +47,8 @@ const char *algorithm_type_str[] = {
"Quarkcoin",
"Twecoin",
"Fugue256",
"NIST"
"NIST",
"Fresh"
};
void sha256(const unsigned char *message, unsigned int len, unsigned char *digest)
@ -515,6 +517,38 @@ static cl_int queue_x14_old_kernel(struct __clState *clState, struct _dev_blk_ct @@ -515,6 +517,38 @@ static cl_int queue_x14_old_kernel(struct __clState *clState, struct _dev_blk_ct
return status;
}
static cl_int queue_fresh_kernel(struct __clState *clState, struct _dev_blk_ctx *blk, __maybe_unused cl_uint threads)
{
cl_kernel *kernel;
unsigned int num;
cl_ulong le_target;
cl_int status = 0;
le_target = *(cl_ulong *)(blk->work->device_target + 24);
flip80(clState->cldata, blk->work->data);
status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL,NULL);
// shavite 1 - search
kernel = &clState->kernel;
num = 0;
CL_SET_ARG(clState->CLbuffer0);
CL_SET_ARG(clState->padbuffer8);
// smid 1 - search1
kernel = clState->extra_kernels;
CL_SET_ARG_0(clState->padbuffer8);
// shavite 2 - search2
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// smid 2 - search3
CL_NEXTKERNEL_SET_ARG_0(clState->padbuffer8);
// echo - search4
num = 0;
CL_NEXTKERNEL_SET_ARG(clState->padbuffer8);
CL_SET_ARG(clState->outputBuffer);
CL_SET_ARG(le_target);
return status;
}
typedef struct _algorithm_settings_t {
const char *name; /* Human-readable identifier */
algorithm_type_t type; //common algorithm type
@ -579,6 +613,9 @@ static algorithm_settings_t algos[] = { @@ -579,6 +613,9 @@ static algorithm_settings_t algos[] = {
{ "bitblockold", ALGO_X15, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 10, 4 * 16 * 4194304, 0, bitblock_regenhash, queue_bitblockold_kernel, gen_hash, append_hamsi_compiler_options},
{ "talkcoin-mod", ALGO_NIST, 1, 1, 1, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 8 * 16 * 4194304, 0, talkcoin_regenhash, queue_talkcoin_mod_kernel, gen_hash, NULL},
{ "fresh", ALGO_FRESH, 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 4, 4 * 16 * 4194304, 0, fresh_regenhash, queue_fresh_kernel, gen_hash, NULL},
// kernels starting from this will have difficulty calculated by using fuguecoin algorithm
#define A_FUGUE(a, b) \
{ a, ALGO_FUGUE, 1, 256, 256, 0, 0, 0xFF, 0xFFFFULL, 0x0000ffffUL, 0, 0, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, b, queue_sph_kernel, sha256, NULL}
@ -595,13 +632,13 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo) @@ -595,13 +632,13 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo)
algorithm_settings_t* src;
// Find algorithm settings and copy
for (src = algos; src->name; src++)
for (src = algos; src->name; src++)
{
if (strcmp(src->name, algo) == 0)
if (strcmp(src->name, algo) == 0)
{
strcpy(dest->name, src->name);
dest->type = src->type;
dest->diff_multiplier1 = src->diff_multiplier1;
dest->diff_multiplier2 = src->diff_multiplier2;
dest->share_diff_multiplier = src->share_diff_multiplier;
@ -622,7 +659,7 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo) @@ -622,7 +659,7 @@ void copy_algorithm_settings(algorithm_t* dest, const char* algo)
}
// if not found
if (src->name == NULL)
if (src->name == NULL)
{
applog(LOG_WARNING, "Algorithm %s not found, using %s.", algo, algos->name);
copy_algorithm_settings(dest, algos->name);
@ -666,8 +703,8 @@ void set_algorithm(algorithm_t* algo, const char* newname_alias) @@ -666,8 +703,8 @@ void set_algorithm(algorithm_t* algo, const char* newname_alias)
{
const char* newname;
//load previous algorithm nfactor in case nfactor was applied before algorithm... or default to 10
uint8_t old_nfactor = ((algo->nfactor)?algo->nfactor:0);
uint8_t nfactor = 10;
uint8_t old_nfactor = ((algo->nfactor)?algo->nfactor:0);
uint8_t nfactor = 0;
if (!(newname = lookup_algorithm_alias(newname_alias, &nfactor)))
newname = newname_alias;
@ -679,13 +716,16 @@ void set_algorithm(algorithm_t* algo, const char* newname_alias) @@ -679,13 +716,16 @@ void set_algorithm(algorithm_t* algo, const char* newname_alias)
nfactor = old_nfactor;
set_algorithm_nfactor(algo, nfactor);
// Doesn't matter for non-scrypt algorithms
if (nfactor > 0)
set_algorithm_nfactor(algo, nfactor);
}
void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor)
{
algo->nfactor = nfactor;
algo->n = (1 << nfactor);
//adjust algo type accordingly
switch (algo->type)
{

5
algorithm.h

@ -22,10 +22,11 @@ typedef enum { @@ -22,10 +22,11 @@ typedef enum {
ALGO_QUARK,
ALGO_TWE,
ALGO_FUGUE,
ALGO_NIST
ALGO_NIST,
ALGO_FRESH
} algorithm_type_t;
extern const char *algorithm_type_str[];
extern const char *algorithm_type_str[];
extern void gen_hash(const unsigned char *data, unsigned int len, unsigned char *hash);

189
algorithm/fresh.c

@ -0,0 +1,189 @@ @@ -0,0 +1,189 @@
/*-
* Copyright 2009 Colin Percival, 2014 savale
* 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.
*/
#include "config.h"
#include "miner.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "sph/sph_shavite.h"
#include "sph/sph_simd.h"
#include "sph/sph_echo.h"
/* Move init out of loop, so init once externally, and then use one single memcpy with that bigger memory block */
typedef struct {
sph_shavite512_context shavite1;
sph_simd512_context simd1;
sph_echo512_context echo1;
sph_shavite512_context shavite2;
sph_simd512_context simd2;
sph_echo512_context echo2;
} FreshHash_context_holder;
FreshHash_context_holder base_contexts;
void init_freshHash_contexts()
{
sph_shavite512_init(&base_contexts.shavite1);
sph_simd512_init(&base_contexts.simd1);
sph_echo512_init(&base_contexts.echo1);
sph_shavite512_init(&base_contexts.shavite2);
sph_simd512_init(&base_contexts.simd2);
sph_echo512_init(&base_contexts.echo2);
}
/*
* Encode a length len/4 vector of (uint32_t) into a length len vector of
* (unsigned char) in big-endian form. Assumes len is a multiple of 4.
*/
static inline void
be32enc_vect(uint32_t *dst, const uint32_t *src, uint32_t len)
{
uint32_t i;
for (i = 0; i < len; i++)
dst[i] = htobe32(src[i]);
}
inline void freshHash(void *state, const void *input)
{
init_freshHash_contexts();
FreshHash_context_holder ctx;
uint32_t hashA[16], hashB[16];
//shavite-simd-shavite-simd-echo
memcpy(&ctx, &base_contexts, sizeof(base_contexts));
sph_shavite512 (&ctx.shavite1, input, 80);
sph_shavite512_close(&ctx.shavite1, hashA);
sph_simd512 (&ctx.simd1, hashA, 64);
sph_simd512_close(&ctx.simd1, hashB);
sph_shavite512 (&ctx.shavite2,hashB, 64);
sph_shavite512_close(&ctx.shavite2, hashA);
sph_simd512 (&ctx.simd2, hashA, 64);
sph_simd512_close(&ctx.simd2, hashB);
sph_echo512 (&ctx.echo1, hashB, 64);
sph_echo512_close(&ctx.echo1, hashA);
memcpy(state, hashA, 32);
}
static const uint32_t diff1targ = 0x0000ffff;
/* Used externally as confirmation of correct OCL code */
int fresh_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce)
{
uint32_t tmp_hash7, Htarg = le32toh(((const uint32_t *)ptarget)[7]);
uint32_t data[20], ohash[8];
//char *scratchbuf;
be32enc_vect(data, (const uint32_t *)pdata, 19);
data[19] = htobe32(nonce);
//scratchbuf = alloca(SCRATCHBUF_SIZE);
freshHash(ohash, data);
tmp_hash7 = be32toh(ohash[7]);
applog(LOG_DEBUG, "htarget %08lx diff1 %08lx hash %08lx",
(long unsigned int)Htarg,
(long unsigned int)diff1targ,
(long unsigned int)tmp_hash7);
if (tmp_hash7 > diff1targ)
return -1;
if (tmp_hash7 > Htarg)
return 0;
return 1;
}
void fresh_regenhash(struct work *work)
{
uint32_t data[20];
char *scratchbuf;
uint32_t *nonce = (uint32_t *)(work->data + 76);
uint32_t *ohash = (uint32_t *)(work->hash);
be32enc_vect(data, (const uint32_t *)work->data, 19);
data[19] = htobe32(*nonce);
freshHash(ohash, data);
}
bool scanhash_fresh(struct thr_info *thr, const unsigned char __maybe_unused *pmidstate,
unsigned char *pdata, unsigned char __maybe_unused *phash1,
unsigned char __maybe_unused *phash, const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_nonce, uint32_t n)
{
uint32_t *nonce = (uint32_t *)(pdata + 76);
char *scratchbuf;
uint32_t data[20];
uint32_t tmp_hash7;
uint32_t Htarg = le32toh(((const uint32_t *)ptarget)[7]);
bool ret = false;
be32enc_vect(data, (const uint32_t *)pdata, 19);
while(1)
{
uint32_t ostate[8];
*nonce = ++n;
data[19] = (n);
freshHash(ostate, data);
tmp_hash7 = (ostate[7]);
applog(LOG_INFO, "data7 %08lx",
(long unsigned int)data[7]);
if (unlikely(tmp_hash7 <= Htarg))
{
((uint32_t *)pdata)[19] = htobe32(n);
*last_nonce = n;
ret = true;
break;
}
if (unlikely((n >= max_nonce) || thr->work_restart))
{
*last_nonce = n;
break;
}
}
return ret;
}

9
algorithm/fresh.h

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
#ifndef FRESHH_H
#define FRESHH_H
#include "miner.h"
extern int fresh_test(unsigned char *pdata, const unsigned char *ptarget, uint32_t nonce);
extern void fresh_regenhash(struct work *work);
#endif /* FRESHH_H */

596
kernel/fresh.cl

@ -0,0 +1,596 @@ @@ -0,0 +1,596 @@
/*
* FRESH kernel implementation.
*
* ==========================(LICENSE BEGIN)============================
*
* Copyright (c) 2014 Savale
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* ===========================(LICENSE END)=============================
*
* @author Savale <info@freshcoin.net>
*/
#ifndef FRESH_CL
#define FRESH_CL
#if __ENDIAN_LITTLE__
#define SPH_LITTLE_ENDIAN 1
#else
#define SPH_BIG_ENDIAN 1
#endif
#define SPH_UPTR sph_u64
typedef unsigned int sph_u32;
typedef int sph_s32;
#ifndef __OPENCL_VERSION__
typedef unsigned long long sph_u64;
typedef long long sph_s64;
#else
typedef unsigned long sph_u64;
typedef long sph_s64;
#endif
#define SPH_64 1
#define SPH_64_TRUE 1
#define SPH_C32(x) ((sph_u32)(x ## U))
#define SPH_T32(x) (as_uint(x))
#define SPH_ROTL32(x, n) rotate(as_uint(x), as_uint(n))
#define SPH_ROTR32(x, n) SPH_ROTL32(x, (32 - (n)))
#define SPH_C64(x) ((sph_u64)(x ## UL))
#define SPH_T64(x) (as_ulong(x))
#define SPH_ROTL64(x, n) rotate(as_ulong(x), (n) & 0xFFFFFFFFFFFFFFFFUL)
#define SPH_ROTR64(x, n) SPH_ROTL64(x, (64 - (n)))
#define SPH_ECHO_64 1
#define SPH_SIMD_NOCOPY 0
#include "shavite.cl"
#include "simd.cl"
#include "echo.cl"
#define SWAP4(x) as_uint(as_uchar4(x).wzyx)
#define SWAP8(x) as_ulong(as_uchar8(x).s76543210)
#if SPH_BIG_ENDIAN
#define DEC64E(x) (x)
#define DEC64BE(x) (*(const __global sph_u64 *) (x));
#define DEC32LE(x) SWAP4(*(const __global sph_u32 *) (x));
#else
#define DEC64E(x) SWAP8(x)
#define DEC64BE(x) SWAP8(*(const __global sph_u64 *) (x));
#define DEC32LE(x) (*(const __global sph_u32 *) (x));
#endif
typedef union {
unsigned char h1[64];
uint h4[16];
ulong h8[8];
} hash_t;
__attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
__kernel void search(__global unsigned char* block, __global hash_t* hashes)
{
uint gid = get_global_id(0);
__global hash_t *hash = &(hashes[gid-get_global_offset(0)]);
__local sph_u32 AES0[256], AES1[256], AES2[256], AES3[256];
int init = get_local_id(0);
int step = get_local_size(0);
for (int i = init; i < 256; i += step)
{
AES0[i] = AES0_C[i];
AES1[i] = AES1_C[i];
AES2[i] = AES2_C[i];
AES3[i] = AES3_C[i];
}
barrier(CLK_LOCAL_MEM_FENCE);
// shavite
// IV
sph_u32 h0 = SPH_C32(0x72FCCDD8), h1 = SPH_C32(0x79CA4727), h2 = SPH_C32(0x128A077B), h3 = SPH_C32(0x40D55AEC);
sph_u32 h4 = SPH_C32(0xD1901A06), h5 = SPH_C32(0x430AE307), h6 = SPH_C32(0xB29F5CD1), h7 = SPH_C32(0xDF07FBFC);
sph_u32 h8 = SPH_C32(0x8E45D73D), h9 = SPH_C32(0x681AB538), hA = SPH_C32(0xBDE86578), hB = SPH_C32(0xDD577E47);
sph_u32 hC = SPH_C32(0xE275EADE), hD = SPH_C32(0x502D9FCD), hE = SPH_C32(0xB9357178), hF = SPH_C32(0x022A4B9A);
// state
sph_u32 rk00, rk01, rk02, rk03, rk04, rk05, rk06, rk07;
sph_u32 rk08, rk09, rk0A, rk0B, rk0C, rk0D, rk0E, rk0F;
sph_u32 rk10, rk11, rk12, rk13, rk14, rk15, rk16, rk17;
sph_u32 rk18, rk19, rk1A, rk1B, rk1C, rk1D, rk1E, rk1F;
sph_u32 sc_count0 = 0x280, sc_count1 = 0, sc_count2 = 0, sc_count3 = 0;
rk00 = DEC32LE(block + 0);
rk01 = DEC32LE(block + 4);
rk02 = DEC32LE(block + 8);
rk03 = DEC32LE(block + 12);
rk04 = DEC32LE(block + 16);
rk05 = DEC32LE(block + 20);
rk06 = DEC32LE(block + 24);
rk07 = DEC32LE(block + 28);
rk08 = DEC32LE(block + 32);
rk09 = DEC32LE(block + 36);
rk0A = DEC32LE(block + 40);
rk0B = DEC32LE(block + 44);
rk0C = DEC32LE(block + 48);
rk0D = DEC32LE(block + 52);
rk0E = DEC32LE(block + 56);
rk0F = DEC32LE(block + 60);
rk10 = DEC32LE(block + 64);
rk11 = DEC32LE(block + 68);
rk12 = DEC32LE(block + 72);
rk13 = gid;
rk14 = 0x80;
rk15 = rk16 = rk17 = rk18 = rk19 = rk1A = 0;
rk1B = 0x2800000;
rk1C = rk1D = rk1E = 0;
rk1F = 0x2000000;
c512(buf);
hash->h4[0] = h0;
hash->h4[1] = h1;
hash->h4[2] = h2;
hash->h4[3] = h3;
hash->h4[4] = h4;
hash->h4[5] = h5;
hash->h4[6] = h6;
hash->h4[7] = h7;
hash->h4[8] = h8;
hash->h4[9] = h9;
hash->h4[10] = hA;
hash->h4[11] = hB;
hash->h4[12] = hC;
hash->h4[13] = hD;
hash->h4[14] = hE;
hash->h4[15] = hF;
barrier(CLK_GLOBAL_MEM_FENCE);
}
__attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
__kernel void search1(__global hash_t* hashes)
{
uint gid = get_global_id(0);
__global hash_t *hash = &(hashes[gid-get_global_offset(0)]);
// simd
s32 q[256];
unsigned char x[128];
for(unsigned int i = 0; i < 64; i++)
x[i] = hash->h1[i];
for(unsigned int i = 64; i < 128; i++)
x[i] = 0;
u32 A0 = C32(0x0BA16B95), A1 = C32(0x72F999AD), A2 = C32(0x9FECC2AE), A3 = C32(0xBA3264FC), A4 = C32(0x5E894929), A5 = C32(0x8E9F30E5), A6 = C32(0x2F1DAA37), A7 = C32(0xF0F2C558);
u32 B0 = C32(0xAC506643), B1 = C32(0xA90635A5), B2 = C32(0xE25B878B), B3 = C32(0xAAB7878F), B4 = C32(0x88817F7A), B5 = C32(0x0A02892B), B6 = C32(0x559A7550), B7 = C32(0x598F657E);
u32 C0 = C32(0x7EEF60A1), C1 = C32(0x6B70E3E8), C2 = C32(0x9C1714D1), C3 = C32(0xB958E2A8), C4 = C32(0xAB02675E), C5 = C32(0xED1C014F), C6 = C32(0xCD8D65BB), C7 = C32(0xFDB7A257);
u32 D0 = C32(0x09254899), D1 = C32(0xD699C7BC), D2 = C32(0x9019B6DC), D3 = C32(0x2B9022E4), D4 = C32(0x8FA14956), D5 = C32(0x21BF9BD3), D6 = C32(0xB94D0943), D7 = C32(0x6FFDDC22);
FFT256(0, 1, 0, ll1);
for (int i = 0; i < 256; i ++)
{
s32 tq;
tq = q[i] + yoff_b_n[i];
tq = REDS2(tq);
tq = REDS1(tq);
tq = REDS1(tq);
q[i] = (tq <= 128 ? tq : tq - 257);
}
A0 ^= hash->h4[0];
A1 ^= hash->h4[1];
A2 ^= hash->h4[2];
A3 ^= hash->h4[3];
A4 ^= hash->h4[4];
A5 ^= hash->h4[5];
A6 ^= hash->h4[6];
A7 ^= hash->h4[7];
B0 ^= hash->h4[8];
B1 ^= hash->h4[9];
B2 ^= hash->h4[10];
B3 ^= hash->h4[11];
B4 ^= hash->h4[12];
B5 ^= hash->h4[13];
B6 ^= hash->h4[14];
B7 ^= hash->h4[15];
ONE_ROUND_BIG(0_, 0, 3, 23, 17, 27);
ONE_ROUND_BIG(1_, 1, 28, 19, 22, 7);
ONE_ROUND_BIG(2_, 2, 29, 9, 15, 5);
ONE_ROUND_BIG(3_, 3, 4, 13, 10, 25);
STEP_BIG(
C32(0x0BA16B95), C32(0x72F999AD), C32(0x9FECC2AE), C32(0xBA3264FC),
C32(0x5E894929), C32(0x8E9F30E5), C32(0x2F1DAA37), C32(0xF0F2C558),
IF, 4, 13, PP8_4_);
STEP_BIG(
C32(0xAC506643), C32(0xA90635A5), C32(0xE25B878B), C32(0xAAB7878F),
C32(0x88817F7A), C32(0x0A02892B), C32(0x559A7550), C32(0x598F657E),
IF, 13, 10, PP8_5_);
STEP_BIG(
C32(0x7EEF60A1), C32(0x6B70E3E8), C32(0x9C1714D1), C32(0xB958E2A8),
C32(0xAB02675E), C32(0xED1C014F), C32(0xCD8D65BB), C32(0xFDB7A257),
IF, 10, 25, PP8_6_);
STEP_BIG(
C32(0x09254899), C32(0xD699C7BC), C32(0x9019B6DC), C32(0x2B9022E4),
C32(0x8FA14956), C32(0x21BF9BD3), C32(0xB94D0943), C32(0x6FFDDC22),
IF, 25, 4, PP8_0_);
u32 COPY_A0 = A0, COPY_A1 = A1, COPY_A2 = A2, COPY_A3 = A3, COPY_A4 = A4, COPY_A5 = A5, COPY_A6 = A6, COPY_A7 = A7;
u32 COPY_B0 = B0, COPY_B1 = B1, COPY_B2 = B2, COPY_B3 = B3, COPY_B4 = B4, COPY_B5 = B5, COPY_B6 = B6, COPY_B7 = B7;
u32 COPY_C0 = C0, COPY_C1 = C1, COPY_C2 = C2, COPY_C3 = C3, COPY_C4 = C4, COPY_C5 = C5, COPY_C6 = C6, COPY_C7 = C7;
u32 COPY_D0 = D0, COPY_D1 = D1, COPY_D2 = D2, COPY_D3 = D3, COPY_D4 = D4, COPY_D5 = D5, COPY_D6 = D6, COPY_D7 = D7;
#define q SIMD_Q
A0 ^= 0x200;
ONE_ROUND_BIG(0_, 0, 3, 23, 17, 27);
ONE_ROUND_BIG(1_, 1, 28, 19, 22, 7);
ONE_ROUND_BIG(2_, 2, 29, 9, 15, 5);
ONE_ROUND_BIG(3_, 3, 4, 13, 10, 25);
STEP_BIG(
COPY_A0, COPY_A1, COPY_A2, COPY_A3,
COPY_A4, COPY_A5, COPY_A6, COPY_A7,
IF, 4, 13, PP8_4_);
STEP_BIG(
COPY_B0, COPY_B1, COPY_B2, COPY_B3,
COPY_B4, COPY_B5, COPY_B6, COPY_B7,
IF, 13, 10, PP8_5_);
STEP_BIG(
COPY_C0, COPY_C1, COPY_C2, COPY_C3,
COPY_C4, COPY_C5, COPY_C6, COPY_C7,
IF, 10, 25, PP8_6_);
STEP_BIG(
COPY_D0, COPY_D1, COPY_D2, COPY_D3,
COPY_D4, COPY_D5, COPY_D6, COPY_D7,
IF, 25, 4, PP8_0_);
#undef q
hash->h4[0] = A0;
hash->h4[1] = A1;
hash->h4[2] = A2;
hash->h4[3] = A3;
hash->h4[4] = A4;
hash->h4[5] = A5;
hash->h4[6] = A6;
hash->h4[7] = A7;
hash->h4[8] = B0;
hash->h4[9] = B1;
hash->h4[10] = B2;
hash->h4[11] = B3;
hash->h4[12] = B4;
hash->h4[13] = B5;
hash->h4[14] = B6;
hash->h4[15] = B7;
barrier(CLK_GLOBAL_MEM_FENCE);
}
__attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
__kernel void search2(__global hash_t* hashes)
{
uint gid = get_global_id(0);
__global hash_t *hash = &(hashes[gid-get_global_offset(0)]);
__local sph_u32 AES0[256], AES1[256], AES2[256], AES3[256];
int init = get_local_id(0);
int step = get_local_size(0);
for (int i = init; i < 256; i += step)
{
AES0[i] = AES0_C[i];
AES1[i] = AES1_C[i];
AES2[i] = AES2_C[i];
AES3[i] = AES3_C[i];
}
barrier(CLK_LOCAL_MEM_FENCE);
// shavite
// IV
sph_u32 h0 = SPH_C32(0x72FCCDD8), h1 = SPH_C32(0x79CA4727), h2 = SPH_C32(0x128A077B), h3 = SPH_C32(0x40D55AEC);
sph_u32 h4 = SPH_C32(0xD1901A06), h5 = SPH_C32(0x430AE307), h6 = SPH_C32(0xB29F5CD1), h7 = SPH_C32(0xDF07FBFC);
sph_u32 h8 = SPH_C32(0x8E45D73D), h9 = SPH_C32(0x681AB538), hA = SPH_C32(0xBDE86578), hB = SPH_C32(0xDD577E47);
sph_u32 hC = SPH_C32(0xE275EADE), hD = SPH_C32(0x502D9FCD), hE = SPH_C32(0xB9357178), hF = SPH_C32(0x022A4B9A);
// state
sph_u32 rk00, rk01, rk02, rk03, rk04, rk05, rk06, rk07;
sph_u32 rk08, rk09, rk0A, rk0B, rk0C, rk0D, rk0E, rk0F;
sph_u32 rk10, rk11, rk12, rk13, rk14, rk15, rk16, rk17;
sph_u32 rk18, rk19, rk1A, rk1B, rk1C, rk1D, rk1E, rk1F;
sph_u32 sc_count0 = 0x200, sc_count1 = 0, sc_count2 = 0, sc_count3 = 0;
rk00 = hash->h4[0];
rk01 = hash->h4[1];
rk02 = hash->h4[2];
rk03 = hash->h4[3];
rk04 = hash->h4[4];
rk05 = hash->h4[5];
rk06 = hash->h4[6];
rk07 = hash->h4[7];
rk08 = hash->h4[8];
rk09 = hash->h4[9];
rk0A = hash->h4[10];
rk0B = hash->h4[11];
rk0C = hash->h4[12];
rk0D = hash->h4[13];
rk0E = hash->h4[14];
rk0F = hash->h4[15];
rk10 = 0x80;
rk11 = rk12 = rk13 = rk14 = rk15 = rk16 = rk17 = rk18 = rk19 = rk1A = 0;
rk1B = 0x2000000;
rk1C = rk1D = rk1E = 0;
rk1F = 0x2000000;
c512(buf);
hash->h4[0] = h0;
hash->h4[1] = h1;
hash->h4[2] = h2;
hash->h4[3] = h3;
hash->h4[4] = h4;
hash->h4[5] = h5;
hash->h4[6] = h6;
hash->h4[7] = h7;
hash->h4[8] = h8;
hash->h4[9] = h9;
hash->h4[10] = hA;
hash->h4[11] = hB;
hash->h4[12] = hC;
hash->h4[13] = hD;
hash->h4[14] = hE;
hash->h4[15] = hF;
barrier(CLK_GLOBAL_MEM_FENCE);
}
__attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
__kernel void search3(__global hash_t* hashes)
{
uint gid = get_global_id(0);
__global hash_t *hash = &(hashes[gid-get_global_offset(0)]);
// simd
s32 q[256];
unsigned char x[128];
for(unsigned int i = 0; i < 64; i++)
x[i] = hash->h1[i];
for(unsigned int i = 64; i < 128; i++)
x[i] = 0;
u32 A0 = C32(0x0BA16B95), A1 = C32(0x72F999AD), A2 = C32(0x9FECC2AE), A3 = C32(0xBA3264FC), A4 = C32(0x5E894929), A5 = C32(0x8E9F30E5), A6 = C32(0x2F1DAA37), A7 = C32(0xF0F2C558);
u32 B0 = C32(0xAC506643), B1 = C32(0xA90635A5), B2 = C32(0xE25B878B), B3 = C32(0xAAB7878F), B4 = C32(0x88817F7A), B5 = C32(0x0A02892B), B6 = C32(0x559A7550), B7 = C32(0x598F657E);
u32 C0 = C32(0x7EEF60A1), C1 = C32(0x6B70E3E8), C2 = C32(0x9C1714D1), C3 = C32(0xB958E2A8), C4 = C32(0xAB02675E), C5 = C32(0xED1C014F), C6 = C32(0xCD8D65BB), C7 = C32(0xFDB7A257);
u32 D0 = C32(0x09254899), D1 = C32(0xD699C7BC), D2 = C32(0x9019B6DC), D3 = C32(0x2B9022E4), D4 = C32(0x8FA14956), D5 = C32(0x21BF9BD3), D6 = C32(0xB94D0943), D7 = C32(0x6FFDDC22);
FFT256(0, 1, 0, ll1);
for (int i = 0; i < 256; i ++)
{
s32 tq;
tq = q[i] + yoff_b_n[i];
tq = REDS2(tq);
tq = REDS1(tq);
tq = REDS1(tq);
q[i] = (tq <= 128 ? tq : tq - 257);
}
A0 ^= hash->h4[0];
A1 ^= hash->h4[1];
A2 ^= hash->h4[2];
A3 ^= hash->h4[3];
A4 ^= hash->h4[4];
A5 ^= hash->h4[5];
A6 ^= hash->h4[6];
A7 ^= hash->h4[7];
B0 ^= hash->h4[8];
B1 ^= hash->h4[9];
B2 ^= hash->h4[10];
B3 ^= hash->h4[11];
B4 ^= hash->h4[12];
B5 ^= hash->h4[13];
B6 ^= hash->h4[14];
B7 ^= hash->h4[15];
ONE_ROUND_BIG(0_, 0, 3, 23, 17, 27);
ONE_ROUND_BIG(1_, 1, 28, 19, 22, 7);
ONE_ROUND_BIG(2_, 2, 29, 9, 15, 5);
ONE_ROUND_BIG(3_, 3, 4, 13, 10, 25);
STEP_BIG(
C32(0x0BA16B95), C32(0x72F999AD), C32(0x9FECC2AE), C32(0xBA3264FC),
C32(0x5E894929), C32(0x8E9F30E5), C32(0x2F1DAA37), C32(0xF0F2C558),
IF, 4, 13, PP8_4_);
STEP_BIG(
C32(0xAC506643), C32(0xA90635A5), C32(0xE25B878B), C32(0xAAB7878F),
C32(0x88817F7A), C32(0x0A02892B), C32(0x559A7550), C32(0x598F657E),
IF, 13, 10, PP8_5_);
STEP_BIG(
C32(0x7EEF60A1), C32(0x6B70E3E8), C32(0x9C1714D1), C32(0xB958E2A8),
C32(0xAB02675E), C32(0xED1C014F), C32(0xCD8D65BB), C32(0xFDB7A257),
IF, 10, 25, PP8_6_);
STEP_BIG(
C32(0x09254899), C32(0xD699C7BC), C32(0x9019B6DC), C32(0x2B9022E4),
C32(0x8FA14956), C32(0x21BF9BD3), C32(0xB94D0943), C32(0x6FFDDC22),
IF, 25, 4, PP8_0_);
u32 COPY_A0 = A0, COPY_A1 = A1, COPY_A2 = A2, COPY_A3 = A3, COPY_A4 = A4, COPY_A5 = A5, COPY_A6 = A6, COPY_A7 = A7;
u32 COPY_B0 = B0, COPY_B1 = B1, COPY_B2 = B2, COPY_B3 = B3, COPY_B4 = B4, COPY_B5 = B5, COPY_B6 = B6, COPY_B7 = B7;
u32 COPY_C0 = C0, COPY_C1 = C1, COPY_C2 = C2, COPY_C3 = C3, COPY_C4 = C4, COPY_C5 = C5, COPY_C6 = C6, COPY_C7 = C7;
u32 COPY_D0 = D0, COPY_D1 = D1, COPY_D2 = D2, COPY_D3 = D3, COPY_D4 = D4, COPY_D5 = D5, COPY_D6 = D6, COPY_D7 = D7;
#define q SIMD_Q
A0 ^= 0x200;
ONE_ROUND_BIG(0_, 0, 3, 23, 17, 27);
ONE_ROUND_BIG(1_, 1, 28, 19, 22, 7);
ONE_ROUND_BIG(2_, 2, 29, 9, 15, 5);
ONE_ROUND_BIG(3_, 3, 4, 13, 10, 25);
STEP_BIG(
COPY_A0, COPY_A1, COPY_A2, COPY_A3,
COPY_A4, COPY_A5, COPY_A6, COPY_A7,
IF, 4, 13, PP8_4_);
STEP_BIG(
COPY_B0, COPY_B1, COPY_B2, COPY_B3,
COPY_B4, COPY_B5, COPY_B6, COPY_B7,
IF, 13, 10, PP8_5_);
STEP_BIG(
COPY_C0, COPY_C1, COPY_C2, COPY_C3,
COPY_C4, COPY_C5, COPY_C6, COPY_C7,
IF, 10, 25, PP8_6_);
STEP_BIG(
COPY_D0, COPY_D1, COPY_D2, COPY_D3,
COPY_D4, COPY_D5, COPY_D6, COPY_D7,
IF, 25, 4, PP8_0_);
#undef q
hash->h4[0] = A0;
hash->h4[1] = A1;
hash->h4[2] = A2;
hash->h4[3] = A3;
hash->h4[4] = A4;
hash->h4[5] = A5;
hash->h4[6] = A6;
hash->h4[7] = A7;
hash->h4[8] = B0;
hash->h4[9] = B1;
hash->h4[10] = B2;
hash->h4[11] = B3;
hash->h4[12] = B4;
hash->h4[13] = B5;
hash->h4[14] = B6;
hash->h4[15] = B7;
barrier(CLK_GLOBAL_MEM_FENCE);
}
__attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
__kernel void search4(__global hash_t* hashes, __global uint* output, const ulong target)
{
uint gid = get_global_id(0);
__global hash_t *hash = &(hashes[gid-get_global_offset(0)]);
__local sph_u32 AES0[256], AES1[256], AES2[256], AES3[256];
int init = get_local_id(0);
int step = get_local_size(0);
for (int i = init; i < 256; i += step)
{
AES0[i] = AES0_C[i];
AES1[i] = AES1_C[i];
AES2[i] = AES2_C[i];
AES3[i] = AES3_C[i];
}
barrier(CLK_LOCAL_MEM_FENCE);
// echo
sph_u64 W00, W01, W10, W11, W20, W21, W30, W31, W40, W41, W50, W51, W60, W61, W70, W71, W80, W81, W90, W91, WA0, WA1, WB0, WB1, WC0, WC1, WD0, WD1, WE0, WE1, WF0, WF1;
sph_u64 Vb00, Vb01, Vb10, Vb11, Vb20, Vb21, Vb30, Vb31, Vb40, Vb41, Vb50, Vb51, Vb60, Vb61, Vb70, Vb71;
Vb00 = Vb10 = Vb20 = Vb30 = Vb40 = Vb50 = Vb60 = Vb70 = 512UL;
Vb01 = Vb11 = Vb21 = Vb31 = Vb41 = Vb51 = Vb61 = Vb71 = 0;
sph_u32 K0 = 512;
sph_u32 K1 = 0;
sph_u32 K2 = 0;
sph_u32 K3 = 0;
W00 = Vb00;
W01 = Vb01;
W10 = Vb10;
W11 = Vb11;
W20 = Vb20;
W21 = Vb21;
W30 = Vb30;
W31 = Vb31;
W40 = Vb40;
W41 = Vb41;
W50 = Vb50;
W51 = Vb51;
W60 = Vb60;
W61 = Vb61;
W70 = Vb70;
W71 = Vb71;
W80 = hash->h8[0];
W81 = hash->h8[1];
W90 = hash->h8[2];
W91 = hash->h8[3];
WA0 = hash->h8[4];
WA1 = hash->h8[5];
WB0 = hash->h8[6];
WB1 = hash->h8[7];
WC0 = 0x80;
WC1 = 0;
WD0 = 0;
WD1 = 0;
WE0 = 0;
WE1 = 0x200000000000000;
WF0 = 0x200;
WF1 = 0;
for (unsigned u = 0; u < 10; u ++)
BIG_ROUND;
Vb00 ^= hash->h8[0] ^ W00 ^ W80;
Vb01 ^= hash->h8[1] ^ W01 ^ W81;
Vb10 ^= hash->h8[2] ^ W10 ^ W90;
Vb11 ^= hash->h8[3] ^ W11 ^ W91;
Vb20 ^= hash->h8[4] ^ W20 ^ WA0;
Vb21 ^= hash->h8[5] ^ W21 ^ WA1;
Vb30 ^= hash->h8[6] ^ W30 ^ WB0;
Vb31 ^= hash->h8[7] ^ W31 ^ WB1;
bool result = (Vb11 <= target);
if (result)
output[output[0xFF]++] = SWAP4(gid);
}
#endif // FRESH_CL

2
winbuild/sgminer.vcxproj

@ -264,6 +264,7 @@ @@ -264,6 +264,7 @@
<ClCompile Include="..\algorithm\bitblock.c" />
<ClCompile Include="..\algorithm\talkcoin.c" />
<ClCompile Include="..\algorithm\x14.c" />
<ClCompile Include="..\algorithm\fresh.c" />
<ClCompile Include="..\api.c" />
<ClCompile Include="..\ccan\opt\helpers.c" />
<ClCompile Include="..\ccan\opt\opt.c" />
@ -321,6 +322,7 @@ @@ -321,6 +322,7 @@
<ClInclude Include="..\algorithm\bitblock.h" />
<ClInclude Include="..\algorithm\talkcoin.h" />
<ClInclude Include="..\algorithm\x14.h" />
<ClInclude Include="..\algorithm\fresh.h" />
<ClInclude Include="..\api.h" />
<ClInclude Include="..\arg-nonnull.h" />
<ClInclude Include="..\bench_block.h" />

34
winbuild/sgminer.vcxproj.filters

@ -179,20 +179,26 @@ @@ -179,20 +179,26 @@
<ClCompile Include="..\config_parser.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\events.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\algorithm\talkcoin.c">
<Filter>Source Files\algorithm</Filter>
</ClCompile>
<ClCompile Include="..\sph\shabal.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\sph\whirlpool.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\algorithm\bitblock.c">
<Filter>Source Files\algorithm</Filter>
</ClCompile>
<ClCompile Include="..\algorithm\x14.c">
<Filter>Source Files\algorithm</Filter>
</ClCompile>
<ClCompile Include="..\sph\whirlpool.c">
<Filter>Source Files\sph</Filter>
</ClCompile>
<ClCompile Include="..\sph\shabal.c">
<Filter>Source Files\sph</Filter>
<ClCompile Include="..\algorithm\fresh.c">
<Filter>Source Files\algorithm</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
@ -352,23 +358,29 @@ @@ -352,23 +358,29 @@
<ClInclude Include="..\config_parser.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\events.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\algorithm\talkcoin.h">
<Filter>Header Files\algorithm</Filter>
</ClInclude>
<ClInclude Include="..\sph\sph_shabal.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\sph\sph_whirlpool.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\algorithm\bitblock.h">
<Filter>Header Files\algorithm</Filter>
</ClInclude>
<ClInclude Include="..\algorithm\x14.h">
<Filter>Header Files\algorithm</Filter>
</ClInclude>
<ClInclude Include="..\sph\sph_whirlpool.h">
<Filter>Header Files\sph</Filter>
</ClInclude>
<ClInclude Include="..\sph\sph_shabal.h">
<Filter>Header Files\sph</Filter>
<ClInclude Include="..\algorithm\fresh.h">
<Filter>Header Files\algorithm</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="README.txt" />
</ItemGroup>
</Project>
</Project>

Loading…
Cancel
Save