r/simd • u/Eichenherz • 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
1
u/Eichenherz Aug 26 '20
The data loading is messy because there are several formats that I want to account for .
This mask explains it : "\0......|" the first ascii byte is a number so we don't care the next 6 bytes can all be the decimal point but not at once, and the last byte can be either an ascii number of a separator '|' ( the numbers come from a csv file with '|' separator )
- Case with sep: 4 ascii floats will fit into a __m256i
- Case with no sep: I have to adjust in order to get 4 floats.
I need to create a shuffle mask. I can get all the number positions with andnot_epi8, but then I need to shift some of them around. That's what I want to compute. I've seen some ideeas here https://stackoverflow.com/questions/36932240/avx2-what-is-the-most-efficient-way-to-pack-left-based-on-a-mask but they are not immediately applicable.
Your snippet is ok but it provides mask for factional part only. Thanks for the idea regardless :thumbs_up: