1 /*
2  *  Copyright (c) 2016 The WebM project authors. 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 #include <arm_neon.h>
12 
13 #include "./vpx_dsp_rtcd.h"
14 #include "vpx_dsp/arm/highbd_idct_neon.h"
15 #include "vpx_dsp/arm/idct_neon.h"
16 #include "vpx_dsp/inv_txfm.h"
17 
18 // res is in reverse row order
highbd_idct4x4_1_add_kernel2(uint16_t ** dest,const int stride,const int16x8_t res,const int16x8_t max)19 static INLINE void highbd_idct4x4_1_add_kernel2(uint16_t **dest,
20                                                 const int stride,
21                                                 const int16x8_t res,
22                                                 const int16x8_t max) {
23   const uint16x4_t a0 = vld1_u16(*dest);
24   const uint16x4_t a1 = vld1_u16(*dest + stride);
25   const int16x8_t a = vreinterpretq_s16_u16(vcombine_u16(a1, a0));
26   // Note: In some profile tests, res is quite close to +/-32767.
27   // We use saturating addition.
28   const int16x8_t b = vqaddq_s16(res, a);
29   const int16x8_t c = vminq_s16(b, max);
30   const uint16x8_t d = vqshluq_n_s16(c, 0);
31   vst1_u16(*dest, vget_high_u16(d));
32   *dest += stride;
33   vst1_u16(*dest, vget_low_u16(d));
34   *dest += stride;
35 }
36 
vpx_highbd_idct4x4_1_add_neon(const tran_low_t * input,uint16_t * dest,int stride,int bd)37 void vpx_highbd_idct4x4_1_add_neon(const tran_low_t *input, uint16_t *dest,
38                                    int stride, int bd) {
39   const int16x8_t max = vdupq_n_s16((1 << bd) - 1);
40   const tran_low_t out0 = HIGHBD_WRAPLOW(
41       dct_const_round_shift(input[0] * (tran_high_t)cospi_16_64), bd);
42   const tran_low_t out1 = HIGHBD_WRAPLOW(
43       dct_const_round_shift(out0 * (tran_high_t)cospi_16_64), bd);
44   const int16_t a1 = ROUND_POWER_OF_TWO(out1, 4);
45   const int16x8_t dc = vdupq_n_s16(a1);
46 
47   highbd_idct4x4_1_add_kernel1(&dest, stride, dc, max);
48   highbd_idct4x4_1_add_kernel1(&dest, stride, dc, max);
49 }
50 
vpx_highbd_idct4x4_16_add_neon(const tran_low_t * input,uint16_t * dest,int stride,int bd)51 void vpx_highbd_idct4x4_16_add_neon(const tran_low_t *input, uint16_t *dest,
52                                     int stride, int bd) {
53   const int16x8_t max = vdupq_n_s16((1 << bd) - 1);
54   int16x8_t a[2];
55   int32x4_t c[4];
56 
57   c[0] = vld1q_s32(input);
58   c[1] = vld1q_s32(input + 4);
59   c[2] = vld1q_s32(input + 8);
60   c[3] = vld1q_s32(input + 12);
61 
62   if (bd == 8) {
63     // Rows
64     a[0] = vcombine_s16(vmovn_s32(c[0]), vmovn_s32(c[1]));
65     a[1] = vcombine_s16(vmovn_s32(c[2]), vmovn_s32(c[3]));
66     transpose_idct4x4_16_bd8(a);
67 
68     // Columns
69     a[1] = vcombine_s16(vget_high_s16(a[1]), vget_low_s16(a[1]));
70     transpose_idct4x4_16_bd8(a);
71     a[0] = vrshrq_n_s16(a[0], 4);
72     a[1] = vrshrq_n_s16(a[1], 4);
73   } else {
74     const int32x4_t cospis = vld1q_s32(kCospi32);
75 
76     if (bd == 10) {
77       idct4x4_16_kernel_bd10(cospis, c);
78       idct4x4_16_kernel_bd10(cospis, c);
79     } else {
80       idct4x4_16_kernel_bd12(cospis, c);
81       idct4x4_16_kernel_bd12(cospis, c);
82     }
83     a[0] = vcombine_s16(vqrshrn_n_s32(c[0], 4), vqrshrn_n_s32(c[1], 4));
84     a[1] = vcombine_s16(vqrshrn_n_s32(c[3], 4), vqrshrn_n_s32(c[2], 4));
85   }
86 
87   highbd_idct4x4_1_add_kernel1(&dest, stride, a[0], max);
88   highbd_idct4x4_1_add_kernel2(&dest, stride, a[1], max);
89 }
90