Avoid the extra generation of a byte flipped hash2 in struct work and directly use the LE work hash.
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
diff --git a/cgminer.c b/cgminer.c
index 95de19c..715a630 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6128,38 +6128,38 @@ void inc_hw_errors(struct thr_info *thr)
thr->cgpu->drv->hw_error(thr);
}
-/* Fills in the work nonce and builds the output data in work->hash2 */
-static void rebuild_hash2(struct work *work, uint32_t nonce)
+/* Fills in the work nonce and builds the output data in work->hash */
+static void rebuild_nonce(struct work *work, uint32_t nonce)
{
uint32_t *work_nonce = (uint32_t *)(work->data + 64 + 12);
*work_nonce = htole32(nonce);
rebuild_hash(work);
- flip32(work->hash2, work->hash);
}
+/* For testing a nonce against diff 1 */
bool test_nonce(struct work *work, uint32_t nonce)
{
- uint32_t *hash2_32 = (uint32_t *)work->hash2;
+ uint32_t *hash_32 = (uint32_t *)(work->hash + 28);
uint32_t diff1targ;
- rebuild_hash2(work, nonce);
-
+ rebuild_nonce(work, nonce);
diff1targ = opt_scrypt ? 0x0000ffffUL : 0;
- return (be32toh(hash2_32[7]) <= diff1targ);
+
+ return (le32toh(*hash_32) <= diff1targ);
}
+/* For testing a nonce against an arbitrary diff */
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;
+ uint64_t *hash64 = (uint64_t *)(work->hash + 24), diff64;
+
+ rebuild_nonce(work, nonce);
+ diff64 = opt_scrypt ? 0x0000ffff00000000ULL : 0x00000000ffff0000ULL;
+ diff64 /= diff;
- diff64 = (double)0x00000000ffff0000ULL / diff;
- rebuild_hash2(work, nonce);
- swap256(hash2_be, work->hash2);
- hash64 = be64toh(*hashbe64);
- return hash64 <= diff64;
+ return (le64toh(*hash64) <= diff64);
}
static void update_work_stats(struct thr_info *thr, struct work *work)
@@ -6189,7 +6189,7 @@ void submit_tested_work(struct thr_info *thr, struct work *work)
struct work *work_out;
update_work_stats(thr, work);
- if (!fulltest(work->hash2, work->target)) {
+ if (!fulltest(work->hash, work->target)) {
applog(LOG_INFO, "Share above target");
return;
}
@@ -6227,7 +6227,7 @@ bool submit_noffset_nonce(struct thr_info *thr, struct work *work_in, uint32_t n
}
ret = true;
update_work_stats(thr, work);
- if (!fulltest(work->hash2, work->target)) {
+ if (!fulltest(work->hash, work->target)) {
applog(LOG_INFO, "Share above target");
goto out;
}
diff --git a/miner.h b/miner.h
index cbde41b..2396f1b 100644
--- a/miner.h
+++ b/miner.h
@@ -1393,7 +1393,6 @@ struct work {
#endif
double device_diff;
uint64_t share_diff;
- unsigned char hash2[32];
int rolls;
int drv_rolllimit; /* How much the driver can roll ntime */
diff --git a/util.c b/util.c
index bae736d..f5472c3 100644
--- a/util.c
+++ b/util.c
@@ -669,21 +669,14 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len)
bool fulltest(const unsigned char *hash, const unsigned char *target)
{
- unsigned char hash_swap[32], target_swap[32];
- uint32_t *hash32 = (uint32_t *) hash_swap;
- uint32_t *target32 = (uint32_t *) target_swap;
- char *hash_str, *target_str;
+ uint32_t *hash32 = (uint32_t *)hash;
+ uint32_t *target32 = (uint32_t *)target;
bool rc = true;
int i;
- swap256(hash_swap, hash);
- swap256(target_swap, target);
-
- for (i = 0; i < 32/4; i++) {
- uint32_t h32tmp = htobe32(hash32[i]);
- uint32_t t32tmp = htole32(target32[i]);
-
- target32[i] = swab32(target32[i]); /* for printing */
+ for (i = 28 / 4; i >= 0; i--) {
+ uint32_t h32tmp = le32toh(hash32[i]);
+ uint32_t t32tmp = le32toh(target32[i]);
if (h32tmp > t32tmp) {
rc = false;
@@ -696,6 +689,11 @@ bool fulltest(const unsigned char *hash, const unsigned char *target)
}
if (opt_debug) {
+ unsigned char hash_swap[32], target_swap[32];
+ char *hash_str, *target_str;
+
+ swab256(hash_swap, hash);
+ swab256(target_swap, target);
hash_str = bin2hex(hash_swap, 32);
target_str = bin2hex(target_swap, 32);