r105: This commit was manufactured by cvs2svn to create tag
[cinelerra_cv/mob.git] / hvirtual / quicktime / libavcodec / alpha / dsputil_alpha.c
blob706462a590cb8efa81918fcb826be46bc74c1fd3
1 /*
2 * Alpha optimized DSP utils
3 * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "asm.h"
21 #include "../dsputil.h"
23 void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels,
24 int line_size, int h);
25 void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
26 int line_size);
27 void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
28 int line_size);
29 void (*put_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels,
30 int line_size);
31 void (*add_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels,
32 int line_size);
34 void get_pixels_mvi(DCTELEM *restrict block,
35 const uint8_t *restrict pixels, int line_size);
36 void diff_pixels_mvi(DCTELEM *block, const uint8_t *s1, const uint8_t *s2,
37 int stride);
38 int pix_abs8x8_mvi(uint8_t *pix1, uint8_t *pix2, int line_size);
39 int pix_abs16x16_mvi_asm(uint8_t *pix1, uint8_t *pix2, int line_size);
40 int pix_abs16x16_x2_mvi(uint8_t *pix1, uint8_t *pix2, int line_size);
41 int pix_abs16x16_y2_mvi(uint8_t *pix1, uint8_t *pix2, int line_size);
42 int pix_abs16x16_xy2_mvi(uint8_t *pix1, uint8_t *pix2, int line_size);
44 #if 0
45 /* These functions were the base for the optimized assembler routines,
46 and remain here for documentation purposes. */
47 static void put_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels,
48 int line_size)
50 int i = 8;
51 uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
53 ASM_ACCEPT_MVI;
55 do {
56 uint64_t shorts0, shorts1;
58 shorts0 = ldq(block);
59 shorts0 = maxsw4(shorts0, 0);
60 shorts0 = minsw4(shorts0, clampmask);
61 stl(pkwb(shorts0), pixels);
63 shorts1 = ldq(block + 4);
64 shorts1 = maxsw4(shorts1, 0);
65 shorts1 = minsw4(shorts1, clampmask);
66 stl(pkwb(shorts1), pixels + 4);
68 pixels += line_size;
69 block += 8;
70 } while (--i);
73 void add_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels,
74 int line_size)
76 int h = 8;
77 /* Keep this function a leaf function by generating the constants
78 manually (mainly for the hack value ;-). */
79 uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
80 uint64_t signmask = zap(-1, 0x33);
81 signmask ^= signmask >> 1; /* 0x8000800080008000 */
83 ASM_ACCEPT_MVI;
85 do {
86 uint64_t shorts0, pix0, signs0;
87 uint64_t shorts1, pix1, signs1;
89 shorts0 = ldq(block);
90 shorts1 = ldq(block + 4);
92 pix0 = unpkbw(ldl(pixels));
93 /* Signed subword add (MMX paddw). */
94 signs0 = shorts0 & signmask;
95 shorts0 &= ~signmask;
96 shorts0 += pix0;
97 shorts0 ^= signs0;
98 /* Clamp. */
99 shorts0 = maxsw4(shorts0, 0);
100 shorts0 = minsw4(shorts0, clampmask);
102 /* Next 4. */
103 pix1 = unpkbw(ldl(pixels + 4));
104 signs1 = shorts1 & signmask;
105 shorts1 &= ~signmask;
106 shorts1 += pix1;
107 shorts1 ^= signs1;
108 shorts1 = maxsw4(shorts1, 0);
109 shorts1 = minsw4(shorts1, clampmask);
111 stl(pkwb(shorts0), pixels);
112 stl(pkwb(shorts1), pixels + 4);
114 pixels += line_size;
115 block += 8;
116 } while (--h);
118 #endif
120 static void clear_blocks_axp(DCTELEM *blocks) {
121 uint64_t *p = (uint64_t *) blocks;
122 int n = sizeof(DCTELEM) * 6 * 64;
124 do {
125 p[0] = 0;
126 p[1] = 0;
127 p[2] = 0;
128 p[3] = 0;
129 p[4] = 0;
130 p[5] = 0;
131 p[6] = 0;
132 p[7] = 0;
133 p += 8;
134 n -= 8 * 8;
135 } while (n);
138 static inline uint64_t avg2_no_rnd(uint64_t a, uint64_t b)
140 return (a & b) + (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
143 static inline uint64_t avg2(uint64_t a, uint64_t b)
145 return (a | b) - (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
148 #if 0
149 /* The XY2 routines basically utilize this scheme, but reuse parts in
150 each iteration. */
151 static inline uint64_t avg4(uint64_t l1, uint64_t l2, uint64_t l3, uint64_t l4)
153 uint64_t r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2)
154 + ((l2 & ~BYTE_VEC(0x03)) >> 2)
155 + ((l3 & ~BYTE_VEC(0x03)) >> 2)
156 + ((l4 & ~BYTE_VEC(0x03)) >> 2);
157 uint64_t r2 = (( (l1 & BYTE_VEC(0x03))
158 + (l2 & BYTE_VEC(0x03))
159 + (l3 & BYTE_VEC(0x03))
160 + (l4 & BYTE_VEC(0x03))
161 + BYTE_VEC(0x02)) >> 2) & BYTE_VEC(0x03);
162 return r1 + r2;
164 #endif
166 #define OP(LOAD, STORE) \
167 do { \
168 STORE(LOAD(pixels), block); \
169 pixels += line_size; \
170 block += line_size; \
171 } while (--h)
173 #define OP_X2(LOAD, STORE) \
174 do { \
175 uint64_t pix1, pix2; \
177 pix1 = LOAD(pixels); \
178 pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56); \
179 STORE(AVG2(pix1, pix2), block); \
180 pixels += line_size; \
181 block += line_size; \
182 } while (--h)
184 #define OP_Y2(LOAD, STORE) \
185 do { \
186 uint64_t pix = LOAD(pixels); \
187 do { \
188 uint64_t next_pix; \
190 pixels += line_size; \
191 next_pix = LOAD(pixels); \
192 STORE(AVG2(pix, next_pix), block); \
193 block += line_size; \
194 pix = next_pix; \
195 } while (--h); \
196 } while (0)
198 #define OP_XY2(LOAD, STORE) \
199 do { \
200 uint64_t pix1 = LOAD(pixels); \
201 uint64_t pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56); \
202 uint64_t pix_l = (pix1 & BYTE_VEC(0x03)) \
203 + (pix2 & BYTE_VEC(0x03)); \
204 uint64_t pix_h = ((pix1 & ~BYTE_VEC(0x03)) >> 2) \
205 + ((pix2 & ~BYTE_VEC(0x03)) >> 2); \
207 do { \
208 uint64_t npix1, npix2; \
209 uint64_t npix_l, npix_h; \
210 uint64_t avg; \
212 pixels += line_size; \
213 npix1 = LOAD(pixels); \
214 npix2 = npix1 >> 8 | ((uint64_t) pixels[8] << 56); \
215 npix_l = (npix1 & BYTE_VEC(0x03)) \
216 + (npix2 & BYTE_VEC(0x03)); \
217 npix_h = ((npix1 & ~BYTE_VEC(0x03)) >> 2) \
218 + ((npix2 & ~BYTE_VEC(0x03)) >> 2); \
219 avg = (((pix_l + npix_l + AVG4_ROUNDER) >> 2) & BYTE_VEC(0x03)) \
220 + pix_h + npix_h; \
221 STORE(avg, block); \
223 block += line_size; \
224 pix_l = npix_l; \
225 pix_h = npix_h; \
226 } while (--h); \
227 } while (0)
229 #define MAKE_OP(OPNAME, SUFF, OPKIND, STORE) \
230 static void OPNAME ## _pixels ## SUFF ## _axp \
231 (uint8_t *restrict block, const uint8_t *restrict pixels, \
232 int line_size, int h) \
234 if ((size_t) pixels & 0x7) { \
235 OPKIND(uldq, STORE); \
236 } else { \
237 OPKIND(ldq, STORE); \
241 static void OPNAME ## _pixels16 ## SUFF ## _axp \
242 (uint8_t *restrict block, const uint8_t *restrict pixels, \
243 int line_size, int h) \
245 OPNAME ## _pixels ## SUFF ## _axp(block, pixels, line_size, h); \
246 OPNAME ## _pixels ## SUFF ## _axp(block + 8, pixels + 8, line_size, h); \
249 #define PIXOP(OPNAME, STORE) \
250 MAKE_OP(OPNAME, , OP, STORE) \
251 MAKE_OP(OPNAME, _x2, OP_X2, STORE) \
252 MAKE_OP(OPNAME, _y2, OP_Y2, STORE) \
253 MAKE_OP(OPNAME, _xy2, OP_XY2, STORE)
255 /* Rounding primitives. */
256 #define AVG2 avg2
257 #define AVG4 avg4
258 #define AVG4_ROUNDER BYTE_VEC(0x02)
259 #define STORE(l, b) stq(l, b)
260 PIXOP(put, STORE);
262 #undef STORE
263 #define STORE(l, b) stq(AVG2(l, ldq(b)), b);
264 PIXOP(avg, STORE);
266 /* Not rounding primitives. */
267 #undef AVG2
268 #undef AVG4
269 #undef AVG4_ROUNDER
270 #undef STORE
271 #define AVG2 avg2_no_rnd
272 #define AVG4 avg4_no_rnd
273 #define AVG4_ROUNDER BYTE_VEC(0x01)
274 #define STORE(l, b) stq(l, b)
275 PIXOP(put_no_rnd, STORE);
277 #undef STORE
278 #define STORE(l, b) stq(AVG2(l, ldq(b)), b);
279 PIXOP(avg_no_rnd, STORE);
281 void put_pixels16_axp_asm(uint8_t *block, const uint8_t *pixels,
282 int line_size, int h)
284 put_pixels_axp_asm(block, pixels, line_size, h);
285 put_pixels_axp_asm(block + 8, pixels + 8, line_size, h);
288 void dsputil_init_alpha(DSPContext* c, unsigned mask)
290 c->put_pixels_tab[0][0] = put_pixels16_axp_asm;
291 c->put_pixels_tab[0][1] = put_pixels16_x2_axp;
292 c->put_pixels_tab[0][2] = put_pixels16_y2_axp;
293 c->put_pixels_tab[0][3] = put_pixels16_xy2_axp;
295 c->put_no_rnd_pixels_tab[0][0] = put_pixels16_axp_asm;
296 c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_axp;
297 c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_axp;
298 c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_axp;
300 c->avg_pixels_tab[0][0] = avg_pixels16_axp;
301 c->avg_pixels_tab[0][1] = avg_pixels16_x2_axp;
302 c->avg_pixels_tab[0][2] = avg_pixels16_y2_axp;
303 c->avg_pixels_tab[0][3] = avg_pixels16_xy2_axp;
305 c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_axp;
306 c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_axp;
307 c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_axp;
308 c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_axp;
310 c->put_pixels_tab[1][0] = put_pixels_axp_asm;
311 c->put_pixels_tab[1][1] = put_pixels_x2_axp;
312 c->put_pixels_tab[1][2] = put_pixels_y2_axp;
313 c->put_pixels_tab[1][3] = put_pixels_xy2_axp;
315 c->put_no_rnd_pixels_tab[1][0] = put_pixels_axp_asm;
316 c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels_x2_axp;
317 c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels_y2_axp;
318 c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels_xy2_axp;
320 c->avg_pixels_tab[1][0] = avg_pixels_axp;
321 c->avg_pixels_tab[1][1] = avg_pixels_x2_axp;
322 c->avg_pixels_tab[1][2] = avg_pixels_y2_axp;
323 c->avg_pixels_tab[1][3] = avg_pixels_xy2_axp;
325 c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels_axp;
326 c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels_x2_axp;
327 c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels_y2_axp;
328 c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels_xy2_axp;
330 c->clear_blocks = clear_blocks_axp;
332 /* amask clears all bits that correspond to present features. */
333 if (amask(AMASK_MVI) == 0) {
334 c->put_pixels_clamped = put_pixels_clamped_mvi_asm;
335 c->add_pixels_clamped = add_pixels_clamped_mvi_asm;
337 c->get_pixels = get_pixels_mvi;
338 c->diff_pixels = diff_pixels_mvi;
339 c->pix_abs8x8 = pix_abs8x8_mvi;
340 c->pix_abs16x16 = pix_abs16x16_mvi_asm;
341 c->pix_abs16x16_x2 = pix_abs16x16_x2_mvi;
342 c->pix_abs16x16_y2 = pix_abs16x16_y2_mvi;
343 c->pix_abs16x16_xy2 = pix_abs16x16_xy2_mvi;
346 put_pixels_clamped_axp_p = c->put_pixels_clamped;
347 add_pixels_clamped_axp_p = c->add_pixels_clamped;