chiark / gitweb /
rand/rand.c (rdrand_quick): Improve the loop.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 6 Jun 2016 10:01:46 +0000 (11:01 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 6 Jun 2016 10:06:17 +0000 (11:06 +0100)
commitc6c463ee1a9faac8b1439f62f85033074c18f96f
treec2602888a2dad08ee163a0d615cc7d2a375ad079
parent8039afaf2c8b0a9bb3359206719859b0da53ea7c
rand/rand.c (rdrand_quick): Improve the loop.

The `RDRAND' instruction can fail, leaving carry clear.  Previously, I
just exposed the carry flag in a register (with `SETC'), and looped
around in C.

Rewrite the loop in assembler.  This is makes the flow cleaner, and
(coincidentally) avoids a dependency on the `SETcc' instructions (though
if I thought a processor might have `RDRAND' and not `SETcc', I wouldn't
have written the original code the way I did).  But the main benefit is
that I don't have nightmares about seeing

...; setc al; test al, al; ...

sequences any more.  There's still the issue of `i' being tested for
zero twice, but I don't think I can fix that without resorting to `asm
goto', and that has its own problems.
rand/rand.c