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 simple_idct_axp(DCTELEM *block);
25 void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels,
26 int line_size, int h);
27 void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
29 void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
33 /* These functions were the base for the optimized assembler routines,
34 and remain here for documentation purposes. */
35 static void put_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels,
39 uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
44 uint64_t shorts0, shorts1;
47 shorts0 = maxsw4(shorts0, 0);
48 shorts0 = minsw4(shorts0, clampmask);
49 stl(pkwb(shorts0), pixels);
51 shorts1 = ldq(block + 4);
52 shorts1 = maxsw4(shorts1, 0);
53 shorts1 = minsw4(shorts1, clampmask);
54 stl(pkwb(shorts1), pixels + 4);
61 void add_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels,
65 /* Keep this function a leaf function by generating the constants
66 manually (mainly for the hack value ;-). */
67 uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
68 uint64_t signmask = zap(-1, 0x33);
69 signmask ^= signmask >> 1; /* 0x8000800080008000 */
74 uint64_t shorts0, pix0, signs0;
75 uint64_t shorts1, pix1, signs1;
78 shorts1 = ldq(block + 4);
80 pix0 = unpkbw(ldl(pixels));
81 /* Signed subword add (MMX paddw). */
82 signs0 = shorts0 & signmask;
87 shorts0 = maxsw4(shorts0, 0);
88 shorts0 = minsw4(shorts0, clampmask);
91 pix1 = unpkbw(ldl(pixels + 4));
92 signs1 = shorts1 & signmask;
96 shorts1 = maxsw4(shorts1, 0);
97 shorts1 = minsw4(shorts1, clampmask);
99 stl(pkwb(shorts0), pixels);
100 stl(pkwb(shorts1), pixels + 4);
108 static inline uint64_t avg2_no_rnd(uint64_t a, uint64_t b)
110 return (a & b) + (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
113 static inline uint64_t avg2(uint64_t a, uint64_t b)
115 return (a | b) - (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
118 static inline uint64_t avg4(uint64_t l1, uint64_t l2, uint64_t l3, uint64_t l4)
120 uint64_t r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2)
121 + ((l2 & ~BYTE_VEC(0x03)) >> 2)
122 + ((l3 & ~BYTE_VEC(0x03)) >> 2)
123 + ((l4 & ~BYTE_VEC(0x03)) >> 2);
124 uint64_t r2 = (( (l1 & BYTE_VEC(0x03))
125 + (l2 & BYTE_VEC(0x03))
126 + (l3 & BYTE_VEC(0x03))
127 + (l4 & BYTE_VEC(0x03))
128 + BYTE_VEC(0x02)) >> 2) & BYTE_VEC(0x03);
132 static inline uint64_t avg4_no_rnd(uint64_t l1, uint64_t l2,
133 uint64_t l3, uint64_t l4)
135 uint64_t r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2)
136 + ((l2 & ~BYTE_VEC(0x03)) >> 2)
137 + ((l3 & ~BYTE_VEC(0x03)) >> 2)
138 + ((l4 & ~BYTE_VEC(0x03)) >> 2);
139 uint64_t r2 = (( (l1 & BYTE_VEC(0x03))
140 + (l2 & BYTE_VEC(0x03))
141 + (l3 & BYTE_VEC(0x03))
142 + (l4 & BYTE_VEC(0x03))
143 + BYTE_VEC(0x01)) >> 2) & BYTE_VEC(0x03);
147 #define OP(LOAD, STORE, INCR) \
149 STORE(LOAD(pixels), block); \
150 pixels += line_size; \
154 #define OP_X2(LOAD, STORE, INCR) \
156 uint64_t pix1, pix2; \
158 pix1 = LOAD(pixels); \
159 pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56); \
160 STORE(AVG2(pix1, pix2), block); \
161 pixels += line_size; \
165 #define OP_Y2(LOAD, STORE, INCR) \
167 uint64_t pix = LOAD(pixels); \
171 pixels += line_size; \
172 next_pix = LOAD(pixels); \
173 STORE(AVG2(pix, next_pix), block); \
179 #define OP_XY2(LOAD, STORE, INCR) \
181 uint64_t pix1 = LOAD(pixels); \
182 uint64_t pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56); \
185 uint64_t next_pix1, next_pix2; \
187 pixels += line_size; \
188 next_pix1 = LOAD(pixels); \
189 next_pix2 = next_pix1 >> 8 | ((uint64_t) pixels[8] << 56); \
191 STORE(AVG4(pix1, pix2, next_pix1, next_pix2), block); \
199 #define MAKE_OP(BTYPE, OPNAME, SUFF, OPKIND, STORE, INCR) \
200 static void OPNAME ## _pixels ## SUFF ## _axp(BTYPE *block, \
201 const uint8_t *pixels, \
202 int line_size, int h) \
204 if ((size_t) pixels & 0x7) { \
205 OPKIND(uldq, STORE, INCR); \
207 OPKIND(ldq, STORE, INCR); \
211 #define PIXOP(BTYPE, OPNAME, STORE, INCR) \
212 MAKE_OP(BTYPE, OPNAME, , OP, STORE, INCR); \
213 MAKE_OP(BTYPE, OPNAME, _x2, OP_X2, STORE, INCR); \
214 MAKE_OP(BTYPE, OPNAME, _y2, OP_Y2, STORE, INCR); \
215 MAKE_OP(BTYPE, OPNAME, _xy2, OP_XY2, STORE, INCR);
217 /* Rounding primitives. */
220 #define STORE(l, b) stq(l, b)
221 PIXOP(uint8_t, put, STORE, line_size);
224 #define STORE(l, b) stq(AVG2(l, ldq(b)), b);
225 PIXOP(uint8_t, avg, STORE, line_size);
227 /* Not rounding primitives. */
231 #define AVG2 avg2_no_rnd
232 #define AVG4 avg4_no_rnd
233 #define STORE(l, b) stq(l, b)
234 PIXOP(uint8_t, put_no_rnd, STORE, line_size);
237 #define STORE(l, b) stq(AVG2(l, ldq(b)), b);
238 PIXOP(uint8_t, avg_no_rnd, STORE, line_size);
240 void dsputil_init_alpha(void)
242 put_pixels_tab[0] = put_pixels_axp_asm;
243 put_pixels_tab[1] = put_pixels_x2_axp;
244 put_pixels_tab[2] = put_pixels_y2_axp;
245 put_pixels_tab[3] = put_pixels_xy2_axp;
247 put_no_rnd_pixels_tab[0] = put_pixels_axp_asm;
248 put_no_rnd_pixels_tab[1] = put_no_rnd_pixels_x2_axp;
249 put_no_rnd_pixels_tab[2] = put_no_rnd_pixels_y2_axp;
250 put_no_rnd_pixels_tab[3] = put_no_rnd_pixels_xy2_axp;
252 avg_pixels_tab[0] = avg_pixels_axp;
253 avg_pixels_tab[1] = avg_pixels_x2_axp;
254 avg_pixels_tab[2] = avg_pixels_y2_axp;
255 avg_pixels_tab[3] = avg_pixels_xy2_axp;
257 avg_no_rnd_pixels_tab[0] = avg_no_rnd_pixels_axp;
258 avg_no_rnd_pixels_tab[1] = avg_no_rnd_pixels_x2_axp;
259 avg_no_rnd_pixels_tab[2] = avg_no_rnd_pixels_y2_axp;
260 avg_no_rnd_pixels_tab[3] = avg_no_rnd_pixels_xy2_axp;
262 /* amask clears all bits that correspond to present features. */
263 if (amask(AMASK_MVI) == 0) {
264 put_pixels_clamped = put_pixels_clamped_mvi_asm;
265 add_pixels_clamped = add_pixels_clamped_mvi_asm;