Browse Source

Avoid the extra generation of a byte flipped hash2 in struct work and directly use the LE work hash.

nfactor-troky
Con Kolivas 11 years ago
parent
commit
759bd39f17
  1. 32
      cgminer.c
  2. 1
      miner.h
  3. 22
      util.c

32
cgminer.c

@ -6128,38 +6128,38 @@ void inc_hw_errors(struct thr_info *thr) @@ -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) @@ -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 @@ -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;
}

1
miner.h

@ -1393,7 +1393,6 @@ struct work { @@ -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 */

22
util.c

@ -669,21 +669,14 @@ bool hex2bin(unsigned char *p, const char *hexstr, size_t len) @@ -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) @@ -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);

Loading…
Cancel
Save