Set a true 256bit binary target based on any diff value in set_target()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
diff --git a/cgminer.c b/cgminer.c
index 52996b6..ca2a4cc 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5912,23 +5912,52 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len)
sha256(hash1, 32, hash);
}
+/* truediffone == 0x00000000FFFF0000000000000000000000000000000000000000000000000000
+ * Generate a 256 bit binary LE target by cutting up diff into 64 bit sized
+ * portions. */
+static double truediffone = 26959535291011309493156476344723991336010898738574164086137773096960.0;
+static double bits192 = 6277101735386680763835789423207666416102355444464034512896.0;
+static double bits128 = 340282366920938463463374607431768211456.0;
+static double bits64 = 18446744073709551616.0;
+
void set_target(unsigned char *dest_target, double diff)
{
- unsigned char target[32], rtarget[32];
+ unsigned char target[32];
uint64_t *data64, h64;
- double d64;
+ double d64, dcut64;
+ d64 = truediffone;
if (opt_scrypt)
- d64 = 0xFFFF00000000ull;
- else
- d64 = 0xFFFF0000ull;
+ d64 *= (double)65536;
d64 /= diff;
- h64 = d64;
- memset(rtarget, 0xFF, 32);
- data64 = (uint64_t *)rtarget;
- *data64 = htobe64(h64);
- swab256(target, rtarget);
+ dcut64 = d64 / bits192;
+ h64 = dcut64;
+ data64 = (uint64_t *)(target + 24);
+ *data64 = htole64(h64);
+ dcut64 = h64;
+ dcut64 *= bits192;
+ d64 -= dcut64;
+
+ dcut64 = d64 / bits128;
+ h64 = dcut64;
+ data64 = (uint64_t *)(target + 16);
+ *data64 = htole64(h64);
+ dcut64 = h64;
+ dcut64 *= bits128;
+ d64 -= dcut64;
+
+ dcut64 = d64 / bits64;
+ h64 = dcut64;
+ data64 = (uint64_t *)(target + 8);
+ *data64 = htole64(h64);
+ dcut64 = h64;
+ dcut64 *= bits64;
+ d64 -= dcut64;
+
+ h64 = d64;
+ data64 = (uint64_t *)(target);
+ *data64 = htole64(h64);
if (opt_debug) {
char *htarget = bin2hex(target, 32);