Fix missing BMI/BMI2 instrinsics under GCC on Solaris (Issue 230)

pull/239/head
Jeffrey Walton 2016-07-20 01:17:55 -04:00
parent 6f0bb9411f
commit 7ec3b29df6
2 changed files with 10 additions and 1 deletions

View File

@ -176,6 +176,7 @@ endif
endif endif
# Tell MacPorts GCC to use Clang integrated assembler # Tell MacPorts GCC to use Clang integrated assembler
# http://github.com/weidai11/cryptopp/issues/190
ifeq ($(GCC_COMPILER)$(MACPORTS_COMPILER),11) ifeq ($(GCC_COMPILER)$(MACPORTS_COMPILER),11)
ifneq ($(findstring -Wa,-q,$(CXXFLAGS)),-Wa,-q) ifneq ($(findstring -Wa,-q,$(CXXFLAGS)),-Wa,-q)
CXXFLAGS += -Wa,-q CXXFLAGS += -Wa,-q
@ -185,6 +186,12 @@ CXXFLAGS += -DCRYPTOPP_CLANG_INTEGRATED_ASSEMBLER=1
endif endif
endif endif
# GCC on Solaris needs -m64. Otherwise, i386 is default
# http://github.com/weidai11/cryptopp/issues/230
ifeq ($(IS_SUN)$(GCC_COMPILER)$(IS_X64),111)
CXXFLAGS += -m64
endif
# Allow use of "/" operator for GNU Assembler. # Allow use of "/" operator for GNU Assembler.
# http://sourceware.org/bugzilla/show_bug.cgi?id=4572 # http://sourceware.org/bugzilla/show_bug.cgi?id=4572
ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),) ifeq ($(findstring -DCRYPTOPP_DISABLE_ASM,$(CXXFLAGS)),)

4
misc.h
View File

@ -702,7 +702,7 @@ inline unsigned int TrailingZeros(word64 v)
// We don't enable for Microsoft because it requires a runtime check. // We don't enable for Microsoft because it requires a runtime check.
// http://msdn.microsoft.com/en-us/library/hh977023%28v=vs.110%29.aspx // http://msdn.microsoft.com/en-us/library/hh977023%28v=vs.110%29.aspx
assert(v != 0); assert(v != 0);
#if defined(__GNUC__) && defined(__BMI__) #if defined(__GNUC__) && defined(__BMI__) && defined(__x86_64__)
return (unsigned int)_tzcnt_u64(v); return (unsigned int)_tzcnt_u64(v);
#elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400) #elif defined(__GNUC__) && (CRYPTOPP_GCC_VERSION >= 30400)
return (unsigned int)__builtin_ctzll(v); return (unsigned int)__builtin_ctzll(v);
@ -815,12 +815,14 @@ inline bool IsPowerOf2<word32>(const word32 &value)
return value > 0 && _blsr_u32(value) == 0; return value > 0 && _blsr_u32(value) == 0;
} }
# if defined(__x86_64__)
template <> template <>
inline bool IsPowerOf2<word64>(const word64 &value) inline bool IsPowerOf2<word64>(const word64 &value)
{ {
return value > 0 && _blsr_u64(value) == 0; return value > 0 && _blsr_u64(value) == 0;
} }
# endif # endif
#endif
//! \brief Tests whether the residue of a value is a power of 2 //! \brief Tests whether the residue of a value is a power of 2
//! \param a the value to test //! \param a the value to test