Skip to content

Commit

Permalink
icarus: Minor optimisation (swap byte order in 32-bit always-aligned …
Browse files Browse the repository at this point in the history
…groups, and skip pointless memory copy)
  • Loading branch information
luke-jr committed May 22, 2014
1 parent a579752 commit 2b3baa2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
18 changes: 2 additions & 16 deletions driver-icarus.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,6 @@ extern const struct bfg_set_device_definition icarus_set_device_funcs[];

extern void convert_icarus_to_cairnsmore(struct cgpu_info *);

static void rev(unsigned char *s, size_t l)
{
size_t i, j;
unsigned char t;

for (i = 0, j = l - 1; i < j; i++, j--) {
t = s[i];
s[i] = s[j];
s[j] = t;
}
}

static inline
uint32_t icarus_nonce32toh(const struct ICARUS_INFO * const info, const uint32_t nonce)
{
Expand Down Expand Up @@ -744,17 +732,15 @@ bool icarus_job_prepare(struct thr_info *thr, struct work *work, __maybe_unused
struct icarus_state * const state = thr->cgpu_data;
uint8_t * const ob_bin = state->ob_bin;

memcpy(ob_bin, work->midstate, 32);
memcpy(ob_bin + 52, work->data + 64, 12);
swab256(ob_bin, work->midstate);
bswap_96p(&ob_bin[0x34], &work->data[0x40]);
if (!(memcmp(&ob_bin[56], "\xff\xff\xff\xff", 4)
|| memcmp(&ob_bin, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32))) {
// This sequence is used on cairnsmore bitstreams for commands, NEVER send it otherwise
applog(LOG_WARNING, "%"PRIpreprv": Received job attempting to send a command, corrupting it!",
icarus->proc_repr);
ob_bin[56] = 0;
}
rev(ob_bin, 32);
rev(ob_bin + 52, 12);

return true;
}
Expand Down
11 changes: 11 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,17 @@ static inline void swab256(void *dest_p, const void *src_p)
dest[7] = swab32(src[0]);
}

static inline
void bswap_96p(void * const dest_p, const void * const src_p)
{
uint32_t * const dest = dest_p;
const uint32_t * const src = src_p;

dest[0] = bswap_32(src[2]);
dest[1] = bswap_32(src[1]);
dest[2] = bswap_32(src[0]);
}

#define flip32(dest_p, src_p) swap32yes(dest_p, src_p, 32 / 4)

#define WATCHDOG_INTERVAL 2
Expand Down

0 comments on commit 2b3baa2

Please sign in to comment.