Skip to content

Instantly share code, notes, and snippets.

@Const-me
Created February 17, 2021 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Const-me/7d1ce74a8bbfbe75d20ff0b935c1660f to your computer and use it in GitHub Desktop.
Save Const-me/7d1ce74a8bbfbe75d20ff0b935c1660f to your computer and use it in GitHub Desktop.
inline __m256i shiftLeftBytes_mem( const __m256i src, int i )
{
assert( i >= 0 && i < 32 );
// Align by 64 bytes so the complete array stays in a single cache line
alignas( 64 ) std::array<uint8_t, 64> buffer;
// Store zeros at offset 0
_mm256_store_si256( ( __m256i* )buffer.data(), _mm256_setzero_si256() );
// Store the source vector at offset 32
_mm256_store_si256( ( __m256i* )( buffer.data() + 32 ), src );
// Load back with the offset
return _mm256_loadu_si256( ( const __m256i* )( buffer.data() + 32 - i ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment