3 eXtended MultiMedia eXtensions GCC interface library for IA32.
5 To use this library, simply include this header file
6 and compile with GCC. You MUST have inlining enabled
7 in order for xmmx_ok() to work; this can be done by
8 simply using -O on the GCC command line.
10 Compiling with -DXMMX_TRACE will cause detailed trace
11 output to be sent to stderr for each mmx operation.
12 This adds lots of code, and obviously slows execution to
13 a crawl, but can be very useful for debugging.
15 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY
16 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
17 LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR ANY PARTICULAR PURPOSE.
21 Based on libmmx, 1997-99 by H. Dietz and R. Fisher
24 It appears that the latest gas has the pand problem fixed, therefore
25 I'll undefine BROKEN_PAND by default.
31 #include "goom_config.h"
35 /* a definir pour avoir exactement le meme resultat que la fonction C
36 * (un chouillat plus lent).. mais la difference est assez peu notable.
38 // #define STRICT_COMPAT
40 #define BUFFPOINTNB 16
41 #define BUFFPOINTMASK 0xffff
45 /* faire : a % sqrtperte <=> a & pertemask*/
47 /* faire : a / sqrtperte <=> a >> PERTEDEC*/
54 #include "goom_graphic.h"
59 return (mm_support () & 0x8) >> 3;
63 zoom_filter_xmmx (int prevX, int prevY,
64 Pixel * expix1, Pixel * expix2,
65 int *lbruS, int *lbruD, int buffratio, int precalCoef[16][16])
67 int bufsize = prevX * prevY; /* taille du buffer */
68 volatile int loop; /* variable de boucle */
70 mmx_t *brutS = (mmx_t *) lbruS; /* buffer de transformation source */
71 mmx_t *brutD = (mmx_t *) lbruD; /* buffer de transformation dest */
73 volatile mmx_t prevXY;
74 volatile mmx_t ratiox;
76 /* volatile mmx_t interpix; */
78 expix1[0].val = expix1[prevX - 1].val = expix1[prevX * prevY - 1].val =
79 expix1[prevX * prevY - prevX].val = 0;
81 prevXY.ud[0] = (prevX - 1) << PERTEDEC;
82 prevXY.ud[1] = (prevY - 1) << PERTEDEC;
84 ratiox.d[0] = buffratio;
85 ratiox.d[1] = buffratio;
87 asm volatile ("\n\t movq %[ratio], %%mm6" "\n\t pslld $16, %%mm6" /* mm6 = [rat16=buffratio<<16 | rat16=buffratio<<16] */
88 "\n\t pxor %%mm7, %%mm7" /* mm7 = 0 */
89 ::[ratio] "m" (ratiox));
94 * NOTE : mm6 et mm7 ne sont pas modifies dans la boucle.
96 while (loop < bufsize) {
98 * pre : mm6 = [rat16|rat16]
99 * post : mm0 = S + ((D-S)*rat16 format [X|Y]
100 * modified = mm0,mm1,mm2
103 asm volatile ("#1 \n\t movq 0(%[brutS]), %%mm0" "#1 \n\t movq 0(%[brutD]), %%mm1" "#1 \n\t psubd %%mm0, %%mm1" /* mm1 = D - S */
104 "#1 \n\t movq %%mm1, %%mm2" /* mm2 = D - S */
105 "#1 \n\t pslld $16, %%mm1" "#1 \n\t pmullw %%mm6, %%mm2" "#1 \n\t pmulhuw %%mm6, %%mm1" "#1 \n\t pslld $16, %%mm0" "#1 \n\t paddd %%mm2, %%mm1" /* mm1 = (D - S) * buffratio >> 16 */
106 "#1 \n\t paddd %%mm1, %%mm0" /* mm0 = S + mm1 */
107 "#1 \n\t psrld $16, %%mm0"::[brutS] "r" (&brutS[loop]),
108 [brutD] "r" (&brutD[loop])
112 * pre : mm0 : position vector on screen
113 * prevXY : coordinate of the lower-right point on screen
115 * modified : mm0,mm1,mm2
118 ("#1 \n\t movq %[prevXY], %%mm1" "#1 \n\t pcmpgtd %%mm0, %%mm1"
119 /* mm0 en X contient (idem pour Y) :
120 * 1111 si prevXY > px
121 * 0000 si prevXY <= px */
123 "#1 \n\t movq %%mm1, %%mm2"
124 "#1 \n\t punpckhdq %%mm2, %%mm2"
125 "#1 \n\t punpckldq %%mm1, %%mm1" "#1 \n\t pand %%mm2, %%mm0"
127 "#1 \n\t pand %%mm1, %%mm0" /* on met a zero la partie qui deborde */
128 ::[prevXY] "m" (prevXY));
131 * pre : mm0 : clipped position on screen
133 * post : mm3 : coefs for this position
134 * mm1 : X vector [0|X]
138 __asm__ __volatile__ ("#2 \n\t movd %%mm0,%%esi"
139 "#2 \n\t movq %%mm0,%%mm1"
140 "#2 \n\t andl $15,%%esi"
141 "#2 \n\t psrlq $32,%%mm1"
142 "#2 \n\t shll $6,%%esi"
143 "#2 \n\t movd %%mm1,%%eax"
144 "#2 \n\t addl %[precalCoef],%%esi"
145 "#2 \n\t andl $15,%%eax"
146 "#2 \n\t movd (%%esi,%%eax,4),%%mm3"::[precalCoef]
147 "g" (precalCoef):"eax", "esi");
150 * extraction des coefficients... (Thread #3)
152 * pre : coef dans mm3
154 * post : coef extraits dans mm3 (c1 & c2)
161 * pre : mm0 : Y pos [*|Y]
164 * post : mm0 : expix1[position]
165 * mm2 : expix1[position+largeur]
169 __asm__ __volatile__ ("#2 \n\t psrld $4, %%mm0" "#2 \n\t psrld $4, %%mm1" /* PERTEDEC = $4 */
170 "#4 \n\t movd %%mm1,%%eax"
171 "#3 \n\t movq %%mm3,%%mm5"
172 "#4 \n\t mull %[prevX]"
173 "#4 \n\t movd %%mm0,%%esi"
174 "#3 \n\t punpcklbw %%mm5, %%mm3"
175 "#4 \n\t addl %%esi, %%eax"
176 "#3 \n\t movq %%mm3, %%mm4"
177 "#3 \n\t movq %%mm3, %%mm5"
178 "#4 \n\t movl %[expix1], %%esi"
179 "#3 \n\t punpcklbw %%mm5, %%mm3"
180 "#4 \n\t movq (%%esi,%%eax,4),%%mm0"
181 "#3 \n\t punpckhbw %%mm5, %%mm4"
182 "#4 \n\t addl %[prevX],%%eax"
183 "#4 \n\t movq (%%esi,%%eax,4),%%mm2"::[expix1] "g" (expix1)
185 :"eax", "esi", "edx");
188 * pre : mm0 : expix1[position]
189 * mm2 : expix1[position+largeur]
193 /* recopie des deux premiers pixels dans mm0 et mm1 */
194 movq_r2r (mm0, mm1); /* b1-v1-r1-a1-b2-v2-r2-a2 */
196 /* depackage du premier pixel */
197 punpcklbw_r2r (mm7, mm0); /* 00-b2-00-v2-00-r2-00-a2 */
199 /* extraction des coefficients... */
201 movq_r2r (mm3, mm5); /* c2-c2-c2-c2-c1-c1-c1-c1 */
203 /*^en parrallele^ *//* depackage du 2ieme pixel */
204 /*^ */ punpckhbw_r2r (mm7, mm1);
205 /* 00-b1-00-v1-00-r1-00-a1 */
207 punpcklbw_r2r (mm7, mm5); /* 00-c1-00-c1-00-c1-00-c1 */
208 punpckhbw_r2r (mm7, mm3); /* 00-c2-00-c2-00-c2-00-c2 */
210 /* multiplication des pixels par les coefficients */
211 pmullw_r2r (mm5, mm0); /* c1*b2-c1*v2-c1*r2-c1*a2 */
212 pmullw_r2r (mm3, mm1); /* c2*b1-c2*v1-c2*r1-c2*a1 */
213 paddw_r2r (mm1, mm0);
215 /* ...extraction des 2 derniers coefficients */
216 movq_r2r (mm4, mm5); /* c4-c4-c4-c4-c3-c3-c3-c3 */
217 punpcklbw_r2r (mm7, mm4); /* 00-c3-00-c3-00-c3-00-c3 */
218 punpckhbw_r2r (mm7, mm5); /* 00-c4-00-c4-00-c4-00-c4 */
220 /* recuperation des 2 derniers pixels */
223 /* depackage des pixels */
224 punpcklbw_r2r (mm7, mm1);
225 punpckhbw_r2r (mm7, mm2);
227 /* multiplication pas les coeffs */
228 pmullw_r2r (mm4, mm1);
229 pmullw_r2r (mm5, mm2);
231 /* ajout des valeurs obtenues � la valeur finale */
232 paddw_r2r (mm1, mm0);
233 paddw_r2r (mm2, mm0);
235 /* division par 256 = 16+16+16+16, puis repackage du pixel final */
237 packuswb_r2r (mm7, mm0);
239 movd_r2m (mm0, expix2[loop]);
243 /* this was femms, which is AMD 3dnow */
244 __asm__ __volatile__ ("emms\n");
247 #define DRAWMETHOD_PLUS_XMMX(_out,_backbuf,_col) \
249 movd_m2r(_backbuf, mm0); \
250 paddusb_m2r(_col, mm0); \
251 movd_r2m(mm0, _out); \
254 #define DRAWMETHOD DRAWMETHOD_PLUS_XMMX(*p,*p,col)
257 draw_line_xmmx (Pixel * data, int x1, int y1, int x2, int y2, int col,
258 int screenx, int screeny)
260 int x, y, dx, dy, yy, xx;
263 if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny)
264 || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx))
285 p = &(data[(screenx * y1) + x1]);
286 for (y = y1; y <= y2; y++) {
291 p = &(data[(screenx * y2) + x1]);
292 for (y = y2; y <= y1; y++) {
299 /* horizontal line */
302 p = &(data[(screenx * y1) + x1]);
303 for (x = x1; x <= x2; x++) {
309 p = &(data[(screenx * y1) + x2]);
310 for (x = x2; x <= x1; x++) {
324 dx = ((dx << 16) / dy);
326 for (y = y1; y <= y2; y++) {
328 p = &(data[(screenx * y) + xx]);
330 if (xx < (screenx - 1)) {
340 dy = ((dy << 16) / dx);
342 for (x = x1; x <= x2; x++) {
344 p = &(data[(screenx * yy) + x]);
346 if (yy < (screeny - 1)) {
361 dx = ((dx << 16) / -dy);
363 for (y = y1; y >= y2; y--) {
365 p = &(data[(screenx * y) + xx]);
367 if (xx < (screenx - 1)) {
377 dy = ((dy << 16) / dx);
379 for (x = x1; x <= x2; x++) {
381 p = &(data[(screenx * yy) + x]);
383 if (yy < (screeny - 1)) {
393 /* this was femms, which is AMD 3dnow */
394 __asm__ __volatile__ ("emms\n");
398 xmmx_supported (void)