Developer knowledge network · moderated exchange

Супольнасць UnreliableCode

Супольнасць распрацоўшчыкаў даследаванняў, зваротнага праектавання і кадавання

Knowledge indexжыць
4Categories
919Threads
2.8KПаведамленні
Analysis

AVX-512 vs AVX2 Pattern Scanning: benchmarks & cache line alignment

sig_scanner_sam
Pattern Master
MEMBER
прадстаўнік: 210
Дата далучэння: Dec 2019
Паведамленні: 11
Дзякуй: 51
1 месяцаў таму · Jul 10, 2026 7:11 PM
#1

Benchmarking 512-bit vector scanning (_mm512_cmpeq_epi8_mask) on Zen 4 / Intel 14th Gen vs 256-bit AVX2:

  • AVX2: Scans 32 bytes per iteration (~4.8 GB/s).
  • AVX-512: Scans 64 bytes per iteration (~9.2 GB/s).
CPP
#include <immintrin.h>
uintptr_t ScanAVX512(const uint8_t* pBase, size_t sz, uint8_t firstByte) {
    __m512i target = _mm512_set1_epi8(firstByte);
    for (size_t i = 0; i < sz - 64; i += 64) {
        __m512i chunk = _mm512_loadu_si512((const __m512i*)(pBase + i));
        __mmask64 mask = _mm512_cmpeq_epi8_mask(chunk, target);
        if (mask != 0) {
            // Match candidate...
        }
    }
    return 0;
}

Scans a 400MB game binary in 43 milliseconds!

ptr_arithmetic
C++ Wizard
MEMBER
прадстаўнік: 162
Дата далучэння: May 2018
Паведамленні: 73
Дзякуй: 42
1 месяцаў таму · Jul 10, 2026 8:22 PM
#2

_mm512_cmpeq_epi8_mask returning a native 64-bit bitmask directly into __mmask64 register avoids the vpmovmskb instruction completely. Huge speedup.

x64_assembler
Assembly Guru
MEMBER
прадстаўнік: 99
Дата далучэння: Sep 2022
Паведамленні: 14
Дзякуй: 16
1 месяцаў таму · Jul 11, 2026 4:32 AM
#3

Impressive throughput. Make sure to check CPUID for AVX-512 support before invoking.