Browse Source

Clean up Ztex change

Luke Dashjr 13 years ago
parent
commit
9300d79f9c
2 changed files with 19 additions and 20 deletions
  1. 16 17
      driver-ztex.c
  2. 3 3
      libztex.c

+ 16 - 17
driver-ztex.c

@@ -145,8 +145,9 @@ static bool ztex_updateFreq(struct thr_info *thr)
 	return rv;
 	return rv;
 }
 }
 
 
-
-static uint32_t ztex_checkNonce(struct work *work, uint32_t nonce)
+static bool ztex_checkNonce(struct libztex_device *ztex,
+                            struct work *work,
+                            struct libztex_hash_data *hdata)
 {
 {
 	uint32_t *data32 = (uint32_t *)(work->data);
 	uint32_t *data32 = (uint32_t *)(work->data);
 	unsigned char swap[80];
 	unsigned char swap[80];
@@ -155,14 +156,18 @@ static uint32_t ztex_checkNonce(struct work *work, uint32_t nonce)
 	unsigned char hash2[32];
 	unsigned char hash2[32];
 	uint32_t *hash2_32 = (uint32_t *)hash2;
 	uint32_t *hash2_32 = (uint32_t *)hash2;
 
 
-	swap32[76/4] = htonl(nonce);
+	swap32[76/4] = htobe32(hdata->nonce);
 
 
 	swap32yes(swap32, data32, 76 / 4);
 	swap32yes(swap32, data32, 76 / 4);
 
 
 	sha2(swap, 80, hash1);
 	sha2(swap, 80, hash1);
 	sha2(hash1, 32, hash2);
 	sha2(hash1, 32, hash2);
 
 
-	return htonl(hash2_32[7]);
+	if (be32toh(hash2_32[7]) != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) {
+		applog(LOG_DEBUG, "%s: checkNonce failed for %08x", ztex->repr, hdata->nonce);
+		return false;
+	}
+	return true;
 }
 }
 
 
 static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
@@ -267,15 +272,13 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 			} else
 			} else
 				lastnonce[i] = nonce;
 				lastnonce[i] = nonce;
 
 
-			if (ztex_checkNonce(work, nonce) != (hdata->hash7 + 0x5be0cd19)) {
-				applog(LOG_DEBUG, "%s: checkNonce failed for %08X", ztex->repr, nonce);
-
+			if (!ztex_checkNonce(ztex, work, &hdata[i])) {
 				// do not count errors in the first 500ms after sendHashData (2x250 wait time)
 				// do not count errors in the first 500ms after sendHashData (2x250 wait time)
-				if (count > 2) {
+				if (count > 2)
 					dclk_errorCount(&ztex->dclk, 1.0 / ztex->numNonces);
 					dclk_errorCount(&ztex->dclk, 1.0 / ztex->numNonces);
-					thr->cgpu->hw_errors++;
-					++hw_errors;
-				}
+
+				thr->cgpu->hw_errors++;
+				++hw_errors;
 			}
 			}
 
 
 			for (j=0; j<=ztex->extraSolutions; j++) {
 			for (j=0; j<=ztex->extraSolutions; j++) {
@@ -285,11 +288,6 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 					continue;
 					continue;
 				}
 				}
 
 
-				// precheck the extraSolutions since they often fail
-				if (j > 0 && ztex_checkNonce(work, nonce) != 0) {
-					continue;
-				}
-
 				found = false;
 				found = false;
 				for (k = 0; k < backlog_max; k++) {
 				for (k = 0; k < backlog_max; k++) {
 					if (backlog[k] == nonce) {
 					if (backlog[k] == nonce) {
@@ -304,7 +302,8 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 						backlog_p = 0;
 						backlog_p = 0;
 
 
 					work->blk.nonce = 0xffffffff;
 					work->blk.nonce = 0xffffffff;
-					submit_nonce(thr, work, nonce);
+					if (!j || test_nonce(work, nonce, false))
+						submit_nonce(thr, work, nonce);
 					applog(LOG_DEBUG, "%s: submitted %08x (from N%dE%d)", ztex->repr, nonce, i, j);
 					applog(LOG_DEBUG, "%s: submitted %08x (from N%dE%d)", ztex->repr, nonce, i, j);
 				}
 				}
 			}
 			}

+ 3 - 3
libztex.c

@@ -885,14 +885,14 @@ int libztex_readHashData(struct libztex_device *ztex, struct libztex_hash_data n
 		memcpy((char*)&nonces[i].nonce, &rbuf[(i*bufsize)+4], 4);
 		memcpy((char*)&nonces[i].nonce, &rbuf[(i*bufsize)+4], 4);
 		memcpy((char*)&nonces[i].hash7, &rbuf[(i*bufsize)+8], 4);
 		memcpy((char*)&nonces[i].hash7, &rbuf[(i*bufsize)+8], 4);
 
 
-		nonces[i].nonce = htole32(nonces[i].nonce);
-		nonces[i].hash7 = htole32(nonces[i].hash7);
+		nonces[i].nonce = le32toh(nonces[i].nonce);
+		nonces[i].hash7 = le32toh(nonces[i].hash7);
 
 
 		nonces[i].nonce -= ztex->offsNonces;
 		nonces[i].nonce -= ztex->offsNonces;
 
 
 		for (j=0; j<ztex->extraSolutions; j++) {
 		for (j=0; j<ztex->extraSolutions; j++) {
 			memcpy((char*)&nonces[i].goldenNonce[j+1], &rbuf[(i*bufsize)+12+(j*4)], 4);
 			memcpy((char*)&nonces[i].goldenNonce[j+1], &rbuf[(i*bufsize)+12+(j*4)], 4);
-			nonces[i].goldenNonce[j+1] = htole32(nonces[i].goldenNonce[j+1]);
+			nonces[i].goldenNonce[j+1] = le32toh(nonces[i].goldenNonce[j+1]);
 			nonces[i].goldenNonce[j+1] -= ztex->offsNonces;
 			nonces[i].goldenNonce[j+1] -= ztex->offsNonces;
 			//applog(LOG_DEBUG, "W %d:%d %0.8x", i, j+1, nonces[i].goldenNonce[j+1]);
 			//applog(LOG_DEBUG, "W %d:%d %0.8x", i, j+1, nonces[i].goldenNonce[j+1]);
 		}
 		}