1 /*
2  *  Copyright (c) 2017 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_dsp_rtcd.h"
15 #include "vpx_dsp/arm/mem_neon.h"
16 
vpx_comp_avg_pred_neon(uint8_t * comp,const uint8_t * pred,int width,int height,const uint8_t * ref,int ref_stride)17 void vpx_comp_avg_pred_neon(uint8_t *comp, const uint8_t *pred, int width,
18                             int height, const uint8_t *ref, int ref_stride) {
19   if (width > 8) {
20     int x, y = height;
21     do {
22       for (x = 0; x < width; x += 16) {
23         const uint8x16_t p = vld1q_u8(pred + x);
24         const uint8x16_t r = vld1q_u8(ref + x);
25         const uint8x16_t avg = vrhaddq_u8(p, r);
26         vst1q_u8(comp + x, avg);
27       }
28       comp += width;
29       pred += width;
30       ref += ref_stride;
31     } while (--y);
32   } else if (width == 8) {
33     int i = width * height;
34     do {
35       const uint8x16_t p = vld1q_u8(pred);
36       uint8x16_t r;
37       const uint8x8_t r_0 = vld1_u8(ref);
38       const uint8x8_t r_1 = vld1_u8(ref + ref_stride);
39       r = vcombine_u8(r_0, r_1);
40       ref += 2 * ref_stride;
41       r = vrhaddq_u8(r, p);
42       vst1q_u8(comp, r);
43 
44       pred += 16;
45       comp += 16;
46       i -= 16;
47     } while (i);
48   } else {
49     int i = width * height;
50     assert(width == 4);
51     do {
52       const uint8x16_t p = vld1q_u8(pred);
53       uint8x16_t r;
54 
55       r = load_unaligned_u8q(ref, ref_stride);
56       ref += 4 * ref_stride;
57       r = vrhaddq_u8(r, p);
58       vst1q_u8(comp, r);
59 
60       pred += 16;
61       comp += 16;
62       i -= 16;
63     } while (i);
64   }
65 }
66