| @@ -0,0 +1,114 @@ |
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Zhao Zhili |
| 3 | + * |
| 4 | + * This file is part of FFmpeg. |
| 5 | + * |
| 6 | + * FFmpeg is free software; you can redistribute it and/or |
| 7 | + * modify it under the terms of the GNU Lesser General Public |
| 8 | + * License as published by the Free Software Foundation; either |
| 9 | + * version 2.1 of the License, or (at your option) any later version. |
| 10 | + * |
| 11 | + * FFmpeg is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * Lesser General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU Lesser General Public |
| 17 | + * License along with FFmpeg; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | + */ |
| 20 | + |
| 21 | +#include "sao.h" |
| 22 | + |
| 23 | +#include <wasm_simd128.h> |
| 24 | + |
| 25 | +void ff_hevc_sao_band_filter_8x8_8_simd128(uint8_t *dst, const uint8_t *src, |
| 26 | + ptrdiff_t stride_dst, |
| 27 | + ptrdiff_t stride_src, |
| 28 | + const int16_t *sao_offset_val, |
| 29 | + int sao_left_class, int width, |
| 30 | + int height) |
| 31 | +{ |
| 32 | + int8_t offset_table[32] = {0}; |
| 33 | + v128_t offset_low, offset_high; |
| 34 | + |
| 35 | + for (int k = 0; k < 4; k++) |
| 36 | + offset_table[(k + sao_left_class) & 31] = (int8_t)sao_offset_val[k + 1]; |
| 37 | + |
| 38 | + offset_low = wasm_v128_load(offset_table); |
| 39 | + offset_high = wasm_v128_load(&offset_table[16]); |
| 40 | + |
| 41 | + for (int y = height; y > 0; y -= 2) { |
| 42 | + v128_t src_v, src_high; |
| 43 | + v128_t v0, v1; |
| 44 | + |
| 45 | + src_v = wasm_v128_load64_zero(src); |
| 46 | + src += stride_src; |
| 47 | + src_v = wasm_v128_load64_lane(src, src_v, 1); |
| 48 | + src += stride_src; |
| 49 | + |
| 50 | + v0 = wasm_u8x16_shr(src_v, 3); |
| 51 | + v1 = wasm_i8x16_sub(v0, wasm_i8x16_const_splat(16)); |
| 52 | + v0 = wasm_i8x16_swizzle(offset_low, v0); |
| 53 | + v1 = wasm_i8x16_swizzle(offset_high, v1); |
| 54 | + v0 = wasm_v128_or(v0, v1); |
| 55 | + src_high = wasm_u16x8_extend_high_u8x16(src_v); |
| 56 | + v1 = wasm_i16x8_extend_high_i8x16(v0); |
| 57 | + src_v = wasm_u16x8_extend_low_u8x16(src_v); |
| 58 | + v0 = wasm_i16x8_extend_low_i8x16(v0); |
| 59 | + |
| 60 | + v0 = wasm_i16x8_add_sat(src_v, v0); |
| 61 | + v1 = wasm_i16x8_add_sat(src_high, v1); |
| 62 | + v0 = wasm_u8x16_narrow_i16x8(v0, v1); |
| 63 | + |
| 64 | + wasm_v128_store64_lane(dst, v0, 0); |
| 65 | + dst += stride_dst; |
| 66 | + wasm_v128_store64_lane(dst, v0, 1); |
| 67 | + dst += stride_dst; |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +void ff_hevc_sao_band_filter_16x16_8_simd128(uint8_t *dst, const uint8_t *src, |
| 72 | + ptrdiff_t stride_dst, |
| 73 | + ptrdiff_t stride_src, |
| 74 | + const int16_t *sao_offset_val, |
| 75 | + int sao_left_class, int width, |
| 76 | + int height) |
| 77 | +{ |
| 78 | + int8_t offset_table[32] = {0}; |
| 79 | + v128_t offset_low, offset_high; |
| 80 | + |
| 81 | + for (int k = 0; k < 4; k++) |
| 82 | + offset_table[(k + sao_left_class) & 31] = (int8_t)sao_offset_val[k + 1]; |
| 83 | + |
| 84 | + offset_low = wasm_v128_load(offset_table); |
| 85 | + offset_high = wasm_v128_load(&offset_table[16]); |
| 86 | + |
| 87 | + for (int y = height; y > 0; y--) { |
| 88 | + for (int x = 0; x < width; x += 16) { |
| 89 | + v128_t src_v, src_high; |
| 90 | + v128_t v0, v1; |
| 91 | + |
| 92 | + src_v = wasm_v128_load(&src[x]); |
| 93 | + |
| 94 | + v0 = wasm_u8x16_shr(src_v, 3); |
| 95 | + v1 = wasm_i8x16_sub(v0, wasm_i8x16_const_splat(16)); |
| 96 | + v0 = wasm_i8x16_swizzle(offset_low, v0); |
| 97 | + v1 = wasm_i8x16_swizzle(offset_high, v1); |
| 98 | + v0 = wasm_v128_or(v0, v1); |
| 99 | + src_high = wasm_u16x8_extend_high_u8x16(src_v); |
| 100 | + v1 = wasm_i16x8_extend_high_i8x16(v0); |
| 101 | + src_v = wasm_u16x8_extend_low_u8x16(src_v); |
| 102 | + v0 = wasm_i16x8_extend_low_i8x16(v0); |
| 103 | + |
| 104 | + v0 = wasm_i16x8_add_sat(src_v, v0); |
| 105 | + v1 = wasm_i16x8_add_sat(src_high, v1); |
| 106 | + v0 = wasm_u8x16_narrow_i16x8(v0, v1); |
| 107 | + wasm_v128_store(&dst[x], v0); |
| 108 | + } |
| 109 | + |
| 110 | + dst += stride_dst; |
| 111 | + src += stride_src; |
| 112 | + } |
| 113 | +} |
| 114 | + |