Arpad Panyik | 159307b | 2023-08-08 14:02:18 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Alliance for Open Media. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef AOM_AOM_DSP_ARM_DIST_WTD_AVG_NEON_H_ |
| 12 | #define AOM_AOM_DSP_ARM_DIST_WTD_AVG_NEON_H_ |
| 13 | |
| 14 | #include <arm_neon.h> |
| 15 | |
| 16 | #include "aom_dsp/aom_dsp_common.h" |
| 17 | #include "av1/common/enums.h" |
| 18 | |
| 19 | static INLINE uint8x8_t dist_wtd_avg_u8x8(uint8x8_t a, uint8x8_t b, |
| 20 | uint8x8_t wta, uint8x8_t wtb) { |
| 21 | uint16x8_t wtd_sum = vmull_u8(a, wta); |
| 22 | |
| 23 | wtd_sum = vmlal_u8(wtd_sum, b, wtb); |
| 24 | |
| 25 | return vrshrn_n_u16(wtd_sum, DIST_PRECISION_BITS); |
| 26 | } |
| 27 | |
| 28 | static INLINE uint16x4_t dist_wtd_avg_u16x4(uint16x4_t a, uint16x4_t b, |
| 29 | uint16x4_t wta, uint16x4_t wtb) { |
| 30 | uint32x4_t wtd_sum = vmull_u16(a, wta); |
| 31 | |
| 32 | wtd_sum = vmlal_u16(wtd_sum, b, wtb); |
| 33 | |
| 34 | return vrshrn_n_u32(wtd_sum, DIST_PRECISION_BITS); |
| 35 | } |
| 36 | |
| 37 | static INLINE uint8x16_t dist_wtd_avg_u8x16(uint8x16_t a, uint8x16_t b, |
| 38 | uint8x16_t wta, uint8x16_t wtb) { |
| 39 | uint16x8_t wtd_sum_lo = vmull_u8(vget_low_u8(a), vget_low_u8(wta)); |
| 40 | uint16x8_t wtd_sum_hi = vmull_u8(vget_high_u8(a), vget_high_u8(wta)); |
| 41 | |
| 42 | wtd_sum_lo = vmlal_u8(wtd_sum_lo, vget_low_u8(b), vget_low_u8(wtb)); |
| 43 | wtd_sum_hi = vmlal_u8(wtd_sum_hi, vget_high_u8(b), vget_high_u8(wtb)); |
| 44 | |
| 45 | uint8x8_t wtd_avg_lo = vrshrn_n_u16(wtd_sum_lo, DIST_PRECISION_BITS); |
| 46 | uint8x8_t wtd_avg_hi = vrshrn_n_u16(wtd_sum_hi, DIST_PRECISION_BITS); |
| 47 | |
| 48 | return vcombine_u8(wtd_avg_lo, wtd_avg_hi); |
| 49 | } |
| 50 | |
| 51 | static INLINE uint16x8_t dist_wtd_avg_u16x8(uint16x8_t a, uint16x8_t b, |
| 52 | uint16x8_t wta, uint16x8_t wtb) { |
| 53 | uint32x4_t wtd_sum_lo = vmull_u16(vget_low_u16(a), vget_low_u16(wta)); |
| 54 | uint32x4_t wtd_sum_hi = vmull_u16(vget_high_u16(a), vget_high_u16(wta)); |
| 55 | |
| 56 | wtd_sum_lo = vmlal_u16(wtd_sum_lo, vget_low_u16(b), vget_low_u16(wtb)); |
| 57 | wtd_sum_hi = vmlal_u16(wtd_sum_hi, vget_high_u16(b), vget_high_u16(wtb)); |
| 58 | |
| 59 | uint16x4_t wtd_avg_lo = vrshrn_n_u32(wtd_sum_lo, DIST_PRECISION_BITS); |
| 60 | uint16x4_t wtd_avg_hi = vrshrn_n_u32(wtd_sum_hi, DIST_PRECISION_BITS); |
| 61 | |
| 62 | return vcombine_u16(wtd_avg_lo, wtd_avg_hi); |
| 63 | } |
| 64 | |
| 65 | #endif // AOM_AOM_DSP_ARM_DIST_WTD_AVG_NEON_H_ |