Skip to content

Commit 015aeda

Browse files
committed
A better packNibbles implementation using AVX512
1 parent 36b4f7e commit 015aeda

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ggml.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,11 @@ static inline __m256 mul_sum_i8_pairs_float(const __m256i x, const __m256i y) {
517517
static inline __m128i packNibbles( __m256i bytes )
518518
{
519519
// Move bits within 16-bit lanes from 0000_abcd_0000_efgh into 0000_0000_abcd_efgh
520+
#if __AVX512F__
521+
const __m256i bytes_srli_4 = _mm256_srli_epi16(bytes, 4); // 0000_0000_abcd_0000
522+
bytes = _mm256_or_si256(bytes, bytes_srli_4); // 0000_abcd_abcd_efgh
523+
return _mm256_cvtepi16_epi8(bytes); // abcd_efgh
524+
#else
520525
const __m256i lowByte = _mm256_set1_epi16( 0xFF );
521526
__m256i high = _mm256_andnot_si256( lowByte, bytes );
522527
__m256i low = _mm256_and_si256( lowByte, bytes );
@@ -527,6 +532,7 @@ static inline __m128i packNibbles( __m256i bytes )
527532
__m128i r0 = _mm256_castsi256_si128( bytes );
528533
__m128i r1 = _mm256_extracti128_si256( bytes, 1 );
529534
return _mm_packus_epi16( r0, r1 );
535+
#endif
530536
}
531537
#else
532538
static inline __m128i packNibbles( __m128i bytes1, __m128i bytes2 )

0 commit comments

Comments
 (0)