Coverage Report

Created: 2026-09-19 07:07

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
26.7M
Z_FORCEINLINE static uint32_t compare256_avx2_static(const uint8_t *src0, const uint8_t *src1) {
20
26.7M
    uint32_t len = 0;
21
22
40.3M
    do {
23
40.3M
        __m256i ymm_src0, ymm_src1, ymm_cmp;
24
40.3M
        ymm_src0 = _mm256_loadu_si256((__m256i*)src0);
25
40.3M
        ymm_src1 = _mm256_loadu_si256((__m256i*)src1);
26
40.3M
        ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1); /* non-identical bytes = 00, identical bytes = FF */
27
40.3M
        unsigned mask = (unsigned)_mm256_movemask_epi8(ymm_cmp);
28
40.3M
        if (mask != 0xFFFFFFFF)
29
19.0M
            return len + zng_ctz32(~mask); /* Invert bits so identical = 0 */
30
31
21.3M
        src0 += 32, src1 += 32, len += 32;
32
33
21.3M
        ymm_src0 = _mm256_loadu_si256((__m256i*)src0);
34
21.3M
        ymm_src1 = _mm256_loadu_si256((__m256i*)src1);
35
21.3M
        ymm_cmp = _mm256_cmpeq_epi8(ymm_src0, ymm_src1);
36
21.3M
        mask = (unsigned)_mm256_movemask_epi8(ymm_cmp);
37
21.3M
        if (mask != 0xFFFFFFFF)
38
4.60M
            return len + zng_ctz32(~mask);
39
40
16.7M
        src0 += 32, src1 += 32, len += 32;
41
16.7M
    } while (len < 256);
42
43
3.03M
    return 256;
44
26.7M
}
45
46
5.69M
Z_INTERNAL uint32_t compare256_avx2(const uint8_t *src0, const uint8_t *src1) {
47
5.69M
    return compare256_avx2_static(src0, src1);
48
5.69M
}
49
50
#define LONGEST_MATCH       longest_match_avx2
51
10.2M
#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
5.19M
#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
5.56M
#define COMPARE256          compare256_avx2_static
65
66
#include "match_tpl.h"
67
68
#endif