From: Chris Duncan Date: Sat, 25 Jan 2025 07:15:11 +0000 (-0800) Subject: Eliminate an atomic operation by performing an exchange if threshold passed. X-Git-Tag: v3.0.0~72 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=1843dfc794c6845c4239c05abd11a8fa1d7e694d;p=nano-pow.git Eliminate an atomic operation by performing an exchange if threshold passed. --- diff --git a/src/shaders/compute.wgsl b/src/shaders/compute.wgsl index abb665b..b6ee298 100644 --- a/src/shaders/compute.wgsl +++ b/src/shaders/compute.wgsl @@ -1432,9 +1432,11 @@ fn main(id: vec3) { /** * 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; }