Coverage Report

Created: 2026-09-13 06:38

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
12.6M
Z_FORCEINLINE static uint32_t compare256_avx2_static(const uint8_t *src0, const uint8_t *src1) {
20
12.6M
    uint32_t len = 0;
21
22
16.6M
    do {
23
16.6M
        __m256i ymm_src0, ymm_src1, ymm_cmp;
24
16.6M
        ymm_src0 = _mm256_loadu_si256((__m256i*)src0);
25
16.6M
        ymm_src1 = _mm256_loadu_si256((__m256i*)src1);
26
16.6M
        ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1); /* non-identical bytes = 00, identical bytes = FF */
27
16.6M
        unsigned mask = (unsigned)_mm256_movemask_epi8(ymm_cmp);
28
16.6M
        if (mask != 0xFFFFFFFF)
29
9.85M
            return len + zng_ctz32(~mask); /* Invert bits so identical = 0 */
30
31
6.76M
        src0 += 32, src1 += 32, len += 32;
32
33
6.76M
        ymm_src0 = _mm256_loadu_si256((__m256i*)src0);
34
6.76M
        ymm_src1 = _mm256_loadu_si256((__m256i*)src1);
35
6.76M
        ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1);
36
6.76M
        mask = (unsigned)_mm256_movemask_epi8(ymm_cmp);
37
6.76M
        if (mask != 0xFFFFFFFF)
38
1.94M
            return len + zng_ctz32(~mask);
39
40
4.81M
        src0 += 32, src1 += 32, len += 32;
41
4.81M
    } while (len < 256);
42
43
845k
    return 256;
44
12.6M
}
45
46
4.79M
Z_INTERNAL uint32_t compare256_avx2(const uint8_t *src0, const uint8_t *src1) {
47
4.79M
    return compare256_avx2_static(src0, src1);
48
4.79M
}
49
50
#define LONGEST_MATCH       longest_match_avx2
51
4.59M
#define COMPARE256          compare256_avx2_static
52
53
#include "match_tpl.h"
54
55
#define LONGEST_MATCH_SLOW
56
#define LONGEST_MATCH       longest_match_slow_knuth_avx2
57
3.25M
#define COMPARE256          compare256_avx2_static
58
59
#include "match_tpl.h"
60
61
#define LONGEST_MATCH_SLOW
62
#define LONGEST_MATCH_SLOW_ROLL
63
#define LONGEST_MATCH       longest_match_slow_roll_avx2
64
0
#define COMPARE256          compare256_avx2_static
65
66
#include "match_tpl.h"
67
68
#endif