• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
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.
10  */
11 
12 #include <arm_neon.h>
13 
14 #include "config/aom_config.h"
15 
16 #include "aom/aom_integer.h"
17 #include "aom_ports/mem.h"
18 
aom_subtract_block_neon(int rows,int cols,int16_t * diff,ptrdiff_t diff_stride,const uint8_t * src,ptrdiff_t src_stride,const uint8_t * pred,ptrdiff_t pred_stride)19 void aom_subtract_block_neon(int rows, int cols, int16_t *diff,
20                              ptrdiff_t diff_stride, const uint8_t *src,
21                              ptrdiff_t src_stride, const uint8_t *pred,
22                              ptrdiff_t pred_stride) {
23   if (cols > 16) {
24     int r = rows;
25     do {
26       int c = 0;
27       do {
28         const uint8x16_t v_src_00 = vld1q_u8(&src[c + 0]);
29         const uint8x16_t v_src_16 = vld1q_u8(&src[c + 16]);
30         const uint8x16_t v_pred_00 = vld1q_u8(&pred[c + 0]);
31         const uint8x16_t v_pred_16 = vld1q_u8(&pred[c + 16]);
32         const uint16x8_t v_diff_lo_00 =
33             vsubl_u8(vget_low_u8(v_src_00), vget_low_u8(v_pred_00));
34         const uint16x8_t v_diff_hi_00 =
35             vsubl_u8(vget_high_u8(v_src_00), vget_high_u8(v_pred_00));
36         const uint16x8_t v_diff_lo_16 =
37             vsubl_u8(vget_low_u8(v_src_16), vget_low_u8(v_pred_16));
38         const uint16x8_t v_diff_hi_16 =
39             vsubl_u8(vget_high_u8(v_src_16), vget_high_u8(v_pred_16));
40         vst1q_s16(&diff[c + 0], vreinterpretq_s16_u16(v_diff_lo_00));
41         vst1q_s16(&diff[c + 8], vreinterpretq_s16_u16(v_diff_hi_00));
42         vst1q_s16(&diff[c + 16], vreinterpretq_s16_u16(v_diff_lo_16));
43         vst1q_s16(&diff[c + 24], vreinterpretq_s16_u16(v_diff_hi_16));
44         c += 32;
45       } while (c < cols);
46       diff += diff_stride;
47       pred += pred_stride;
48       src += src_stride;
49     } while (--r != 0);
50   } else if (cols > 8) {
51     int r = rows;
52     do {
53       const uint8x16_t v_src = vld1q_u8(&src[0]);
54       const uint8x16_t v_pred = vld1q_u8(&pred[0]);
55       const uint16x8_t v_diff_lo =
56           vsubl_u8(vget_low_u8(v_src), vget_low_u8(v_pred));
57       const uint16x8_t v_diff_hi =
58           vsubl_u8(vget_high_u8(v_src), vget_high_u8(v_pred));
59       vst1q_s16(&diff[0], vreinterpretq_s16_u16(v_diff_lo));
60       vst1q_s16(&diff[8], vreinterpretq_s16_u16(v_diff_hi));
61       diff += diff_stride;
62       pred += pred_stride;
63       src += src_stride;
64     } while (--r != 0);
65   } else if (cols > 4) {
66     int r = rows;
67     do {
68       const uint8x8_t v_src = vld1_u8(&src[0]);
69       const uint8x8_t v_pred = vld1_u8(&pred[0]);
70       const uint16x8_t v_diff = vsubl_u8(v_src, v_pred);
71       vst1q_s16(&diff[0], vreinterpretq_s16_u16(v_diff));
72       diff += diff_stride;
73       pred += pred_stride;
74       src += src_stride;
75     } while (--r != 0);
76   } else {
77     int r = rows;
78     do {
79       int c = 0;
80       do {
81         diff[c] = src[c] - pred[c];
82       } while (++c < cols);
83       diff += diff_stride;
84       pred += pred_stride;
85       src += src_stride;
86     } while (--r != 0);
87   }
88 }
89 
90 #if CONFIG_AV1_HIGHBITDEPTH
aom_highbd_subtract_block_neon(int rows,int cols,int16_t * diff,ptrdiff_t diff_stride,const uint8_t * src8,ptrdiff_t src_stride,const uint8_t * pred8,ptrdiff_t pred_stride)91 void aom_highbd_subtract_block_neon(int rows, int cols, int16_t *diff,
92                                     ptrdiff_t diff_stride, const uint8_t *src8,
93                                     ptrdiff_t src_stride, const uint8_t *pred8,
94                                     ptrdiff_t pred_stride) {
95   uint16_t *src = CONVERT_TO_SHORTPTR(src8);
96   uint16_t *pred = CONVERT_TO_SHORTPTR(pred8);
97 
98   if (cols > 16) {
99     int r = rows;
100     do {
101       int c = 0;
102       do {
103         const uint16x8_t v_src_00 = vld1q_u16(&src[c + 0]);
104         const uint16x8_t v_pred_00 = vld1q_u16(&pred[c + 0]);
105         const uint16x8_t v_diff_00 = vsubq_u16(v_src_00, v_pred_00);
106         const uint16x8_t v_src_08 = vld1q_u16(&src[c + 8]);
107         const uint16x8_t v_pred_08 = vld1q_u16(&pred[c + 8]);
108         const uint16x8_t v_diff_08 = vsubq_u16(v_src_08, v_pred_08);
109         vst1q_s16(&diff[c + 0], vreinterpretq_s16_u16(v_diff_00));
110         vst1q_s16(&diff[c + 8], vreinterpretq_s16_u16(v_diff_08));
111         c += 16;
112       } while (c < cols);
113       diff += diff_stride;
114       pred += pred_stride;
115       src += src_stride;
116     } while (--r != 0);
117   } else if (cols > 8) {
118     int r = rows;
119     do {
120       const uint16x8_t v_src_00 = vld1q_u16(&src[0]);
121       const uint16x8_t v_pred_00 = vld1q_u16(&pred[0]);
122       const uint16x8_t v_diff_00 = vsubq_u16(v_src_00, v_pred_00);
123       const uint16x8_t v_src_08 = vld1q_u16(&src[8]);
124       const uint16x8_t v_pred_08 = vld1q_u16(&pred[8]);
125       const uint16x8_t v_diff_08 = vsubq_u16(v_src_08, v_pred_08);
126       vst1q_s16(&diff[0], vreinterpretq_s16_u16(v_diff_00));
127       vst1q_s16(&diff[8], vreinterpretq_s16_u16(v_diff_08));
128       diff += diff_stride;
129       pred += pred_stride;
130       src += src_stride;
131     } while (--r != 0);
132   } else if (cols > 4) {
133     int r = rows;
134     do {
135       const uint16x8_t v_src_r0 = vld1q_u16(&src[0]);
136       const uint16x8_t v_src_r1 = vld1q_u16(&src[src_stride]);
137       const uint16x8_t v_pred_r0 = vld1q_u16(&pred[0]);
138       const uint16x8_t v_pred_r1 = vld1q_u16(&pred[pred_stride]);
139       const uint16x8_t v_diff_r0 = vsubq_u16(v_src_r0, v_pred_r0);
140       const uint16x8_t v_diff_r1 = vsubq_u16(v_src_r1, v_pred_r1);
141       vst1q_s16(&diff[0], vreinterpretq_s16_u16(v_diff_r0));
142       vst1q_s16(&diff[diff_stride], vreinterpretq_s16_u16(v_diff_r1));
143       diff += diff_stride << 1;
144       pred += pred_stride << 1;
145       src += src_stride << 1;
146       r -= 2;
147     } while (r != 0);
148   } else {
149     int r = rows;
150     do {
151       const uint16x4_t v_src_r0 = vld1_u16(&src[0]);
152       const uint16x4_t v_src_r1 = vld1_u16(&src[src_stride]);
153       const uint16x4_t v_pred_r0 = vld1_u16(&pred[0]);
154       const uint16x4_t v_pred_r1 = vld1_u16(&pred[pred_stride]);
155       const uint16x4_t v_diff_r0 = vsub_u16(v_src_r0, v_pred_r0);
156       const uint16x4_t v_diff_r1 = vsub_u16(v_src_r1, v_pred_r1);
157       vst1_s16(&diff[0], vreinterpret_s16_u16(v_diff_r0));
158       vst1_s16(&diff[diff_stride], vreinterpret_s16_u16(v_diff_r1));
159       diff += diff_stride << 1;
160       pred += pred_stride << 1;
161       src += src_stride << 1;
162       r -= 2;
163     } while (r != 0);
164   }
165 }
166 #endif  // CONFIG_AV1_HIGHBITDEPTH
167