Commit ac5b12e1a0e29f3b3fd8633ff417f4815a2e29c6

Con Kolivas 2013-10-31T17:15:42

Allow arbitrary diffs to be tested against nonces via a test_nonce_diff function.

diff --git a/cgminer.c b/cgminer.c
index de17230..58d0211 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6104,6 +6104,18 @@ bool test_nonce(struct work *work, uint32_t nonce)
 	return (be32toh(hash2_32[7]) <= diff1targ);
 }
 
+bool test_nonce_diff(struct work *work, uint32_t nonce, double diff)
+{
+	uint32_t hash2_be[8];
+	uint64_t *hashbe64 = (uint64_t *)hash2_be, hash64, diff64;
+
+	diff64 = (double)0x00000000ffff0000ULL / diff;
+	rebuild_hash2(work, nonce);
+	swap256(hash2_be, work->hash2);
+	hash64 = be64toh(*hashbe64);
+	return hash64 <= diff64;
+}
+
 static void update_work_stats(struct thr_info *thr, struct work *work)
 {
 	work->share_diff = share_diff(work);
diff --git a/miner.h b/miner.h
index f39a7d7..a801427 100644
--- a/miner.h
+++ b/miner.h
@@ -1490,6 +1490,7 @@ struct modminer_fpga_state {
 extern void get_datestamp(char *, size_t, struct timeval *);
 extern void inc_hw_errors(struct thr_info *thr);
 extern bool test_nonce(struct work *work, uint32_t nonce);
+extern bool test_nonce_diff(struct work *work, uint32_t nonce, double diff);
 extern void submit_tested_work(struct thr_info *thr, struct work *work);
 extern bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
 extern bool submit_noffset_nonce(struct thr_info *thr, struct work *work, uint32_t nonce,