+///--------------------------------------------------------------------------
+/// Checking `rdrand'.
+
+FUNC(dispatch_x86ish_rdrand)
+ // Enter with two arguments: a code OP requesting `rdrand' (0), and a
+ // pointer X_OUT to a 32-bit word. Try to generate a random word
+ // using the requested instruction. If successful, set *X_OUT to the
+ // generated word, and return zero; otherwise, return -1.
+
+#if CPUFAM_X86
+# define OP eax
+# define X_OUT edx
+# define COUNT ecx
+ mov OP, [SP + 4]
+ mov X_OUT, [SP + 8]
+#endif
+#if CPUFAM_AMD64 && ABI_SYSV
+# define OP edi
+# define X_OUT rsi
+# define COUNT ecx
+#endif
+#if CPUFAM_AMD64 && ABI_WIN
+# define OP rcx
+# define X_OUT rdx
+# define COUNT r8d
+#endif
+ endprologue
+
+ mov COUNT, 16 // fairly persistent
+0: rdrand eax
+ jc 9f
+ dec COUNT
+ jnz 0b
+ jmp 8f
+
+ // Failed to come up with a random value.
+8: mov eax, -1
+ ret
+
+ // Success.
+9: mov [X_OUT], eax
+ xor eax, eax
+ ret
+
+#undef X_OUT
+#undef COUNT
+
+ENDFUNC
+