/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 | | |
19 | 0 | static inline void slide_hash_chain(Pos *table, uint32_t entries, const __m128i wsize) { |
20 | 0 | table += entries; |
21 | 0 | table -= 16; |
22 | | |
23 | | /* alloc_deflate() ensures this pointer is aligned on an 64 byte boundary */ |
24 | 0 | do { |
25 | 0 | __m128i value1, value2, result1, result2; |
26 | |
|
27 | 0 | value1 = _mm_load_si128((__m128i *)table); |
28 | 0 | value2 = _mm_load_si128((__m128i *)(table + 8)); |
29 | 0 | result1 = _mm_subs_epu16(value1, wsize); |
30 | 0 | result2 = _mm_subs_epu16(value2, wsize); |
31 | 0 | _mm_store_si128((__m128i *)table, result1); |
32 | 0 | _mm_store_si128((__m128i *)(table + 8), result2); |
33 | |
|
34 | 0 | table -= 16; |
35 | 0 | entries -= 16; |
36 | 0 | } while (entries > 0); |
37 | 0 | } |
38 | | |
39 | 0 | Z_INTERNAL void slide_hash_sse2(deflate_state *s) { |
40 | 0 | Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t"); |
41 | 0 | uint16_t wsize = (uint16_t)s->w_size; |
42 | 0 | const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); |
43 | |
|
44 | 0 | slide_hash_chain(s->head, HASH_SIZE, xmm_wsize); |
45 | 0 | slide_hash_chain(s->prev, wsize, xmm_wsize); |
46 | 0 | } |
47 | | |
48 | 0 | Z_INTERNAL void slide_hash_head_sse2(deflate_state *s) { |
49 | 0 | Assert(s->w_size <= UINT16_MAX, "w_size should fit in uint16_t"); |
50 | 0 | uint16_t wsize = (uint16_t)s->w_size; |
51 | 0 | const __m128i xmm_wsize = _mm_set1_epi16((short)wsize); |
52 | |
|
53 | 0 | slide_hash_chain(s->head, HASH_SIZE, xmm_wsize); |
54 | 0 | } |
55 | | |
56 | | #endif |