]> zoso.dev Git - nano-pow.git/commitdiff
Eliminate an atomic operation by performing an exchange if threshold passed.
authorChris Duncan <chris@zoso.dev>
Sat, 25 Jan 2025 07:15:11 +0000 (23:15 -0800)
committerChris Duncan <chris@zoso.dev>
Sat, 25 Jan 2025 07:15:11 +0000 (23:15 -0800)
src/shaders/compute.wgsl

index abb665b8a2f0be70d12c4097310bbfe94523127e..b6ee29892c69a6010a937e56d954ba119286de08 100644 (file)
@@ -1432,9 +1432,11 @@ fn main(id: vec3<u32>) {
        /**
        * Set nonce if it passes the threshold and no other thread has set it
        */
-       if ((BLAKE2B_IV32_0.y ^ v0.y ^ v8.y) > threshold && atomicLoad(&work.found) == 0u) {
-               atomicStore(&work.found, 1u);
+       if ((BLAKE2B_IV32_0.y ^ v0.y ^ v8.y) > threshold) {
+               let wasFound: u32 = atomicExchange(&work.found, 1u);
+               if (wasFound == 0u) {
                work.nonce = m0;
+               }
        }
        return;
 }