| 198 | |
| 199 | template <unsigned Length> |
| 200 | FORCE_INLINE void mine(const SmallString &functionName, const SmallString &functionParams, uint32_t selector) |
| 201 | { |
| 202 | bool go = true; |
| 203 | |
| 204 | const uint64_t numThreads = omp_get_max_threads(); |
| 205 | const uint64_t end = 0xfffffffff0000000ull; |
| 206 | |
| 207 | std::cout << "Starting mining with " << numThreads << " threads...\n"; |
| 208 | |
| 209 | union Sponge { |
| 210 | uint64_t uint64s[25]; |
| 211 | char chars[200]; |
| 212 | }; |
| 213 | |
| 214 | #pragma omp parallel for |
| 215 | for (uint64_t t = 0; t < numThreads; ++t) { |
| 216 | #if defined (__AVX2__) |
| 217 | #define STEP 4 |
| 218 | #else |
| 219 | #define STEP 1 |
| 220 | #endif |
| 221 | uint64_t i = 0; |
| 222 | for (uint64_t nonce = t * STEP; nonce < end && go; nonce += numThreads * STEP) { |
| 223 | #define CHECK_SELECTOR(I) \ |
| 224 | if (c##I == selector) { \ |
| 225 | *fillSponge<Length>(s##I.chars, functionName, nonce + I, functionParams) = 0x00u; \ |
| 226 | std::cout << "Function found: " << s##I.chars << "\n"; \ |
| 227 | go = false; \ |
| 228 | } |
| 229 | |
| 230 | #if defined (__AVX2__) |
| 231 | Sponge s0, s1, s2, s3; |
| 232 | *fillSponge<Length>(s0.chars, functionName, nonce + 0, functionParams) = 0x01u; |
| 233 | *fillSponge<Length>(s1.chars, functionName, nonce + 1, functionParams) = 0x01u; |
| 234 | *fillSponge<Length>(s2.chars, functionName, nonce + 2, functionParams) = 0x01u; |
| 235 | *fillSponge<Length>(s3.chars, functionName, nonce + 3, functionParams) = 0x01u; |
| 236 | V sponge[25]; |
| 237 | #define SET_SPONGE(I) sponge[I] = V(s0.uint64s[I], s1.uint64s[I], s2.uint64s[I], s3.uint64s[I]); |
| 238 | SET_SPONGE(0) SET_SPONGE(1) SET_SPONGE(2) SET_SPONGE(3) |
| 239 | SET_SPONGE(4) SET_SPONGE(5) SET_SPONGE(6) SET_SPONGE(7) |
| 240 | SET_SPONGE(8) SET_SPONGE(9) SET_SPONGE(10) SET_SPONGE(11) |
| 241 | SET_SPONGE(12) SET_SPONGE(13) SET_SPONGE(14) SET_SPONGE(15) SET_SPONGE(16) |
| 242 | memset(sponge + 17, 0, sizeof(V) * 8); |
| 243 | uint32_t c0, c1, c2, c3; |
| 244 | COMPUTE_SELECTORS(c0, c1, c2, c3, sponge); |
| 245 | CHECK_SELECTOR(0) CHECK_SELECTOR(1) CHECK_SELECTOR(2) CHECK_SELECTOR(3) |
| 246 | #else |
| 247 | Sponge s0; |
| 248 | *fillSponge<Length>(s0.chars, functionName, nonce, functionParams) = 0x01u; |
| 249 | memset(s0.uint64s + 17, 0, sizeof(uint64_t) * 8); |
| 250 | uint32_t c0; |
| 251 | COMPUTE_SELECTORS(c0, s0.uint64s); |
| 252 | CHECK_SELECTOR(0) |
| 253 | #endif |
| 254 | if (t == 0) if ((++i & 0x3fffff) == 0) std::cout << nonce << " hashes done.\n"; |
| 255 | } |
| 256 | } |
| 257 | } |
nothing calls this directly
no outgoing calls
no test coverage detected