/src/c-blosc2/internal-complibs/zlib-ng-2.0.7/insert_string_tpl.h
Line | Count | Source |
1 | | #ifndef INSERT_STRING_H_ |
2 | | #define INSERT_STRING_H_ |
3 | | |
4 | | /* insert_string.h -- Private insert_string functions shared with more than |
5 | | * one insert string implementation |
6 | | * |
7 | | * Copyright (C) 1995-2013 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 | | /* =========================================================================== |
26 | | * Quick insert string str in the dictionary and set match_head to the previous head |
27 | | * of the hash chain (the most recent string with same hash key). Return |
28 | | * the previous length of the hash chain. |
29 | | */ |
30 | 58.9M | Z_INTERNAL Pos QUICK_INSERT_STRING(deflate_state *const s, const uint32_t str) { |
31 | 58.9M | Pos head; |
32 | 58.9M | uint8_t *strstart = s->window + str; |
33 | 58.9M | uint32_t val, hm, h = 0; |
34 | | |
35 | | #ifdef UNALIGNED_OK |
36 | | val = *(uint32_t *)(strstart); |
37 | | #else |
38 | 58.9M | val = ((uint32_t)(strstart[0])); |
39 | 58.9M | val |= ((uint32_t)(strstart[1]) << 8); |
40 | 58.9M | val |= ((uint32_t)(strstart[2]) << 16); |
41 | 58.9M | val |= ((uint32_t)(strstart[3]) << 24); |
42 | 58.9M | #endif |
43 | | |
44 | 58.9M | UPDATE_HASH(s, h, val); |
45 | 58.9M | hm = h & HASH_MASK; |
46 | | |
47 | 58.9M | head = s->head[hm]; |
48 | 58.9M | if (LIKELY(head != str)) { |
49 | 58.9M | s->prev[str & s->w_mask] = head; |
50 | 58.9M | s->head[hm] = (Pos)str; |
51 | 58.9M | } |
52 | 58.9M | return head; |
53 | 58.9M | } |
54 | | |
55 | | /* =========================================================================== |
56 | | * Insert string str in the dictionary and set match_head to the previous head |
57 | | * of the hash chain (the most recent string with same hash key). Return |
58 | | * the previous length of the hash chain. |
59 | | * IN assertion: all calls to to INSERT_STRING are made with consecutive |
60 | | * input characters and the first MIN_MATCH bytes of str are valid |
61 | | * (except for the last MIN_MATCH-1 bytes of the input file). |
62 | | */ |
63 | 1.05M | Z_INTERNAL void INSERT_STRING(deflate_state *const s, const uint32_t str, uint32_t count) { |
64 | 1.05M | uint8_t *strstart = s->window + str; |
65 | 1.05M | uint8_t *strend = strstart + count - 1; /* last position */ |
66 | | |
67 | 23.4M | for (Pos idx = (Pos)str; strstart <= strend; idx++, strstart++) { |
68 | 22.3M | uint32_t val, hm, h = 0; |
69 | | |
70 | | #ifdef UNALIGNED_OK |
71 | | val = *(uint32_t *)(strstart); |
72 | | #else |
73 | 22.3M | val = ((uint32_t)(strstart[0])); |
74 | 22.3M | val |= ((uint32_t)(strstart[1]) << 8); |
75 | 22.3M | val |= ((uint32_t)(strstart[2]) << 16); |
76 | 22.3M | val |= ((uint32_t)(strstart[3]) << 24); |
77 | 22.3M | #endif |
78 | | |
79 | 22.3M | UPDATE_HASH(s, h, val); |
80 | 22.3M | hm = h & HASH_MASK; |
81 | | |
82 | 22.3M | Pos head = s->head[hm]; |
83 | 22.3M | if (LIKELY(head != idx)) { |
84 | 22.3M | s->prev[idx & s->w_mask] = head; |
85 | 22.3M | s->head[hm] = idx; |
86 | 22.3M | } |
87 | 22.3M | } |
88 | 1.05M | } |
89 | | #endif |