Commit ca91994709be3da34af2bbb27aa9a0820bbb7fbc

Con Kolivas 2013-10-26T23:14:34

Simplify the set_target function, allowing it to work properly for fractional diffs.

diff --git a/cgminer.c b/cgminer.c
index f6f5cce..c93479f 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5922,38 +5922,23 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len)
 	sha256(hash1, 32, hash);
 }
 
-/* Diff 1 is a 256 bit unsigned integer of
- * 0x00000000ffff0000000000000000000000000000000000000000000000000000
- * so we use a big endian 64 bit unsigned integer centred on the 5th byte to
- * cover a huge range of difficulty targets, though not all 256 bits' worth */
 void set_target(unsigned char *dest_target, double diff)
 {
-	unsigned char target[32];
+	unsigned char target[32], rtarget[32];
 	uint64_t *data64, h64;
 	double d64;
 
-	d64 = diffone;
+	if (opt_scrypt)
+		d64 = 0xFFFF00000000ull;
+	else
+		d64 = 0xFFFF0000ull;
 	d64 /= diff;
 	h64 = d64;
 
-	memset(target, 0, 32);
-	if (h64) {
-		unsigned char rtarget[32];
-
-		memset(rtarget, 0, 32);
-		if (opt_scrypt)
-			data64 = (uint64_t *)(rtarget + 2);
-		else
-			data64 = (uint64_t *)(rtarget + 4);
-		*data64 = htobe64(h64);
-		swab256(target, rtarget);
-	} else {
-		/* Support for the classic all FFs just-below-1 diff */
-		if (opt_scrypt)
-			memset(target, 0xff, 30);
-		else
-			memset(target, 0xff, 28);
-	}
+	memset(rtarget, 0xFF, 32);
+	data64 = (uint64_t *)rtarget;
+	*data64 = htobe64(h64);
+	swab256(target, rtarget);
 
 	if (opt_debug) {
 		char *htarget = bin2hex(target, 32);