aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/cpuid.cpp6
-rw-r--r--src/utils/info.txt1
-rw-r--r--src/utils/loadstor.h1
-rw-r--r--src/utils/prefetch.h39
4 files changed, 44 insertions, 3 deletions
diff --git a/src/utils/cpuid.cpp b/src/utils/cpuid.cpp
index 4f22ef867..d5149e2e5 100644
--- a/src/utils/cpuid.cpp
+++ b/src/utils/cpuid.cpp
@@ -31,12 +31,12 @@ u64bit x86_processor_flags()
#if defined(BOTAN_TARGET_ARCH_IS_X86) || defined(BOTAN_TARGET_ARCH_IS_AMD64)
-#if defined(__GNUG__)
+#if defined(BOTAN_BUILD_COMPILER_IS_GCC)
u32bit a = 1, b = 0, c = 0, d = 0;
#if defined(__i386__) && defined(__PIC__)
- // ebx is used in PIC on 32-bit x86, so save and restore it
+ // ebx is reserved for PIC on 32-bit x86, so save and restore it
asm("xchgl %%ebx, %1\n\t"
"cpuid\n\t"
"xchgl %%ebx, %1\n\t"
@@ -49,7 +49,7 @@ u64bit x86_processor_flags()
proc_flags = ((u64bit)c << 32) | d;
-#elif defined(_MSC_VER)
+#elif defined(BOTAN_BUILD_COMPILER_IS_MSVC)
int cpuinfo[4] = { 0 };
__cpuid(cpuinfo, 1);
diff --git a/src/utils/info.txt b/src/utils/info.txt
index f530fb03a..c9648af51 100644
--- a/src/utils/info.txt
+++ b/src/utils/info.txt
@@ -23,6 +23,7 @@ mlock.h
mlock.cpp
parsing.cpp
parsing.h
+prefetch.h
rotate.h
rounding.h
stl_util.h
diff --git a/src/utils/loadstor.h b/src/utils/loadstor.h
index 77ed1554e..8c64deaee 100644
--- a/src/utils/loadstor.h
+++ b/src/utils/loadstor.h
@@ -12,6 +12,7 @@
#include <botan/types.h>
#include <botan/bswap.h>
#include <botan/rotate.h>
+#include <botan/prefetch.h>
#if BOTAN_TARGET_UNALIGNED_LOADSTOR_OK
diff --git a/src/utils/prefetch.h b/src/utils/prefetch.h
new file mode 100644
index 000000000..100829dce
--- /dev/null
+++ b/src/utils/prefetch.h
@@ -0,0 +1,39 @@
+/*
+* Prefetching Operations
+* (C) 2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#ifndef BOTAN_PREFETCH_H__
+#define BOTAN_PREFETCH_H__
+
+#include <botan/cpuid.h>
+
+namespace Botan {
+
+inline void prefetch_readonly(const void* addr_void, u32bit length)
+ {
+#if defined(__GNUG__)
+ const byte* addr = static_cast<const byte*>(addr_void);
+ const u32bit cl_size = CPUID::cache_line_size();
+
+ for(u32bit i = 0; i <= length; i += cl_size)
+ __builtin_prefetch(addr + i, 0);
+#endif
+ }
+
+inline void prefetch_readwrite(const void* addr_void, u32bit length)
+ {
+#if defined(__GNUG__)
+ const byte* addr = static_cast<const byte*>(addr_void);
+ const u32bit cl_size = CPUID::cache_line_size();
+
+ for(u32bit i = 0; i <= length; i += cl_size)
+ __builtin_prefetch(addr + i, 1);
+#endif
+ }
+
+}
+
+#endif