Skip to content

Commit

Permalink
implement Ivy Bridge RDRAND support
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
  • Loading branch information
tycho committed Jun 19, 2012
1 parent 958b85e commit 8d7e1c8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/rnd.c
Expand Up @@ -15,6 +15,20 @@ extern int NDECL(rand);
# endif # endif
#endif /* LINT */ #endif /* LINT */


#ifdef __RDRND__
#include <immintrin.h>
unsigned int rdrand()
{
unsigned int x;
if (!_rdrand32_step(&x))
return rand();
else
return x;
}
#undef RND
#define RND(x) (int)(rdrand() % (long)(x))
#endif

#ifdef OVL0 #ifdef OVL0


int int
Expand Down
5 changes: 5 additions & 0 deletions sys/unix/Makefile.src
Expand Up @@ -184,6 +184,11 @@ endif


LFLAGS = LFLAGS =


ifeq ($(RNG),rdrand)
CFLAGS += -mrdrnd
LFLAGS += -mrdrnd
endif

# The Qt and Be window systems are written in C++, while the rest of # The Qt and Be window systems are written in C++, while the rest of
# NetHack is standard C. If using Qt, uncomment the LINK line here to get # NetHack is standard C. If using Qt, uncomment the LINK line here to get
# the C++ libraries linked in. # the C++ libraries linked in.
Expand Down
5 changes: 5 additions & 0 deletions sys/unix/Makefile.utl
Expand Up @@ -103,6 +103,11 @@ endif


LFLAGS = LFLAGS =


ifeq ($(RNG),rdrand)
CFLAGS += -mrdrnd
LFLAGS += -mrdrnd
endif

LIBS = LIBS =


# If you are cross-compiling, you must use this: # If you are cross-compiling, you must use this:
Expand Down

0 comments on commit 8d7e1c8

Please sign in to comment.