github.com/grailbio/base@v0.0.11/compress/libdeflate/arm/matchfinder_impl.h (about) 1 #ifndef GO_SRC_GITHUB_COM_GRAILBIO_BASE_COMPRESS_LIBDEFLATE_ARM_MATCHFINDER_IMPL_H_ // NOLINT(whitespace/line_length) 2 #define GO_SRC_GITHUB_COM_GRAILBIO_BASE_COMPRESS_LIBDEFLATE_ARM_MATCHFINDER_IMPL_H_ // NOLINT(whitespace/line_length) 3 /* 4 * arm/matchfinder_impl.h - ARM implementations of matchfinder functions 5 * 6 * Copyright 2016 Eric Biggers 7 * 8 * Permission is hereby granted, free of charge, to any person 9 * obtaining a copy of this software and associated documentation 10 * files (the "Software"), to deal in the Software without 11 * restriction, including without limitation the rights to use, 12 * copy, modify, merge, publish, distribute, sublicense, and/or sell 13 * copies of the Software, and to permit persons to whom the 14 * Software is furnished to do so, subject to the following 15 * conditions: 16 * 17 * The above copyright notice and this permission notice shall be 18 * included in all copies or substantial portions of the Software. 19 * 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 * OTHER DEALINGS IN THE SOFTWARE. 28 */ 29 30 #ifdef __ARM_NEON 31 # if MATCHFINDER_ALIGNMENT < 16 32 # undef MATCHFINDER_ALIGNMENT 33 # define MATCHFINDER_ALIGNMENT 16 34 # endif 35 # include <arm_neon.h> 36 static forceinline bool 37 matchfinder_init_neon(mf_pos_t *data, size_t size) 38 { 39 int16x8_t v, *p; 40 size_t n; 41 42 if (size % (sizeof(int16x8_t) * 4) != 0) 43 return false; 44 45 STATIC_ASSERT(sizeof(mf_pos_t) == 2); 46 v = (int16x8_t) { 47 MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, 48 MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, 49 MATCHFINDER_INITVAL, MATCHFINDER_INITVAL, 50 }; 51 p = (int16x8_t *)data; 52 n = size / (sizeof(int16x8_t) * 4); 53 do { 54 p[0] = v; 55 p[1] = v; 56 p[2] = v; 57 p[3] = v; 58 p += 4; 59 } while (--n); 60 return true; 61 } 62 #undef arch_matchfinder_init 63 #define arch_matchfinder_init matchfinder_init_neon 64 65 static forceinline bool 66 matchfinder_rebase_neon(mf_pos_t *data, size_t size) 67 { 68 int16x8_t v, *p; 69 size_t n; 70 71 if (size % (sizeof(int16x8_t) * 4) != 0) 72 return false; 73 74 STATIC_ASSERT(sizeof(mf_pos_t) == 2); 75 v = (int16x8_t) { 76 (u16)-MATCHFINDER_WINDOW_SIZE, (u16)-MATCHFINDER_WINDOW_SIZE, 77 (u16)-MATCHFINDER_WINDOW_SIZE, (u16)-MATCHFINDER_WINDOW_SIZE, 78 (u16)-MATCHFINDER_WINDOW_SIZE, (u16)-MATCHFINDER_WINDOW_SIZE, 79 (u16)-MATCHFINDER_WINDOW_SIZE, (u16)-MATCHFINDER_WINDOW_SIZE, 80 }; 81 p = (int16x8_t *)data; 82 n = size / (sizeof(int16x8_t) * 4); 83 do { 84 p[0] = vqaddq_s16(p[0], v); 85 p[1] = vqaddq_s16(p[1], v); 86 p[2] = vqaddq_s16(p[2], v); 87 p[3] = vqaddq_s16(p[3], v); 88 p += 4; 89 } while (--n); 90 return true; 91 } 92 #undef arch_matchfinder_rebase 93 #define arch_matchfinder_rebase matchfinder_rebase_neon 94 95 #endif /* __ARM_NEON */ 96 97 #endif // GO_SRC_GITHUB_COM_GRAILBIO_BASE_COMPRESS_LIBDEFLATE_ARM_MATCHFINDER_IMPL_H_ NOLINT(whitespace/line_length)