Commit a9a1f07f1f7b7091d1062b6513f0d7d7871146d5

Con Kolivas 2014-01-26T22:10:46

The second_run bool in libbitfury should be per device. Microoptimise its and job_switched usage, removing the unused results array for NF1 devices.

diff --git a/driver-bitfury.h b/driver-bitfury.h
index e802915..d3a3435 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -86,8 +86,8 @@ struct bitfury_info {
 	struct bitfury_payload opayload;
 	unsigned newbuf[17];
 	unsigned oldbuf[17];
-	int job_switched;
-	unsigned int results[16];
+	bool job_switched;
+	bool second_run;
 	struct work *work;
 	struct work *owork;
 };
diff --git a/libbitfury.c b/libbitfury.c
index 17f2cc1..bd10ff0 100644
--- a/libbitfury.c
+++ b/libbitfury.c
@@ -293,7 +293,6 @@ bool bitfury_checkresults(struct thr_info *thr, struct work *work, uint32_t nonc
 bool libbitfury_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury,
 			     struct bitfury_info *info)
 {
-	static unsigned second_run;
 	unsigned *newbuf = info->newbuf;
 	unsigned *oldbuf = info->oldbuf;
 	struct bitfury_payload *p = &(info->payload);
@@ -314,25 +313,27 @@ bool libbitfury_sendHashData(struct thr_info *thr, struct cgpu_info *bitfury,
 
 	info->job_switched = newbuf[16] != oldbuf[16];
 
-	if (second_run && info->job_switched) {
-		int i;
+	if (likely(info->second_run)) {
+		if (info->job_switched) {
+			int i;
 
-		for (i = 0; i < 16; i++) {
-			if (oldbuf[i] != newbuf[i] && info->owork) {
-				uint32_t nonce; //possible nonce
+			for (i = 0; i < 16; i++) {
+				if (oldbuf[i] != newbuf[i] && info->owork) {
+					uint32_t nonce; //possible nonce
 
-				nonce = decnonce(newbuf[i]);
-				if (bitfury_checkresults(thr, info->owork, nonce))
-					info->nonces++;
+					nonce = decnonce(newbuf[i]);
+					if (bitfury_checkresults(thr, info->owork, nonce))
+						info->nonces++;
+				}
 			}
-		}
 
-		memcpy(op, p, sizeof(struct bitfury_payload));
-		memcpy(oldbuf, newbuf, 17 * 4);
-	}
+			memcpy(op, p, sizeof(struct bitfury_payload));
+			memcpy(oldbuf, newbuf, 17 * 4);
+		}
+	} else
+		info->second_run = true;
 
 	cgsleep_ms(BITFURY_REFRESH_DELAY);
-	second_run = 1;
 
 	return true;
 }