Add CRYPTOPP_LIKELY and CRYPTOPP_UNLIKELY macros

pull/326/head
Jeffrey Walton 2016-09-27 20:45:50 -04:00
parent 8d227675a9
commit 7ae1267673
1 changed files with 12 additions and 0 deletions

12
misc.h
View File

@ -114,6 +114,18 @@ NAMESPACE_BEGIN(CryptoPP)
// Forward declaration for IntToString specialization
class Integer;
// ************** branch prediction ***************
// Micro-optimization, use juditiously. Be sure you find a hotspot
// using 'make coverage', and its in a tight loop. Otherwise, DFW.
#if defined(__GNUC__)
# define CRYPTOPP_LIKELY(x) __builtin_expect(!!(x), 1)
# define CRYPTOPP_UNLIKELY(x) __builtin_expect(!!(x), 0)
#else
# define CRYPTOPP_LIKELY(x) (x)
# define CRYPTOPP_UNLIKELY(x) (x)
#endif
// ************** compile-time assertion ***************
#if CRYPTOPP_DOXYGEN_PROCESSING