Coverage Report

Created: 2025-11-06 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/zlib-ng/insert_string_tpl.h
Line
Count
Source
1
#ifndef INSERT_STRING_H_
2
#define INSERT_STRING_H_
3
4
/* insert_string_tpl.h -- Private insert_string functions shared with more than
5
 *                        one insert string implementation
6
 *
7
 * Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
8
 *
9
 * Copyright (C) 2013 Intel Corporation. All rights reserved.
10
 * Authors:
11
 *  Wajdi Feghali   <wajdi.k.feghali@intel.com>
12
 *  Jim Guilford    <james.guilford@intel.com>
13
 *  Vinodh Gopal    <vinodh.gopal@intel.com>
14
 *  Erdinc Ozturk   <erdinc.ozturk@intel.com>
15
 *  Jim Kukunas     <james.t.kukunas@linux.intel.com>
16
 *
17
 * Portions are Copyright (C) 2016 12Sided Technology, LLC.
18
 * Author:
19
 *  Phil Vachon     <pvachon@12sidedtech.com>
20
 *
21
 * For conditions of distribution and use, see copyright notice in zlib.h
22
 *
23
 */
24
25
#include "zmemory.h"
26
27
#ifndef HASH_CALC_OFFSET
28
86.1M
#  define HASH_CALC_OFFSET 0
29
#endif
30
#ifndef HASH_CALC_MASK
31
124M
#  define HASH_CALC_MASK HASH_MASK
32
#endif
33
#ifndef HASH_CALC_READ
34
#  if BYTE_ORDER == LITTLE_ENDIAN
35
#    define HASH_CALC_READ \
36
124M
        val = zng_memread_4(strstart);
37
#  else
38
#    define HASH_CALC_READ \
39
        val = ZSWAP32(zng_memread_4(strstart));
40
#  endif
41
#endif
42
43
/* ===========================================================================
44
 * Update a hash value with the given input byte
45
 * IN  assertion: all calls to UPDATE_HASH are made with consecutive
46
 *    input characters, so that a running hash key can be computed from the
47
 *    previous key instead of complete recalculation each time.
48
 */
49
23.0M
Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) {
50
23.0M
    HASH_CALC(h, val);
51
23.0M
    return h & HASH_CALC_MASK;
52
23.0M
}
Unexecuted instantiation: update_hash
update_hash_roll
Line
Count
Source
49
23.0M
Z_INTERNAL uint32_t UPDATE_HASH(uint32_t h, uint32_t val) {
50
23.0M
    HASH_CALC(h, val);
51
23.0M
    return h & HASH_CALC_MASK;
52
23.0M
}
53
54
/* ===========================================================================
55
 * Quick insert string str in the dictionary and set match_head to the previous head
56
 * of the hash chain (the most recent string with same hash key). Return
57
 * the previous length of the hash chain.
58
 */
59
107M
Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) {
60
107M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
61
107M
    uint32_t val, hm;
62
107M
    Pos head;
63
64
107M
    HASH_CALC_VAR_INIT;
65
107M
    HASH_CALC_READ;
66
107M
    HASH_CALC(HASH_CALC_VAR, val);
67
107M
    HASH_CALC_VAR &= HASH_CALC_MASK;
68
107M
    hm = HASH_CALC_VAR;
69
70
107M
    head = s->head[hm];
71
107M
    if (LIKELY(head != str)) {
72
107M
        s->prev[str & s->w_mask] = head;
73
107M
        s->head[hm] = (Pos)str;
74
107M
    }
75
107M
    return head;
76
107M
}
quick_insert_string
Line
Count
Source
59
82.3M
Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) {
60
82.3M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
61
82.3M
    uint32_t val, hm;
62
82.3M
    Pos head;
63
64
82.3M
    HASH_CALC_VAR_INIT;
65
82.3M
    HASH_CALC_READ;
66
82.3M
    HASH_CALC(HASH_CALC_VAR, val);
67
82.3M
    HASH_CALC_VAR &= HASH_CALC_MASK;
68
82.3M
    hm = HASH_CALC_VAR;
69
70
82.3M
    head = s->head[hm];
71
82.3M
    if (LIKELY(head != str)) {
72
82.3M
        s->prev[str & s->w_mask] = head;
73
82.3M
        s->head[hm] = (Pos)str;
74
82.3M
    }
75
82.3M
    return head;
76
82.3M
}
quick_insert_string_roll
Line
Count
Source
59
25.0M
Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, uint32_t str) {
60
25.0M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
61
25.0M
    uint32_t val, hm;
62
25.0M
    Pos head;
63
64
25.0M
    HASH_CALC_VAR_INIT;
65
25.0M
    HASH_CALC_READ;
66
25.0M
    HASH_CALC(HASH_CALC_VAR, val);
67
25.0M
    HASH_CALC_VAR &= HASH_CALC_MASK;
68
25.0M
    hm = HASH_CALC_VAR;
69
70
25.0M
    head = s->head[hm];
71
25.0M
    if (LIKELY(head != str)) {
72
25.0M
        s->prev[str & s->w_mask] = head;
73
25.0M
        s->head[hm] = (Pos)str;
74
25.0M
    }
75
25.0M
    return head;
76
25.0M
}
77
78
/* ===========================================================================
79
 * Insert string str in the dictionary and set match_head to the previous head
80
 * of the hash chain (the most recent string with same hash key). Return
81
 * the previous length of the hash chain.
82
 * IN  assertion: all calls to INSERT_STRING are made with consecutive
83
 *    input characters and the first STD_MIN_MATCH bytes of str are valid
84
 *    (except for the last STD_MIN_MATCH-1 bytes of the input file).
85
 */
86
6.71M
Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) {
87
6.71M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
88
6.71M
    uint8_t *strend = strstart + count;
89
90
    /* Local pointers to avoid indirection */
91
6.71M
    Pos *headp = s->head;
92
6.71M
    Pos *prevp = s->prev;
93
6.71M
    const unsigned int w_mask = s->w_mask;
94
95
67.1M
    for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) {
96
60.4M
        uint32_t val, hm;
97
98
60.4M
        HASH_CALC_VAR_INIT;
99
60.4M
        HASH_CALC_READ;
100
60.4M
        HASH_CALC(HASH_CALC_VAR, val);
101
60.4M
        HASH_CALC_VAR &= HASH_CALC_MASK;
102
60.4M
        hm = HASH_CALC_VAR;
103
104
60.4M
        Pos head = headp[hm];
105
60.4M
        if (LIKELY(head != idx)) {
106
60.4M
            prevp[idx & w_mask] = head;
107
60.4M
            headp[hm] = idx;
108
60.4M
        }
109
60.4M
    }
110
6.71M
}
insert_string
Line
Count
Source
86
3.77M
Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) {
87
3.77M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
88
3.77M
    uint8_t *strend = strstart + count;
89
90
    /* Local pointers to avoid indirection */
91
3.77M
    Pos *headp = s->head;
92
3.77M
    Pos *prevp = s->prev;
93
3.77M
    const unsigned int w_mask = s->w_mask;
94
95
45.5M
    for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) {
96
41.8M
        uint32_t val, hm;
97
98
41.8M
        HASH_CALC_VAR_INIT;
99
41.8M
        HASH_CALC_READ;
100
41.8M
        HASH_CALC(HASH_CALC_VAR, val);
101
41.8M
        HASH_CALC_VAR &= HASH_CALC_MASK;
102
41.8M
        hm = HASH_CALC_VAR;
103
104
41.8M
        Pos head = headp[hm];
105
41.8M
        if (LIKELY(head != idx)) {
106
41.8M
            prevp[idx & w_mask] = head;
107
41.8M
            headp[hm] = idx;
108
41.8M
        }
109
41.8M
    }
110
3.77M
}
insert_string_roll
Line
Count
Source
86
2.93M
Z_INTERNAL void INSERT_STRING(deflate_state *const s, uint32_t str, uint32_t count) {
87
2.93M
    uint8_t *strstart = s->window + str + HASH_CALC_OFFSET;
88
2.93M
    uint8_t *strend = strstart + count;
89
90
    /* Local pointers to avoid indirection */
91
2.93M
    Pos *headp = s->head;
92
2.93M
    Pos *prevp = s->prev;
93
2.93M
    const unsigned int w_mask = s->w_mask;
94
95
21.5M
    for (Pos idx = (Pos)str; strstart < strend; idx++, strstart++) {
96
18.6M
        uint32_t val, hm;
97
98
18.6M
        HASH_CALC_VAR_INIT;
99
18.6M
        HASH_CALC_READ;
100
18.6M
        HASH_CALC(HASH_CALC_VAR, val);
101
18.6M
        HASH_CALC_VAR &= HASH_CALC_MASK;
102
18.6M
        hm = HASH_CALC_VAR;
103
104
18.6M
        Pos head = headp[hm];
105
18.6M
        if (LIKELY(head != idx)) {
106
18.6M
            prevp[idx & w_mask] = head;
107
18.6M
            headp[hm] = idx;
108
18.6M
        }
109
18.6M
    }
110
2.93M
}
111
#endif