Skip to content

Commit

Permalink
Merge pull request #4 from n8sh/setVolatile
Browse files Browse the repository at this point in the history
Add fallback behavior using volatileStore, now supports GDC
  • Loading branch information
DarkRiDDeR committed May 24, 2020
2 parents 4f03772 + 0647b71 commit 294ac9e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/zero_memory/package.d
Expand Up @@ -72,7 +72,21 @@ pure nothrow @nogc
}
else
{
assert(0, "Only DMD and LDC compilers supported");
static if (__VERSION__ >= 2089)
import core.volatile : volatileStore;
else
import core.bitop : volatileStore;
static void zero(void* p, size_t remaining) @nogc nothrow
{
for (; remaining != 0 && (cast(size_t) p) % size_t.alignof != 0; ++p, --remaining)
volatileStore(cast(ubyte*) p, ubyte(0));
for (; remaining >= size_t.sizeof; p += size_t.sizeof, remaining -= size_t.sizeof)
volatileStore(cast(size_t*) p, size_t(0));
for (; remaining != 0; ++p, --remaining)
volatileStore(cast(ubyte*) p, ubyte(0));
}
// Workaround because volatileStore is not annotated "pure".
(cast(void function(void*, size_t) @nogc nothrow pure) &zero)(p, length);
}
}

Expand Down

0 comments on commit 294ac9e

Please sign in to comment.