/src/zlib-ng/arch/x86/slide_hash_sse2.c
Line | Count | Source |
1 | | /* |
2 | | * SSE optimized hash slide |
3 | | * |
4 | | * Copyright (C) 2017 Intel Corporation |
5 | | * Authors: |
6 | | * Arjan van de Ven <arjan@linux.intel.com> |
7 | | * Jim Kukunas <james.t.kukunas@linux.intel.com> |
8 | | * |
9 | | * For conditions of distribution and use, see copyright notice in zlib.h |
10 | | */ |
11 | | |
12 | | #ifdef X86_SSE2 |
13 | | |
14 | | #include "zbuild.h" |
15 | | #include "deflate.h" |
16 | | |
17 | | #include <immintrin.h> |
18 | | #include <assert.h> |
19 | | |
20 | | static inline void slide_hash_chain(Pos *table0, Pos *table1, uint32_t entries0, |
21 | 0 | uint32_t entries1, const __m128i wsize) { |
22 | 0 | uint32_t entries; |
23 | 0 | Pos *table; |
24 | 0 | __m128i value0, value1, result0, result1; |
25 | |
|
26 | 0 | int on_chain = 0; |
27 | |
|
28 | 0 | next_chain: |
29 | 0 | table = (on_chain) ? table1 : table0; |
30 | 0 | entries = (on_chain) ? entries1 : entries0; |
31 | |
|
32 | 0 | table += entries; |
33 | 0 | table -= 16; |
34 | | |
35 | | /* ZALLOC allocates this pointer unless the user chose a custom allocator. |
36 | | * Our alloc function is aligned to 64 byte boundaries */ |
37 | 0 | do { |
38 | 0 | value0 = _mm_load_si128((__m128i *)table); |
39 | 0 | value1 = _mm_load_si128((__m128i *)(table + 8)); |
40 | 0 | result0 = _mm_subs_epu16(value0, wsize); |
41 | 0 | result1 = _mm_subs_epu16(value1, wsize); |
42 | 0 | _mm_store_si128((__m128i *)table, result0); |
43 | 0 | _mm_store_si128((__m128i *)(table + 8), result1); |
44 | |
|
45 | 0 | table -= 16; |
46 | 0 | entries -= 16; |
47 | 0 | } while (entries > 0); |
48 | |
|
49 | 0 | ++on_chain; |
50 | 0 | if (on_chain > 1) { |
51 | 0 | return; |
52 | 0 | } else { |
53 | 0 | goto next_chain; |
54 | 0 | } |
55 | 0 | } |
56 | | |
57 | 0 | Z_INTERNAL void slide_hash_sse2(deflate_state *s) { |
58 | 0 | Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t"); |
59 | 0 | uint16_t wsize = (uint16_t)s->w_size; |
60 | 0 | const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); |
61 | |
|
62 | 0 | assert(((uintptr_t)s->head & 15) == 0); |
63 | 0 | assert(((uintptr_t)s->prev & 15) == 0); |
64 | |
|
65 | 0 | slide_hash_chain(s->head, s->prev, HASH_SIZE, wsize, xmm_wsize); |
66 | 0 | } |
67 | | |
68 | | #endif |