X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/a90d420cbe87490c844ae422c966e746d3134b07..6c0946ef1f1fa9b75b8c6d65ea0554ff4e1ec4eb:/rand/rand-x86ish.S diff --git a/rand/rand-x86ish.S b/rand/rand-x86ish.S index 61de2b84..b91a9373 100644 --- a/rand/rand-x86ish.S +++ b/rand/rand-x86ish.S @@ -37,6 +37,17 @@ ///-------------------------------------------------------------------------- /// Quick random generation. +// Common register allocation. +#if CPUFAM_X86 +# define COUNT ecx +#endif +#if CPUFAM_AMD64 && ABI_SYSV +# define COUNT ecx +#endif +#if CPUFAM_AMD64 && ABI_WIN +# define COUNT r8d +#endif + FUNC(rand_quick_x86ish_rdrand) // Enter with a pointer to the random context in the first argument. // Return zero on success, or -1 on error. @@ -44,15 +55,12 @@ FUNC(rand_quick_x86ish_rdrand) #if CPUFAM_X86 mov edx, [SP + 4] stalloc 28 -# define COUNT ecx #endif #if CPUFAM_AMD64 && ABI_SYSV stalloc 8 -# define COUNT ecx #endif #if CPUFAM_AMD64 && ABI_WIN stalloc 40 -# define COUNT r8d #endif endprologue @@ -66,6 +74,34 @@ FUNC(rand_quick_x86ish_rdrand) // Failed. mov eax, -1 jmp 9f +ENDFUNC + +FUNC(rand_quick_x86ish_rdseed) + // Enter with a pointer to the random context in the first argument. + // Return zero on success, or -1 on error. + +#if CPUFAM_X86 + mov edx, [SP + 4] + stalloc 28 +#endif +#if CPUFAM_AMD64 && ABI_SYSV + stalloc 8 +#endif +#if CPUFAM_AMD64 && ABI_WIN + stalloc 40 +#endif + endprologue + + // Try to fetch a random number. + mov COUNT, 16 +0: rdseed AX + jc 1f + dec COUNT + jnz 0b + + // Failed. + mov eax, -1 + jmp 9f // Success. 1: @@ -106,4 +142,6 @@ FUNC(rand_quick_x86ish_rdrand) ret ENDFUNC +#undef COUNT + ///----- That's all, folks --------------------------------------------------