Skip to content

Commit

Permalink
Add MAYBE_UNCONST_CAST macro for Sun CC 12.4. Enable CRYPTOPP_BOOL_SS…
Browse files Browse the repository at this point in the history
…E2_INTRINSICS_AVAILABLE for Sun CC 12.4 and above
  • Loading branch information
noloader committed Jun 14, 2016
1 parent 2bf3e87 commit c042616
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 35 deletions.
5 changes: 5 additions & 0 deletions blake2.cpp
Expand Up @@ -22,6 +22,11 @@ NAMESPACE_BEGIN(CryptoPP)
# undef CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
#endif

// Testing shows Sun CC needs 12.4 for _mm_set_epi64x
#if (__SUNPRO_CC <= 0x5130)
# undef CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
#endif

// Visual Studio needs VS2008 (1500); no dependency on _mm_set_epi64x()
// http://msdn.microsoft.com/en-us/library/bb892950%28v=vs.90%29.aspx
#if defined(_MSC_VER) && (_MSC_VER < 1500)
Expand Down
72 changes: 37 additions & 35 deletions integer.cpp
Expand Up @@ -47,8 +47,10 @@
// "Error: The operand ___LKDB cannot be assigned to", http://github.com/weidai11/cryptopp/issues/188
#if (__SUNPRO_CC == 0x5130)
# define MAYBE_CONST
# define MAYBE_UNCONST_CAST const_cast<word*>
#else
# define MAYBE_CONST const
# define MAYBE_UNCONST_CAST
#endif

// "Inline assembly operands don't work with .intel_syntax",
Expand Down Expand Up @@ -219,7 +221,7 @@ class DWord
DWord() : m_whole(0) {memset(&m_whole, 0xa, sizeof(m_whole));}
#elif (defined(__COVERITY__) || !defined(NDEBUG)) && !defined(CRYPTOPP_NATIVE_DWORD_AVAILABLE)
// Repeating pattern of 1010 for debug builds to break things...
DWord() : m_halfs() {memset(&m_halfs, 0xa, sizeof(m_halfs));}
DWord() : m_halfs() {memset(&m_halfs, 0xaa, sizeof(m_halfs));}
#else
DWord() {}
#endif
Expand Down Expand Up @@ -352,7 +354,7 @@ class Word
Word() : m_whole(0) {}
#elif !defined(NDEBUG)
// Repeating pattern of 1010 for debug builds to break things...
Word() : m_whole(0) {memset(&m_whole, 0xa, sizeof(m_whole));}
Word() : m_whole(0) {memset(&m_whole, 0xaa, sizeof(m_whole));}
#else
Word() {}
#endif
Expand Down Expand Up @@ -495,15 +497,15 @@ inline word DWord::operator%(word a)

// ********************************************************

// Use some tricks to share assembly code between MSVC and GCC
// Use some tricks to share assembly code between MSVC, GCC, Clang and Sun CC.
#if defined(__GNUC__)
#define AddPrologue \
int result; \
__asm__ __volatile__ \
( \
INTEL_NOPREFIX
#define AddEpilogue \
".att_syntax prefix;" \
ATT_PREFIX \
: "=a" (result)\
: "d" (C), "a" (A), "D" (B), "c" (N) \
: "%esi", "memory", "cc" \
Expand All @@ -512,28 +514,28 @@ inline word DWord::operator%(word a)
#define MulPrologue \
__asm__ __volatile__ \
( \
".intel_syntax noprefix;" \
INTEL_NOPREFIX \
AS1( push ebx) \
AS2( mov ebx, edx)
#define MulEpilogue \
AS1( pop ebx) \
".att_syntax prefix;" \
ATT_PREFIX \
: \
: "d" (s_maskLow16), "c" (C), "a" (A), "D" (B) \
: "%esi", "memory", "cc" \
);
#define SquPrologue MulPrologue
#define SquEpilogue \
AS1( pop ebx) \
".att_syntax prefix;" \
ATT_PREFIX \
: \
: "d" (s_maskLow16), "c" (C), "a" (A) \
: "%esi", "%edi", "memory", "cc" \
);
#define TopPrologue MulPrologue
#define TopEpilogue \
AS1( pop ebx) \
".att_syntax prefix;" \
ATT_PREFIX \
: \
: "d" (s_maskLow16), "c" (C), "a" (A), "D" (B), "S" (L) \
: "memory", "cc" \
Expand Down Expand Up @@ -881,7 +883,7 @@ int CRYPTOPP_FASTCALL Baseline_Sub(size_t N, word *C, const word *A, const word
static word LinearMultiply(word *C, const word *AA, word B, size_t N)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);

word carry=0;
for(unsigned i=0; i<N; i++)
Expand Down Expand Up @@ -1183,77 +1185,77 @@ static word LinearMultiply(word *C, const word *AA, word B, size_t N)
void Baseline_Multiply2(word *R, const word *AA, const word *BB)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Mul_2
}

void Baseline_Multiply4(word *R, const word *AA, const word *BB)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Mul_4
}

void Baseline_Multiply8(word *R, const word *AA, const word *BB)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Mul_8
}

void Baseline_Square2(word *R, const word *AA)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);

Squ_2
}

void Baseline_Square4(word *R, const word *AA)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);

Squ_4
}

void Baseline_Square8(word *R, const word *AA)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);

Squ_8
}

void Baseline_MultiplyBottom2(word *R, const word *AA, const word *BB)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Bot_2
}

void Baseline_MultiplyBottom4(word *R, const word *AA, const word *BB)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Bot_4
}

void Baseline_MultiplyBottom8(word *R, const word *AA, const word *BB)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Bot_8
}
Expand Down Expand Up @@ -1293,8 +1295,8 @@ void Baseline_MultiplyTop2(word *R, const word *A, const word *B, word L)
void Baseline_MultiplyTop4(word *R, const word *AA, const word *BB, word L)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Top_Begin(4)
Top_Acc(1, 1) Top_Acc(2, 0) \
Expand All @@ -1307,8 +1309,8 @@ void Baseline_MultiplyTop4(word *R, const word *AA, const word *BB, word L)
void Baseline_MultiplyTop8(word *R, const word *AA, const word *BB, word L)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Top_Begin(8)
Top_Acc(1, 5) Top_Acc(2, 4) Top_Acc(3, 3) Top_Acc(4, 2) Top_Acc(5, 1) Top_Acc(6, 0) \
Expand All @@ -1326,34 +1328,34 @@ void Baseline_MultiplyTop8(word *R, const word *AA, const word *BB, word L)
void Baseline_Multiply16(word *R, const word *AA, const word *BB)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Mul_16
}

void Baseline_Square16(word *R, const word *AA)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);

Squ_16
}

void Baseline_MultiplyBottom16(word *R, const word *AA, const word *BB)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Bot_16
}

void Baseline_MultiplyTop16(word *R, const word *AA, const word *BB, word L)
{
// http://github.com/weidai11/cryptopp/issues/188
MAYBE_CONST word* A = const_cast<word*>(AA);
MAYBE_CONST word* B = const_cast<word*>(BB);
MAYBE_CONST word* A = MAYBE_UNCONST_CAST(AA);
MAYBE_CONST word* B = MAYBE_UNCONST_CAST(BB);

Top_Begin(16)
Top_Acc(1, 13) Top_Acc(2, 12) Top_Acc(3, 11) Top_Acc(4, 10) Top_Acc(5, 9) Top_Acc(6, 8) Top_Acc(7, 7) Top_Acc(8, 6) Top_Acc(9, 5) Top_Acc(10, 4) Top_Acc(11, 3) Top_Acc(12, 2) Top_Acc(13, 1) Top_Acc(14, 0) \
Expand Down

0 comments on commit c042616

Please sign in to comment.