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
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
,
27 void add_pixels_clamped_mvi_asm(const DCTELEM
*block
, uint8_t *pixels
,
29 void (*put_pixels_clamped_axp_p
)(const DCTELEM
*block
, uint8_t *pixels
,
31 void (*add_pixels_clamped_axp_p
)(const DCTELEM
*block
, uint8_t *pixels
,
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
,
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
);
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
,
51 uint64_t clampmask
= zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
56 uint64_t shorts0
, shorts1
;
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);
73 void add_pixels_clamped_mvi(const DCTELEM
*block
, uint8_t *pixels
,
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 */
86 uint64_t shorts0
, pix0
, signs0
;
87 uint64_t shorts1
, pix1
, signs1
;
90 shorts1
= ldq(block
+ 4);
92 pix0
= unpkbw(ldl(pixels
));
93 /* Signed subword add (MMX paddw). */
94 signs0
= shorts0
& signmask
;
99 shorts0
= maxsw4(shorts0
, 0);
100 shorts0
= minsw4(shorts0
, clampmask
);
103 pix1
= unpkbw(ldl(pixels
+ 4));
104 signs1
= shorts1
& signmask
;
105 shorts1
&= ~signmask
;
108 shorts1
= maxsw4(shorts1
, 0);
109 shorts1
= minsw4(shorts1
, clampmask
);
111 stl(pkwb(shorts0
), pixels
);
112 stl(pkwb(shorts1
), pixels
+ 4);
120 static void clear_blocks_axp(DCTELEM
*blocks
) {
121 uint64_t *p
= (uint64_t *) blocks
;
122 int n
= sizeof(DCTELEM
) * 6 * 64;
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);
149 /* The XY2 routines basically utilize this scheme, but reuse parts in
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);
166 #define OP(LOAD, STORE) \
168 STORE(LOAD(pixels), block); \
169 pixels += line_size; \
170 block += line_size; \
173 #define OP_X2(LOAD, STORE) \
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; \
184 #define OP_Y2(LOAD, STORE) \
186 uint64_t pix = LOAD(pixels); \
190 pixels += line_size; \
191 next_pix = LOAD(pixels); \
192 STORE(AVG2(pix, next_pix), block); \
193 block += line_size; \
198 #define OP_XY2(LOAD, STORE) \
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); \
208 uint64_t npix1, npix2; \
209 uint64_t npix_l, npix_h; \
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)) \
223 block += line_size; \
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); \
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. */
258 #define AVG4_ROUNDER BYTE_VEC(0x02)
259 #define STORE(l, b) stq(l, b)
263 #define STORE(l, b) stq(AVG2(l, ldq(b)), b);
266 /* Not rounding primitives. */
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
);
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
;