ggml-quants: use _mm256_testz_si256 for mask checks in AVX2 #17641
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
_mm256_testz_si256directly checks if all bits of a vector are zero, which is a more efficient approach for conditional branching than extracting an 8-bit mask and then checking if the mask is non-zero. This optimization leverages specific AVX2 instruction capabilities, potentially reducing instruction latency and improving overall performance by avoiding unnecessary register transfers for the mask.References:
When to use _mm256_testz_si256 vs _mm256_movemask_epi8:
https://stackoverflow.com/questions/27643534/when-to-use-mm256-testz-si256-vs-mm256-movemask-epi8
AVX2: _mm256_testz_si256 vs _mm256_cmpeq_epi32 and _mm256_movemask_epi8:
https://stackoverflow.com/questions/43206253/avx2-mm256-testz-si256-vs-mm256-cmpeq-epi32-and-mm256-movemask-epi8
Intel Intrinsics Guide for
_mm256_testz_si256:https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_testz_si256
Intel Intrinsics Guide for
_mm256_movemask_epi8:https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_movemask_epi8
Efficiently checking for zero vectors with AVX2:
https://lemire.me/blog/2018/06/18/efficiently-checking-for-zero-vectors-with-avx2/
Co-Authored-By: Gemini 2.5 Pro (References and description commit changes)