1/*
2 *  Copyright (c) 2013 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#include <stdlib.h>
11
12#include "./vp9_rtcd.h"
13#include "vp9/common/vp9_common.h"
14#include "vp9/common/mips/dspr2/vp9_common_dspr2.h"
15
16#if HAVE_DSPR2
17void vp9_h_predictor_4x4_dspr2(uint8_t *dst, ptrdiff_t stride,
18                               const uint8_t *above, const uint8_t *left) {
19  int32_t  tmp1, tmp2, tmp3, tmp4;
20
21  __asm__ __volatile__ (
22      "lb         %[tmp1],      (%[left])                    \n\t"
23      "lb         %[tmp2],      1(%[left])                   \n\t"
24      "lb         %[tmp3],      2(%[left])                   \n\t"
25      "lb         %[tmp4],      3(%[left])                   \n\t"
26      "replv.qb   %[tmp1],      %[tmp1]                      \n\t"
27      "replv.qb   %[tmp2],      %[tmp2]                      \n\t"
28      "replv.qb   %[tmp3],      %[tmp3]                      \n\t"
29      "replv.qb   %[tmp4],      %[tmp4]                      \n\t"
30      "sw         %[tmp1],      (%[dst])                     \n\t"
31      "add        %[dst],       %[dst],         %[stride]    \n\t"
32      "sw         %[tmp2],      (%[dst])                     \n\t"
33      "add        %[dst],       %[dst],         %[stride]    \n\t"
34      "sw         %[tmp3],      (%[dst])                     \n\t"
35      "add        %[dst],       %[dst],         %[stride]    \n\t"
36      "sw         %[tmp4],      (%[dst])                     \n\t"
37
38      : [tmp1] "=&r" (tmp1), [tmp2] "=&r" (tmp2),
39        [tmp3] "=&r" (tmp3), [tmp4] "=&r" (tmp4)
40      : [left] "r" (left), [dst] "r" (dst), [stride] "r" (stride)
41  );
42}
43
44void vp9_dc_predictor_4x4_dspr2(uint8_t *dst, ptrdiff_t stride,
45                                const uint8_t *above, const uint8_t *left) {
46  int32_t  expected_dc;
47  int32_t  average;
48  int32_t  tmp, above_c, above_l, above_r, left_c, left_r, left_l;
49
50  __asm__ __volatile__ (
51      "lw              %[above_c],         (%[above])                    \n\t"
52      "lw              %[left_c],          (%[left])                     \n\t"
53
54      "preceu.ph.qbl   %[above_l],         %[above_c]                    \n\t"
55      "preceu.ph.qbr   %[above_r],         %[above_c]                    \n\t"
56      "preceu.ph.qbl   %[left_l],          %[left_c]                     \n\t"
57      "preceu.ph.qbr   %[left_r],          %[left_c]                     \n\t"
58
59      "addu.ph         %[average],         %[above_r],       %[above_l]  \n\t"
60      "addu.ph         %[average],         %[average],       %[left_l]   \n\t"
61      "addu.ph         %[average],         %[average],       %[left_r]   \n\t"
62      "addiu           %[average],         %[average],       4           \n\t"
63      "srl             %[tmp],             %[average],       16          \n\t"
64      "addu.ph         %[average],         %[tmp],           %[average]  \n\t"
65      "srl             %[expected_dc],     %[average],       3           \n\t"
66      "replv.qb        %[expected_dc],     %[expected_dc]                \n\t"
67
68      "sw              %[expected_dc],     (%[dst])                      \n\t"
69      "add             %[dst],              %[dst],          %[stride]   \n\t"
70      "sw              %[expected_dc],     (%[dst])                      \n\t"
71      "add             %[dst],              %[dst],          %[stride]   \n\t"
72      "sw              %[expected_dc],     (%[dst])                      \n\t"
73      "add             %[dst],              %[dst],          %[stride]   \n\t"
74      "sw              %[expected_dc],     (%[dst])                      \n\t"
75
76      : [above_c] "=&r" (above_c), [above_l] "=&r" (above_l),
77        [above_r] "=&r" (above_r), [left_c] "=&r" (left_c),
78        [left_l] "=&r" (left_l), [left_r] "=&r" (left_r),
79        [average] "=&r" (average), [tmp] "=&r" (tmp),
80        [expected_dc] "=&r" (expected_dc)
81      : [above] "r" (above), [left] "r" (left),
82        [dst] "r" (dst), [stride] "r" (stride)
83  );
84}
85
86void vp9_tm_predictor_4x4_dspr2(uint8_t *dst, ptrdiff_t stride,
87                                const uint8_t *above, const uint8_t *left) {
88  int32_t  abovel, abover;
89  int32_t  left0, left1, left2, left3;
90  int32_t  res0, res1;
91  int32_t  resl;
92  int32_t  resr;
93  int32_t  top_left;
94  uint8_t  *cm = vp9_ff_cropTbl;
95
96  __asm__ __volatile__ (
97      "ulw             %[resl],       (%[above])                         \n\t"
98
99      "lbu             %[left0],       (%[left])                         \n\t"
100      "lbu             %[left1],       1(%[left])                        \n\t"
101      "lbu             %[left2],       2(%[left])                        \n\t"
102      "lbu             %[left3],       3(%[left])                        \n\t"
103
104      "lbu             %[top_left],    -1(%[above])                      \n\t"
105
106      "preceu.ph.qbl   %[abovel],      %[resl]                           \n\t"
107      "preceu.ph.qbr   %[abover],      %[resl]                           \n\t"
108
109      "replv.ph        %[left0],       %[left0]                          \n\t"
110      "replv.ph        %[left1],       %[left1]                          \n\t"
111      "replv.ph        %[left2],       %[left2]                          \n\t"
112      "replv.ph        %[left3],       %[left3]                          \n\t"
113
114      "replv.ph        %[top_left],    %[top_left]                       \n\t"
115
116      "addu.ph         %[resl],        %[abovel],         %[left0]       \n\t"
117      "subu.ph         %[resl],        %[resl],           %[top_left]    \n\t"
118
119      "addu.ph         %[resr],        %[abover],         %[left0]       \n\t"
120      "subu.ph         %[resr],        %[resr],           %[top_left]    \n\t"
121
122      "sll             %[res0],        %[resr],           16             \n\t"
123      "sra             %[res0],        %[res0],           16             \n\t"
124      "lbux            %[res0],        %[res0](%[cm])                    \n\t"
125
126      "sra             %[res1],        %[resr],           16             \n\t"
127      "lbux            %[res1],        %[res1](%[cm])                    \n\t"
128      "sb              %[res0],        (%[dst])                          \n\t"
129
130      "sll             %[res0],        %[resl],           16             \n\t"
131      "sra             %[res0],        %[res0],           16             \n\t"
132      "lbux            %[res0],        %[res0](%[cm])                    \n\t"
133      "sb              %[res1],        1(%[dst])                         \n\t"
134
135      "sra             %[res1],        %[resl],           16             \n\t"
136      "lbux            %[res1],        %[res1](%[cm])                    \n\t"
137
138      "addu.ph         %[resl],        %[abovel],         %[left1]       \n\t"
139      "subu.ph         %[resl],        %[resl],           %[top_left]    \n\t"
140
141      "addu.ph         %[resr],        %[abover],         %[left1]       \n\t"
142      "subu.ph         %[resr],        %[resr],           %[top_left]    \n\t"
143
144      "sb              %[res0],        2(%[dst])                         \n\t"
145      "sb              %[res1],        3(%[dst])                         \n\t"
146
147      "add             %[dst],          %[dst],           %[stride]      \n\t"
148
149      "sll             %[res0],        %[resr],           16             \n\t"
150      "sra             %[res0],        %[res0],           16             \n\t"
151      "lbux            %[res0],        %[res0](%[cm])                    \n\t"
152
153      "sra             %[res1],        %[resr],           16             \n\t"
154      "lbux            %[res1],        %[res1](%[cm])                    \n\t"
155      "sb              %[res0],        (%[dst])                          \n\t"
156
157      "sll             %[res0],        %[resl],           16             \n\t"
158      "sra             %[res0],        %[res0],           16             \n\t"
159      "lbux            %[res0],        %[res0](%[cm])                    \n\t"
160
161      "sb              %[res1],        1(%[dst])                         \n\t"
162      "sra             %[res1],        %[resl],           16             \n\t"
163      "lbux            %[res1],        %[res1](%[cm])                    \n\t"
164
165      "addu.ph         %[resl],        %[abovel],         %[left2]       \n\t"
166      "subu.ph         %[resl],        %[resl],           %[top_left]    \n\t"
167
168      "addu.ph         %[resr],        %[abover],         %[left2]       \n\t"
169      "subu.ph         %[resr],        %[resr],           %[top_left]    \n\t"
170
171      "sb              %[res0],        2(%[dst])                         \n\t"
172      "sb              %[res1],        3(%[dst])                         \n\t"
173
174      "add             %[dst],          %[dst],           %[stride]      \n\t"
175
176      "sll             %[res0],        %[resr],           16             \n\t"
177      "sra             %[res0],        %[res0],           16             \n\t"
178      "lbux            %[res0],        %[res0](%[cm])                    \n\t"
179
180
181      "sra             %[res1],        %[resr],           16             \n\t"
182      "lbux            %[res1],        %[res1](%[cm])                    \n\t"
183      "sb              %[res0],        (%[dst])                          \n\t"
184
185      "sll             %[res0],        %[resl],           16             \n\t"
186      "sra             %[res0],        %[res0],           16             \n\t"
187      "lbux            %[res0],        %[res0](%[cm])                    \n\t"
188
189
190      "sb              %[res1],        1(%[dst])                         \n\t"
191      "sra             %[res1],        %[resl],           16             \n\t"
192      "lbux            %[res1],        %[res1](%[cm])                    \n\t"
193
194      "addu.ph         %[resl],        %[abovel],        %[left3]        \n\t"
195      "subu.ph         %[resl],        %[resl],          %[top_left]     \n\t"
196
197      "addu.ph         %[resr],        %[abover],        %[left3]        \n\t"
198      "subu.ph         %[resr],        %[resr],          %[top_left]     \n\t"
199
200      "sb              %[res0],        2(%[dst])                         \n\t"
201      "sb              %[res1],        3(%[dst])                         \n\t"
202
203      "add             %[dst],          %[dst],          %[stride]       \n\t"
204
205      "sll             %[res0],        %[resr],           16             \n\t"
206      "sra             %[res0],        %[res0],           16             \n\t"
207      "lbux            %[res0],        %[res0](%[cm])                    \n\t"
208
209      "sra             %[res1],        %[resr],           16             \n\t"
210      "lbux            %[res1],        %[res1](%[cm])                    \n\t"
211      "sb              %[res0],        (%[dst])                          \n\t"
212
213      "sll             %[res0],        %[resl],           16             \n\t"
214      "sra             %[res0],        %[res0],           16             \n\t"
215      "lbux            %[res0],        %[res0](%[cm])                    \n\t"
216      "sb              %[res1],        1(%[dst])                         \n\t"
217
218      "sra             %[res1],        %[resl],           16             \n\t"
219      "lbux            %[res1],        %[res1](%[cm])                    \n\t"
220
221      "sb              %[res0],        2(%[dst])                         \n\t"
222      "sb              %[res1],        3(%[dst])                         \n\t"
223
224      : [abovel] "=&r" (abovel), [abover] "=&r" (abover),
225        [left0] "=&r" (left0), [left1] "=&r" (left1), [left2] "=&r" (left2),
226        [res0] "=&r" (res0), [res1] "=&r" (res1), [left3] "=&r" (left3),
227        [resl] "=&r" (resl), [resr] "=&r" (resr), [top_left] "=&r" (top_left)
228      : [above] "r" (above), [left] "r" (left),
229        [dst] "r" (dst), [stride] "r" (stride), [cm] "r" (cm)
230  );
231}
232#endif  // #if HAVE_DSPR2
233