X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=arch%2Farch-x86_64.h;h=8f33fc541ee6f266e96f9f507ccc3782d618392c;hb=16dc07107d2abddccf7e42f684c16c3d8657b324;hp=61ac75eefef97a64423cecbef4eff32c2b7199ff;hpb=68d96e515825185b232bbc8d2e5b5136b90514be;p=fio.git diff --git a/arch/arch-x86_64.h b/arch/arch-x86_64.h index 61ac75ee..8f33fc54 100644 --- a/arch/arch-x86_64.h +++ b/arch/arch-x86_64.h @@ -60,4 +60,34 @@ static inline unsigned long long get_cpu_clock(void) #define ARCH_HAVE_SSE4_2 #define ARCH_HAVE_CPU_CLOCK +#define RDRAND_LONG ".byte 0x48,0x0f,0xc7,0xf0" +#define RDSEED_LONG ".byte 0x48,0x0f,0xc7,0xf8" +#define RDRAND_RETRY 100 + +static inline int arch_rand_long(unsigned long *val) +{ + int ok; + + asm volatile("1: " RDRAND_LONG "\n\t" + "jc 2f\n\t" + "decl %0\n\t" + "jnz 1b\n\t" + "2:" + : "=r" (ok), "=a" (*val) + : "0" (RDRAND_RETRY)); + + return ok; +} + +static inline int arch_rand_seed(unsigned long *seed) +{ + unsigned char ok; + + asm volatile(RDSEED_LONG "\n\t" + "setc %0" + : "=qm" (ok), "=a" (*seed)); + + return 0; +} + #endif