Enable 16-byte alignment full-time for i386 and x86_64?

8 views
Skip to first unread message

Jeffrey Walton

unread,
Aug 27, 2017, 5:49:22 PM8/27/17
to Crypto++ Users
Hi Everyone,

We are catching a crash under 32-bit Solaris since splitting sources into base+simd. After investigation it appears our aligned allocator is _not_ providing aligned allocations.  This makes sense since we are favoring base+simd.  Here's the culprit from secblock.h (https://github.com/weidai11/cryptopp/blob/master/secblock.h#L172):

  template <class T, bool T_Align16 = false>
  class AllocatorWithCleanup : public AllocatorBase<T>
  {
    ...
    #if CRYPTOPP_BOOL_ALIGN16
    if (T_Align16 && size*sizeof(T) >= 16)
      return (pointer)AlignedAllocate(size*sizeof(T));
    #endif
  }

CRYPTOPP_BOOL_ALIGN16 is 0 because we are base, not simd. And a class file like aria.h does not get -mssse3, so it will never witness CRYPTOPP_BOOL_ALIGN16 set to 1. However, aria-simd.cpp assumes 16-byte aligned.

We did not experience the crash under GCC because its heap allocations are 16-byte aligned by default. Ditto for Apple and BSDs. We side stepped it by dumb luck. However, Sun's default alignment is 8.

To combat this split view of aligned allocations I want to enable CRYPTOPP_BOOL_ALIGN16 for all i386 and x86_64 builds since its nearly certain some SSE will be used.

There is a downside. If you have a 1995 era 486 or early Pentium then you may see wasted space. But you are already suffering so a little more should not hurt too much. Think of it as taking one for the team. (You can also manually disable it).

Are there any objections to enabling CRYPTOPP_BOOL_ALIGN16 for all i386 and amd64 builds?

Jeff

Jeffrey Walton

unread,
Aug 28, 2017, 6:18:53 AM8/28/17
to Crypto++ Users

We are catching a crash under 32-bit Solaris since splitting sources into base+simd. After investigation it appears our aligned allocator is _not_ providing aligned allocations.  This makes sense since we are favoring base+simd.  Here's the culprit from secblock.h (https://github.com/weidai11/cryptopp/blob/master/secblock.h#L172):

  template <class T, bool T_Align16 = false>
  class AllocatorWithCleanup : public AllocatorBase<T>
  {
    ...
    #if CRYPTOPP_BOOL_ALIGN16
    if (T_Align16 && size*sizeof(T) >= 16)
      return (pointer)AlignedAllocate(size*sizeof(T));
    #endif
  }

CRYPTOPP_BOOL_ALIGN16 is 0 because we are base, not simd. And a class file like aria.h does not get -mssse3, so it will never witness CRYPTOPP_BOOL_ALIGN16 set to 1. However, aria-simd.cpp assumes 16-byte aligned.

We did not experience the crash under GCC because its heap allocations are 16-byte aligned by default. Ditto for Apple and BSDs. We side stepped it by dumb luck. However, Sun's default alignment is 8.

To combat this split view of aligned allocations I want to enable CRYPTOPP_BOOL_ALIGN16 for all i386 and x86_64 builds since its nearly certain some SSE will be used.


CRYPTOPP_DISABLE_ASM can be used to stop the 16-byte alignment of buffers so folks can continue to enjoy their i486's and i586's.

Jeff
Reply all
Reply to author
Forward
0 new messages