Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LucasJones/cpuminer-multi
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasjones committed May 23, 2014
2 parents 5e287fa + adce8dc commit 9bebbb3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
30 changes: 14 additions & 16 deletions aesb-x64.S
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
fast_aesb_single_round:
_fast_aesb_single_round:
#if defined(_WIN64) || defined(__CYGWIN__)
movdqu (%rcx), %xmm1
movdqa (%rcx), %xmm1
aesenc (%r8), %xmm1
movdqu %xmm1, (%rdx)
movdqa %xmm1, (%rdx)
#else
movdqu (%rdi), %xmm1
movdqa (%rdi), %xmm1
aesenc (%rdx), %xmm1
movdqu %xmm1, (%rsi)
movdqa %xmm1, (%rsi)
#endif
ret

Expand All @@ -28,30 +28,28 @@ _fast_aesb_single_round:
fast_aesb_pseudo_round_mut:
_fast_aesb_pseudo_round_mut:
#if defined(_WIN64) || defined(__CYGWIN__)
mov $0, %r9
mov $10, %r10
movdqu (%rcx), %xmm1
mov %rdx, %r9
add $0xA0, %r9
movdqa (%rcx), %xmm1

.LOOP:
aesenc (%rdx), %xmm1
add $0x10, %rdx
inc %r9
cmp %r10, %r9
cmp %r9, %rdx
jl .LOOP

movdqu %xmm1, (%rcx)
movdqa %xmm1, (%rcx)
#else
mov $0, %r9
mov $10, %r10
movdqu (%rdi), %xmm1
mov %rsi, %r9
add $0xA0, %r9
movdqa (%rdi), %xmm1

.LOOP:
aesenc (%rsi), %xmm1
add $0x10, %rsi
inc %r9
cmp %r10, %r9
cmp %r9, %rsi
jl .LOOP

movdqu %xmm1, (%rdi)
movdqa %xmm1, (%rdi)
#endif
ret
2 changes: 2 additions & 0 deletions crypto/oaes_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ static const char _NR[] = {
#include <stddef.h>
#include <time.h>
#include <sys/timeb.h>
#if !((defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__APPLE__))
#include <malloc.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down
12 changes: 9 additions & 3 deletions cryptonight.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static inline void xor_blocks_dst(const uint8_t* a, const uint8_t* b, uint8_t* d
struct cryptonight_ctx {
uint8_t long_state[MEMORY] __attribute((aligned(16)));
union cn_slow_hash_state state;
uint8_t text[INIT_SIZE_BYTE];
uint8_t text[INIT_SIZE_BYTE] __attribute((aligned(16)));
uint8_t a[AES_BLOCK_SIZE] __attribute__((aligned(16)));
uint8_t b[AES_BLOCK_SIZE] __attribute__((aligned(16)));
uint8_t c[AES_BLOCK_SIZE] __attribute__((aligned(16)));
Expand Down Expand Up @@ -194,7 +194,9 @@ void cryptonight_hash_ctx(void* output, const void* input, size_t len, struct cr
}

void cryptonight_hash(void* output, const void* input, size_t len) {
cryptonight_hash_ctx(output, input, len, alloca(sizeof(struct cryptonight_ctx)));
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));
cryptonight_hash_ctx(output, input, len, ctx);
free(ctx);
}

void cryptonight_hash_ctx_aes_ni(void* output, const void* input, size_t len, struct cryptonight_ctx* ctx) {
Expand Down Expand Up @@ -269,14 +271,15 @@ int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
const uint32_t Htarg = ptarget[7];
uint32_t hash[HASH_SIZE / 4] __attribute__((aligned(32)));

struct cryptonight_ctx *ctx = alloca(sizeof(struct cryptonight_ctx));
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*)malloc(sizeof(struct cryptonight_ctx));

if (aes_ni) {
do {
*nonceptr = ++n;
cryptonight_hash_ctx_aes_ni(hash, pdata, 76, ctx);
if (unlikely(hash[7] < ptarget[7])) {
*hashes_done = n - first_nonce + 1;
free(ctx);
return true;
}
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));
Expand All @@ -286,10 +289,13 @@ int scanhash_cryptonight(int thr_id, uint32_t *pdata, const uint32_t *ptarget,
cryptonight_hash_ctx(hash, pdata, 76, ctx);
if (unlikely(hash[7] < ptarget[7])) {
*hashes_done = n - first_nonce + 1;
free(ctx);
return true;
}
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));
}

free(ctx);
*hashes_done = n - first_nonce + 1;
return 0;
}

0 comments on commit 9bebbb3

Please sign in to comment.