Merge branch 'master' of github.com:tromp/equihash

merge
This commit is contained in:
John Tromp 2016-10-21 19:29:33 -04:00
commit 020c40d9e1
1 changed files with 68 additions and 1 deletions

View File

@ -252,6 +252,7 @@ struct equi {
nslot = 0;
return n;
}
#if 0 // merge sort not so performant after all
// if merged != 0, mergesort indices and return true if dupe found
// if merged == 0, order indices as in Wagner condition
bool orderindices(u32 *indices, u32 size, u32 *merged) {
@ -308,6 +309,72 @@ struct equi {
#endif
if (soli < MAXSOLS) listindices1(WK, t, sols[soli], 0);
}
#else
void orderindices(u32 *indices, u32 size) {
if (indices[0] > indices[size]) {
for (u32 i=0; i < size; i++) {
const u32 tmp = indices[i];
indices[i] = indices[size+i];
indices[size+i] = tmp;
}
}
}
bool listindices0(u32 r, const tree t, u32 *indices, u16 *dupes) {
if (r == 0) {
u32 idx = t.getindex();
if (dupes) {
u32 bin = idx & (PROOFSIZE-1);
u16 msb = idx >> WK;
if (msb == dupes[bin])
return true;
dupes[bin] = msb;
}
*indices = idx;
return false;
}
const slot1 *buck = hta.heap1[t.bucketid()];
const u32 size = 1 << --r;
u32 *indices1 = indices + size;
u32 tagi = hashwords(hashsize(r));
if (listindices1(r, buck[t.slotid0()][tagi].tag, indices, dupes)
|| listindices1(r, buck[t.slotid1()][tagi].tag, indices1, dupes))
return true;;
orderindices(indices, size);
return false;
}
bool listindices1(u32 r, const tree t, u32 *indices, u16 *dupes) {
const slot0 *buck = hta.heap0[t.bucketid()];
const u32 size = 1 << --r;
u32 *indices1 = indices + size;
u32 tagi = hashwords(hashsize(r));
if (listindices0(r, buck[t.slotid0()][tagi].tag, indices, dupes)
|| listindices0(r, buck[t.slotid1()][tagi].tag, indices1, dupes))
return true;
orderindices(indices, size);
return false;
}
void candidate(const tree t) {
proof prf;
u16 dupes[PROOFSIZE];
memset(dupes, 0xffff, PROOFSIZE * sizeof(u16));
if (listindices1(WK, t, prf, dupes)) // assume WK odd
return;
qsort(prf, PROOFSIZE, sizeof(u32), &compu32);
for (u32 i=1; i<PROOFSIZE; i++)
if (prf[i] <= prf[i-1])
return;
#ifdef ATOMIC
u32 soli = std::atomic_fetch_add_explicit(&nsols, 1U, std::memory_order_relaxed);
#else
u32 soli = nsols++;
#endif
memset(dupes, 0xffff, PROOFSIZE * sizeof(u16));
if (soli < MAXSOLS) {
bool dupe = listindices1(WK, t, sols[soli], dupes); // assume WK odd
assert(!dupe);
}
}
#endif
void showbsizes(u32 r) {
printf(" x%d b%d h%d\n", xfull, bfull, hfull);
xfull = bfull = hfull = 0;
@ -894,7 +961,7 @@ struct equi {
}
}
}
// printf(" %d candidates ", nc);
printf(" %d candidates ", nc);
}
};