Skip to content

Commit

Permalink
unified shabal
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyFFM committed Jan 26, 2019
1 parent a53490b commit 221bc3d
Show file tree
Hide file tree
Showing 17 changed files with 1,850 additions and 200 deletions.
10 changes: 9 additions & 1 deletion src/c/common.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#include "common.h"
#include <string.h>

void write_seed(char seed[32], uint64_t numeric_id) {
numeric_id = bswap_64(numeric_id);
memmove(&seed[0], &numeric_id, 8);
memset(&seed[8], 0, 8);
seed[16] = -128; // shabal message termination bit
memset(&seed[17], 0, 15);
}

void write_term(char term[32]) {
term[0] = -128; // shabal message termination bit
memset(&term[1], 0, 31);
}
}
60 changes: 58 additions & 2 deletions src/c/common.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,65 @@
#include <stdint.h>

#pragma once

#ifdef _MSC_VER

#include <stdlib.h>
#define bswap_32(x) _byteswap_ulong(x)
#define bswap_64(x) _byteswap_uint64(x)

#elif defined(__APPLE__)

// Mac OS X / Darwin features
#include <libkern/OSByteOrder.h>
#define bswap_32(x) OSSwapInt32(x)
#define bswap_64(x) OSSwapInt64(x)

#elif defined(__sun) || defined(sun)

#include <sys/byteorder.h>
#define bswap_32(x) BSWAP_32(x)
#define bswap_64(x) BSWAP_64(x)

#elif defined(__FreeBSD__)

#include <sys/endian.h>
#define bswap_32(x) bswap32(x)
#define bswap_64(x) bswap64(x)

#elif defined(__OpenBSD__)

#include <sys/types.h>
#define bswap_32(x) swap32(x)
#define bswap_64(x) swap64(x)

#elif defined(__NetBSD__)

#include <machine/bswap.h>
#include <sys/types.h>
#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
#define bswap_32(x) bswap32(x)
#define bswap_64(x) bswap64(x)
#endif

#else

#include <byteswap.h>

#endif

#define HASH_SIZE 32
#define HASH_CAP 4096
#define NUM_SCOOPS 4096
#define SCOOP_SIZE 64
#define NONCE_SIZE (HASH_CAP * SCOOP_SIZE) // 4096*64

void write_seed(char seed[32], uint64_t numeric_id);

void write_term(char term[32]);

#define SET_BEST_DEADLINE(d, o) \
if ((d) < *best_deadline) { \
*best_deadline = (d); \
*best_offset = (o); \
}

void write_term(char term[32]);
359 changes: 327 additions & 32 deletions src/c/mshabal_128_avx.c

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions src/c/mshabal_128_avx.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ typedef struct {
mshabal_u32 state[(12 + 16 + 16) * MSHABAL128_VECTOR_SIZE];
mshabal_u32 Whigh, Wlow;
unsigned out_size;
} mshabal_context;
} mshabal128_context;

#pragma pack(1)
typedef struct {
mshabal_u32 state[(12 + 16 + 16) * MSHABAL128_VECTOR_SIZE];
mshabal_u32 Whigh, Wlow;
unsigned out_size;
} mshabal_context_fast;
} mshabal128_context_fast;
#pragma pack()

/*
* Initialize a context structure. The output size must be a multiple
* of 32, between 32 and 512 (inclusive). The output size is expressed
* in bits.
*/
void mshabal_init_avx(mshabal_context *sc, unsigned out_size);
void mshabal_init_avx(mshabal128_context *sc, unsigned out_size);

/*
* Process some more data bytes; four chunks of data, pointed to by
Expand All @@ -126,7 +126,7 @@ void mshabal_init_avx(mshabal_context *sc, unsigned out_size);
* corresponding instance is deactivated (the final value obtained from
* that instance is undefined).
*/
void mshabal_avx(mshabal_context *sc, const void *data0, const void *data1, const void *data2,
void mshabal_avx(mshabal128_context *sc, const void *data0, const void *data1, const void *data2,
const void *data3, size_t len);

/*
Expand All @@ -151,15 +151,22 @@ void mshabal_avx(mshabal_context *sc, const void *data0, const void *data1, cons
* release it, or reinitialize it with mshabal_init(). The mshabal_close()
* function does NOT imply a hidden call to mshabal_init().
*/
void mshabal_close_avx(mshabal_context *sc, unsigned ub0, unsigned ub1, unsigned ub2,
void mshabal_close_avx(mshabal128_context *sc, unsigned ub0, unsigned ub1, unsigned ub2,
unsigned ub3, unsigned n, void *dst0, void *dst1, void *dst2,
void *dst3);

/*
* optimised Shabal Routine for PoC Mining
* optimised Shabal routine for PoC mining
*/
void mshabal_deadline_fast_avx(mshabal_context_fast *sc, void *message, void *termination, void *dst0,
void mshabal_deadline_fast_avx(mshabal128_context_fast *sc, void *message, void *termination, void *dst0,
void *dst1, void *dst2, void *dst3);

/*
* optimised Shabal routine for PoC plotting and hashing
*/
void mshabal_hash_fast_avx(mshabal128_context_fast *sc, void *message, void *termination,
void *dst, unsigned num);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 221bc3d

Please sign in to comment.