1 /*
2 * Copyright (c) 2014 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 #include <assert.h>
13
14 #include "./vpx_config.h"
15 #include "./vpx_dsp_rtcd.h"
16 #include "vpx/vpx_integer.h"
17 #include "vpx_dsp/arm/mem_neon.h"
18
vpx_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 vpx_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 int r = rows, c;
24
25 if (cols > 16) {
26 do {
27 for (c = 0; c < cols; c += 32) {
28 const uint8x16_t s0 = vld1q_u8(&src[c + 0]);
29 const uint8x16_t s1 = vld1q_u8(&src[c + 16]);
30 const uint8x16_t p0 = vld1q_u8(&pred[c + 0]);
31 const uint8x16_t p1 = vld1q_u8(&pred[c + 16]);
32 const uint16x8_t d0 = vsubl_u8(vget_low_u8(s0), vget_low_u8(p0));
33 const uint16x8_t d1 = vsubl_u8(vget_high_u8(s0), vget_high_u8(p0));
34 const uint16x8_t d2 = vsubl_u8(vget_low_u8(s1), vget_low_u8(p1));
35 const uint16x8_t d3 = vsubl_u8(vget_high_u8(s1), vget_high_u8(p1));
36 vst1q_s16(&diff[c + 0], vreinterpretq_s16_u16(d0));
37 vst1q_s16(&diff[c + 8], vreinterpretq_s16_u16(d1));
38 vst1q_s16(&diff[c + 16], vreinterpretq_s16_u16(d2));
39 vst1q_s16(&diff[c + 24], vreinterpretq_s16_u16(d3));
40 }
41 diff += diff_stride;
42 pred += pred_stride;
43 src += src_stride;
44 } while (--r);
45 } else if (cols > 8) {
46 do {
47 const uint8x16_t s = vld1q_u8(&src[0]);
48 const uint8x16_t p = vld1q_u8(&pred[0]);
49 const uint16x8_t d0 = vsubl_u8(vget_low_u8(s), vget_low_u8(p));
50 const uint16x8_t d1 = vsubl_u8(vget_high_u8(s), vget_high_u8(p));
51 vst1q_s16(&diff[0], vreinterpretq_s16_u16(d0));
52 vst1q_s16(&diff[8], vreinterpretq_s16_u16(d1));
53 diff += diff_stride;
54 pred += pred_stride;
55 src += src_stride;
56 } while (--r);
57 } else if (cols > 4) {
58 do {
59 const uint8x8_t s = vld1_u8(&src[0]);
60 const uint8x8_t p = vld1_u8(&pred[0]);
61 const uint16x8_t v_diff = vsubl_u8(s, p);
62 vst1q_s16(&diff[0], vreinterpretq_s16_u16(v_diff));
63 diff += diff_stride;
64 pred += pred_stride;
65 src += src_stride;
66 } while (--r);
67 } else {
68 assert(cols == 4);
69 do {
70 const uint8x8_t s = load_unaligned_u8(src, (int)src_stride);
71 const uint8x8_t p = load_unaligned_u8(pred, (int)pred_stride);
72 const uint16x8_t d = vsubl_u8(s, p);
73 vst1_s16(diff + 0 * diff_stride, vreinterpret_s16_u16(vget_low_u16(d)));
74 vst1_s16(diff + 1 * diff_stride, vreinterpret_s16_u16(vget_high_u16(d)));
75 diff += 2 * diff_stride;
76 pred += 2 * pred_stride;
77 src += 2 * src_stride;
78 r -= 2;
79 } while (r);
80 }
81 }
82
83 #if CONFIG_VP9_HIGHBITDEPTH
vpx_highbd_subtract_block_neon(int rows,int cols,int16_t * diff_ptr,ptrdiff_t diff_stride,const uint8_t * src8_ptr,ptrdiff_t src_stride,const uint8_t * pred8_ptr,ptrdiff_t pred_stride,int bd)84 void vpx_highbd_subtract_block_neon(int rows, int cols, int16_t *diff_ptr,
85 ptrdiff_t diff_stride,
86 const uint8_t *src8_ptr,
87 ptrdiff_t src_stride,
88 const uint8_t *pred8_ptr,
89 ptrdiff_t pred_stride, int bd) {
90 int r = rows, c;
91 uint16_t *src = CONVERT_TO_SHORTPTR(src8_ptr);
92 uint16_t *pred = CONVERT_TO_SHORTPTR(pred8_ptr);
93 (void)bd;
94
95 if (cols >= 16) {
96 do {
97 for (c = 0; c < cols; c += 16) {
98 const uint16x8_t s0 = vld1q_u16(&src[c + 0]);
99 const uint16x8_t s1 = vld1q_u16(&src[c + 8]);
100 const uint16x8_t p0 = vld1q_u16(&pred[c + 0]);
101 const uint16x8_t p1 = vld1q_u16(&pred[c + 8]);
102 const uint16x8_t d0 = vsubq_u16(s0, p0);
103 const uint16x8_t d1 = vsubq_u16(s1, p1);
104 vst1q_s16(&diff_ptr[c + 0], vreinterpretq_s16_u16(d0));
105 vst1q_s16(&diff_ptr[c + 8], vreinterpretq_s16_u16(d1));
106 }
107 diff_ptr += diff_stride;
108 pred += pred_stride;
109 src += src_stride;
110 } while (--r);
111 } else if (cols >= 8) {
112 do {
113 for (c = 0; c < cols; c += 8) {
114 const uint16x8_t s = vld1q_u16(&src[c]);
115 const uint16x8_t p = vld1q_u16(&pred[c]);
116 const uint16x8_t d0 = vsubq_u16(s, p);
117 vst1q_s16(&diff_ptr[c], vreinterpretq_s16_u16(d0));
118 }
119 diff_ptr += diff_stride;
120 pred += pred_stride;
121 src += src_stride;
122 } while (--r);
123 } else if (cols >= 4) {
124 do {
125 for (c = 0; c < cols; c += 4) {
126 const uint16x4_t s = vld1_u16(&src[c]);
127 const uint16x4_t p = vld1_u16(&pred[c]);
128 const uint16x4_t v_diff = vsub_u16(s, p);
129 vst1_s16(&diff_ptr[c], vreinterpret_s16_u16(v_diff));
130 }
131 diff_ptr += diff_stride;
132 pred += pred_stride;
133 src += src_stride;
134 } while (--r);
135 }
136 }
137 #endif // CONFIG_VP9_HIGHBITDEPTH
138