2 * Copyright (c) 2017 ARM Limited.
4 * SPDX-License-Identifier: MIT
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 /** Sorts element-wise two vectors.
27 * @param[in, out] a First vector
28 * @param[in, out] b Second vector
32 uchar8 min_val = min(a, b); \
33 uchar8 max_val = max(a, b); \
38 // Sorting networks below were generated using http://pages.ripco.net/~jgamble/nw.html
40 /** Sorting network to sort 5 vectors of 8 elements and return their median.
42 * @param[in] p0 First element vector
43 * @param[in] p1 Second element vector
44 * @param[in] p2 Third element vector
45 * @param[in] p3 Fourth element vector
46 * @param[in] p4 Fifth element vector
48 * @return Median values for 8 elements.
50 inline uchar8 sort5(uchar8 p0, uchar8 p1, uchar8 p2, uchar8 p3, uchar8 p4)
64 /** Sorting network to sort 9 vectors of 8 elements and return their median.
66 * @param[in] p0 First element vector
67 * @param[in] p1 Second element vector
68 * @param[in] p2 Third element vector
69 * @param[in] p3 Fourth element vector
70 * @param[in] p4 Fifth element vector
71 * @param[in] p5 Sixth element vector
72 * @param[in] p6 Seventh element vector
73 * @param[in] p7 Eigth element vector
74 * @param[in] p8 Ninth element vector
76 * @return Median values for 8 elements.
78 inline uchar8 sort9(uchar8 p0, uchar8 p1, uchar8 p2, uchar8 p3, uchar8 p4, uchar8 p5, uchar8 p6, uchar8 p7, uchar8 p8)
103 /** Calculate the minimum of a sliding window of size 3.
105 * @param val Values to calculate the minimum values
107 * @return Minimum values of 8 elements on a sliding window of size 3.
109 inline uchar8 row_reduce_min_3(uchar16 val)
111 return min(val.s01234567, min(val.s12345678, val.s23456789));
114 /** Calculate the maximum of a sliding window of size 3.
116 * @param val Values to calculate the maximum values
118 * @return Maximum values of 8 elements on a sliding window of size 3.
120 inline uchar8 row_reduce_max_3(uchar16 val)
122 return max(val.s01234567, max(val.s12345678, val.s23456789));
125 /** Calculate the minimum of a sliding window of size 5.
127 * @param val Values to calculate the minimum values
129 * @return Minimum values of 8 elements on a sliding window of size 5.
131 inline uchar8 row_reduce_min_5(uchar16 val)
133 return min(val.s01234567, min(min(val.s12345678, val.s23456789), min(val.s3456789A, val.s456789AB)));
136 /** Calculate the maximum of a sliding window of size 5.
138 * @param val Values to calculate the maximum values
140 * @return Maximum values of 8 elements on a sliding window of size 5.
142 inline uchar8 row_reduce_max_5(uchar16 val)
144 return max(val.s01234567, max(max(val.s12345678, val.s23456789), max(val.s3456789A, val.s456789AB)));