From ca962ee58bad8373a76cf6c303abd0e5625bb710 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Thu, 11 Oct 2012 10:46:45 +1100 Subject: [PATCH] Use a 64 bit unsigned integer on the diff target to generate the hex target. --- cgminer.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/cgminer.c b/cgminer.c index 05729e06..8bc0e24e 100644 --- a/cgminer.c +++ b/cgminer.c @@ -4533,18 +4533,13 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len) static void set_work_target(struct work *work, int diff) { unsigned char rtarget[33], target[33]; - uint8_t *data8; - int i, j; - - /* Scale to any diff by setting number of bits according to diff */ - hex2bin(rtarget, "00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32); - data8 = (uint8_t *)(rtarget + 4); - for (i = 1, j = 0; i < diff; i++, j++) { - int byte = j / 8; - int bit = j % 8; + uint64_t *data64, h64; - data8[byte] &= ~(128 >> bit); - } + hex2bin(rtarget, "00000000ffff0000000000000000000000000000000000000000000000000000", 32); + data64 = (uint64_t *)(rtarget + 4); + h64 = be64toh(*data64); + h64 /= (uint64_t)diff; + *data64 = htobe64(h64); swab256(target, rtarget); if (opt_debug) { char *htarget = bin2hex(target, 32);