Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdlib.h> |
| 13 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 14 | #include "config/aom_config.h" |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 15 | #include "config/aom_dsp_rtcd.h" |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "aom_dsp/aom_dsp_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | #include "aom_ports/mem.h" |
| 19 | |
| 20 | static INLINE int8_t signed_char_clamp(int t) { |
| 21 | return (int8_t)clamp(t, -128, 127); |
| 22 | } |
| 23 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | static INLINE int16_t signed_char_clamp_high(int t, int bd) { |
| 25 | switch (bd) { |
| 26 | case 10: return (int16_t)clamp(t, -128 * 4, 128 * 4 - 1); |
| 27 | case 12: return (int16_t)clamp(t, -128 * 16, 128 * 16 - 1); |
| 28 | case 8: |
| 29 | default: return (int16_t)clamp(t, -128, 128 - 1); |
| 30 | } |
| 31 | } |
Yaowu Xu | 6d0ed3e | 2018-02-12 10:38:16 -0800 | [diff] [blame] | 32 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 33 | // should we apply any filter at all: 11111111 yes, 00000000 no |
Ryan Lei | 392d0ff | 2017-02-09 13:05:42 -0800 | [diff] [blame] | 34 | static INLINE int8_t filter_mask2(uint8_t limit, uint8_t blimit, uint8_t p1, |
| 35 | uint8_t p0, uint8_t q0, uint8_t q1) { |
| 36 | int8_t mask = 0; |
| 37 | mask |= (abs(p1 - p0) > limit) * -1; |
| 38 | mask |= (abs(q1 - q0) > limit) * -1; |
| 39 | mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit) * -1; |
| 40 | return ~mask; |
| 41 | } |
Yaowu Xu | 6d0ed3e | 2018-02-12 10:38:16 -0800 | [diff] [blame] | 42 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | static INLINE int8_t filter_mask(uint8_t limit, uint8_t blimit, uint8_t p3, |
| 44 | uint8_t p2, uint8_t p1, uint8_t p0, uint8_t q0, |
| 45 | uint8_t q1, uint8_t q2, uint8_t q3) { |
| 46 | int8_t mask = 0; |
| 47 | mask |= (abs(p3 - p2) > limit) * -1; |
| 48 | mask |= (abs(p2 - p1) > limit) * -1; |
| 49 | mask |= (abs(p1 - p0) > limit) * -1; |
| 50 | mask |= (abs(q1 - q0) > limit) * -1; |
| 51 | mask |= (abs(q2 - q1) > limit) * -1; |
| 52 | mask |= (abs(q3 - q2) > limit) * -1; |
| 53 | mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit) * -1; |
| 54 | return ~mask; |
| 55 | } |
| 56 | |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 57 | static INLINE int8_t filter_mask3_chroma(uint8_t limit, uint8_t blimit, |
| 58 | uint8_t p2, uint8_t p1, uint8_t p0, |
| 59 | uint8_t q0, uint8_t q1, uint8_t q2) { |
| 60 | int8_t mask = 0; |
| 61 | mask |= (abs(p2 - p1) > limit) * -1; |
| 62 | mask |= (abs(p1 - p0) > limit) * -1; |
| 63 | mask |= (abs(q1 - q0) > limit) * -1; |
| 64 | mask |= (abs(q2 - q1) > limit) * -1; |
| 65 | mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit) * -1; |
| 66 | return ~mask; |
| 67 | } |
| 68 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 69 | static INLINE int8_t flat_mask3_chroma(uint8_t thresh, uint8_t p2, uint8_t p1, |
| 70 | uint8_t p0, uint8_t q0, uint8_t q1, |
| 71 | uint8_t q2) { |
| 72 | int8_t mask = 0; |
| 73 | mask |= (abs(p1 - p0) > thresh) * -1; |
| 74 | mask |= (abs(q1 - q0) > thresh) * -1; |
| 75 | mask |= (abs(p2 - p0) > thresh) * -1; |
| 76 | mask |= (abs(q2 - q0) > thresh) * -1; |
| 77 | return ~mask; |
| 78 | } |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 79 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 80 | static INLINE int8_t flat_mask4(uint8_t thresh, uint8_t p3, uint8_t p2, |
| 81 | uint8_t p1, uint8_t p0, uint8_t q0, uint8_t q1, |
| 82 | uint8_t q2, uint8_t q3) { |
| 83 | int8_t mask = 0; |
| 84 | mask |= (abs(p1 - p0) > thresh) * -1; |
| 85 | mask |= (abs(q1 - q0) > thresh) * -1; |
| 86 | mask |= (abs(p2 - p0) > thresh) * -1; |
| 87 | mask |= (abs(q2 - q0) > thresh) * -1; |
| 88 | mask |= (abs(p3 - p0) > thresh) * -1; |
| 89 | mask |= (abs(q3 - q0) > thresh) * -1; |
| 90 | return ~mask; |
| 91 | } |
| 92 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 93 | // is there high edge variance internal edge: 11111111 yes, 00000000 no |
| 94 | static INLINE int8_t hev_mask(uint8_t thresh, uint8_t p1, uint8_t p0, |
| 95 | uint8_t q0, uint8_t q1) { |
| 96 | int8_t hev = 0; |
| 97 | hev |= (abs(p1 - p0) > thresh) * -1; |
| 98 | hev |= (abs(q1 - q0) > thresh) * -1; |
| 99 | return hev; |
| 100 | } |
| 101 | |
| 102 | static INLINE void filter4(int8_t mask, uint8_t thresh, uint8_t *op1, |
| 103 | uint8_t *op0, uint8_t *oq0, uint8_t *oq1) { |
| 104 | int8_t filter1, filter2; |
| 105 | |
| 106 | const int8_t ps1 = (int8_t)*op1 ^ 0x80; |
| 107 | const int8_t ps0 = (int8_t)*op0 ^ 0x80; |
| 108 | const int8_t qs0 = (int8_t)*oq0 ^ 0x80; |
| 109 | const int8_t qs1 = (int8_t)*oq1 ^ 0x80; |
| 110 | const uint8_t hev = hev_mask(thresh, *op1, *op0, *oq0, *oq1); |
| 111 | |
| 112 | // add outer taps if we have high edge variance |
| 113 | int8_t filter = signed_char_clamp(ps1 - qs1) & hev; |
| 114 | |
| 115 | // inner taps |
| 116 | filter = signed_char_clamp(filter + 3 * (qs0 - ps0)) & mask; |
| 117 | |
| 118 | // save bottom 3 bits so that we round one side +4 and the other +3 |
| 119 | // if it equals 4 we'll set to adjust by -1 to account for the fact |
| 120 | // we'd round 3 the other way |
| 121 | filter1 = signed_char_clamp(filter + 4) >> 3; |
| 122 | filter2 = signed_char_clamp(filter + 3) >> 3; |
| 123 | |
| 124 | *oq0 = signed_char_clamp(qs0 - filter1) ^ 0x80; |
| 125 | *op0 = signed_char_clamp(ps0 + filter2) ^ 0x80; |
| 126 | |
| 127 | // outer tap adjustments |
| 128 | filter = ROUND_POWER_OF_TWO(filter1, 1) & ~hev; |
| 129 | |
| 130 | *oq1 = signed_char_clamp(qs1 - filter) ^ 0x80; |
| 131 | *op1 = signed_char_clamp(ps1 + filter) ^ 0x80; |
| 132 | } |
| 133 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 134 | void aom_lpf_horizontal_4_c(uint8_t *s, int p /* pitch */, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 135 | const uint8_t *blimit, const uint8_t *limit, |
| 136 | const uint8_t *thresh) { |
| 137 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 138 | int count = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 139 | |
| 140 | // loop filter designed to work using chars so that we can make maximum use |
| 141 | // of 8 bit simd instructions. |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 142 | for (i = 0; i < count; ++i) { |
Ryan Lei | 392d0ff | 2017-02-09 13:05:42 -0800 | [diff] [blame] | 143 | const uint8_t p1 = s[-2 * p], p0 = s[-p]; |
| 144 | const uint8_t q0 = s[0 * p], q1 = s[1 * p]; |
| 145 | const int8_t mask = filter_mask2(*limit, *blimit, p1, p0, q0, q1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 146 | filter4(mask, *thresh, s - 2 * p, s - 1 * p, s, s + 1 * p); |
| 147 | ++s; |
| 148 | } |
| 149 | } |
| 150 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 151 | void aom_lpf_horizontal_4_dual_c(uint8_t *s, int p, const uint8_t *blimit0, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 152 | const uint8_t *limit0, const uint8_t *thresh0, |
| 153 | const uint8_t *blimit1, const uint8_t *limit1, |
| 154 | const uint8_t *thresh1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 155 | aom_lpf_horizontal_4_c(s, p, blimit0, limit0, thresh0); |
Yi Luo | 771a80a | 2017-11-27 15:31:31 -0800 | [diff] [blame] | 156 | aom_lpf_horizontal_4_c(s + 4, p, blimit1, limit1, thresh1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 159 | void aom_lpf_vertical_4_c(uint8_t *s, int pitch, const uint8_t *blimit, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 160 | const uint8_t *limit, const uint8_t *thresh) { |
| 161 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 162 | int count = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 163 | |
| 164 | // loop filter designed to work using chars so that we can make maximum use |
| 165 | // of 8 bit simd instructions. |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 166 | for (i = 0; i < count; ++i) { |
Ryan Lei | 392d0ff | 2017-02-09 13:05:42 -0800 | [diff] [blame] | 167 | const uint8_t p1 = s[-2], p0 = s[-1]; |
| 168 | const uint8_t q0 = s[0], q1 = s[1]; |
| 169 | const int8_t mask = filter_mask2(*limit, *blimit, p1, p0, q0, q1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 170 | filter4(mask, *thresh, s - 2, s - 1, s, s + 1); |
| 171 | s += pitch; |
| 172 | } |
| 173 | } |
| 174 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 175 | void aom_lpf_vertical_4_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 176 | const uint8_t *limit0, const uint8_t *thresh0, |
| 177 | const uint8_t *blimit1, const uint8_t *limit1, |
| 178 | const uint8_t *thresh1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 179 | aom_lpf_vertical_4_c(s, pitch, blimit0, limit0, thresh0); |
Yi Luo | 771a80a | 2017-11-27 15:31:31 -0800 | [diff] [blame] | 180 | aom_lpf_vertical_4_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 183 | static INLINE void filter6(int8_t mask, uint8_t thresh, int8_t flat, |
| 184 | uint8_t *op2, uint8_t *op1, uint8_t *op0, |
| 185 | uint8_t *oq0, uint8_t *oq1, uint8_t *oq2) { |
| 186 | if (flat && mask) { |
| 187 | const uint8_t p2 = *op2, p1 = *op1, p0 = *op0; |
| 188 | const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2; |
| 189 | |
| 190 | // 5-tap filter [1, 2, 2, 2, 1] |
| 191 | *op1 = ROUND_POWER_OF_TWO(p2 * 3 + p1 * 2 + p0 * 2 + q0, 3); |
| 192 | *op0 = ROUND_POWER_OF_TWO(p2 + p1 * 2 + p0 * 2 + q0 * 2 + q1, 3); |
| 193 | *oq0 = ROUND_POWER_OF_TWO(p1 + p0 * 2 + q0 * 2 + q1 * 2 + q2, 3); |
| 194 | *oq1 = ROUND_POWER_OF_TWO(p0 + q0 * 2 + q1 * 2 + q2 * 3, 3); |
| 195 | } else { |
| 196 | filter4(mask, thresh, op1, op0, oq0, oq1); |
| 197 | } |
| 198 | } |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 199 | |
Cheng Chen | 60f5961 | 2017-05-25 15:08:41 -0700 | [diff] [blame] | 200 | static INLINE void filter8(int8_t mask, uint8_t thresh, int8_t flat, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 201 | uint8_t *op3, uint8_t *op2, uint8_t *op1, |
| 202 | uint8_t *op0, uint8_t *oq0, uint8_t *oq1, |
| 203 | uint8_t *oq2, uint8_t *oq3) { |
| 204 | if (flat && mask) { |
| 205 | const uint8_t p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0; |
| 206 | const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3; |
| 207 | |
| 208 | // 7-tap filter [1, 1, 1, 2, 1, 1, 1] |
| 209 | *op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0, 3); |
| 210 | *op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1, 3); |
| 211 | *op0 = ROUND_POWER_OF_TWO(p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2, 3); |
| 212 | *oq0 = ROUND_POWER_OF_TWO(p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3, 3); |
| 213 | *oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3, 3); |
| 214 | *oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3, 3); |
| 215 | } else { |
| 216 | filter4(mask, thresh, op1, op0, oq0, oq1); |
| 217 | } |
| 218 | } |
| 219 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 220 | void aom_lpf_horizontal_6_c(uint8_t *s, int p, const uint8_t *blimit, |
| 221 | const uint8_t *limit, const uint8_t *thresh) { |
| 222 | int i; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 223 | int count = 4; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 224 | |
| 225 | // loop filter designed to work using chars so that we can make maximum use |
| 226 | // of 8 bit simd instructions. |
| 227 | for (i = 0; i < count; ++i) { |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 228 | const uint8_t p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p]; |
| 229 | const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p]; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 230 | |
| 231 | const int8_t mask = |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 232 | filter_mask3_chroma(*limit, *blimit, p2, p1, p0, q0, q1, q2); |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 233 | const int8_t flat = flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2); |
| 234 | filter6(mask, *thresh, flat, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p, |
| 235 | s + 2 * p); |
| 236 | ++s; |
| 237 | } |
| 238 | } |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 239 | |
Victoria Zhislina | 424d571 | 2018-06-09 15:21:11 +0300 | [diff] [blame] | 240 | void aom_lpf_horizontal_6_dual_c(uint8_t *s, int p, const uint8_t *blimit0, |
| 241 | const uint8_t *limit0, const uint8_t *thresh0, |
| 242 | const uint8_t *blimit1, const uint8_t *limit1, |
| 243 | const uint8_t *thresh1) { |
| 244 | aom_lpf_horizontal_6_c(s, p, blimit0, limit0, thresh0); |
| 245 | aom_lpf_horizontal_6_c(s + 4, p, blimit1, limit1, thresh1); |
| 246 | } |
| 247 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 248 | void aom_lpf_horizontal_8_c(uint8_t *s, int p, const uint8_t *blimit, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 249 | const uint8_t *limit, const uint8_t *thresh) { |
| 250 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 251 | int count = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 252 | |
| 253 | // loop filter designed to work using chars so that we can make maximum use |
| 254 | // of 8 bit simd instructions. |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 255 | for (i = 0; i < count; ++i) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 256 | const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p]; |
| 257 | const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p]; |
| 258 | |
| 259 | const int8_t mask = |
| 260 | filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3); |
| 261 | const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3); |
| 262 | filter8(mask, *thresh, flat, s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s, |
| 263 | s + 1 * p, s + 2 * p, s + 3 * p); |
| 264 | ++s; |
| 265 | } |
| 266 | } |
| 267 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 268 | void aom_lpf_horizontal_8_dual_c(uint8_t *s, int p, const uint8_t *blimit0, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 269 | const uint8_t *limit0, const uint8_t *thresh0, |
| 270 | const uint8_t *blimit1, const uint8_t *limit1, |
| 271 | const uint8_t *thresh1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 272 | aom_lpf_horizontal_8_c(s, p, blimit0, limit0, thresh0); |
Yi Luo | 771a80a | 2017-11-27 15:31:31 -0800 | [diff] [blame] | 273 | aom_lpf_horizontal_8_c(s + 4, p, blimit1, limit1, thresh1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 276 | void aom_lpf_vertical_6_c(uint8_t *s, int pitch, const uint8_t *blimit, |
| 277 | const uint8_t *limit, const uint8_t *thresh) { |
| 278 | int i; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 279 | int count = 4; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 280 | |
| 281 | for (i = 0; i < count; ++i) { |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 282 | const uint8_t p2 = s[-3], p1 = s[-2], p0 = s[-1]; |
| 283 | const uint8_t q0 = s[0], q1 = s[1], q2 = s[2]; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 284 | const int8_t mask = |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 285 | filter_mask3_chroma(*limit, *blimit, p2, p1, p0, q0, q1, q2); |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 286 | const int8_t flat = flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2); |
| 287 | filter6(mask, *thresh, flat, s - 3, s - 2, s - 1, s, s + 1, s + 2); |
| 288 | s += pitch; |
| 289 | } |
| 290 | } |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 291 | |
Victoria Zhislina | 424d571 | 2018-06-09 15:21:11 +0300 | [diff] [blame] | 292 | void aom_lpf_vertical_6_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0, |
| 293 | const uint8_t *limit0, const uint8_t *thresh0, |
| 294 | const uint8_t *blimit1, const uint8_t *limit1, |
| 295 | const uint8_t *thresh1) { |
| 296 | aom_lpf_vertical_6_c(s, pitch, blimit0, limit0, thresh0); |
| 297 | aom_lpf_vertical_6_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1); |
| 298 | } |
| 299 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 300 | void aom_lpf_vertical_8_c(uint8_t *s, int pitch, const uint8_t *blimit, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 301 | const uint8_t *limit, const uint8_t *thresh) { |
| 302 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 303 | int count = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 304 | |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 305 | for (i = 0; i < count; ++i) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 306 | const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1]; |
| 307 | const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3]; |
| 308 | const int8_t mask = |
| 309 | filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3); |
| 310 | const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3); |
| 311 | filter8(mask, *thresh, flat, s - 4, s - 3, s - 2, s - 1, s, s + 1, s + 2, |
| 312 | s + 3); |
| 313 | s += pitch; |
| 314 | } |
| 315 | } |
| 316 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 317 | void aom_lpf_vertical_8_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 318 | const uint8_t *limit0, const uint8_t *thresh0, |
| 319 | const uint8_t *blimit1, const uint8_t *limit1, |
| 320 | const uint8_t *thresh1) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 321 | aom_lpf_vertical_8_c(s, pitch, blimit0, limit0, thresh0); |
Yi Luo | 771a80a | 2017-11-27 15:31:31 -0800 | [diff] [blame] | 322 | aom_lpf_vertical_8_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 325 | static INLINE void filter14(int8_t mask, uint8_t thresh, int8_t flat, |
| 326 | int8_t flat2, uint8_t *op6, uint8_t *op5, |
| 327 | uint8_t *op4, uint8_t *op3, uint8_t *op2, |
| 328 | uint8_t *op1, uint8_t *op0, uint8_t *oq0, |
| 329 | uint8_t *oq1, uint8_t *oq2, uint8_t *oq3, |
| 330 | uint8_t *oq4, uint8_t *oq5, uint8_t *oq6) { |
| 331 | if (flat2 && flat && mask) { |
| 332 | const uint8_t p6 = *op6, p5 = *op5, p4 = *op4, p3 = *op3, p2 = *op2, |
| 333 | p1 = *op1, p0 = *op0; |
| 334 | const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3, q4 = *oq4, |
| 335 | q5 = *oq5, q6 = *oq6; |
| 336 | |
| 337 | // 13-tap filter [1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1] |
| 338 | *op5 = ROUND_POWER_OF_TWO(p6 * 7 + p5 * 2 + p4 * 2 + p3 + p2 + p1 + p0 + q0, |
| 339 | 4); |
| 340 | *op4 = ROUND_POWER_OF_TWO( |
| 341 | p6 * 5 + p5 * 2 + p4 * 2 + p3 * 2 + p2 + p1 + p0 + q0 + q1, 4); |
| 342 | *op3 = ROUND_POWER_OF_TWO( |
| 343 | p6 * 4 + p5 + p4 * 2 + p3 * 2 + p2 * 2 + p1 + p0 + q0 + q1 + q2, 4); |
| 344 | *op2 = ROUND_POWER_OF_TWO( |
| 345 | p6 * 3 + p5 + p4 + p3 * 2 + p2 * 2 + p1 * 2 + p0 + q0 + q1 + q2 + q3, |
| 346 | 4); |
| 347 | *op1 = ROUND_POWER_OF_TWO(p6 * 2 + p5 + p4 + p3 + p2 * 2 + p1 * 2 + p0 * 2 + |
| 348 | q0 + q1 + q2 + q3 + q4, |
| 349 | 4); |
| 350 | *op0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 * 2 + |
| 351 | q0 * 2 + q1 + q2 + q3 + q4 + q5, |
| 352 | 4); |
| 353 | *oq0 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 * 2 + |
| 354 | q1 * 2 + q2 + q3 + q4 + q5 + q6, |
| 355 | 4); |
| 356 | *oq1 = ROUND_POWER_OF_TWO(p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 * 2 + |
| 357 | q2 * 2 + q3 + q4 + q5 + q6 * 2, |
| 358 | 4); |
| 359 | *oq2 = ROUND_POWER_OF_TWO( |
| 360 | p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 * 2 + q3 * 2 + q4 + q5 + q6 * 3, |
| 361 | 4); |
| 362 | *oq3 = ROUND_POWER_OF_TWO( |
| 363 | p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 * 2 + q4 * 2 + q5 + q6 * 4, 4); |
| 364 | *oq4 = ROUND_POWER_OF_TWO( |
| 365 | p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 * 2 + q5 * 2 + q6 * 5, 4); |
| 366 | *oq5 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 * 2 + q6 * 7, |
| 367 | 4); |
| 368 | } else { |
| 369 | filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3); |
| 370 | } |
| 371 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 372 | |
| 373 | static void mb_lpf_horizontal_edge_w(uint8_t *s, int p, const uint8_t *blimit, |
| 374 | const uint8_t *limit, |
| 375 | const uint8_t *thresh, int count) { |
| 376 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 377 | int step = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 378 | |
| 379 | // loop filter designed to work using chars so that we can make maximum use |
| 380 | // of 8 bit simd instructions. |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 381 | for (i = 0; i < step * count; ++i) { |
Yaowu Xu | cbfffa8 | 2018-02-12 15:04:57 -0800 | [diff] [blame] | 382 | const uint8_t p6 = s[-7 * p], p5 = s[-6 * p], p4 = s[-5 * p], |
| 383 | p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p]; |
Ryan Lei | dd6fa06 | 2017-04-13 12:05:33 -0700 | [diff] [blame] | 384 | const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p], |
Yaowu Xu | cbfffa8 | 2018-02-12 15:04:57 -0800 | [diff] [blame] | 385 | q4 = s[4 * p], q5 = s[5 * p], q6 = s[6 * p]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 386 | const int8_t mask = |
| 387 | filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3); |
| 388 | const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3); |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 389 | const int8_t flat2 = flat_mask4(1, p6, p5, p4, p0, q0, q4, q5, q6); |
| 390 | |
| 391 | filter14(mask, *thresh, flat, flat2, s - 7 * p, s - 6 * p, s - 5 * p, |
| 392 | s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p, |
| 393 | s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p, s + 6 * p); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 394 | ++s; |
| 395 | } |
| 396 | } |
| 397 | |
Ryan | 2680275 | 2018-02-20 10:29:05 -0800 | [diff] [blame] | 398 | void aom_lpf_horizontal_14_c(uint8_t *s, int p, const uint8_t *blimit, |
James Zern | 1dbe80b | 2017-11-22 20:59:44 -0800 | [diff] [blame] | 399 | const uint8_t *limit, const uint8_t *thresh) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 400 | mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1); |
| 401 | } |
| 402 | |
Cheng Chen | 85fea90 | 2018-05-17 18:58:20 -0700 | [diff] [blame] | 403 | void aom_lpf_horizontal_14_dual_c(uint8_t *s, int p, const uint8_t *blimit0, |
| 404 | const uint8_t *limit0, const uint8_t *thresh0, |
| 405 | const uint8_t *blimit1, const uint8_t *limit1, |
| 406 | const uint8_t *thresh1) { |
| 407 | mb_lpf_horizontal_edge_w(s, p, blimit0, limit0, thresh0, 1); |
| 408 | mb_lpf_horizontal_edge_w(s + 4, p, blimit1, limit1, thresh1, 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static void mb_lpf_vertical_edge_w(uint8_t *s, int p, const uint8_t *blimit, |
| 412 | const uint8_t *limit, const uint8_t *thresh, |
| 413 | int count) { |
| 414 | int i; |
| 415 | |
| 416 | for (i = 0; i < count; ++i) { |
Yaowu Xu | cbfffa8 | 2018-02-12 15:04:57 -0800 | [diff] [blame] | 417 | const uint8_t p6 = s[-7], p5 = s[-6], p4 = s[-5], p3 = s[-4], p2 = s[-3], |
| 418 | p1 = s[-2], p0 = s[-1]; |
Ryan Lei | dd6fa06 | 2017-04-13 12:05:33 -0700 | [diff] [blame] | 419 | const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3], q4 = s[4], |
Yaowu Xu | cbfffa8 | 2018-02-12 15:04:57 -0800 | [diff] [blame] | 420 | q5 = s[5], q6 = s[6]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 421 | const int8_t mask = |
| 422 | filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3); |
| 423 | const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3); |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 424 | const int8_t flat2 = flat_mask4(1, p6, p5, p4, p0, q0, q4, q5, q6); |
| 425 | |
| 426 | filter14(mask, *thresh, flat, flat2, s - 7, s - 6, s - 5, s - 4, s - 3, |
| 427 | s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4, s + 5, s + 6); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 428 | s += p; |
| 429 | } |
| 430 | } |
| 431 | |
Ryan | 2680275 | 2018-02-20 10:29:05 -0800 | [diff] [blame] | 432 | void aom_lpf_vertical_14_c(uint8_t *s, int p, const uint8_t *blimit, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 433 | const uint8_t *limit, const uint8_t *thresh) { |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 434 | mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 4); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Cheng Chen | 85fea90 | 2018-05-17 18:58:20 -0700 | [diff] [blame] | 437 | void aom_lpf_vertical_14_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0, |
| 438 | const uint8_t *limit0, const uint8_t *thresh0, |
| 439 | const uint8_t *blimit1, const uint8_t *limit1, |
| 440 | const uint8_t *thresh1) { |
| 441 | mb_lpf_vertical_edge_w(s, pitch, blimit0, limit0, thresh0, 4); |
| 442 | mb_lpf_vertical_edge_w(s + 4 * pitch, pitch, blimit1, limit1, thresh1, 4); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Ryan Lei | 392d0ff | 2017-02-09 13:05:42 -0800 | [diff] [blame] | 445 | // Should we apply any filter at all: 11111111 yes, 00000000 no ? |
| 446 | static INLINE int8_t highbd_filter_mask2(uint8_t limit, uint8_t blimit, |
| 447 | uint16_t p1, uint16_t p0, uint16_t q0, |
| 448 | uint16_t q1, int bd) { |
| 449 | int8_t mask = 0; |
| 450 | int16_t limit16 = (uint16_t)limit << (bd - 8); |
| 451 | int16_t blimit16 = (uint16_t)blimit << (bd - 8); |
| 452 | mask |= (abs(p1 - p0) > limit16) * -1; |
| 453 | mask |= (abs(q1 - q0) > limit16) * -1; |
| 454 | mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit16) * -1; |
| 455 | return ~mask; |
| 456 | } |
Ryan Lei | 392d0ff | 2017-02-09 13:05:42 -0800 | [diff] [blame] | 457 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 458 | // Should we apply any filter at all: 11111111 yes, 00000000 no ? |
| 459 | static INLINE int8_t highbd_filter_mask(uint8_t limit, uint8_t blimit, |
| 460 | uint16_t p3, uint16_t p2, uint16_t p1, |
| 461 | uint16_t p0, uint16_t q0, uint16_t q1, |
| 462 | uint16_t q2, uint16_t q3, int bd) { |
| 463 | int8_t mask = 0; |
| 464 | int16_t limit16 = (uint16_t)limit << (bd - 8); |
| 465 | int16_t blimit16 = (uint16_t)blimit << (bd - 8); |
| 466 | mask |= (abs(p3 - p2) > limit16) * -1; |
| 467 | mask |= (abs(p2 - p1) > limit16) * -1; |
| 468 | mask |= (abs(p1 - p0) > limit16) * -1; |
| 469 | mask |= (abs(q1 - q0) > limit16) * -1; |
| 470 | mask |= (abs(q2 - q1) > limit16) * -1; |
| 471 | mask |= (abs(q3 - q2) > limit16) * -1; |
| 472 | mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit16) * -1; |
| 473 | return ~mask; |
| 474 | } |
| 475 | |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 476 | static INLINE int8_t highbd_filter_mask3_chroma(uint8_t limit, uint8_t blimit, |
| 477 | uint16_t p2, uint16_t p1, |
| 478 | uint16_t p0, uint16_t q0, |
| 479 | uint16_t q1, uint16_t q2, |
| 480 | int bd) { |
| 481 | int8_t mask = 0; |
| 482 | int16_t limit16 = (uint16_t)limit << (bd - 8); |
| 483 | int16_t blimit16 = (uint16_t)blimit << (bd - 8); |
| 484 | mask |= (abs(p2 - p1) > limit16) * -1; |
| 485 | mask |= (abs(p1 - p0) > limit16) * -1; |
| 486 | mask |= (abs(q1 - q0) > limit16) * -1; |
| 487 | mask |= (abs(q2 - q1) > limit16) * -1; |
| 488 | mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit16) * -1; |
| 489 | return ~mask; |
| 490 | } |
| 491 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 492 | static INLINE int8_t highbd_flat_mask3_chroma(uint8_t thresh, uint16_t p2, |
| 493 | uint16_t p1, uint16_t p0, |
| 494 | uint16_t q0, uint16_t q1, |
| 495 | uint16_t q2, int bd) { |
| 496 | int8_t mask = 0; |
| 497 | int16_t thresh16 = (uint16_t)thresh << (bd - 8); |
| 498 | mask |= (abs(p1 - p0) > thresh16) * -1; |
| 499 | mask |= (abs(q1 - q0) > thresh16) * -1; |
| 500 | mask |= (abs(p2 - p0) > thresh16) * -1; |
| 501 | mask |= (abs(q2 - q0) > thresh16) * -1; |
| 502 | return ~mask; |
| 503 | } |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 504 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 505 | static INLINE int8_t highbd_flat_mask4(uint8_t thresh, uint16_t p3, uint16_t p2, |
| 506 | uint16_t p1, uint16_t p0, uint16_t q0, |
| 507 | uint16_t q1, uint16_t q2, uint16_t q3, |
| 508 | int bd) { |
| 509 | int8_t mask = 0; |
| 510 | int16_t thresh16 = (uint16_t)thresh << (bd - 8); |
| 511 | mask |= (abs(p1 - p0) > thresh16) * -1; |
| 512 | mask |= (abs(q1 - q0) > thresh16) * -1; |
| 513 | mask |= (abs(p2 - p0) > thresh16) * -1; |
| 514 | mask |= (abs(q2 - q0) > thresh16) * -1; |
| 515 | mask |= (abs(p3 - p0) > thresh16) * -1; |
| 516 | mask |= (abs(q3 - q0) > thresh16) * -1; |
| 517 | return ~mask; |
| 518 | } |
| 519 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 520 | // Is there high edge variance internal edge: |
| 521 | // 11111111_11111111 yes, 00000000_00000000 no ? |
| 522 | static INLINE int16_t highbd_hev_mask(uint8_t thresh, uint16_t p1, uint16_t p0, |
| 523 | uint16_t q0, uint16_t q1, int bd) { |
| 524 | int16_t hev = 0; |
| 525 | int16_t thresh16 = (uint16_t)thresh << (bd - 8); |
| 526 | hev |= (abs(p1 - p0) > thresh16) * -1; |
| 527 | hev |= (abs(q1 - q0) > thresh16) * -1; |
| 528 | return hev; |
| 529 | } |
| 530 | |
| 531 | static INLINE void highbd_filter4(int8_t mask, uint8_t thresh, uint16_t *op1, |
| 532 | uint16_t *op0, uint16_t *oq0, uint16_t *oq1, |
| 533 | int bd) { |
| 534 | int16_t filter1, filter2; |
| 535 | // ^0x80 equivalent to subtracting 0x80 from the values to turn them |
| 536 | // into -128 to +127 instead of 0 to 255. |
| 537 | int shift = bd - 8; |
| 538 | const int16_t ps1 = (int16_t)*op1 - (0x80 << shift); |
| 539 | const int16_t ps0 = (int16_t)*op0 - (0x80 << shift); |
| 540 | const int16_t qs0 = (int16_t)*oq0 - (0x80 << shift); |
| 541 | const int16_t qs1 = (int16_t)*oq1 - (0x80 << shift); |
| 542 | const uint16_t hev = highbd_hev_mask(thresh, *op1, *op0, *oq0, *oq1, bd); |
| 543 | |
| 544 | // Add outer taps if we have high edge variance. |
| 545 | int16_t filter = signed_char_clamp_high(ps1 - qs1, bd) & hev; |
| 546 | |
| 547 | // Inner taps. |
| 548 | filter = signed_char_clamp_high(filter + 3 * (qs0 - ps0), bd) & mask; |
| 549 | |
| 550 | // Save bottom 3 bits so that we round one side +4 and the other +3 |
| 551 | // if it equals 4 we'll set to adjust by -1 to account for the fact |
| 552 | // we'd round 3 the other way. |
| 553 | filter1 = signed_char_clamp_high(filter + 4, bd) >> 3; |
| 554 | filter2 = signed_char_clamp_high(filter + 3, bd) >> 3; |
| 555 | |
| 556 | *oq0 = signed_char_clamp_high(qs0 - filter1, bd) + (0x80 << shift); |
| 557 | *op0 = signed_char_clamp_high(ps0 + filter2, bd) + (0x80 << shift); |
| 558 | |
| 559 | // Outer tap adjustments. |
| 560 | filter = ROUND_POWER_OF_TWO(filter1, 1) & ~hev; |
| 561 | |
| 562 | *oq1 = signed_char_clamp_high(qs1 - filter, bd) + (0x80 << shift); |
| 563 | *op1 = signed_char_clamp_high(ps1 + filter, bd) + (0x80 << shift); |
| 564 | } |
| 565 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 566 | void aom_highbd_lpf_horizontal_4_c(uint16_t *s, int p /* pitch */, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 567 | const uint8_t *blimit, const uint8_t *limit, |
| 568 | const uint8_t *thresh, int bd) { |
| 569 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 570 | int count = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 571 | |
| 572 | // loop filter designed to work using chars so that we can make maximum use |
| 573 | // of 8 bit simd instructions. |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 574 | for (i = 0; i < count; ++i) { |
Ryan Lei | 392d0ff | 2017-02-09 13:05:42 -0800 | [diff] [blame] | 575 | const uint16_t p1 = s[-2 * p]; |
| 576 | const uint16_t p0 = s[-p]; |
| 577 | const uint16_t q0 = s[0 * p]; |
| 578 | const uint16_t q1 = s[1 * p]; |
| 579 | const int8_t mask = |
| 580 | highbd_filter_mask2(*limit, *blimit, p1, p0, q0, q1, bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 581 | highbd_filter4(mask, *thresh, s - 2 * p, s - 1 * p, s, s + 1 * p, bd); |
| 582 | ++s; |
| 583 | } |
| 584 | } |
| 585 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 586 | void aom_highbd_lpf_horizontal_4_dual_c( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 587 | uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0, |
| 588 | const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1, |
| 589 | const uint8_t *thresh1, int bd) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 590 | aom_highbd_lpf_horizontal_4_c(s, p, blimit0, limit0, thresh0, bd); |
Yi Luo | 771a80a | 2017-11-27 15:31:31 -0800 | [diff] [blame] | 591 | aom_highbd_lpf_horizontal_4_c(s + 4, p, blimit1, limit1, thresh1, bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 594 | void aom_highbd_lpf_vertical_4_c(uint16_t *s, int pitch, const uint8_t *blimit, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 595 | const uint8_t *limit, const uint8_t *thresh, |
| 596 | int bd) { |
| 597 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 598 | int count = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 599 | |
| 600 | // loop filter designed to work using chars so that we can make maximum use |
| 601 | // of 8 bit simd instructions. |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 602 | for (i = 0; i < count; ++i) { |
Ryan Lei | 392d0ff | 2017-02-09 13:05:42 -0800 | [diff] [blame] | 603 | const uint16_t p1 = s[-2], p0 = s[-1]; |
| 604 | const uint16_t q0 = s[0], q1 = s[1]; |
| 605 | const int8_t mask = |
| 606 | highbd_filter_mask2(*limit, *blimit, p1, p0, q0, q1, bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 607 | highbd_filter4(mask, *thresh, s - 2, s - 1, s, s + 1, bd); |
| 608 | s += pitch; |
| 609 | } |
| 610 | } |
| 611 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 612 | void aom_highbd_lpf_vertical_4_dual_c( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 613 | uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0, |
| 614 | const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1, |
| 615 | const uint8_t *thresh1, int bd) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 616 | aom_highbd_lpf_vertical_4_c(s, pitch, blimit0, limit0, thresh0, bd); |
Yi Luo | 771a80a | 2017-11-27 15:31:31 -0800 | [diff] [blame] | 617 | aom_highbd_lpf_vertical_4_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1, |
| 618 | bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 621 | static INLINE void highbd_filter6(int8_t mask, uint8_t thresh, int8_t flat, |
| 622 | uint16_t *op2, uint16_t *op1, uint16_t *op0, |
| 623 | uint16_t *oq0, uint16_t *oq1, uint16_t *oq2, |
| 624 | int bd) { |
| 625 | if (flat && mask) { |
| 626 | const uint16_t p2 = *op2, p1 = *op1, p0 = *op0; |
| 627 | const uint16_t q0 = *oq0, q1 = *oq1, q2 = *oq2; |
| 628 | |
| 629 | // 5-tap filter [1, 2, 2, 2, 1] |
| 630 | *op1 = ROUND_POWER_OF_TWO(p2 * 3 + p1 * 2 + p0 * 2 + q0, 3); |
| 631 | *op0 = ROUND_POWER_OF_TWO(p2 + p1 * 2 + p0 * 2 + q0 * 2 + q1, 3); |
| 632 | *oq0 = ROUND_POWER_OF_TWO(p1 + p0 * 2 + q0 * 2 + q1 * 2 + q2, 3); |
| 633 | *oq1 = ROUND_POWER_OF_TWO(p0 + q0 * 2 + q1 * 2 + q2 * 3, 3); |
| 634 | } else { |
| 635 | highbd_filter4(mask, thresh, op1, op0, oq0, oq1, bd); |
| 636 | } |
| 637 | } |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 638 | |
Cheng Chen | 60f5961 | 2017-05-25 15:08:41 -0700 | [diff] [blame] | 639 | static INLINE void highbd_filter8(int8_t mask, uint8_t thresh, int8_t flat, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 640 | uint16_t *op3, uint16_t *op2, uint16_t *op1, |
| 641 | uint16_t *op0, uint16_t *oq0, uint16_t *oq1, |
| 642 | uint16_t *oq2, uint16_t *oq3, int bd) { |
| 643 | if (flat && mask) { |
| 644 | const uint16_t p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0; |
| 645 | const uint16_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3; |
| 646 | |
| 647 | // 7-tap filter [1, 1, 1, 2, 1, 1, 1] |
| 648 | *op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0, 3); |
| 649 | *op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1, 3); |
| 650 | *op0 = ROUND_POWER_OF_TWO(p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2, 3); |
| 651 | *oq0 = ROUND_POWER_OF_TWO(p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3, 3); |
| 652 | *oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3, 3); |
| 653 | *oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3, 3); |
| 654 | } else { |
| 655 | highbd_filter4(mask, thresh, op1, op0, oq0, oq1, bd); |
| 656 | } |
| 657 | } |
| 658 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 659 | void aom_highbd_lpf_horizontal_8_c(uint16_t *s, int p, const uint8_t *blimit, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 660 | const uint8_t *limit, const uint8_t *thresh, |
| 661 | int bd) { |
| 662 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 663 | int count = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 664 | |
| 665 | // loop filter designed to work using chars so that we can make maximum use |
| 666 | // of 8 bit simd instructions. |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 667 | for (i = 0; i < count; ++i) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 668 | const uint16_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p]; |
| 669 | const uint16_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p]; |
| 670 | |
| 671 | const int8_t mask = |
| 672 | highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd); |
| 673 | const int8_t flat = |
| 674 | highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd); |
| 675 | highbd_filter8(mask, *thresh, flat, s - 4 * p, s - 3 * p, s - 2 * p, |
| 676 | s - 1 * p, s, s + 1 * p, s + 2 * p, s + 3 * p, bd); |
| 677 | ++s; |
| 678 | } |
| 679 | } |
| 680 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 681 | void aom_highbd_lpf_horizontal_6_c(uint16_t *s, int p, const uint8_t *blimit, |
| 682 | const uint8_t *limit, const uint8_t *thresh, |
| 683 | int bd) { |
| 684 | int i; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 685 | int count = 4; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 686 | |
| 687 | // loop filter designed to work using chars so that we can make maximum use |
| 688 | // of 8 bit simd instructions. |
| 689 | for (i = 0; i < count; ++i) { |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 690 | const uint16_t p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p]; |
| 691 | const uint16_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p]; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 692 | |
| 693 | const int8_t mask = |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 694 | highbd_filter_mask3_chroma(*limit, *blimit, p2, p1, p0, q0, q1, q2, bd); |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 695 | const int8_t flat = highbd_flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2, bd); |
| 696 | highbd_filter6(mask, *thresh, flat, s - 3 * p, s - 2 * p, s - 1 * p, s, |
| 697 | s + 1 * p, s + 2 * p, bd); |
| 698 | ++s; |
| 699 | } |
| 700 | } |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 701 | |
Victoria Zhislina | 424d571 | 2018-06-09 15:21:11 +0300 | [diff] [blame] | 702 | void aom_highbd_lpf_horizontal_6_dual_c( |
| 703 | uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0, |
| 704 | const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1, |
| 705 | const uint8_t *thresh1, int bd) { |
| 706 | aom_highbd_lpf_horizontal_6_c(s, p, blimit0, limit0, thresh0, bd); |
| 707 | aom_highbd_lpf_horizontal_6_c(s + 4, p, blimit1, limit1, thresh1, bd); |
| 708 | } |
| 709 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 710 | void aom_highbd_lpf_horizontal_8_dual_c( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 711 | uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0, |
| 712 | const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1, |
| 713 | const uint8_t *thresh1, int bd) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 714 | aom_highbd_lpf_horizontal_8_c(s, p, blimit0, limit0, thresh0, bd); |
Yi Luo | 771a80a | 2017-11-27 15:31:31 -0800 | [diff] [blame] | 715 | aom_highbd_lpf_horizontal_8_c(s + 4, p, blimit1, limit1, thresh1, bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 718 | void aom_highbd_lpf_vertical_6_c(uint16_t *s, int pitch, const uint8_t *blimit, |
| 719 | const uint8_t *limit, const uint8_t *thresh, |
| 720 | int bd) { |
| 721 | int i; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 722 | int count = 4; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 723 | |
| 724 | for (i = 0; i < count; ++i) { |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 725 | const uint16_t p2 = s[-3], p1 = s[-2], p0 = s[-1]; |
| 726 | const uint16_t q0 = s[0], q1 = s[1], q2 = s[2]; |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 727 | const int8_t mask = |
Ryan | 0c90a5b | 2018-01-02 10:10:45 -0800 | [diff] [blame] | 728 | highbd_filter_mask3_chroma(*limit, *blimit, p2, p1, p0, q0, q1, q2, bd); |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 729 | const int8_t flat = highbd_flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2, bd); |
| 730 | highbd_filter6(mask, *thresh, flat, s - 3, s - 2, s - 1, s, s + 1, s + 2, |
| 731 | bd); |
| 732 | s += pitch; |
| 733 | } |
| 734 | } |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 735 | |
Victoria Zhislina | 424d571 | 2018-06-09 15:21:11 +0300 | [diff] [blame] | 736 | void aom_highbd_lpf_vertical_6_dual_c( |
| 737 | uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0, |
| 738 | const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1, |
| 739 | const uint8_t *thresh1, int bd) { |
| 740 | aom_highbd_lpf_vertical_6_c(s, pitch, blimit0, limit0, thresh0, bd); |
| 741 | aom_highbd_lpf_vertical_6_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1, |
| 742 | bd); |
| 743 | } |
| 744 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 745 | void aom_highbd_lpf_vertical_8_c(uint16_t *s, int pitch, const uint8_t *blimit, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 746 | const uint8_t *limit, const uint8_t *thresh, |
| 747 | int bd) { |
| 748 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 749 | int count = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 750 | |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 751 | for (i = 0; i < count; ++i) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 752 | const uint16_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1]; |
| 753 | const uint16_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3]; |
| 754 | const int8_t mask = |
| 755 | highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd); |
| 756 | const int8_t flat = |
| 757 | highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd); |
| 758 | highbd_filter8(mask, *thresh, flat, s - 4, s - 3, s - 2, s - 1, s, s + 1, |
| 759 | s + 2, s + 3, bd); |
| 760 | s += pitch; |
| 761 | } |
| 762 | } |
| 763 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 764 | void aom_highbd_lpf_vertical_8_dual_c( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 765 | uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0, |
| 766 | const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1, |
| 767 | const uint8_t *thresh1, int bd) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 768 | aom_highbd_lpf_vertical_8_c(s, pitch, blimit0, limit0, thresh0, bd); |
Yi Luo | 771a80a | 2017-11-27 15:31:31 -0800 | [diff] [blame] | 769 | aom_highbd_lpf_vertical_8_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1, |
| 770 | bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 773 | static INLINE void highbd_filter14(int8_t mask, uint8_t thresh, int8_t flat, |
| 774 | int8_t flat2, uint16_t *op6, uint16_t *op5, |
| 775 | uint16_t *op4, uint16_t *op3, uint16_t *op2, |
| 776 | uint16_t *op1, uint16_t *op0, uint16_t *oq0, |
| 777 | uint16_t *oq1, uint16_t *oq2, uint16_t *oq3, |
| 778 | uint16_t *oq4, uint16_t *oq5, uint16_t *oq6, |
| 779 | int bd) { |
| 780 | if (flat2 && flat && mask) { |
| 781 | const uint16_t p6 = *op6; |
| 782 | const uint16_t p5 = *op5; |
| 783 | const uint16_t p4 = *op4; |
| 784 | const uint16_t p3 = *op3; |
| 785 | const uint16_t p2 = *op2; |
| 786 | const uint16_t p1 = *op1; |
| 787 | const uint16_t p0 = *op0; |
| 788 | const uint16_t q0 = *oq0; |
| 789 | const uint16_t q1 = *oq1; |
| 790 | const uint16_t q2 = *oq2; |
| 791 | const uint16_t q3 = *oq3; |
| 792 | const uint16_t q4 = *oq4; |
| 793 | const uint16_t q5 = *oq5; |
| 794 | const uint16_t q6 = *oq6; |
| 795 | |
| 796 | // 13-tap filter [1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1] |
| 797 | *op5 = ROUND_POWER_OF_TWO(p6 * 7 + p5 * 2 + p4 * 2 + p3 + p2 + p1 + p0 + q0, |
| 798 | 4); |
| 799 | *op4 = ROUND_POWER_OF_TWO( |
| 800 | p6 * 5 + p5 * 2 + p4 * 2 + p3 * 2 + p2 + p1 + p0 + q0 + q1, 4); |
| 801 | *op3 = ROUND_POWER_OF_TWO( |
| 802 | p6 * 4 + p5 + p4 * 2 + p3 * 2 + p2 * 2 + p1 + p0 + q0 + q1 + q2, 4); |
| 803 | *op2 = ROUND_POWER_OF_TWO( |
| 804 | p6 * 3 + p5 + p4 + p3 * 2 + p2 * 2 + p1 * 2 + p0 + q0 + q1 + q2 + q3, |
| 805 | 4); |
| 806 | *op1 = ROUND_POWER_OF_TWO(p6 * 2 + p5 + p4 + p3 + p2 * 2 + p1 * 2 + p0 * 2 + |
| 807 | q0 + q1 + q2 + q3 + q4, |
| 808 | 4); |
| 809 | *op0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 * 2 + |
| 810 | q0 * 2 + q1 + q2 + q3 + q4 + q5, |
| 811 | 4); |
| 812 | *oq0 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 * 2 + |
| 813 | q1 * 2 + q2 + q3 + q4 + q5 + q6, |
| 814 | 4); |
| 815 | *oq1 = ROUND_POWER_OF_TWO(p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 * 2 + |
| 816 | q2 * 2 + q3 + q4 + q5 + q6 * 2, |
| 817 | 4); |
| 818 | *oq2 = ROUND_POWER_OF_TWO( |
| 819 | p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 * 2 + q3 * 2 + q4 + q5 + q6 * 3, |
| 820 | 4); |
| 821 | *oq3 = ROUND_POWER_OF_TWO( |
| 822 | p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 * 2 + q4 * 2 + q5 + q6 * 4, 4); |
| 823 | *oq4 = ROUND_POWER_OF_TWO( |
| 824 | p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 * 2 + q5 * 2 + q6 * 5, 4); |
| 825 | *oq5 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 * 2 + q6 * 7, |
| 826 | 4); |
| 827 | } else { |
| 828 | highbd_filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3, |
| 829 | bd); |
| 830 | } |
| 831 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 832 | |
| 833 | static void highbd_mb_lpf_horizontal_edge_w(uint16_t *s, int p, |
| 834 | const uint8_t *blimit, |
| 835 | const uint8_t *limit, |
| 836 | const uint8_t *thresh, int count, |
| 837 | int bd) { |
| 838 | int i; |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 839 | int step = 4; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 840 | |
| 841 | // loop filter designed to work using chars so that we can make maximum use |
| 842 | // of 8 bit simd instructions. |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 843 | for (i = 0; i < step * count; ++i) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 844 | const uint16_t p3 = s[-4 * p]; |
| 845 | const uint16_t p2 = s[-3 * p]; |
| 846 | const uint16_t p1 = s[-2 * p]; |
| 847 | const uint16_t p0 = s[-p]; |
| 848 | const uint16_t q0 = s[0 * p]; |
| 849 | const uint16_t q1 = s[1 * p]; |
| 850 | const uint16_t q2 = s[2 * p]; |
| 851 | const uint16_t q3 = s[3 * p]; |
| 852 | const int8_t mask = |
| 853 | highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd); |
| 854 | const int8_t flat = |
| 855 | highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd); |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 856 | |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 857 | const int8_t flat2 = |
| 858 | highbd_flat_mask4(1, s[-7 * p], s[-6 * p], s[-5 * p], p0, q0, s[4 * p], |
| 859 | s[5 * p], s[6 * p], bd); |
| 860 | |
| 861 | highbd_filter14(mask, *thresh, flat, flat2, s - 7 * p, s - 6 * p, s - 5 * p, |
| 862 | s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p, |
| 863 | s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p, s + 6 * p, bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 864 | ++s; |
| 865 | } |
| 866 | } |
| 867 | |
Ryan | 2680275 | 2018-02-20 10:29:05 -0800 | [diff] [blame] | 868 | void aom_highbd_lpf_horizontal_14_c(uint16_t *s, int p, const uint8_t *blimit, |
James Zern | 684b7bd | 2017-11-28 12:55:51 -0800 | [diff] [blame] | 869 | const uint8_t *limit, const uint8_t *thresh, |
| 870 | int bd) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 871 | highbd_mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1, bd); |
| 872 | } |
| 873 | |
Cheng Chen | 85fea90 | 2018-05-17 18:58:20 -0700 | [diff] [blame] | 874 | void aom_highbd_lpf_horizontal_14_dual_c( |
| 875 | uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0, |
| 876 | const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1, |
| 877 | const uint8_t *thresh1, int bd) { |
| 878 | highbd_mb_lpf_horizontal_edge_w(s, p, blimit0, limit0, thresh0, 1, bd); |
| 879 | highbd_mb_lpf_horizontal_edge_w(s + 4, p, blimit1, limit1, thresh1, 1, bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | static void highbd_mb_lpf_vertical_edge_w(uint16_t *s, int p, |
| 883 | const uint8_t *blimit, |
| 884 | const uint8_t *limit, |
| 885 | const uint8_t *thresh, int count, |
| 886 | int bd) { |
| 887 | int i; |
| 888 | |
| 889 | for (i = 0; i < count; ++i) { |
| 890 | const uint16_t p3 = s[-4]; |
| 891 | const uint16_t p2 = s[-3]; |
| 892 | const uint16_t p1 = s[-2]; |
| 893 | const uint16_t p0 = s[-1]; |
| 894 | const uint16_t q0 = s[0]; |
| 895 | const uint16_t q1 = s[1]; |
| 896 | const uint16_t q2 = s[2]; |
| 897 | const uint16_t q3 = s[3]; |
| 898 | const int8_t mask = |
| 899 | highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd); |
| 900 | const int8_t flat = |
| 901 | highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd); |
Ola Hugosson | 4ce8521 | 2017-09-12 14:53:13 +0200 | [diff] [blame] | 902 | const int8_t flat2 = |
| 903 | highbd_flat_mask4(1, s[-7], s[-6], s[-5], p0, q0, s[4], s[5], s[6], bd); |
| 904 | |
| 905 | highbd_filter14(mask, *thresh, flat, flat2, s - 7, s - 6, s - 5, s - 4, |
| 906 | s - 3, s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4, s + 5, |
| 907 | s + 6, bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 908 | s += p; |
| 909 | } |
| 910 | } |
| 911 | |
Ryan | 2680275 | 2018-02-20 10:29:05 -0800 | [diff] [blame] | 912 | void aom_highbd_lpf_vertical_14_c(uint16_t *s, int p, const uint8_t *blimit, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 913 | const uint8_t *limit, const uint8_t *thresh, |
| 914 | int bd) { |
Ryan Lei | 17905ed | 2017-05-23 18:28:51 -0700 | [diff] [blame] | 915 | highbd_mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 4, bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 916 | } |
| 917 | |
Cheng Chen | 85fea90 | 2018-05-17 18:58:20 -0700 | [diff] [blame] | 918 | void aom_highbd_lpf_vertical_14_dual_c( |
| 919 | uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0, |
| 920 | const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1, |
| 921 | const uint8_t *thresh1, int bd) { |
| 922 | highbd_mb_lpf_vertical_edge_w(s, pitch, blimit0, limit0, thresh0, 4, bd); |
| 923 | highbd_mb_lpf_vertical_edge_w(s + 4 * pitch, pitch, blimit1, limit1, thresh1, |
| 924 | 4, bd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 925 | } |