Permalink
Browse files

implement Ivy Bridge RDRAND support

Signed-off-by: Steven Noonan <steven@uplinklabs.net>
  • Loading branch information...
tycho committed Jun 19, 2012
1 parent 958b85e commit 8d7e1c8f03afff30d22b7562a3d00384c7616f77
Showing with 24 additions and 0 deletions.
  1. +14 −0 src/rnd.c
  2. +5 −0 sys/unix/Makefile.src
  3. +5 −0 sys/unix/Makefile.utl
View
@@ -15,6 +15,20 @@ extern int NDECL(rand);
# endif
#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
int
View
@@ -184,6 +184,11 @@ endif
LFLAGS =
+ifeq ($(RNG),rdrand)
+CFLAGS += -mrdrnd
+LFLAGS += -mrdrnd
+endif
+
# 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
# the C++ libraries linked in.
View
@@ -103,6 +103,11 @@ endif
LFLAGS =
+ifeq ($(RNG),rdrand)
+CFLAGS += -mrdrnd
+LFLAGS += -mrdrnd
+endif
+
LIBS =
# If you are cross-compiling, you must use this:

0 comments on commit 8d7e1c8

Please sign in to comment.