2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef included_vector_neon_h
17 #define included_vector_neon_h
22 #define u8x16_splat(i) vdupq_n_u8(i)
23 #define u16x8_splat(i) vdupq_n_u16(i)
24 #define i16x8_splat(i) vdupq_n_s16(i)
25 #define u32x4_splat(i) vdupq_n_u32(i)
26 #define i32x4_splat(i) vdupq_n_s32(i)
29 #define u16x8_add(a,b) vaddq_u16(a,b)
30 #define i16x8_add(a,b) vaddq_s16(a,b)
31 #define u16x8_sub_saturate(a,b) vsubq_u16(a,b)
32 #define i16x8_sub_saturate(a,b) vsubq_s16(a,b)
35 /* Compare operations. */
36 #define u8x16_is_equal(a,b) vceqq_u8(a,b)
37 #define i8x16_is_equal(a,b) vceqq_s8(a,b)
38 #define u16x8_is_equal(a,b) vceqq_u16(a,b)
39 #define i16x8_is_equal(a,b) vceqq_i16(a,b)
40 #define u32x4_is_equal(a,b) vceqq_u32(a,b)
41 #define i32x4_is_equal(a,b) vceqq_s32(a,b)
42 #define i8x16_is_greater(a,b) vcgtq_s8(a,b)
43 #define i16x8_is_greater(a,b) vcgtq_u8(a,b)
44 #define i32x4_is_greater(a,b) vcgtq_s32(a,b)
47 u8x16_is_zero (u8x16 x)
50 return u8x16_is_equal (x, zero);
54 u16x8_is_zero (u16x8 x)
57 return u16x8_is_equal (x, zero);
61 u32x4_is_zero (u32x4 x)
64 return u32x4_is_equal (x, zero);
67 /* Converts all ones/zeros compare mask to bitmap. */
69 u8x16_compare_byte_mask (u8x16 x)
71 static int8_t const __attribute__ ((aligned (16))) xr[8] =
73 -7, -6, -5, -4, -3, -2, -1, 0};
74 uint8x8_t mask_and = vdup_n_u8 (0x80);
75 int8x8_t mask_shift = vld1_s8 (xr);
77 uint8x8_t lo = vget_low_u8 (x);
78 uint8x8_t hi = vget_high_u8 (x);
80 lo = vand_u8 (lo, mask_and);
81 lo = vshl_u8 (lo, mask_shift);
83 hi = vand_u8 (hi, mask_and);
84 hi = vshl_u8 (hi, mask_shift);
86 lo = vpadd_u8 (lo, lo);
87 lo = vpadd_u8 (lo, lo);
88 lo = vpadd_u8 (lo, lo);
90 hi = vpadd_u8 (hi, hi);
91 hi = vpadd_u8 (hi, hi);
92 hi = vpadd_u8 (hi, hi);
94 return ((hi[0] << 8) | (lo[0] & 0xff));
98 u16x8_zero_byte_mask (u16x8 input)
100 u8x16 vall_one = vdupq_n_u8 (0x0);
101 u8x16 res_values = { 0x01, 0x02, 0x04, 0x08,
102 0x10, 0x20, 0x40, 0x80,
103 0x01, 0x02, 0x04, 0x08,
104 0x10, 0x20, 0x40, 0x80
107 /* input --> [0x80, 0x40, 0x01, 0xf0, ... ] */
109 vreinterpretq_u8_u16 (vceqq_u16 (input, vreinterpretq_u16_u8 (vall_one)));
110 u8x16 before_merge = vminq_u8 (test_result, res_values);
111 /*before_merge--> [0x80, 0x00, 0x00, 0x10, ... ] */
112 /* u8x16 --> [a,b,c,d, e,f,g,h, i,j,k,l, m,n,o,p] */
113 /* pair add until we have 2 uint64_t */
114 u16x8 merge1 = vpaddlq_u8 (before_merge);
115 /* u16x8--> [a+b,c+d, e+f,g+h, i+j,k+l, m+n,o+p] */
116 u32x4 merge2 = vpaddlq_u16 (merge1);
117 /* u32x4--> [a+b+c+d, e+f+g+h, i+j+k+l, m+n+o+p] */
118 u64x2 merge3 = vpaddlq_u32 (merge2);
119 /* u64x2--> [a+b+c+d+e+f+g+h, i+j+k+l+m+n+o+p] */
120 return (u32) (vgetq_lane_u64 (merge3, 1) << 8) + vgetq_lane_u64 (merge3, 0);
123 #endif /* included_vector_neon_h */
126 * fd.io coding-style-patch-verification: ON
129 * eval: (c-set-style "gnu")