Coverage Report

Created: 2026-06-10 06:34

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
56.1M
static inline uint32_t compare256_avx2_static(const uint8_t *src0, const uint8_t *src1) {
20
56.1M
    uint32_t len = 0;
21
22
69.1M
    do {
23
69.1M
        __m256i ymm_src0, ymm_src1, ymm_cmp;
24
69.1M
        ymm_src0 = _mm256_loadu_si256((__m256i*)src0);
25
69.1M
        ymm_src1 = _mm256_loadu_si256((__m256i*)src1);
26
69.1M
        ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1); /* non-identical bytes = 00, identical bytes = FF */
27
69.1M
        unsigned mask = (unsigned)_mm256_movemask_epi8(ymm_cmp);
28
69.1M
        if (mask != 0xFFFFFFFF)
29
49.0M
            return len + zng_ctz32(~mask); /* Invert bits so identical = 0 */
30
31
20.0M
        src0 += 32, src1 += 32, len += 32;
32
33
20.0M
        ymm_src0 = _mm256_loadu_si256((__m256i*)src0);
34
20.0M
        ymm_src1 = _mm256_loadu_si256((__m256i*)src1);
35
20.0M
        ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1);
36
20.0M
        mask = (unsigned)_mm256_movemask_epi8(ymm_cmp);
37
20.0M
        if (mask != 0xFFFFFFFF)
38
4.15M
            return len + zng_ctz32(~mask);
39
40
15.9M
        src0 += 32, src1 += 32, len += 32;
41
15.9M
    } while (len < 256);
42
43
2.92M
    return 256;
44
56.1M
}
45
46
4.95M
Z_INTERNAL uint32_t compare256_avx2(const uint8_t *src0, const uint8_t *src1) {
47
4.95M
    return compare256_avx2_static(src0, src1);
48
4.95M
}
49
50
#define LONGEST_MATCH       longest_match_avx2
51
35.2M
#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