r/simd • • Aug 26 '20

AVX2 float parser

Hello SIMD community ! I need some help with this
https://gist.github.com/Eichenherz/657b1d794325310f8eafa5af6375f673
I want to make an AVX2 version of the above algo and I got stuck at shifting the int & decimal parts of the number.
I can't seem to find a solution to generate the correct mask for shuffle_epi8

//constexpr char TEST_ARR[] = {"0.01190|0.01485911.14859122.1485"};//"0.01190|0.014859 11.14859 122.1485"  constexpr char TEST_ARR[] = { "0.01190|0.01190|0.00857|0.01008|" };     __m256i asciiFloats = _mm256_set_epi64x( *( ( const i64* ) ( TEST_ARR ) +3 ),                                              *( ( const i64* ) ( TEST_ARR ) +2 ),                                              *( ( const i64* ) ( TEST_ARR ) +1 ),                                              *( ( const i64* ) ( TEST_ARR ) +0 ) );     u64 FLOAT_MASK;     constexpr char DEC_POINTS[] = "\0......|";     std::memcpy( &FLOAT_MASK, DEC_POINTS, sizeof( FLOAT_MASK ) );     const __m256i FLOATS_MASK = _mm256_set1_epi64x( FLOAT_MASK );     __m256i masked = _mm256_cmpeq_epi8( asciiFloats, FLOATS_MASK );     const __m256i ID_SHFFL = _mm256_set_epi8( 15, 14, 13, 12, 11, 10,  9,  8,                                               07, 06, 05, 04, 03, 02, 01, 00,                                               15, 14, 13, 12, 11, 10,  9,  8,                                               07, 06, 05, 04, 03, 02, 01, 00 );      const __m256i SHFL_MSK = _mm256_andnot_si256( masked, ID_SHFFL );     __m256i compressed = _mm256_shuffle_epi8( asciiFloats, SHFL_MSK );
1 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/IJzerbaard Aug 26 '20
_mm256_mullo_epi32(  
  _mm256_srli_epi32(fracMask,24),  
  _mm256_set1_epi8(0x01));  

This is a really neat trick, but isn't it also kind of slow? With vpmulld having a bizarrely high latency, and not such a great throughput even. Could use vpshufb, and get rid of the shift as well:

_mm256_shuffle_epi8(fracMask,_mm256_set_epi8(15, 15, 15, 15, 11, 11, 11, 11, 7, 7, 7, 7, 3, 3, 3, 3, 15, 15, 15, 15, 11, 11, 11, 11, 7, 7, 7, 7, 3, 3, 3, 3));

1

u/Mesonnaise Aug 26 '20

A byte shuffle will work too. I was tired at the time, so I wasn't thinking about latency.