]> granicus.if.org Git - libvpx/blob - vpx_dsp/ppc/sad_vsx.c
Merge "vp9: SVC: Adjust some speed settings for SVC speed >= 7."
[libvpx] / vpx_dsp / ppc / sad_vsx.c
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 <stdlib.h>
12
13 #include "./vpx_dsp_rtcd.h"
14
15 #include "vpx_dsp/ppc/types_vsx.h"
16
17 #include "vpx/vpx_integer.h"
18 #include "vpx_ports/mem.h"
19
20 #define PROCESS16(offset)           \
21   v_a = vec_vsx_ld(offset, a);      \
22   v_b = vec_vsx_ld(offset, b);      \
23   v_ah = unpack_to_s16_h(v_a);      \
24   v_al = unpack_to_s16_l(v_a);      \
25   v_bh = unpack_to_s16_h(v_b);      \
26   v_bl = unpack_to_s16_l(v_b);      \
27   v_subh = vec_sub(v_ah, v_bh);     \
28   v_subl = vec_sub(v_al, v_bl);     \
29   v_absh = vec_abs(v_subh);         \
30   v_absl = vec_abs(v_subl);         \
31   v_sad = vec_sum4s(v_absh, v_sad); \
32   v_sad = vec_sum4s(v_absl, v_sad);
33
34 #define SAD16(height)                                                     \
35   unsigned int vpx_sad16x##height##_vsx(const uint8_t *a, int a_stride,   \
36                                         const uint8_t *b, int b_stride) { \
37     int y;                                                                \
38     unsigned int sad[4];                                                  \
39     uint8x16_t v_a, v_b;                                                  \
40     int16x8_t v_ah, v_al, v_bh, v_bl, v_absh, v_absl, v_subh, v_subl;     \
41     int32x4_t v_sad = vec_splat_s32(0);                                   \
42                                                                           \
43     for (y = 0; y < height; y++) {                                        \
44       PROCESS16(0);                                                       \
45                                                                           \
46       a += a_stride;                                                      \
47       b += b_stride;                                                      \
48     }                                                                     \
49     vec_vsx_st((uint32x4_t)v_sad, 0, sad);                                \
50                                                                           \
51     return sad[3] + sad[2] + sad[1] + sad[0];                             \
52   }
53
54 #define SAD32(height)                                                     \
55   unsigned int vpx_sad32x##height##_vsx(const uint8_t *a, int a_stride,   \
56                                         const uint8_t *b, int b_stride) { \
57     int y;                                                                \
58     unsigned int sad[4];                                                  \
59     uint8x16_t v_a, v_b;                                                  \
60     int16x8_t v_ah, v_al, v_bh, v_bl, v_absh, v_absl, v_subh, v_subl;     \
61     int32x4_t v_sad = vec_splat_s32(0);                                   \
62                                                                           \
63     for (y = 0; y < height; y++) {                                        \
64       PROCESS16(0);                                                       \
65       PROCESS16(16);                                                      \
66                                                                           \
67       a += a_stride;                                                      \
68       b += b_stride;                                                      \
69     }                                                                     \
70     vec_vsx_st((uint32x4_t)v_sad, 0, sad);                                \
71                                                                           \
72     return sad[3] + sad[2] + sad[1] + sad[0];                             \
73   }
74
75 #define SAD64(height)                                                     \
76   unsigned int vpx_sad64x##height##_vsx(const uint8_t *a, int a_stride,   \
77                                         const uint8_t *b, int b_stride) { \
78     int y;                                                                \
79     unsigned int sad[4];                                                  \
80     uint8x16_t v_a, v_b;                                                  \
81     int16x8_t v_ah, v_al, v_bh, v_bl, v_absh, v_absl, v_subh, v_subl;     \
82     int32x4_t v_sad = vec_splat_s32(0);                                   \
83                                                                           \
84     for (y = 0; y < height; y++) {                                        \
85       PROCESS16(0);                                                       \
86       PROCESS16(16);                                                      \
87       PROCESS16(32);                                                      \
88       PROCESS16(48);                                                      \
89                                                                           \
90       a += a_stride;                                                      \
91       b += b_stride;                                                      \
92     }                                                                     \
93     vec_vsx_st((uint32x4_t)v_sad, 0, sad);                                \
94                                                                           \
95     return sad[3] + sad[2] + sad[1] + sad[0];                             \
96   }
97
98 SAD16(8);
99 SAD16(16);
100 SAD16(32);
101 SAD32(16);
102 SAD32(32);
103 SAD32(64);
104 SAD64(32);
105 SAD64(64);
106
107 #define SAD16AVG(height)                                                      \
108   unsigned int vpx_sad16x##height##_avg_vsx(                                  \
109       const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
110       const uint8_t *second_pred) {                                           \
111     DECLARE_ALIGNED(16, uint8_t, comp_pred[16 * height]);                     \
112     vpx_comp_avg_pred_vsx(comp_pred, second_pred, 16, height, ref,            \
113                           ref_stride);                                        \
114                                                                               \
115     return vpx_sad16x##height##_vsx(src, src_stride, comp_pred, 16);          \
116   }
117
118 #define SAD32AVG(height)                                                      \
119   unsigned int vpx_sad32x##height##_avg_vsx(                                  \
120       const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
121       const uint8_t *second_pred) {                                           \
122     DECLARE_ALIGNED(32, uint8_t, comp_pred[32 * height]);                     \
123     vpx_comp_avg_pred_vsx(comp_pred, second_pred, 32, height, ref,            \
124                           ref_stride);                                        \
125                                                                               \
126     return vpx_sad32x##height##_vsx(src, src_stride, comp_pred, 32);          \
127   }
128
129 #define SAD64AVG(height)                                                      \
130   unsigned int vpx_sad64x##height##_avg_vsx(                                  \
131       const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \
132       const uint8_t *second_pred) {                                           \
133     DECLARE_ALIGNED(64, uint8_t, comp_pred[64 * height]);                     \
134     vpx_comp_avg_pred_vsx(comp_pred, second_pred, 64, height, ref,            \
135                           ref_stride);                                        \
136                                                                               \
137     return vpx_sad64x##height##_vsx(src, src_stride, comp_pred, 64);          \
138   }
139
140 SAD16AVG(8);
141 SAD16AVG(16);
142 SAD16AVG(32);
143 SAD32AVG(16);
144 SAD32AVG(32);
145 SAD32AVG(64);
146 SAD64AVG(32);
147 SAD64AVG(64);