Coverage Report

Created: 2026-05-28 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zlib-ng/arch/x86/compare256_avx2.c
Line
Count
Source
1
/* compare256_avx2.c -- AVX2 version of compare256
2
 * Copyright Mika T. Lindqvist  <postmaster@raasu.org>
3
 * For conditions of distribution and use, see copyright notice in zlib.h
4
 */
5
6
#include "zbuild.h"
7
#include "zendian.h"
8
#include "zmemory.h"
9
#include "deflate.h"
10
#include "fallback_builtins.h"
11
12
#ifdef X86_AVX2
13
14
#include <immintrin.h>
15
#ifdef _MSC_VER
16
#  include <nmmintrin.h>
17
#endif
18
19
54.6M
static inline uint32_t compare256_avx2_static(const uint8_t *src0, const uint8_t *src1) {
20
54.6M
    uint32_t len = 0;
21
22
67.4M
    do {
23
67.4M
        __m256i ymm_src0, ymm_src1, ymm_cmp;
24
67.4M
        ymm_src0 = _mm256_loadu_si256((__m256i*)src0);
25
67.4M
        ymm_src1 = _mm256_loadu_si256((__m256i*)src1);
26
67.4M
        ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1); /* non-identical bytes = 00, identical bytes = FF */
27
67.4M
        unsigned mask = (unsigned)_mm256_movemask_epi8(ymm_cmp);
28
67.4M
        if (mask != 0xFFFFFFFF)
29
47.8M
            return len + zng_ctz32(~mask); /* Invert bits so identical = 0 */
30
31
19.6M
        src0 += 32, src1 += 32, len += 32;
32
33
19.6M
        ymm_src0 = _mm256_loadu_si256((__m256i*)src0);
34
19.6M
        ymm_src1 = _mm256_loadu_si256((__m256i*)src1);
35
19.6M
        ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1);
36
19.6M
        mask = (unsigned)_mm256_movemask_epi8(ymm_cmp);
37
19.6M
        if (mask != 0xFFFFFFFF)
38
3.95M
            return len + zng_ctz32(~mask);
39
40
15.6M
        src0 += 32, src1 += 32, len += 32;
41
15.6M
    } while (len < 256);
42
43
2.90M
    return 256;
44
54.6M
}
45
46
4.73M
Z_INTERNAL uint32_t compare256_avx2(const uint8_t *src0, const uint8_t *src1) {
47
4.73M
    return compare256_avx2_static(src0, src1);
48
4.73M
}
49
50
#define LONGEST_MATCH       longest_match_avx2
51
33.9M
#define COMPARE256          compare256_avx2_static
52
53
#include "match_tpl.h"
54
55
#define LONGEST_MATCH_ROLL
56
#define LONGEST_MATCH       longest_match_roll_avx2
57
15.9M
#define COMPARE256          compare256_avx2_static
58
59
#include "match_tpl.h"
60
61
#endif