Integer class hack due to Sun CC

12 views
Skip to first unread message

Jeffrey Walton

unread,
Jun 14, 2016, 7:46:53 AM6/14/16
to Crypto++ Users
Hi Everyone,

Integer class took a bug report under Sun Studio 12.4. Also see Issue 184: Error: The operand "___LKDB" cannot be assigned to (http://github.com/weidai11/cryptopp/issues/188).

Sun CC 12.4 is an important Sun compiler because its their C++11 compiler. I'm fairly certain the bug report is bogus, and its a compiler bug. Never the less, we had to work around it.

The hack is available at http://github.com/weidai11/cryptopp/commit/7e06c1dce4b0ebc89708ba7afbcc23ff9093f4ea. The essence of the hack is:

  #if (__SUNPRO_CC == 0x5130)
  # define MAYBE_CONST
  #else
  # define MAYBE_CONST const
  #endif

    ...
  static word LinearMultiply(word *C, const word *AA, word B, size_t N)
  {
    MAYBE_CONST word* A = const_cast<word*>(AA);

    word carry=0;
    for(unsigned i=0; i<N; i++)
    {
        Declare2Words(p);
        MultiplyWords(p, A[i], B);
        Acc2WordsBy1(p, carry);
        C[i] = LowWord(p);
        carry = HighWord(p);
    }
    return carry;
  }

Under Sun CC, we cast away the const-ness. Under other compilers, we cast it away but restore it through MAYBE_CONST. For the other compilers, we are just creating a shadow.

I want to ensure there are __**NO**__ performance hits for this one.

If possible, could we get some testing under Visual Studio 2015 and 2016?

Jeff

Jeffrey Walton

unread,
Jun 14, 2016, 10:39:17 AM6/14/16
to Crypto++ Users


On Tuesday, June 14, 2016 at 7:46:53 AM UTC-4, Jeffrey Walton wrote:
Hi Everyone,

Integer class took a bug report under Sun Studio 12.4. Also see Issue 184: Error: The operand "___LKDB" cannot be assigned to (http://github.com/weidai11/cryptopp/issues/188).

Sun CC 12.4 is an important Sun compiler because its their C++11 compiler. I'm fairly certain the bug report is bogus, and its a compiler bug. Never the less, we had to work around it.

The hack is available at http://github.com/weidai11/cryptopp/commit/7e06c1dce4b0ebc89708ba7afbcc23ff9093f4ea. The essence of the hack is:

  #if (__SUNPRO_CC == 0x5130)
  # define MAYBE_CONST
  #else
  # define MAYBE_CONST const
  #endif

This was changed a small bit:


   #if (__SUNPRO_CC == 0x5130)
   # define MAYBE_CONST
   # define MAYBE_UNCONST_CAST const_cast<word*>

   #else
   # define MAYBE_CONST const
   # define MAYBE_UNCONST_CAST
   #endif

It allows us to avoid the un-const cast completely if its not needed. It gets used as expected:

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

        Squ_2
    }

Also see http://github.com/weidai11/cryptopp/commit/c042616ba5951c843a9b6e2d1c7f7b5a3893ccb9.

To test these changes, jump on the Solaris branch with 'git checkout solaris'. Or, visit GitHub, select Solaris from the drop down, then select Download ZIP.

Jeff

Jeffrey Walton

unread,
Jun 15, 2016, 5:05:11 AM6/15/16
to Crypto++ Users
Reply all
Reply to author
Forward
0 new messages