1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-08 22:08:02 +00:00

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

This commit is contained in:
Con Kolivas 2013-11-02 11:04:06 +11:00
parent e95b42ea54
commit 759bd39f17
3 changed files with 26 additions and 29 deletions

View File

@ -6128,38 +6128,38 @@ void inc_hw_errors(struct thr_info *thr)
thr->cgpu->drv->hw_error(thr); thr->cgpu->drv->hw_error(thr);
} }
/* Fills in the work nonce and builds the output data in work->hash2 */ /* Fills in the work nonce and builds the output data in work->hash */
static void rebuild_hash2(struct work *work, uint32_t nonce) static void rebuild_nonce(struct work *work, uint32_t nonce)
{ {
uint32_t *work_nonce = (uint32_t *)(work->data + 64 + 12); uint32_t *work_nonce = (uint32_t *)(work->data + 64 + 12);
*work_nonce = htole32(nonce); *work_nonce = htole32(nonce);
rebuild_hash(work); rebuild_hash(work);
flip32(work->hash2, work->hash);
} }
/* For testing a nonce against diff 1 */
bool test_nonce(struct work *work, uint32_t nonce) 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; uint32_t diff1targ;
rebuild_hash2(work, nonce); rebuild_nonce(work, nonce);
diff1targ = opt_scrypt ? 0x0000ffffUL : 0; 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) bool test_nonce_diff(struct work *work, uint32_t nonce, double diff)
{ {
uint32_t hash2_be[8]; uint64_t *hash64 = (uint64_t *)(work->hash + 24), diff64;
uint64_t *hashbe64 = (uint64_t *)hash2_be, hash64, diff64;
diff64 = (double)0x00000000ffff0000ULL / diff; rebuild_nonce(work, nonce);
rebuild_hash2(work, nonce); diff64 = opt_scrypt ? 0x0000ffff00000000ULL : 0x00000000ffff0000ULL;
swap256(hash2_be, work->hash2); diff64 /= diff;
hash64 = be64toh(*hashbe64);
return hash64 <= diff64; return (le64toh(*hash64) <= diff64);
} }
static void update_work_stats(struct thr_info *thr, struct work *work) 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; struct work *work_out;
update_work_stats(thr, work); update_work_stats(thr, work);
if (!fulltest(work->hash2, work->target)) { if (!fulltest(work->hash, work->target)) {
applog(LOG_INFO, "Share above target"); applog(LOG_INFO, "Share above target");
return; return;
} }
@ -6227,7 +6227,7 @@ bool submit_noffset_nonce(struct thr_info *thr, struct work *work_in, uint32_t n
} }
ret = true; ret = true;
update_work_stats(thr, work); update_work_stats(thr, work);
if (!fulltest(work->hash2, work->target)) { if (!fulltest(work->hash, work->target)) {
applog(LOG_INFO, "Share above target"); applog(LOG_INFO, "Share above target");
goto out; goto out;
} }

View File

@ -1393,7 +1393,6 @@ struct work {
#endif #endif
double device_diff; double device_diff;
uint64_t share_diff; uint64_t share_diff;
unsigned char hash2[32];
int rolls; int rolls;
int drv_rolllimit; /* How much the driver can roll ntime */ int drv_rolllimit; /* How much the driver can roll ntime */

22
util.c
View File

@ -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) bool fulltest(const unsigned char *hash, const unsigned char *target)
{ {
unsigned char hash_swap[32], target_swap[32]; uint32_t *hash32 = (uint32_t *)hash;
uint32_t *hash32 = (uint32_t *) hash_swap; uint32_t *target32 = (uint32_t *)target;
uint32_t *target32 = (uint32_t *) target_swap;
char *hash_str, *target_str;
bool rc = true; bool rc = true;
int i; int i;
swap256(hash_swap, hash); for (i = 28 / 4; i >= 0; i--) {
swap256(target_swap, target); uint32_t h32tmp = le32toh(hash32[i]);
uint32_t t32tmp = le32toh(target32[i]);
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 */
if (h32tmp > t32tmp) { if (h32tmp > t32tmp) {
rc = false; rc = false;
@ -696,6 +689,11 @@ bool fulltest(const unsigned char *hash, const unsigned char *target)
} }
if (opt_debug) { 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); hash_str = bin2hex(hash_swap, 32);
target_str = bin2hex(target_swap, 32); target_str = bin2hex(target_swap, 32);