3 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 mmx_ok() to work; this can be done by
8 simply using -O on the GCC command line.
10 Compiling with -DMMX_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.
20 1997-99 by H. Dietz and R. Fisher
23 It appears that the latest gas has the pand problem fixed, therefore
24 I'll undefine BROKEN_PAND by default.
31 #include "goom_config.h"
35 #define BUFFPOINTNB 16
36 #define BUFFPOINTMASK 0xffff
40 #include "goom_graphic.h"
43 // faire : a % sqrtperte <=> a & pertemask
45 // faire : a / sqrtperte <=> a >> PERTEDEC
51 return (mm_support () & 0x1);
55 zoom_filter_mmx (int prevX, int prevY,
56 Pixel * expix1, Pixel * expix2,
57 int *brutS, int *brutD, int buffratio, int precalCoef[16][16])
59 unsigned int ax = (prevX - 1) << PERTEDEC, ay = (prevY - 1) << PERTEDEC;
61 int bufsize = prevX * prevY;
64 __asm__ __volatile__ ("pxor %mm7,%mm7");
66 for (loop = 0; loop < bufsize; loop++) {
72 int myPos = loop << 1, myPos2 = myPos + 1;
73 int brutSmypos = brutS[myPos];
75 px = brutSmypos + (((brutD[myPos] -
76 brutSmypos) * buffratio) >> BUFFPOINTNB);
77 brutSmypos = brutS[myPos2];
78 py = brutSmypos + (((brutD[myPos2] -
79 brutSmypos) * buffratio) >> BUFFPOINTNB);
81 if ((py >= ay) || (px >= ax)) {
84 pos = ((px >> PERTEDEC) + prevX * (py >> PERTEDEC));
86 coeffs = precalCoef[px & PERTEMASK][py & PERTEMASK];
89 __asm__ __volatile__ ("movd %2, %%mm6 \n\t"
90 /* recuperation des deux premiers pixels dans mm0 et mm1 */
91 "movq (%3,%1,4), %%mm0 \n\t" /* b1-v1-r1-a1-b2-v2-r2-a2 */
92 "movq %%mm0, %%mm1 \n\t" /* b1-v1-r1-a1-b2-v2-r2-a2 */
93 /* depackage du premier pixel */
94 "punpcklbw %%mm7, %%mm0 \n\t" /* 00-b2-00-v2-00-r2-00-a2 */
95 "movq %%mm6, %%mm5 \n\t" /* ??-??-??-??-c4-c3-c2-c1 */
96 /* depackage du 2ieme pixel */
97 "punpckhbw %%mm7, %%mm1 \n\t" /* 00-b1-00-v1-00-r1-00-a1 */
98 /* extraction des coefficients... */
99 "punpcklbw %%mm5, %%mm6 \n\t" /* c4-c4-c3-c3-c2-c2-c1-c1 */
100 "movq %%mm6, %%mm4 \n\t" /* c4-c4-c3-c3-c2-c2-c1-c1 */
101 "movq %%mm6, %%mm5 \n\t" /* c4-c4-c3-c3-c2-c2-c1-c1 */
102 "punpcklbw %%mm5, %%mm6 \n\t" /* c2-c2-c2-c2-c1-c1-c1-c1 */
103 "punpckhbw %%mm5, %%mm4 \n\t" /* c4-c4-c4-c4-c3-c3-c3-c3 */
104 "movq %%mm6, %%mm3 \n\t" /* c2-c2-c2-c2-c1-c1-c1-c1 */
105 "punpcklbw %%mm7, %%mm6 \n\t" /* 00-c1-00-c1-00-c1-00-c1 */
106 "punpckhbw %%mm7, %%mm3 \n\t" /* 00-c2-00-c2-00-c2-00-c2 */
107 /* multiplication des pixels par les coefficients */
108 "pmullw %%mm6, %%mm0 \n\t" /* c1*b2-c1*v2-c1*r2-c1*a2 */
109 "pmullw %%mm3, %%mm1 \n\t" /* c2*b1-c2*v1-c2*r1-c2*a1 */
110 "paddw %%mm1, %%mm0 \n\t"
111 /* ...extraction des 2 derniers coefficients */
112 "movq %%mm4, %%mm5 \n\t" /* c4-c4-c4-c4-c3-c3-c3-c3 */
113 "punpcklbw %%mm7, %%mm4 \n\t" /* 00-c3-00-c3-00-c3-00-c3 */
114 "punpckhbw %%mm7, %%mm5 \n\t" /* 00-c4-00-c4-00-c4-00-c4 */
115 /* ajouter la longueur de ligne a esi */
116 "addl 8(%%ebp),%1 \n\t"
117 /* recuperation des 2 derniers pixels */
118 "movq (%3,%1,4), %%mm1 \n\t" "movq %%mm1, %%mm2 \n\t"
119 /* depackage des pixels */
120 "punpcklbw %%mm7, %%mm1 \n\t" "punpckhbw %%mm7, %%mm2 \n\t"
121 /* multiplication pas les coeffs */
122 "pmullw %%mm4, %%mm1 \n\t" "pmullw %%mm5, %%mm2 \n\t"
123 /* ajout des valeurs obtenues ? la valeur finale */
124 "paddw %%mm1, %%mm0 \n\t" "paddw %%mm2, %%mm0 \n\t"
125 /* division par 256 = 16+16+16+16, puis repackage du pixel final */
126 "psrlw $8, %%mm0 \n\t"
127 "packuswb %%mm7, %%mm0 \n\t" "movd %%mm0,%0 \n\t":"=g" (expix2[loop])
128 :"r" (pos), "r" (coeffs), "r" (expix1)
136 #define DRAWMETHOD_PLUS_MMX(_out,_backbuf,_col) \
138 movd_m2r(_backbuf, mm0); \
139 paddusb_m2r(_col, mm0); \
140 movd_r2m(mm0, _out); \
143 #define DRAWMETHOD DRAWMETHOD_PLUS_MMX(*p,*p,col)
146 draw_line_mmx (Pixel * data, int x1, int y1, int x2, int y2, int col,
147 int screenx, int screeny)
149 int x, y, dx, dy, yy, xx;
152 if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny)
153 || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx))
174 p = &(data[(screenx * y1) + x1]);
175 for (y = y1; y <= y2; y++) {
180 p = &(data[(screenx * y2) + x1]);
181 for (y = y2; y <= y1; y++) {
188 /* horizontal line */
191 p = &(data[(screenx * y1) + x1]);
192 for (x = x1; x <= x2; x++) {
198 p = &(data[(screenx * y1) + x2]);
199 for (x = x2; x <= x1; x++) {
213 dx = ((dx << 16) / dy);
215 for (y = y1; y <= y2; y++) {
217 p = &(data[(screenx * y) + xx]);
219 if (xx < (screenx - 1)) {
229 dy = ((dy << 16) / dx);
231 for (x = x1; x <= x2; x++) {
233 p = &(data[(screenx * yy) + x]);
235 if (yy < (screeny - 1)) {
250 dx = ((dx << 16) / -dy);
252 for (y = y1; y >= y2; y--) {
254 p = &(data[(screenx * y) + xx]);
256 if (xx < (screenx - 1)) {
266 dy = ((dy << 16) / dx);
268 for (x = x1; x <= x2; x++) {
270 p = &(data[(screenx * yy) + x]);
272 if (yy < (screeny - 1)) {
283 /* __asm__ __volatile__ ("emms"); */
291 #endif /* HAVE_MMX */