Used CRYPTOPP_UNLIKELY on gf2n.cpp hotspot
parent
7ae1267673
commit
6bf0d32279
15
gf2n.cpp
15
gf2n.cpp
|
|
@ -689,7 +689,13 @@ const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
|
||||||
// temp ^= ((temp >> j) & 1) << ((t1 + j) & (sizeof(temp)*8-1));
|
// temp ^= ((temp >> j) & 1) << ((t1 + j) & (sizeof(temp)*8-1));
|
||||||
if (t1 < WORD_BITS)
|
if (t1 < WORD_BITS)
|
||||||
for (unsigned int j=0; j<WORD_BITS-t1; j++)
|
for (unsigned int j=0; j<WORD_BITS-t1; j++)
|
||||||
temp ^= ((temp >> j) & 1) << (t1 + j);
|
{
|
||||||
|
// Coverity finding on shift amount of 'word x << (t1+j)'.
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
b[t1/WORD_BITS-1] ^= temp << t1%WORD_BITS;
|
b[t1/WORD_BITS-1] ^= temp << t1%WORD_BITS;
|
||||||
|
|
||||||
|
|
@ -717,11 +723,10 @@ const GF2NT::Element& GF2NT::MultiplicativeInverse(const Element &a) const
|
||||||
for (unsigned int j=0; j<WORD_BITS-t1; j++)
|
for (unsigned int j=0; j<WORD_BITS-t1; j++)
|
||||||
{
|
{
|
||||||
// Coverity finding on shift amount of 'word x << (t1+j)'.
|
// Coverity finding on shift amount of 'word x << (t1+j)'.
|
||||||
// temp ^= ((temp >> j) & 1) << (t1 + j);
|
// temp ^= ((temp >> j) & 1) << (t1 + j);
|
||||||
|
|
||||||
CRYPTOPP_ASSERT(t1+j < WORD_BITS);
|
|
||||||
const unsigned int shift = t1 + j;
|
const unsigned int shift = t1 + j;
|
||||||
temp ^= ((shift >= WORD_BITS) ? 0 : ((temp >> j) & 1) << shift);
|
CRYPTOPP_ASSERT(shift < WORD_BITS);
|
||||||
|
temp ^= (CRYPTOPP_UNLIKELY(shift >= WORD_BITS) ? 0 : ((temp >> j) & 1) << shift);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
1
misc.h
1
misc.h
|
|
@ -118,6 +118,7 @@ class Integer;
|
||||||
|
|
||||||
// Micro-optimization, use juditiously. Be sure you find a hotspot
|
// Micro-optimization, use juditiously. Be sure you find a hotspot
|
||||||
// using 'make coverage', and its in a tight loop. Otherwise, DFW.
|
// using 'make coverage', and its in a tight loop. Otherwise, DFW.
|
||||||
|
// Also see http://www.akkadia.org/drepper/cpumemory.pdf
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
# define CRYPTOPP_LIKELY(x) __builtin_expect(!!(x), 1)
|
# define CRYPTOPP_LIKELY(x) __builtin_expect(!!(x), 1)
|
||||||
# define CRYPTOPP_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
# define CRYPTOPP_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue