| 1 |
/* chunkset_neon.c -- NEON inline functions to copy small data chunks. |
| 2 |
* For conditions of distribution and use, see copyright notice in zlib.h |
| 3 |
*/ |
| 4 |
|
| 5 |
#ifdef ARM_NEON |
| 6 |
#include "neon_intrins.h" |
| 7 |
#include "../../zbuild.h" |
| 8 |
#include "../generic/chunk_permute_table.h" |
| 9 |
|
| 10 |
typedef uint8x16_t chunk_t; |
| 11 |
|
| 12 |
#define CHUNK_SIZE 16 |
| 13 |
|
| 14 |
#define HAVE_CHUNKMEMSET_2 |
| 15 |
#define HAVE_CHUNKMEMSET_4 |
| 16 |
#define HAVE_CHUNKMEMSET_8 |
| 17 |
#define HAVE_CHUNK_MAG |
| 18 |
|
| 19 |
static const lut_rem_pair perm_idx_lut[13] = { |
| 20 |
{0, 1}, /* 3 */ |
| 21 |
{0, 0}, /* don't care */ |
| 22 |
{1 * 32, 1}, /* 5 */ |
| 23 |
{2 * 32, 4}, /* 6 */ |
| 24 |
{3 * 32, 2}, /* 7 */ |
| 25 |
{0 * 32, 0}, /* don't care */ |
| 26 |
{4 * 32, 7}, /* 9 */ |
| 27 |
{5 * 32, 6}, /* 10 */ |
| 28 |
{6 * 32, 5}, /* 11 */ |
| 29 |
{7 * 32, 4}, /* 12 */ |
| 30 |
{8 * 32, 3}, /* 13 */ |
| 31 |
{9 * 32, 2}, /* 14 */ |
| 32 |
{10 * 32, 1},/* 15 */ |
| 33 |
}; |
| 34 |
|
| 35 |
static inline void chunkmemset_2(uint8_t *from, chunk_t *chunk) { |
| 36 |
uint16_t tmp; |
| 37 |
memcpy(&tmp, from, sizeof(tmp)); |
| 38 |
*chunk = vreinterpretq_u8_u16(vdupq_n_u16(tmp)); |
| 39 |
} |
| 40 |
|
| 41 |
static inline void chunkmemset_4(uint8_t *from, chunk_t *chunk) { |
| 42 |
uint32_t tmp; |
| 43 |
memcpy(&tmp, from, sizeof(tmp)); |
| 44 |
*chunk = vreinterpretq_u8_u32(vdupq_n_u32(tmp)); |
| 45 |
} |
| 46 |
|
| 47 |
static inline void chunkmemset_8(uint8_t *from, chunk_t *chunk) { |
| 48 |
uint64_t tmp; |
| 49 |
memcpy(&tmp, from, sizeof(tmp)); |
| 50 |
*chunk = vreinterpretq_u8_u64(vdupq_n_u64(tmp)); |
| 51 |
} |
| 52 |
|
| 53 |
#define CHUNKSIZE chunksize_neon |
| 54 |
#define CHUNKCOPY chunkcopy_neon |
| 55 |
#define CHUNKUNROLL chunkunroll_neon |
| 56 |
#define CHUNKMEMSET chunkmemset_neon |
| 57 |
#define CHUNKMEMSET_SAFE chunkmemset_safe_neon |
| 58 |
|
| 59 |
static inline void loadchunk(uint8_t const *s, chunk_t *chunk) { |
| 60 |
*chunk = vld1q_u8(s); |
| 61 |
} |
| 62 |
|
| 63 |
static inline void storechunk(uint8_t *out, chunk_t *chunk) { |
| 64 |
vst1q_u8(out, *chunk); |
| 65 |
} |
| 66 |
|
| 67 |
static inline chunk_t GET_CHUNK_MAG(uint8_t *buf, uint32_t *chunk_rem, uint32_t dist) { |
| 68 |
lut_rem_pair lut_rem = perm_idx_lut[dist - 3]; |
| 69 |
*chunk_rem = lut_rem.remval; |
| 70 |
|
| 71 |
/* See note in chunkset_ssse3.c for why this is ok */ |
| 72 |
__msan_unpoison(buf + dist, 16 - dist); |
| 73 |
|
| 74 |
/* This version of table is only available on aarch64 */ |
| 75 |
#if defined(_M_ARM64) || defined(_M_ARM64EC) || defined(__aarch64__) |
| 76 |
uint8x16_t ret_vec = vld1q_u8(buf); |
| 77 |
|
| 78 |
uint8x16_t perm_vec = vld1q_u8(permute_table + lut_rem.idx); |
| 79 |
return vqtbl1q_u8(ret_vec, perm_vec); |
| 80 |
#else |
| 81 |
uint8x8_t ret0, ret1, a, b, perm_vec0, perm_vec1; |
| 82 |
perm_vec0 = vld1_u8(permute_table + lut_rem.idx); |
| 83 |
perm_vec1 = vld1_u8(permute_table + lut_rem.idx + 8); |
| 84 |
a = vld1_u8(buf); |
| 85 |
b = vld1_u8(buf + 8); |
| 86 |
ret0 = vtbl1_u8(a, perm_vec0); |
| 87 |
uint8x8x2_t ab = {{a, b}}; |
| 88 |
ret1 = vtbl2_u8(ab, perm_vec1); |
| 89 |
return vcombine_u8(ret0, ret1); |
| 90 |
#endif |
| 91 |
} |
| 92 |
|
| 93 |
#include "chunkset_tpl.h" |
| 94 |
|
| 95 |
#define INFLATE_FAST inflate_fast_neon |
| 96 |
|
| 97 |
#include "inffast_tpl.h" |
| 98 |
|
| 99 |
#endif |