Skip to content

Commit

Permalink
Switch between POWER7 and POWER4 (GH weidai11#656)
Browse files Browse the repository at this point in the history
This is kind of tricky. We automatically drop from POWER7 to POWER4 if 7 is not available. However, if POWER7 is available the runtime test checks for HasAltivec(), and not HasPower7(), if the drop does not occur.
All of this goodness is happening on an old Apple G4 laptop with Gentoo. It is a "new toolchain on old hardware".
  • Loading branch information
noloader committed Nov 18, 2018
1 parent aae108d commit 59ba3b6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions blake2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ extern void BLAKE2_Compress64_NEON(const byte* input, BLAKE2b_State& state);
#endif

#if CRYPTOPP_ALTIVEC_AVAILABLE
// BLAKE2_Compress32_POWER7 may be compiled with either -mcpu=power7 or
// -mcpu=power4. The makefile drops to POWER4 if POWER7 is not available.
extern void BLAKE2_Compress32_POWER7(const byte* input, BLAKE2s_State& state);
#endif

Expand Down Expand Up @@ -390,8 +392,7 @@ std::string BLAKE2s::AlgorithmProvider() const
#if (CRYPTOPP_POWER7_AVAILABLE)
if (HasPower7())
return "Power7";
#endif
#if (CRYPTOPP_ALTIVEC_AVAILABLE)
#elif (CRYPTOPP_ALTIVEC_AVAILABLE)
if (HasAltivec())
return "Altivec";
#endif
Expand Down Expand Up @@ -666,9 +667,16 @@ void BLAKE2s::Compress(const byte *input)
return BLAKE2_Compress32_NEON(input, *m_state.data());
}
#endif
#if CRYPTOPP_ALTIVEC_AVAILABLE
#if CRYPTOPP_POWER7_AVAILABLE
if(HasPower7())
{
// BLAKE2_Compress32_POWER7 compiled with -mcpu=power7 and -DCRYPTOPP_POWER7_AVAILABLE
return BLAKE2_Compress32_POWER7(input, *m_state.data());
}
#elif CRYPTOPP_ALTIVEC_AVAILABLE
if(HasAltivec())
{
// BLAKE2_Compress32_POWER7 compiled with -mcpu=power4 and -DCRYPTOPP_ALTIVEC_AVAILABLE
return BLAKE2_Compress32_POWER7(input, *m_state.data());
}
#endif
Expand Down

0 comments on commit 59ba3b6

Please sign in to comment.