From ed83c875543c1c2cd146ceb912d9b6c8ddccacbc Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 20 Sep 2012 11:54:44 -0700 Subject: [PATCH] cpu.x86: Add ghetto RDRAND support. Proper support wouldn't use alien-assembly and would take a count parameter. --- basis/cpu/x86/assembler/assembler.factor | 2 ++ basis/cpu/x86/features/features.factor | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/basis/cpu/x86/assembler/assembler.factor b/basis/cpu/x86/assembler/assembler.factor index e86c704cc5..6426af85cd 100644 --- a/basis/cpu/x86/assembler/assembler.factor +++ b/basis/cpu/x86/assembler/assembler.factor @@ -451,6 +451,8 @@ PRIVATE> : RDMSR ( -- ) 0x0f , 0x32 , ; ! Only available in privileged level 0 : RDPMC ( -- ) 0x0f , 0x33 , ; +: RDRAND ( dst -- ) { 0b110 t { 0x0f 0xc7 } } 1-operand ; + ! x87 Floating Point Unit : FSTPS ( operand -- ) { 0b011 f 0xd9 } 1-operand ; diff --git a/basis/cpu/x86/features/features.factor b/basis/cpu/x86/features/features.factor index 27dba50613..7dcc325111 100644 --- a/basis/cpu/x86/features/features.factor +++ b/basis/cpu/x86/features/features.factor @@ -141,6 +141,26 @@ HOOK: (cpuid) cpu ( rax rcx regs -- ) : tm1? ( -- ? ) 1 cpuid fourth 29 bit? ; : tm2? ( -- ? ) 1 cpuid third 8 bit? ; +: rdrand8 ( -- x ) + uchar { } cdecl [ + AL RDRAND + ] alien-assembly ; + +: rdrand16 ( -- x ) + ushort { } cdecl [ + AX RDRAND + ] alien-assembly ; + +: rdrand32 ( -- x ) + uint { } cdecl [ + EAX RDRAND + ] alien-assembly ; + +: rdrand64 ( -- x ) + ulonglong { } cdecl [ + RAX RDRAND + ] alien-assembly ; + MEMO: enable-popcnt? ( -- ? ) popcnt? "disable-popcnt" get not and ;