Fix PowerPC related typo in spantmp2.h
[mesa.git] / src / mesa / drivers / dri / common / spantmp2.h
1 /*
2 * Copyright 2000-2001 VA Linux Systems, Inc.
3 * (C) Copyright IBM Corporation 2004
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file spantmp2.h
28 *
29 * Template file of span read / write functions.
30 *
31 * \author Keith Whitwell <keithw@tungstengraphics.com>
32 * \author Gareth Hughes <gareth@nvidia.com>
33 * \author Ian Romanick <idr@us.ibm.com>
34 */
35
36 #include "main/colormac.h"
37 #include "spantmp_common.h"
38
39 #ifndef DBG
40 #define DBG 0
41 #endif
42
43 #ifndef HW_READ_CLIPLOOP
44 #define HW_READ_CLIPLOOP() HW_CLIPLOOP()
45 #endif
46
47 #ifndef HW_WRITE_CLIPLOOP
48 #define HW_WRITE_CLIPLOOP() HW_CLIPLOOP()
49 #endif
50
51 #if (SPANTMP_PIXEL_FMT == GL_RGB) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)
52
53 /**
54 ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5
55 **/
56
57 #ifndef GET_VALUE
58 #ifndef GET_PTR
59 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
60 #endif
61
62 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
63 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
64 #endif /* GET_VALUE */
65
66 #define INIT_MONO_PIXEL(p, color) \
67 p = PACK_COLOR_565( color[0], color[1], color[2] )
68
69 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
70 PUT_VALUE(_x, _y, ((((int)r & 0xf8) << 8) | \
71 (((int)g & 0xfc) << 3) | \
72 (((int)b & 0xf8) >> 3))) \
73
74 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
75
76 #define READ_RGBA( rgba, _x, _y ) \
77 do { \
78 GLushort p = GET_VALUE(_x, _y); \
79 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
80 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
81 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
82 rgba[3] = 0xff; \
83 } while (0)
84
85 #elif (SPANTMP_PIXEL_FMT == GL_RGB) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5_REV)
86
87 /**
88 ** GL_RGB, GL_UNSIGNED_SHORT_5_6_5_REV
89 **/
90
91 #ifndef GET_VALUE
92 #ifndef GET_PTR
93 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
94 #endif
95
96 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
97 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
98 #endif /* GET_VALUE */
99
100 #define INIT_MONO_PIXEL(p, color) \
101 p = PACK_COLOR_565_REV( color[0], color[1], color[2] )
102
103 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
104 PUT_VALUE(_x, _y, PACK_COLOR_565_REV( r, g, b ))
105
106 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
107
108 #define READ_RGBA( rgba, _x, _y ) \
109 do { \
110 GLushort p = GET_VALUE(_x, _y); \
111 p = p << 8 | p >> 8; \
112 rgba[0] = ((p >> 8) & 0xf8) * 255 / 0xf8; \
113 rgba[1] = ((p >> 3) & 0xfc) * 255 / 0xfc; \
114 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
115 rgba[3] = 0xff; \
116 } while (0)
117
118 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4)
119
120 /**
121 ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4
122 **/
123
124 #ifndef GET_VALUE
125 #ifndef GET_PTR
126 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
127 #endif
128
129 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
130 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
131 #endif /* GET_VALUE */
132
133 #define INIT_MONO_PIXEL(p, color) \
134 p = PACK_COLOR_4444_REV(color[3], color[0], color[1], color[2])
135
136 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
137 PUT_VALUE(_x, _y, PACK_COLOR_4444_REV(a, r, g, b)) \
138
139 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
140
141 #define READ_RGBA( rgba, _x, _y ) \
142 do { \
143 GLushort p = GET_VALUE(_x, _y); \
144 rgba[0] = ((p >> 0) & 0xf) * 0x11; \
145 rgba[1] = ((p >> 12) & 0xf) * 0x11; \
146 rgba[2] = ((p >> 4) & 0xf) * 0x11; \
147 rgba[3] = ((p >> 8) & 0xf) * 0x11; \
148 } while (0)
149
150
151 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_4_4_4_4_REV)
152
153 /**
154 ** GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV
155 **/
156
157 #ifndef GET_VALUE
158 #ifndef GET_PTR
159 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
160 #endif
161
162 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
163 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
164 #endif /* GET_VALUE */
165
166 #define INIT_MONO_PIXEL(p, color) \
167 p = PACK_COLOR_4444(color[3], color[0], color[1], color[2])
168
169 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
170 PUT_VALUE(_x, _y, PACK_COLOR_4444(a, r, g, b)) \
171
172 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
173
174 #define READ_RGBA( rgba, _x, _y ) \
175 do { \
176 GLushort p = GET_VALUE(_x, _y); \
177 rgba[0] = ((p >> 8) & 0xf) * 0x11; \
178 rgba[1] = ((p >> 4) & 0xf) * 0x11; \
179 rgba[2] = ((p >> 0) & 0xf) * 0x11; \
180 rgba[3] = ((p >> 12) & 0xf) * 0x11; \
181 } while (0)
182
183
184 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5_REV)
185
186 /**
187 ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV
188 **/
189
190 #ifndef GET_VALUE
191 #ifndef GET_PTR
192 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
193 #endif
194
195 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
196 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
197 #endif /* GET_VALUE */
198
199 #define INIT_MONO_PIXEL(p, color) \
200 p = PACK_COLOR_1555(color[3], color[0], color[1], color[2])
201
202 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
203 PUT_VALUE(_x, _y, PACK_COLOR_1555(a, r, g, b)) \
204
205 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
206
207 #define READ_RGBA( rgba, _x, _y ) \
208 do { \
209 GLushort p = GET_VALUE(_x, _y); \
210 rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8; \
211 rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8; \
212 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
213 rgba[3] = ((p >> 15) & 0x1) * 0xff; \
214 } while (0)
215
216 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_1_5_5_5)
217
218 /**
219 ** GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5
220 **/
221
222 #ifndef GET_VALUE
223 #ifndef GET_PTR
224 #define GET_PTR(_x, _y) (buf + (_x) * 2 + (_y) * pitch)
225 #endif
226
227 #define GET_VALUE(_x, _y) *(volatile GLushort *)(GET_PTR(_x, _y))
228 #define PUT_VALUE(_x, _y, _v) *(volatile GLushort *)(GET_PTR(_x, _y)) = (_v)
229 #endif /* GET_VALUE */
230
231 #define INIT_MONO_PIXEL(p, color) \
232 p = PACK_COLOR_1555_REV(color[3], color[0], color[1], color[2])
233
234 #define WRITE_RGBA( _x, _y, r, g, b, a ) \
235 PUT_VALUE(_x, _y, PACK_COLOR_1555_REV(a, r, g, b)) \
236
237 #define WRITE_PIXEL( _x, _y, p ) PUT_VALUE(_x, _y, p)
238
239 #define READ_RGBA( rgba, _x, _y ) \
240 do { \
241 GLushort p = GET_VALUE(_x, _y); \
242 p = p << 8 | p >> 8; \
243 rgba[0] = ((p >> 7) & 0xf8) * 255 / 0xf8; \
244 rgba[1] = ((p >> 2) & 0xf8) * 255 / 0xf8; \
245 rgba[2] = ((p << 3) & 0xf8) * 255 / 0xf8; \
246 rgba[3] = ((p >> 15) & 0x1) * 0xff; \
247 } while (0)
248
249 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
250
251 /**
252 ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV
253 **/
254
255 #ifndef GET_VALUE
256 #ifndef GET_PTR
257 #define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch)
258 #endif
259
260 #define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
261 #define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
262 #endif /* GET_VALUE */
263
264 # define INIT_MONO_PIXEL(p, color) \
265 p = PACK_COLOR_8888(color[3], color[0], color[1], color[2])
266
267 # define WRITE_RGBA(_x, _y, r, g, b, a) \
268 PUT_VALUE(_x, _y, ((r << 16) | \
269 (g << 8) | \
270 (b << 0) | \
271 (a << 24)))
272
273 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
274
275 # if defined( USE_X86_ASM )
276 # define READ_RGBA(rgba, _x, _y) \
277 do { \
278 GLuint p = GET_VALUE(_x, _y); \
279 __asm__ __volatile__( "bswap %0; rorl $8, %0" \
280 : "=r" (p) : "0" (p) ); \
281 ((GLuint *)rgba)[0] = p; \
282 } while (0)
283 # elif defined( MESA_BIG_ENDIAN )
284 /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
285 * rotlwi instruction. It also produces good code on SPARC.
286 */
287 # define READ_RGBA( rgba, _x, _y ) \
288 do { \
289 GLuint p = GET_VALUE(_x, _y); \
290 GLuint t = p; \
291 *((uint32_t *) rgba) = (t >> 24) | (p << 8); \
292 } while (0)
293 # else
294 # define READ_RGBA( rgba, _x, _y ) \
295 do { \
296 GLuint p = GET_VALUE(_x, _y); \
297 rgba[0] = (p >> 16) & 0xff; \
298 rgba[1] = (p >> 8) & 0xff; \
299 rgba[2] = (p >> 0) & 0xff; \
300 rgba[3] = (p >> 24) & 0xff; \
301 } while (0)
302 # endif
303
304 #elif (SPANTMP_PIXEL_FMT == GL_BGRA) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8)
305
306 /**
307 ** GL_BGRA, GL_UNSIGNED_INT_8_8_8_8
308 **/
309
310 #ifndef GET_VALUE
311 #ifndef GET_PTR
312 #define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch)
313 #endif
314
315 #define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
316 #define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
317 #endif /* GET_VALUE */
318
319 # define INIT_MONO_PIXEL(p, color) \
320 p = PACK_COLOR_8888(color[2], color[1], color[0], color[3])
321
322 # define WRITE_RGBA(_x, _y, r, g, b, a) \
323 PUT_VALUE(_x, _y, ((r << 8) | \
324 (g << 16) | \
325 (b << 24) | \
326 (a << 0)))
327
328 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
329
330 # if defined( USE_X86_ASM )
331 # define READ_RGBA(rgba, _x, _y) \
332 do { \
333 GLuint p = GET_VALUE(_x, _y); \
334 __asm__ __volatile__( "rorl $8, %0" \
335 : "=r" (p) : "0" (p) ); \
336 ((GLuint *)rgba)[0] = p; \
337 } while (0)
338 # elif defined( MESA_BIG_ENDIAN )
339 /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
340 * rotlwi instruction. It also produces good code on SPARC.
341 */
342 # define READ_RGBA( rgba, _x, _y ) \
343 do { \
344 GLuint p = CPU_TO_LE32(GET_VALUE(_x, _y)); \
345 GLuint t = p; \
346 *((uint32_t *) rgba) = (t >> 24) | (p << 8); \
347 } while (0)
348 # else
349 # define READ_RGBA( rgba, _x, _y ) \
350 do { \
351 GLuint p = GET_VALUE(_x, _y); \
352 rgba[0] = (p >> 8) & 0xff; \
353 rgba[1] = (p >> 16) & 0xff; \
354 rgba[2] = (p >> 24) & 0xff; \
355 rgba[3] = (p >> 0) & 0xff; \
356 } while (0)
357 # endif
358
359 #elif (SPANTMP_PIXEL_FMT == GL_BGR) && (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
360
361 /**
362 ** GL_BGR, GL_UNSIGNED_INT_8_8_8_8_REV
363 **
364 ** This is really for MESA_FORMAT_XRGB8888. The spantmp code needs to be
365 ** kicked to the curb, and we need to just code-gen this.
366 **/
367
368 #ifndef GET_VALUE
369 #ifndef GET_PTR
370 #define GET_PTR(_x, _y) ( buf + (_x) * 4 + (_y) * pitch)
371 #endif
372
373 #define GET_VALUE(_x, _y) *(volatile GLuint *)(GET_PTR(_x, _y))
374 #define PUT_VALUE(_x, _y, _v) *(volatile GLuint *)(GET_PTR(_x, _y)) = (_v)
375 #endif /* GET_VALUE */
376
377 # define INIT_MONO_PIXEL(p, color) \
378 p = PACK_COLOR_8888(0xff, color[0], color[1], color[2])
379
380 # define WRITE_RGBA(_x, _y, r, g, b, a) \
381 PUT_VALUE(_x, _y, ((r << 16) | \
382 (g << 8) | \
383 (b << 0) | \
384 (0xff << 24)))
385
386 #define WRITE_PIXEL(_x, _y, p) PUT_VALUE(_x, _y, p)
387
388 # if defined( USE_X86_ASM )
389 # define READ_RGBA(rgba, _x, _y) \
390 do { \
391 GLuint p = GET_VALUE(_x, _y); \
392 __asm__ __volatile__( "bswap %0; rorl $8, %0" \
393 : "=r" (p) : "0" (p) ); \
394 ((GLuint *)rgba)[0] = p | 0xff000000; \
395 } while (0)
396 # elif defined( MESA_BIG_ENDIAN )
397 /* On PowerPC with GCC 3.4.2 the shift madness below becomes a single
398 * rotlwi instruction. It also produces good code on SPARC.
399 */
400 # define READ_RGBA( rgba, _x, _y ) \
401 do { \
402 GLuint p = GET_VALUE(_x, _y); \
403 *((uint32_t *) rgba) = (p << 8) | 0xff; \
404 } while (0)
405 # else
406 # define READ_RGBA( rgba, _x, _y ) \
407 do { \
408 GLuint p = GET_VALUE(_x, _y); \
409 rgba[0] = (p >> 16) & 0xff; \
410 rgba[1] = (p >> 8) & 0xff; \
411 rgba[2] = (p >> 0) & 0xff; \
412 rgba[3] = 0xff; \
413 } while (0)
414 # endif
415
416 #else
417 #error SPANTMP_PIXEL_FMT must be set to a valid value!
418 #endif
419
420
421
422 /**
423 ** Assembly routines.
424 **/
425
426 #if defined( USE_MMX_ASM ) || defined( USE_SSE_ASM )
427 #include "x86/read_rgba_span_x86.h"
428 #include "x86/common_x86_asm.h"
429 #endif
430
431 static void TAG(WriteRGBASpan)( GLcontext *ctx,
432 struct gl_renderbuffer *rb,
433 GLuint n, GLint x, GLint y,
434 const void *values, const GLubyte mask[] )
435 {
436 HW_WRITE_LOCK()
437 {
438 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
439 GLint x1;
440 GLint n1;
441 LOCAL_VARS;
442
443 y = Y_FLIP(y);
444
445 HW_WRITE_CLIPLOOP()
446 {
447 GLint i = 0;
448 CLIPSPAN(x,y,n,x1,n1,i);
449
450 if (DBG) fprintf(stderr, "WriteRGBASpan %d..%d (x1 %d)\n",
451 (int)i, (int)n1, (int)x1);
452
453 if (mask)
454 {
455 for (;n1>0;i++,x1++,n1--)
456 if (mask[i])
457 WRITE_RGBA( x1, y,
458 rgba[i][0], rgba[i][1],
459 rgba[i][2], rgba[i][3] );
460 }
461 else
462 {
463 for (;n1>0;i++,x1++,n1--)
464 WRITE_RGBA( x1, y,
465 rgba[i][0], rgba[i][1],
466 rgba[i][2], rgba[i][3] );
467 }
468 }
469 HW_ENDCLIPLOOP();
470 }
471 HW_WRITE_UNLOCK();
472 }
473
474 static void TAG(WriteRGBSpan)( GLcontext *ctx,
475 struct gl_renderbuffer *rb,
476 GLuint n, GLint x, GLint y,
477 const void *values, const GLubyte mask[] )
478 {
479 HW_WRITE_LOCK()
480 {
481 const GLubyte (*rgb)[3] = (const GLubyte (*)[3]) values;
482 GLint x1;
483 GLint n1;
484 LOCAL_VARS;
485
486 y = Y_FLIP(y);
487
488 HW_WRITE_CLIPLOOP()
489 {
490 GLint i = 0;
491 CLIPSPAN(x,y,n,x1,n1,i);
492
493 if (DBG) fprintf(stderr, "WriteRGBSpan %d..%d (x1 %d)\n",
494 (int)i, (int)n1, (int)x1);
495
496 if (mask)
497 {
498 for (;n1>0;i++,x1++,n1--)
499 if (mask[i])
500 WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
501 }
502 else
503 {
504 for (;n1>0;i++,x1++,n1--)
505 WRITE_RGBA( x1, y, rgb[i][0], rgb[i][1], rgb[i][2], 255 );
506 }
507 }
508 HW_ENDCLIPLOOP();
509 }
510 HW_WRITE_UNLOCK();
511 }
512
513 static void TAG(WriteRGBAPixels)( GLcontext *ctx,
514 struct gl_renderbuffer *rb,
515 GLuint n, const GLint x[], const GLint y[],
516 const void *values, const GLubyte mask[] )
517 {
518 HW_WRITE_LOCK()
519 {
520 const GLubyte (*rgba)[4] = (const GLubyte (*)[4]) values;
521 GLint i;
522 LOCAL_VARS;
523
524 if (DBG) fprintf(stderr, "WriteRGBAPixels\n");
525
526 HW_WRITE_CLIPLOOP()
527 {
528 if (mask)
529 {
530 for (i=0;i<n;i++)
531 {
532 if (mask[i]) {
533 const int fy = Y_FLIP(y[i]);
534 if (CLIPPIXEL(x[i],fy))
535 WRITE_RGBA( x[i], fy,
536 rgba[i][0], rgba[i][1],
537 rgba[i][2], rgba[i][3] );
538 }
539 }
540 }
541 else
542 {
543 for (i=0;i<n;i++)
544 {
545 const int fy = Y_FLIP(y[i]);
546 if (CLIPPIXEL(x[i],fy))
547 WRITE_RGBA( x[i], fy,
548 rgba[i][0], rgba[i][1],
549 rgba[i][2], rgba[i][3] );
550 }
551 }
552 }
553 HW_ENDCLIPLOOP();
554 }
555 HW_WRITE_UNLOCK();
556 }
557
558
559 static void TAG(WriteMonoRGBASpan)( GLcontext *ctx,
560 struct gl_renderbuffer *rb,
561 GLuint n, GLint x, GLint y,
562 const void *value, const GLubyte mask[] )
563 {
564 HW_WRITE_LOCK()
565 {
566 const GLubyte *color = (const GLubyte *) value;
567 GLint x1;
568 GLint n1;
569 LOCAL_VARS;
570 INIT_MONO_PIXEL(p, color);
571
572 y = Y_FLIP( y );
573
574 if (DBG) fprintf(stderr, "WriteMonoRGBASpan\n");
575
576 HW_WRITE_CLIPLOOP()
577 {
578 GLint i = 0;
579 CLIPSPAN(x,y,n,x1,n1,i);
580 if (mask)
581 {
582 for (;n1>0;i++,x1++,n1--)
583 if (mask[i])
584 WRITE_PIXEL( x1, y, p );
585 }
586 else
587 {
588 for (;n1>0;i++,x1++,n1--)
589 WRITE_PIXEL( x1, y, p );
590 }
591 }
592 HW_ENDCLIPLOOP();
593 }
594 HW_WRITE_UNLOCK();
595 }
596
597
598 static void TAG(WriteMonoRGBAPixels)( GLcontext *ctx,
599 struct gl_renderbuffer *rb,
600 GLuint n,
601 const GLint x[], const GLint y[],
602 const void *value,
603 const GLubyte mask[] )
604 {
605 HW_WRITE_LOCK()
606 {
607 const GLubyte *color = (const GLubyte *) value;
608 GLint i;
609 LOCAL_VARS;
610 INIT_MONO_PIXEL(p, color);
611
612 if (DBG) fprintf(stderr, "WriteMonoRGBAPixels\n");
613
614 HW_WRITE_CLIPLOOP()
615 {
616 if (mask)
617 {
618 for (i=0;i<n;i++)
619 if (mask[i]) {
620 int fy = Y_FLIP(y[i]);
621 if (CLIPPIXEL( x[i], fy ))
622 WRITE_PIXEL( x[i], fy, p );
623 }
624 }
625 else
626 {
627 for (i=0;i<n;i++) {
628 int fy = Y_FLIP(y[i]);
629 if (CLIPPIXEL( x[i], fy ))
630 WRITE_PIXEL( x[i], fy, p );
631 }
632 }
633 }
634 HW_ENDCLIPLOOP();
635 }
636 HW_WRITE_UNLOCK();
637 }
638
639
640 static void TAG(ReadRGBASpan)( GLcontext *ctx,
641 struct gl_renderbuffer *rb,
642 GLuint n, GLint x, GLint y, void *values)
643 {
644 HW_READ_LOCK()
645 {
646 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
647 GLint x1,n1;
648 LOCAL_VARS;
649
650 y = Y_FLIP(y);
651
652 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
653
654 HW_READ_CLIPLOOP()
655 {
656 GLint i = 0;
657 CLIPSPAN(x,y,n,x1,n1,i);
658 for (;n1>0;i++,x1++,n1--)
659 READ_RGBA( rgba[i], x1, y );
660 }
661 HW_ENDCLIPLOOP();
662 }
663 HW_READ_UNLOCK();
664 }
665
666
667 #if defined(GET_PTR) && \
668 defined(USE_MMX_ASM) && \
669 (((SPANTMP_PIXEL_FMT == GL_BGRA) && \
670 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \
671 ((SPANTMP_PIXEL_FMT == GL_RGB) && \
672 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
673 static void TAG2(ReadRGBASpan,_MMX)( GLcontext *ctx,
674 struct gl_renderbuffer *rb,
675 GLuint n, GLint x, GLint y, void *values)
676 {
677 #ifndef USE_INNER_EMMS
678 /* The EMMS instruction is directly in-lined here because using GCC's
679 * built-in _mm_empty function was found to utterly destroy performance.
680 */
681 __asm__ __volatile__( "emms" );
682 #endif
683
684 HW_READ_LOCK()
685 {
686 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
687 GLint x1,n1;
688 LOCAL_VARS;
689
690 y = Y_FLIP(y);
691
692 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
693
694 HW_READ_CLIPLOOP()
695 {
696 GLint i = 0;
697 CLIPSPAN(x,y,n,x1,n1,i);
698
699 {
700 const void * src = GET_PTR( x1, y );
701 #if (SPANTMP_PIXEL_FMT == GL_RGB) && \
702 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)
703 _generic_read_RGBA_span_RGB565_MMX( src, rgba[i], n1 );
704 #else
705 _generic_read_RGBA_span_BGRA8888_REV_MMX( src, rgba[i], n1 );
706 #endif
707 }
708 }
709 HW_ENDCLIPLOOP();
710 }
711 HW_READ_UNLOCK();
712 #ifndef USE_INNER_EMMS
713 __asm__ __volatile__( "emms" );
714 #endif
715 }
716 #endif
717
718
719 #if defined(GET_PTR) && \
720 defined(USE_SSE_ASM) && \
721 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
722 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
723 static void TAG2(ReadRGBASpan,_SSE2)( GLcontext *ctx,
724 struct gl_renderbuffer *rb,
725 GLuint n, GLint x, GLint y,
726 void *values)
727 {
728 HW_READ_LOCK()
729 {
730 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
731 GLint x1,n1;
732 LOCAL_VARS;
733
734 y = Y_FLIP(y);
735
736 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
737
738 HW_READ_CLIPLOOP()
739 {
740 GLint i = 0;
741 CLIPSPAN(x,y,n,x1,n1,i);
742
743 {
744 const void * src = GET_PTR( x1, y );
745 _generic_read_RGBA_span_BGRA8888_REV_SSE2( src, rgba[i], n1 );
746 }
747 }
748 HW_ENDCLIPLOOP();
749 }
750 HW_READ_UNLOCK();
751 }
752 #endif
753
754 #if defined(GET_PTR) && \
755 defined(USE_SSE_ASM) && \
756 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
757 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
758 static void TAG2(ReadRGBASpan,_SSE)( GLcontext *ctx,
759 struct gl_renderbuffer *rb,
760 GLuint n, GLint x, GLint y,
761 void *values)
762 {
763 #ifndef USE_INNER_EMMS
764 /* The EMMS instruction is directly in-lined here because using GCC's
765 * built-in _mm_empty function was found to utterly destroy performance.
766 */
767 __asm__ __volatile__( "emms" );
768 #endif
769
770 HW_READ_LOCK()
771 {
772 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
773 GLint x1,n1;
774 LOCAL_VARS;
775
776 y = Y_FLIP(y);
777
778 if (DBG) fprintf(stderr, "ReadRGBASpan\n");
779
780 HW_READ_CLIPLOOP()
781 {
782 GLint i = 0;
783 CLIPSPAN(x,y,n,x1,n1,i);
784
785 {
786 const void * src = GET_PTR( x1, y );
787 _generic_read_RGBA_span_BGRA8888_REV_SSE( src, rgba[i], n1 );
788 }
789 }
790 HW_ENDCLIPLOOP();
791 }
792 HW_READ_UNLOCK();
793 #ifndef USE_INNER_EMMS
794 __asm__ __volatile__( "emms" );
795 #endif
796 }
797 #endif
798
799
800 static void TAG(ReadRGBAPixels)( GLcontext *ctx,
801 struct gl_renderbuffer *rb,
802 GLuint n, const GLint x[], const GLint y[],
803 void *values )
804 {
805 HW_READ_LOCK()
806 {
807 GLubyte (*rgba)[4] = (GLubyte (*)[4]) values;
808 GLubyte *mask = NULL; /* remove someday */
809 GLint i;
810 LOCAL_VARS;
811
812 if (DBG) fprintf(stderr, "ReadRGBAPixels\n");
813
814 HW_READ_CLIPLOOP()
815 {
816 if (mask)
817 {
818 for (i=0;i<n;i++)
819 if (mask[i]) {
820 int fy = Y_FLIP( y[i] );
821 if (CLIPPIXEL( x[i], fy ))
822 READ_RGBA( rgba[i], x[i], fy );
823 }
824 }
825 else
826 {
827 for (i=0;i<n;i++) {
828 int fy = Y_FLIP( y[i] );
829 if (CLIPPIXEL( x[i], fy ))
830 READ_RGBA( rgba[i], x[i], fy );
831 }
832 }
833 }
834 HW_ENDCLIPLOOP();
835 }
836 HW_READ_UNLOCK();
837 }
838
839 static void TAG(InitPointers)(struct gl_renderbuffer *rb)
840 {
841 rb->PutRow = TAG(WriteRGBASpan);
842 rb->PutRowRGB = TAG(WriteRGBSpan);
843 rb->PutMonoRow = TAG(WriteMonoRGBASpan);
844 rb->PutValues = TAG(WriteRGBAPixels);
845 rb->PutMonoValues = TAG(WriteMonoRGBAPixels);
846 rb->GetValues = TAG(ReadRGBAPixels);
847
848 #if defined(GET_PTR)
849 #if defined(USE_SSE_ASM) && \
850 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
851 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
852 if ( cpu_has_xmm2 ) {
853 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE2" );
854 rb->GetRow = TAG2(ReadRGBASpan, _SSE2);
855 }
856 else
857 #endif
858 #if defined(USE_SSE_ASM) && \
859 (SPANTMP_PIXEL_FMT == GL_BGRA) && \
860 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)
861 if ( cpu_has_xmm ) {
862 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "SSE" );
863 rb->GetRow = TAG2(ReadRGBASpan, _SSE);
864 }
865 else
866 #endif
867 #if defined(USE_MMX_ASM) && \
868 (((SPANTMP_PIXEL_FMT == GL_BGRA) && \
869 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_INT_8_8_8_8_REV)) || \
870 ((SPANTMP_PIXEL_FMT == GL_RGB) && \
871 (SPANTMP_PIXEL_TYPE == GL_UNSIGNED_SHORT_5_6_5)))
872 if ( cpu_has_mmx ) {
873 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "MMX" );
874 rb->GetRow = TAG2(ReadRGBASpan, _MMX);
875 }
876 else
877 #endif
878 #endif /* GET_PTR */
879 {
880 if (DBG) fprintf( stderr, "Using %s version of GetRow\n", "C" );
881 rb->GetRow = TAG(ReadRGBASpan);
882 }
883
884 }
885
886
887 #undef INIT_MONO_PIXEL
888 #undef WRITE_PIXEL
889 #undef WRITE_RGBA
890 #undef READ_RGBA
891 #undef TAG
892 #undef TAG2
893 #undef GET_VALUE
894 #undef PUT_VALUE
895 #undef GET_PTR
896 #undef SPANTMP_PIXEL_FMT
897 #undef SPANTMP_PIXEL_TYPE