Removed likely and unlikely macros

Benchmarking showed the use of the macros slowed things down. Profile guided bracnh reordering, committed at dc99266599a0e72d, provided a better benefit
This commit is contained in:
Jeffrey Walton 2016-09-28 18:18:55 -04:00
parent 6560635405
commit 6af5b8424f
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
2 changed files with 2 additions and 17 deletions

View File

@ -685,8 +685,6 @@ const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
b[i] = b[i+1];
b[BitsToWords(m)-1] = 0;
// TODO: the shift by "t1+j" (64-bits) is being flagged as potential UB
// temp ^= ((temp >> j) & 1) << ((t1 + j) & (sizeof(temp)*8-1));
if (t1 < WORD_BITS)
for (unsigned int j=0; j<WORD_BITS-t1; j++)
{
@ -694,7 +692,7 @@ const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
// temp ^= ((temp >> j) & 1) << (t1 + j);
const unsigned int shift = t1 + j;
CRYPTOPP_ASSERT(shift < WORD_BITS);
temp ^= (CRYPTOPP_UNLIKELY(shift >= WORD_BITS) ? 0 : ((temp >> j) & 1) << shift);
temp ^= (shift < WORD_BITS) ? (((temp >> j) & 1) << shift) : 0;
}
else
b[t1/WORD_BITS-1] ^= temp << t1%WORD_BITS;
@ -726,7 +724,7 @@ const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
// temp ^= ((temp >> j) & 1) << (t1 + j);
const unsigned int shift = t1 + j;
CRYPTOPP_ASSERT(shift < WORD_BITS);
temp ^= (CRYPTOPP_UNLIKELY(shift >= WORD_BITS) ? 0 : ((temp >> j) & 1) << shift);
temp ^= (shift < WORD_BITS) ? (((temp >> j) & 1) << shift) : 0;
}
}
else

13
misc.h
View File

@ -114,19 +114,6 @@ 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.
// Also see http://www.akkadia.org/drepper/cpumemory.pdf
#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