Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
2597 lines (2428 loc) · 88.6 KB

SDL_blit_N.c

File metadata and controls

2597 lines (2428 loc) · 88.6 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Feb 1, 2006
Feb 1, 2006
3
Copyright (C) 1997-2006 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
#include "SDL_video.h"
Feb 10, 2006
Feb 10, 2006
25
#include "SDL_endian.h"
Nov 18, 2003
Nov 18, 2003
26
#include "SDL_cpuinfo.h"
Feb 10, 2006
Feb 10, 2006
27
#include "SDL_blit.h"
Apr 26, 2001
Apr 26, 2001
28
29
30
/* Functions to blit from N-bit surfaces to other surfaces */
Feb 16, 2006
Feb 16, 2006
31
#if SDL_ALTIVEC_BLITTERS
May 17, 2006
May 17, 2006
32
33
34
#if __MWERKS__
#pragma altivec_model on
#endif
Nov 17, 2005
Nov 17, 2005
35
#ifdef HAVE_ALTIVEC_H
Oct 20, 2005
Oct 20, 2005
36
#include <altivec.h>
Nov 17, 2005
Nov 17, 2005
37
#endif
Feb 7, 2006
Feb 7, 2006
38
#define assert(X)
Feb 21, 2006
Feb 21, 2006
39
#ifdef __MACOSX__
Apr 17, 2005
Apr 17, 2005
40
#include <sys/sysctl.h>
May 28, 2006
May 28, 2006
41
static size_t
May 29, 2006
May 29, 2006
42
GetL3CacheSize(void)
Apr 17, 2005
Apr 17, 2005
43
44
45
{
const char key[] = "hw.l3cachesize";
u_int64_t result = 0;
May 29, 2006
May 29, 2006
46
size_t typeSize = sizeof(result);
Apr 17, 2005
Apr 17, 2005
47
48
May 29, 2006
May 29, 2006
49
int err = sysctlbyname(key, &result, &typeSize, NULL, 0);
May 28, 2006
May 28, 2006
50
51
if (0 != err)
return 0;
Apr 17, 2005
Apr 17, 2005
52
53
54
55
return result;
}
#else
May 28, 2006
May 28, 2006
56
static size_t
May 29, 2006
May 29, 2006
57
GetL3CacheSize(void)
Apr 17, 2005
Apr 17, 2005
58
59
60
61
{
/* XXX: Just guess G4 */
return 2097152;
}
Feb 21, 2006
Feb 21, 2006
62
#endif /* __MACOSX__ */
Apr 17, 2005
Apr 17, 2005
63
Feb 21, 2006
Feb 21, 2006
64
#if (defined(__MACOSX__) && (__GNUC__ < 4))
May 28, 2006
May 28, 2006
65
#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
Oct 20, 2005
Oct 20, 2005
66
(vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
May 28, 2006
May 28, 2006
67
#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
Oct 20, 2005
Oct 20, 2005
68
69
(vector unsigned short) ( a,b,c,d,e,f,g,h )
#else
May 28, 2006
May 28, 2006
70
#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
Oct 20, 2005
Oct 20, 2005
71
(vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
May 28, 2006
May 28, 2006
72
#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
Oct 20, 2005
Oct 20, 2005
73
74
75
(vector unsigned short) { a,b,c,d,e,f,g,h }
#endif
Apr 17, 2005
Apr 17, 2005
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
#define VSWIZZLE32(a,b,c,d) (vector unsigned char) \
( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \
0x04+a, 0x04+b, 0x04+c, 0x04+d, \
0x08+a, 0x08+b, 0x08+c, 0x08+d, \
0x0C+a, 0x0C+b, 0x0C+c, 0x0C+d )
#define MAKE8888(dstfmt, r, g, b, a) \
( ((r<<dstfmt->Rshift)&dstfmt->Rmask) | \
((g<<dstfmt->Gshift)&dstfmt->Gmask) | \
((b<<dstfmt->Bshift)&dstfmt->Bmask) | \
((a<<dstfmt->Ashift)&dstfmt->Amask) )
/*
* Data Stream Touch...Altivec cache prefetching.
*
* Don't use this on a G5...however, the speed boost is very significant
* on a G4.
*/
#define DST_CHAN_SRC 1
#define DST_CHAN_DEST 2
/* macro to set DST control word value... */
#define DST_CTRL(size, count, stride) \
(((size) << 24) | ((count) << 16) | (stride))
#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
? vec_lvsl(0, src) \
: vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
/* Calculate the permute vector used for 32->32 swizzling */
May 28, 2006
May 28, 2006
107
static vector unsigned char
May 29, 2006
May 29, 2006
108
calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt)
Apr 17, 2005
Apr 17, 2005
109
110
{
/*
May 28, 2006
May 28, 2006
111
* We have to assume that the bits that aren't used by other
Apr 17, 2005
Apr 17, 2005
112
113
114
115
116
117
118
119
120
* colors is alpha, and it's one complete byte, since some formats
* leave alpha with a zero mask, but we should still swizzle the bits.
*/
/* ARGB */
const static struct SDL_PixelFormat default_pixel_format = {
NULL, 0, 0,
0, 0, 0, 0,
16, 8, 0, 24,
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000,
May 28, 2006
May 28, 2006
121
122
0, 0
};
Apr 17, 2005
Apr 17, 2005
123
124
125
126
127
128
if (!srcfmt) {
srcfmt = &default_pixel_format;
}
if (!dstfmt) {
dstfmt = &default_pixel_format;
}
May 29, 2006
May 29, 2006
129
130
131
132
133
const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00,
0x04, 0x04, 0x04, 0x04,
0x08, 0x08, 0x08, 0x08,
0x0C, 0x0C, 0x0C,
0x0C);
Apr 17, 2005
Apr 17, 2005
134
135
136
vector unsigned char vswiz;
vector unsigned int srcvec;
#define RESHIFT(X) (3 - ((X) >> 3))
May 29, 2006
May 29, 2006
137
138
139
Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
Apr 17, 2005
Apr 17, 2005
140
141
142
Uint32 amask;
/* Use zero for alpha if either surface doesn't have alpha */
if (dstfmt->Amask) {
May 28, 2006
May 28, 2006
143
amask =
May 29, 2006
May 29, 2006
144
145
((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->
Ashift);
May 28, 2006
May 28, 2006
146
147
148
149
150
151
152
} else {
amask =
0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
0xFFFFFFFF);
}
#undef RESHIFT
((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask);
May 29, 2006
May 29, 2006
153
vswiz = vec_add(plus, (vector unsigned char) vec_splat(srcvec, 0));
May 28, 2006
May 28, 2006
154
return (vswiz);
Apr 17, 2005
Apr 17, 2005
155
156
}
May 29, 2006
May 29, 2006
157
static void Blit_RGB888_RGB565(SDL_BlitInfo * info);
May 28, 2006
May 28, 2006
158
static void
May 29, 2006
May 29, 2006
159
Blit_RGB888_RGB565Altivec(SDL_BlitInfo * info)
May 28, 2006
May 28, 2006
160
{
Apr 17, 2005
Apr 17, 2005
161
162
163
164
165
166
int height = info->d_height;
Uint8 *src = (Uint8 *) info->s_pixels;
int srcskip = info->s_skip;
Uint8 *dst = (Uint8 *) info->d_pixels;
int dstskip = info->d_skip;
SDL_PixelFormat *srcfmt = info->src;
May 29, 2006
May 29, 2006
167
168
169
170
171
172
173
174
vector unsigned char valpha = vec_splat_u8(0);
vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
0x00, 0x0a, 0x00, 0x0e,
0x00, 0x12, 0x00, 0x16,
0x00, 0x1a, 0x00, 0x1e);
vector unsigned short v1 = vec_splat_u16(1);
vector unsigned short v3 = vec_splat_u16(3);
May 28, 2006
May 28, 2006
175
vector unsigned short v3f =
May 29, 2006
May 29, 2006
176
177
VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f,
0x003f, 0x003f, 0x003f, 0x003f);
May 28, 2006
May 28, 2006
178
vector unsigned short vfc =
May 29, 2006
May 29, 2006
179
180
181
182
VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc,
0x00fc, 0x00fc, 0x00fc, 0x00fc);
vector unsigned short vf800 = (vector unsigned short) vec_splat_u8(-7);
vf800 = vec_sl(vf800, vec_splat_u16(8));
Apr 17, 2005
Apr 17, 2005
183
184
185
186
187
188
189
190
191
192
193
194
while (height--) {
vector unsigned char valigner;
vector unsigned char voverflow;
vector unsigned char vsrc;
int width = info->d_width;
int extrawidth;
/* do scalar until we can align... */
#define ONE_PIXEL_BLEND(condition, widthvar) \
while (condition) { \
Oct 20, 2005
Oct 20, 2005
195
Uint32 Pixel; \
Apr 17, 2005
Apr 17, 2005
196
unsigned sR, sG, sB, sA; \
Oct 20, 2005
Oct 20, 2005
197
DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \
Apr 17, 2005
Apr 17, 2005
198
199
200
201
202
203
204
205
206
sR, sG, sB, sA); \
*(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \
((sG << 3) & 0x000007E0) | \
((sB >> 3) & 0x0000001F)); \
dst += 2; \
src += 4; \
widthvar--; \
}
May 29, 2006
May 29, 2006
207
ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
Apr 17, 2005
Apr 17, 2005
208
209
/* After all that work, here's the vector part! */
May 28, 2006
May 28, 2006
210
extrawidth = (width % 8); /* trailing unaligned stores */
Apr 17, 2005
Apr 17, 2005
211
width -= extrawidth;
May 29, 2006
May 29, 2006
212
213
vsrc = vec_ld(0, src);
valigner = VEC_ALIGNER(src);
Apr 17, 2005
Apr 17, 2005
214
215
216
217
218
219
while (width) {
vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
vector unsigned int vsrc1, vsrc2;
vector unsigned char vdst;
May 29, 2006
May 29, 2006
220
221
222
voverflow = vec_ld(15, src);
vsrc = vec_perm(vsrc, voverflow, valigner);
vsrc1 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute);
Apr 17, 2005
Apr 17, 2005
223
224
src += 16;
vsrc = voverflow;
May 29, 2006
May 29, 2006
225
226
227
voverflow = vec_ld(15, src);
vsrc = vec_perm(vsrc, voverflow, valigner);
vsrc2 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute);
Apr 17, 2005
Apr 17, 2005
228
/* 1555 */
May 29, 2006
May 29, 2006
229
230
231
232
233
234
235
vpixel = (vector unsigned short) vec_packpx(vsrc1, vsrc2);
vgpixel = (vector unsigned short) vec_perm(vsrc1, vsrc2, vgmerge);
vgpixel = vec_and(vgpixel, vfc);
vgpixel = vec_sl(vgpixel, v3);
vrpixel = vec_sl(vpixel, v1);
vrpixel = vec_and(vrpixel, vf800);
vbpixel = vec_and(vpixel, v3f);
May 28, 2006
May 28, 2006
236
vdst =
May 29, 2006
May 29, 2006
237
238
vec_or((vector unsigned char) vrpixel,
(vector unsigned char) vgpixel);
Apr 17, 2005
Apr 17, 2005
239
/* 565 */
May 29, 2006
May 29, 2006
240
241
vdst = vec_or(vdst, (vector unsigned char) vbpixel);
vec_st(vdst, 0, dst);
Apr 17, 2005
Apr 17, 2005
242
243
244
245
246
247
248
width -= 8;
src += 16;
dst += 16;
vsrc = voverflow;
}
May 29, 2006
May 29, 2006
249
assert(width == 0);
Apr 17, 2005
Apr 17, 2005
250
251
/* do scalar until we can align... */
May 29, 2006
May 29, 2006
252
ONE_PIXEL_BLEND((extrawidth), extrawidth);
Apr 17, 2005
Apr 17, 2005
253
254
#undef ONE_PIXEL_BLEND
May 28, 2006
May 28, 2006
255
src += srcskip; /* move to next row, accounting for pitch. */
Apr 17, 2005
Apr 17, 2005
256
257
258
259
260
261
dst += dstskip;
}
}
May 28, 2006
May 28, 2006
262
static void
May 29, 2006
May 29, 2006
263
Blit_RGB565_32Altivec(SDL_BlitInfo * info)
May 28, 2006
May 28, 2006
264
{
Apr 17, 2005
Apr 17, 2005
265
266
267
268
269
270
271
272
273
274
275
int height = info->d_height;
Uint8 *src = (Uint8 *) info->s_pixels;
int srcskip = info->s_skip;
Uint8 *dst = (Uint8 *) info->d_pixels;
int dstskip = info->d_skip;
SDL_PixelFormat *srcfmt = info->src;
SDL_PixelFormat *dstfmt = info->dst;
unsigned alpha;
vector unsigned char valpha;
vector unsigned char vpermute;
vector unsigned short vf800;
May 29, 2006
May 29, 2006
276
277
278
279
vector unsigned int v8 = vec_splat_u32(8);
vector unsigned int v16 = vec_add(v8, v8);
vector unsigned short v2 = vec_splat_u16(2);
vector unsigned short v3 = vec_splat_u16(3);
Apr 17, 2005
Apr 17, 2005
280
/*
May 28, 2006
May 28, 2006
281
282
283
284
0x10 - 0x1f is the alpha
0x00 - 0x0e evens are the red
0x01 - 0x0f odds are zero
*/
May 29, 2006
May 29, 2006
285
286
287
288
289
vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
0x10, 0x02, 0x01, 0x01,
0x10, 0x04, 0x01, 0x01,
0x10, 0x06, 0x01,
0x01);
May 28, 2006
May 28, 2006
290
291
vector unsigned char vredalpha2 =
(vector unsigned
May 29, 2006
May 29, 2006
292
char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16))
May 28, 2006
May 28, 2006
293
);
Apr 17, 2005
Apr 17, 2005
294
/*
May 28, 2006
May 28, 2006
295
296
297
0x00 - 0x0f is ARxx ARxx ARxx ARxx
0x11 - 0x0f odds are blue
*/
May 29, 2006
May 29, 2006
298
299
300
301
vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
0x04, 0x05, 0x06, 0x13,
0x08, 0x09, 0x0a, 0x15,
0x0c, 0x0d, 0x0e, 0x17);
May 28, 2006
May 28, 2006
302
vector unsigned char vblue2 =
May 29, 2006
May 29, 2006
303
(vector unsigned char) (vec_add((vector unsigned int) vblue1, v8)
May 28, 2006
May 28, 2006
304
);
Apr 17, 2005
Apr 17, 2005
305
/*
May 28, 2006
May 28, 2006
306
307
308
0x00 - 0x0f is ARxB ARxB ARxB ARxB
0x10 - 0x0e evens are green
*/
May 29, 2006
May 29, 2006
309
310
311
312
vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
0x04, 0x05, 0x12, 0x07,
0x08, 0x09, 0x14, 0x0b,
0x0c, 0x0d, 0x16, 0x0f);
May 28, 2006
May 28, 2006
313
314
vector unsigned char vgreen2 =
(vector unsigned
May 29, 2006
May 29, 2006
315
char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8))
May 28, 2006
May 28, 2006
316
317
318
);
May 29, 2006
May 29, 2006
319
320
assert(srcfmt->BytesPerPixel == 2);
assert(dstfmt->BytesPerPixel == 4);
May 28, 2006
May 28, 2006
321
May 29, 2006
May 29, 2006
322
323
vf800 = (vector unsigned short) vec_splat_u8(-7);
vf800 = vec_sl(vf800, vec_splat_u16(8));
Apr 17, 2005
Apr 17, 2005
324
325
if (dstfmt->Amask && srcfmt->alpha) {
May 28, 2006
May 28, 2006
326
((unsigned char *) &valpha)[0] = alpha = srcfmt->alpha;
May 29, 2006
May 29, 2006
327
valpha = vec_splat(valpha, 0);
Apr 17, 2005
Apr 17, 2005
328
329
} else {
alpha = 0;
May 29, 2006
May 29, 2006
330
valpha = vec_splat_u8(0);
Apr 17, 2005
Apr 17, 2005
331
332
}
May 29, 2006
May 29, 2006
333
vpermute = calc_swizzle32(NULL, dstfmt);
Apr 17, 2005
Apr 17, 2005
334
335
336
337
338
339
340
341
342
343
344
345
while (height--) {
vector unsigned char valigner;
vector unsigned char voverflow;
vector unsigned char vsrc;
int width = info->d_width;
int extrawidth;
/* do scalar until we can align... */
#define ONE_PIXEL_BLEND(condition, widthvar) \
while (condition) { \
unsigned sR, sG, sB; \
Oct 20, 2005
Oct 20, 2005
346
347
348
349
unsigned short Pixel = *((unsigned short *)src); \
sR = (Pixel >> 8) & 0xf8; \
sG = (Pixel >> 3) & 0xfc; \
sB = (Pixel << 3) & 0xf8; \
Apr 17, 2005
Apr 17, 2005
350
351
352
353
354
ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
src += 2; \
dst += 4; \
widthvar--; \
}
May 29, 2006
May 29, 2006
355
ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
Apr 17, 2005
Apr 17, 2005
356
357
/* After all that work, here's the vector part! */
May 28, 2006
May 28, 2006
358
extrawidth = (width % 8); /* trailing unaligned stores */
Apr 17, 2005
Apr 17, 2005
359
width -= extrawidth;
May 29, 2006
May 29, 2006
360
361
vsrc = vec_ld(0, src);
valigner = VEC_ALIGNER(src);
Apr 17, 2005
Apr 17, 2005
362
363
364
365
366
while (width) {
vector unsigned short vR, vG, vB;
vector unsigned char vdst1, vdst2;
May 29, 2006
May 29, 2006
367
368
voverflow = vec_ld(15, src);
vsrc = vec_perm(vsrc, voverflow, valigner);
May 28, 2006
May 28, 2006
369
May 29, 2006
May 29, 2006
370
371
372
vR = vec_and((vector unsigned short) vsrc, vf800);
vB = vec_sl((vector unsigned short) vsrc, v3);
vG = vec_sl(vB, v2);
May 28, 2006
May 28, 2006
373
374
vdst1 =
May 29, 2006
May 29, 2006
375
376
377
378
379
380
(vector unsigned char) vec_perm((vector unsigned char) vR,
valpha, vredalpha1);
vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
vdst1 = vec_perm(vdst1, valpha, vpermute);
vec_st(vdst1, 0, dst);
May 28, 2006
May 28, 2006
381
382
vdst2 =
May 29, 2006
May 29, 2006
383
384
385
386
387
388
(vector unsigned char) vec_perm((vector unsigned char) vR,
valpha, vredalpha2);
vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
vdst2 = vec_perm(vdst2, valpha, vpermute);
vec_st(vdst2, 16, dst);
May 28, 2006
May 28, 2006
389
Apr 17, 2005
Apr 17, 2005
390
391
392
393
394
395
width -= 8;
dst += 32;
src += 16;
vsrc = voverflow;
}
May 29, 2006
May 29, 2006
396
assert(width == 0);
Apr 17, 2005
Apr 17, 2005
397
398
399
/* do scalar until we can align... */
May 29, 2006
May 29, 2006
400
ONE_PIXEL_BLEND((extrawidth), extrawidth);
Apr 17, 2005
Apr 17, 2005
401
402
#undef ONE_PIXEL_BLEND
May 28, 2006
May 28, 2006
403
src += srcskip; /* move to next row, accounting for pitch. */
Apr 17, 2005
Apr 17, 2005
404
405
406
407
408
dst += dstskip;
}
}
Sep 8, 2005
Sep 8, 2005
409
May 28, 2006
May 28, 2006
410
static void
May 29, 2006
May 29, 2006
411
Blit_RGB555_32Altivec(SDL_BlitInfo * info)
May 28, 2006
May 28, 2006
412
{
Sep 8, 2005
Sep 8, 2005
413
414
415
416
417
418
419
420
421
422
423
int height = info->d_height;
Uint8 *src = (Uint8 *) info->s_pixels;
int srcskip = info->s_skip;
Uint8 *dst = (Uint8 *) info->d_pixels;
int dstskip = info->d_skip;
SDL_PixelFormat *srcfmt = info->src;
SDL_PixelFormat *dstfmt = info->dst;
unsigned alpha;
vector unsigned char valpha;
vector unsigned char vpermute;
vector unsigned short vf800;
May 29, 2006
May 29, 2006
424
425
426
427
vector unsigned int v8 = vec_splat_u32(8);
vector unsigned int v16 = vec_add(v8, v8);
vector unsigned short v1 = vec_splat_u16(1);
vector unsigned short v3 = vec_splat_u16(3);
Sep 8, 2005
Sep 8, 2005
428
/*
May 28, 2006
May 28, 2006
429
430
431
432
0x10 - 0x1f is the alpha
0x00 - 0x0e evens are the red
0x01 - 0x0f odds are zero
*/
May 29, 2006
May 29, 2006
433
434
435
436
437
vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
0x10, 0x02, 0x01, 0x01,
0x10, 0x04, 0x01, 0x01,
0x10, 0x06, 0x01,
0x01);
May 28, 2006
May 28, 2006
438
439
vector unsigned char vredalpha2 =
(vector unsigned
May 29, 2006
May 29, 2006
440
char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16))
May 28, 2006
May 28, 2006
441
);
Sep 8, 2005
Sep 8, 2005
442
/*
May 28, 2006
May 28, 2006
443
444
445
0x00 - 0x0f is ARxx ARxx ARxx ARxx
0x11 - 0x0f odds are blue
*/
May 29, 2006
May 29, 2006
446
447
448
449
vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
0x04, 0x05, 0x06, 0x13,
0x08, 0x09, 0x0a, 0x15,
0x0c, 0x0d, 0x0e, 0x17);
May 28, 2006
May 28, 2006
450
vector unsigned char vblue2 =
May 29, 2006
May 29, 2006
451
(vector unsigned char) (vec_add((vector unsigned int) vblue1, v8)
May 28, 2006
May 28, 2006
452
);
Sep 8, 2005
Sep 8, 2005
453
/*
May 28, 2006
May 28, 2006
454
455
456
0x00 - 0x0f is ARxB ARxB ARxB ARxB
0x10 - 0x0e evens are green
*/
May 29, 2006
May 29, 2006
457
458
459
460
vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
0x04, 0x05, 0x12, 0x07,
0x08, 0x09, 0x14, 0x0b,
0x0c, 0x0d, 0x16, 0x0f);
May 28, 2006
May 28, 2006
461
462
vector unsigned char vgreen2 =
(vector unsigned
May 29, 2006
May 29, 2006
463
char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8))
May 28, 2006
May 28, 2006
464
465
466
);
May 29, 2006
May 29, 2006
467
468
assert(srcfmt->BytesPerPixel == 2);
assert(dstfmt->BytesPerPixel == 4);
May 28, 2006
May 28, 2006
469
May 29, 2006
May 29, 2006
470
471
vf800 = (vector unsigned short) vec_splat_u8(-7);
vf800 = vec_sl(vf800, vec_splat_u16(8));
Sep 8, 2005
Sep 8, 2005
472
473
if (dstfmt->Amask && srcfmt->alpha) {
May 28, 2006
May 28, 2006
474
((unsigned char *) &valpha)[0] = alpha = srcfmt->alpha;
May 29, 2006
May 29, 2006
475
valpha = vec_splat(valpha, 0);
Sep 8, 2005
Sep 8, 2005
476
477
} else {
alpha = 0;
May 29, 2006
May 29, 2006
478
valpha = vec_splat_u8(0);
Sep 8, 2005
Sep 8, 2005
479
480
}
May 29, 2006
May 29, 2006
481
vpermute = calc_swizzle32(NULL, dstfmt);
Sep 8, 2005
Sep 8, 2005
482
483
484
485
486
487
488
489
490
491
492
493
while (height--) {
vector unsigned char valigner;
vector unsigned char voverflow;
vector unsigned char vsrc;
int width = info->d_width;
int extrawidth;
/* do scalar until we can align... */
#define ONE_PIXEL_BLEND(condition, widthvar) \
while (condition) { \
unsigned sR, sG, sB; \
Oct 20, 2005
Oct 20, 2005
494
495
496
497
unsigned short Pixel = *((unsigned short *)src); \
sR = (Pixel >> 7) & 0xf8; \
sG = (Pixel >> 2) & 0xf8; \
sB = (Pixel << 3) & 0xf8; \
Sep 8, 2005
Sep 8, 2005
498
499
500
501
502
ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
src += 2; \
dst += 4; \
widthvar--; \
}
May 29, 2006
May 29, 2006
503
ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
Sep 8, 2005
Sep 8, 2005
504
505
/* After all that work, here's the vector part! */
May 28, 2006
May 28, 2006
506
extrawidth = (width % 8); /* trailing unaligned stores */
Sep 8, 2005
Sep 8, 2005
507
width -= extrawidth;
May 29, 2006
May 29, 2006
508
509
vsrc = vec_ld(0, src);
valigner = VEC_ALIGNER(src);
Sep 8, 2005
Sep 8, 2005
510
511
512
513
514
while (width) {
vector unsigned short vR, vG, vB;
vector unsigned char vdst1, vdst2;
May 29, 2006
May 29, 2006
515
516
voverflow = vec_ld(15, src);
vsrc = vec_perm(vsrc, voverflow, valigner);
May 28, 2006
May 28, 2006
517
May 29, 2006
May 29, 2006
518
519
520
vR = vec_and(vec_sl((vector unsigned short) vsrc, v1), vf800);
vB = vec_sl((vector unsigned short) vsrc, v3);
vG = vec_sl(vB, v3);
May 28, 2006
May 28, 2006
521
522
vdst1 =
May 29, 2006
May 29, 2006
523
524
525
526
527
528
(vector unsigned char) vec_perm((vector unsigned char) vR,
valpha, vredalpha1);
vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
vdst1 = vec_perm(vdst1, valpha, vpermute);
vec_st(vdst1, 0, dst);
May 28, 2006
May 28, 2006
529
530
vdst2 =
May 29, 2006
May 29, 2006
531
532
533
534
535
536
(vector unsigned char) vec_perm((vector unsigned char) vR,
valpha, vredalpha2);
vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
vdst2 = vec_perm(vdst2, valpha, vpermute);
vec_st(vdst2, 16, dst);
May 28, 2006
May 28, 2006
537
Sep 8, 2005
Sep 8, 2005
538
539
540
541
542
543
width -= 8;
dst += 32;
src += 16;
vsrc = voverflow;
}
May 29, 2006
May 29, 2006
544
assert(width == 0);
Sep 8, 2005
Sep 8, 2005
545
546
547
/* do scalar until we can align... */
May 29, 2006
May 29, 2006
548
ONE_PIXEL_BLEND((extrawidth), extrawidth);
Sep 8, 2005
Sep 8, 2005
549
550
#undef ONE_PIXEL_BLEND
May 28, 2006
May 28, 2006
551
src += srcskip; /* move to next row, accounting for pitch. */
Sep 8, 2005
Sep 8, 2005
552
553
554
555
556
dst += dstskip;
}
}
May 29, 2006
May 29, 2006
557
558
static void BlitNtoNKey(SDL_BlitInfo * info);
static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info);
May 28, 2006
May 28, 2006
559
static void
May 29, 2006
May 29, 2006
560
Blit32to32KeyAltivec(SDL_BlitInfo * info)
Apr 17, 2005
Apr 17, 2005
561
562
563
564
565
566
567
568
569
570
571
{
int height = info->d_height;
Uint32 *srcp = (Uint32 *) info->s_pixels;
int srcskip = info->s_skip;
Uint32 *dstp = (Uint32 *) info->d_pixels;
int dstskip = info->d_skip;
SDL_PixelFormat *srcfmt = info->src;
int srcbpp = srcfmt->BytesPerPixel;
SDL_PixelFormat *dstfmt = info->dst;
int dstbpp = dstfmt->BytesPerPixel;
int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
May 28, 2006
May 28, 2006
572
unsigned alpha = dstfmt->Amask ? srcfmt->alpha : 0;
Apr 17, 2005
Apr 17, 2005
573
Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
May 28, 2006
May 28, 2006
574
Uint32 ckey = info->src->colorkey;
Apr 17, 2005
Apr 17, 2005
575
576
577
578
579
vector unsigned int valpha;
vector unsigned char vpermute;
vector unsigned char vzero;
vector unsigned int vckey;
vector unsigned int vrgbmask;
May 29, 2006
May 29, 2006
580
vpermute = calc_swizzle32(srcfmt, dstfmt);
Apr 17, 2005
Apr 17, 2005
581
if (info->d_width < 16) {
May 28, 2006
May 28, 2006
582
if (copy_alpha) {
May 29, 2006
May 29, 2006
583
BlitNtoNKeyCopyAlpha(info);
Apr 17, 2005
Apr 17, 2005
584
} else {
May 29, 2006
May 29, 2006
585
BlitNtoNKey(info);
Apr 17, 2005
Apr 17, 2005
586
}
Mar 9, 2006
Mar 9, 2006
587
return;
Apr 17, 2005
Apr 17, 2005
588
}
May 29, 2006
May 29, 2006
589
vzero = vec_splat_u8(0);
Apr 17, 2005
Apr 17, 2005
590
if (alpha) {
May 28, 2006
May 28, 2006
591
592
((unsigned char *) &valpha)[0] = (unsigned char) alpha;
valpha =
May 29, 2006
May 29, 2006
593
(vector unsigned int) vec_splat((vector unsigned char) valpha, 0);
Apr 17, 2005
Apr 17, 2005
594
} else {
May 28, 2006
May 28, 2006
595
valpha = (vector unsigned int) vzero;
Apr 17, 2005
Apr 17, 2005
596
597
}
ckey &= rgbmask;
May 28, 2006
May 28, 2006
598
((unsigned int *) (char *) &vckey)[0] = ckey;
May 29, 2006
May 29, 2006
599
vckey = vec_splat(vckey, 0);
May 28, 2006
May 28, 2006
600
((unsigned int *) (char *) &vrgbmask)[0] = rgbmask;
May 29, 2006
May 29, 2006
601
vrgbmask = vec_splat(vrgbmask, 0);
Apr 17, 2005
Apr 17, 2005
602
603
604
605
606
while (height--) {
#define ONE_PIXEL_BLEND(condition, widthvar) \
if (copy_alpha) { \
while (condition) { \
Oct 20, 2005
Oct 20, 2005
607
Uint32 Pixel; \
Apr 17, 2005
Apr 17, 2005
608
unsigned sR, sG, sB, sA; \
Oct 20, 2005
Oct 20, 2005
609
DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \
Apr 17, 2005
Apr 17, 2005
610
sR, sG, sB, sA); \
Oct 20, 2005
Oct 20, 2005
611
if ( (Pixel & rgbmask) != ckey ) { \
Apr 17, 2005
Apr 17, 2005
612
613
614
ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
sR, sG, sB, sA); \
} \
Oct 20, 2005
Oct 20, 2005
615
616
dstp = (Uint32 *) (((Uint8 *) dstp) + dstbpp); \
srcp = (Uint32 *) (((Uint8 *) srcp) + srcbpp); \
Apr 17, 2005
Apr 17, 2005
617
618
619
620
widthvar--; \
} \
} else { \
while (condition) { \
Oct 20, 2005
Oct 20, 2005
621
Uint32 Pixel; \
Apr 17, 2005
Apr 17, 2005
622
unsigned sR, sG, sB; \
Oct 20, 2005
Oct 20, 2005
623
624
625
RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \
if ( Pixel != ckey ) { \
RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
Apr 17, 2005
Apr 17, 2005
626
627
628
ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
sR, sG, sB, alpha); \
} \
Oct 20, 2005
Oct 20, 2005
629
630
dstp = (Uint32 *) (((Uint8 *)dstp) + dstbpp); \
srcp = (Uint32 *) (((Uint8 *)srcp) + srcbpp); \
Apr 17, 2005
Apr 17, 2005
631
632
633
634
widthvar--; \
} \
}
int width = info->d_width;
May 29, 2006
May 29, 2006
635
636
ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
assert(width > 0);
Apr 17, 2005
Apr 17, 2005
637
638
if (width > 0) {
int extrawidth = (width % 4);
May 29, 2006
May 29, 2006
639
640
vector unsigned char valigner = VEC_ALIGNER(srcp);
vector unsigned int vs = vec_ld(0, srcp);
Apr 17, 2005
Apr 17, 2005
641
width -= extrawidth;
May 29, 2006
May 29, 2006
642
assert(width >= 4);
Apr 17, 2005
Apr 17, 2005
643
644
645
while (width) {
vector unsigned char vsel;
vector unsigned int vd;
May 29, 2006
May 29, 2006
646
vector unsigned int voverflow = vec_ld(15, srcp);
Apr 17, 2005
Apr 17, 2005
647
/* load the source vec */
May 29, 2006
May 29, 2006
648
vs = vec_perm(vs, voverflow, valigner);
Apr 17, 2005
Apr 17, 2005
649
/* vsel is set for items that match the key */
May 29, 2006
May 29, 2006
650
651
vsel = (vector unsigned char) vec_and(vs, vrgbmask);
vsel = (vector unsigned char) vec_cmpeq(vs, vckey);
Apr 17, 2005
Apr 17, 2005
652
/* permute the src vec to the dest format */
May 29, 2006
May 29, 2006
653
vs = vec_perm(vs, valpha, vpermute);
Apr 17, 2005
Apr 17, 2005
654
/* load the destination vec */
May 29, 2006
May 29, 2006
655
vd = vec_ld(0, dstp);
Apr 17, 2005
Apr 17, 2005
656
/* select the source and dest into vs */
May 29, 2006
May 29, 2006
657
658
659
vd = (vector unsigned int) vec_sel((vector unsigned char) vs,
(vector unsigned char) vd,
vsel);
May 28, 2006
May 28, 2006
660
May 29, 2006
May 29, 2006
661
vec_st(vd, 0, dstp);
Apr 17, 2005
Apr 17, 2005
662
663
664
665
666
srcp += 4;
width -= 4;
dstp += 4;
vs = voverflow;
}
May 29, 2006
May 29, 2006
667
ONE_PIXEL_BLEND((extrawidth), extrawidth);
Apr 17, 2005
Apr 17, 2005
668
669
670
671
672
673
674
675
676
#undef ONE_PIXEL_BLEND
srcp += srcskip >> 2;
dstp += dstskip >> 2;
}
}
}
/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
/* Use this on a G5 */
May 28, 2006
May 28, 2006
677
static void
May 29, 2006
May 29, 2006
678
ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info)
Apr 17, 2005
Apr 17, 2005
679
680
681
682
683
684
685
686
{
int height = info->d_height;
Uint32 *src = (Uint32 *) info->s_pixels;
int srcskip = info->s_skip;
Uint32 *dst = (Uint32 *) info->d_pixels;
int dstskip = info->d_skip;
SDL_PixelFormat *srcfmt = info->src;
SDL_PixelFormat *dstfmt = info->dst;
May 29, 2006
May 29, 2006
687
688
vector unsigned int vzero = vec_splat_u32(0);
vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
Apr 17, 2005
Apr 17, 2005
689
690
691
if (dstfmt->Amask && !srcfmt->Amask) {
if (srcfmt->alpha) {
vector unsigned char valpha;
May 28, 2006
May 28, 2006
692
((unsigned char *) &valpha)[0] = srcfmt->alpha;
May 29, 2006
May 29, 2006
693
vzero = (vector unsigned int) vec_splat(valpha, 0);
Apr 17, 2005
Apr 17, 2005
694
695
696
}
}
May 29, 2006
May 29, 2006
697
698
assert(srcfmt->BytesPerPixel == 4);
assert(dstfmt->BytesPerPixel == 4);
Apr 17, 2005
Apr 17, 2005
699
700
701
702
703
704
705
706
707
708
709
710
while (height--) {
vector unsigned char valigner;
vector unsigned int vbits;
vector unsigned int voverflow;
Uint32 bits;
Uint8 r, g, b, a;
int width = info->d_width;
int extrawidth;
/* do scalar until we can align... */
May 29, 2006
May 29, 2006
711
while ((UNALIGNED_PTR(dst)) && (width)) {
Apr 17, 2005
Apr 17, 2005
712
bits = *(src++);
May 29, 2006
May 29, 2006
713
714
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
Apr 17, 2005
Apr 17, 2005
715
716
717
718
719
720
width--;
}
/* After all that work, here's the vector part! */
extrawidth = (width % 4);
width -= extrawidth;
May 29, 2006
May 29, 2006
721
722
valigner = VEC_ALIGNER(src);
vbits = vec_ld(0, src);
Apr 17, 2005
Apr 17, 2005
723
May 28, 2006
May 28, 2006
724
while (width) {
May 29, 2006
May 29, 2006
725
voverflow = vec_ld(15, src);
Apr 17, 2005
Apr 17, 2005
726
727
src += 4;
width -= 4;
May 29, 2006
May 29, 2006
728
729
730
vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
vec_st(vbits, 0, dst); /* store it back out. */
Apr 17, 2005
Apr 17, 2005
731
732
733
734
dst += 4;
vbits = voverflow;
}
May 29, 2006
May 29, 2006
735
assert(width == 0);
Apr 17, 2005
Apr 17, 2005
736
737
738
/* cover pixels at the end of the row that didn't fit in 16 bytes. */
while (extrawidth) {
May 28, 2006
May 28, 2006
739
bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
May 29, 2006
May 29, 2006
740
741
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
Apr 17, 2005
Apr 17, 2005
742
743
744
extrawidth--;
}
May 28, 2006
May 28, 2006
745
src += srcskip >> 2; /* move to next row, accounting for pitch. */
Apr 17, 2005
Apr 17, 2005
746
747
748
749
750
751
752
dst += dstskip >> 2;
}
}
/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
/* Use this on a G4 */
May 28, 2006
May 28, 2006
753
static void
May 29, 2006
May 29, 2006
754
ConvertAltivec32to32_prefetch(SDL_BlitInfo * info)
Apr 17, 2005
Apr 17, 2005
755
{
May 29, 2006
May 29, 2006
756
757
const int scalar_dst_lead = sizeof(Uint32) * 4;
const int vector_dst_lead = sizeof(Uint32) * 16;
Apr 17, 2005
Apr 17, 2005
758
759
760
761
762
763
764
765
int height = info->d_height;
Uint32 *src = (Uint32 *) info->s_pixels;
int srcskip = info->s_skip;
Uint32 *dst = (Uint32 *) info->d_pixels;
int dstskip = info->d_skip;
SDL_PixelFormat *srcfmt = info->src;
SDL_PixelFormat *dstfmt = info->dst;
May 29, 2006
May 29, 2006
766
767
vector unsigned int vzero = vec_splat_u32(0);
vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
Apr 17, 2005
Apr 17, 2005
768
769
770
if (dstfmt->Amask && !srcfmt->Amask) {
if (srcfmt->alpha) {
vector unsigned char valpha;
May 28, 2006
May 28, 2006
771
((unsigned char *) &valpha)[0] = srcfmt->alpha;
May 29, 2006
May 29, 2006
772
vzero = (vector unsigned int) vec_splat(valpha, 0);
Apr 17, 2005
Apr 17, 2005
773
774
775
}
}
May 29, 2006
May 29, 2006
776
777
assert(srcfmt->BytesPerPixel == 4);
assert(dstfmt->BytesPerPixel == 4);
Apr 17, 2005
Apr 17, 2005
778
779
780
781
782
783
784
785
786
787
788
789
while (height--) {
vector unsigned char valigner;
vector unsigned int vbits;
vector unsigned int voverflow;
Uint32 bits;
Uint8 r, g, b, a;
int width = info->d_width;
int extrawidth;
/* do scalar until we can align... */
May 29, 2006
May 29, 2006
790
791
792
793
794
while ((UNALIGNED_PTR(dst)) && (width)) {
vec_dstt(src + scalar_dst_lead, DST_CTRL(2, 32, 1024),
DST_CHAN_SRC);
vec_dstst(dst + scalar_dst_lead, DST_CTRL(2, 32, 1024),
DST_CHAN_DEST);
Apr 17, 2005
Apr 17, 2005
795
bits = *(src++);
May 29, 2006
May 29, 2006
796
797
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
Apr 17, 2005
Apr 17, 2005
798
799
800
801
802
803
width--;
}
/* After all that work, here's the vector part! */
extrawidth = (width % 4);
width -= extrawidth;
May 29, 2006
May 29, 2006
804
805
valigner = VEC_ALIGNER(src);
vbits = vec_ld(0, src);
Apr 17, 2005
Apr 17, 2005
806
807
while (width) {
May 29, 2006
May 29, 2006
808
809
810
811
812
vec_dstt(src + vector_dst_lead, DST_CTRL(2, 32, 1024),
DST_CHAN_SRC);
vec_dstst(dst + vector_dst_lead, DST_CTRL(2, 32, 1024),
DST_CHAN_DEST);
voverflow = vec_ld(15, src);
Apr 17, 2005
Apr 17, 2005
813
814
src += 4;
width -= 4;
May 29, 2006
May 29, 2006
815
816
817
vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
vec_st(vbits, 0, dst); /* store it back out. */
Apr 17, 2005
Apr 17, 2005
818
819
820
dst += 4;
vbits = voverflow;
}
May 28, 2006
May 28, 2006
821
May 29, 2006
May 29, 2006
822
assert(width == 0);
Apr 17, 2005
Apr 17, 2005
823
824
825
/* cover pixels at the end of the row that didn't fit in 16 bytes. */
while (extrawidth) {
May 28, 2006
May 28, 2006
826
bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
May 29, 2006
May 29, 2006
827
828
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
Apr 17, 2005
Apr 17, 2005
829
830
831
extrawidth--;
}
May 28, 2006
May 28, 2006
832
src += srcskip >> 2; /* move to next row, accounting for pitch. */
Apr 17, 2005
Apr 17, 2005
833
834
835
dst += dstskip >> 2;
}
May 29, 2006
May 29, 2006
836
837
vec_dss(DST_CHAN_SRC);
vec_dss(DST_CHAN_DEST);
Apr 17, 2005
Apr 17, 2005
838
839
}
May 28, 2006
May 28, 2006
840
static Uint32
May 29, 2006
May 29, 2006
841
GetBlitFeatures(void)
Apr 17, 2005
Apr 17, 2005
842
843
844
845
{
static Uint32 features = 0xffffffff;
if (features == 0xffffffff) {
/* Provide an override for testing .. */
May 29, 2006
May 29, 2006
846
char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES");
Apr 17, 2005
Apr 17, 2005
847
848
if (override) {
features = 0;
May 29, 2006
May 29, 2006
849
SDL_sscanf(override, "%u", &features);
Apr 17, 2005
Apr 17, 2005
850
} else {
May 28, 2006
May 28, 2006
851
852
features = (0
/* Feature 1 is has-MMX */
May 29, 2006
May 29, 2006
853
| ((SDL_HasMMX())? 1 : 0)
May 28, 2006
May 28, 2006
854
/* Feature 2 is has-AltiVec */
May 29, 2006
May 29, 2006
855
| ((SDL_HasAltiVec())? 2 : 0)
May 28, 2006
May 28, 2006
856
857
/* Feature 4 is dont-use-prefetch */
/* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */
May 29, 2006
May 29, 2006
858
| ((GetL3CacheSize() == 0) ? 4 : 0)
May 28, 2006
May 28, 2006
859
);
Apr 17, 2005
Apr 17, 2005
860
861
862
863
}
}
return features;
}
May 28, 2006
May 28, 2006
864
May 17, 2006
May 17, 2006
865
866
867
#if __MWERKS__
#pragma altivec_model off
#endif
Apr 17, 2005
Apr 17, 2005
868
869
870
871
872
#else
/* Feature 1 is has-MMX */
#define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
#endif
Apr 20, 2005
Apr 20, 2005
873
/* This is now endian dependent */
Feb 26, 2006
Feb 26, 2006
874
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Apr 20, 2005
Apr 20, 2005
875
876
#define HI 1
#define LO 0
Feb 26, 2006
Feb 26, 2006
877
#else /* SDL_BYTEORDER == SDL_BIG_ENDIAN */
Apr 20, 2005
Apr 20, 2005
878
879
880
881
#define HI 0
#define LO 1
#endif
Feb 16, 2006
Feb 16, 2006
882
#if SDL_HERMES_BLITTERS
Apr 26, 2001
Apr 26, 2001
883
884
885
886
887
888
889
/* Heheheh, we coerce Hermes into using SDL blit information */
#define X86_ASSEMBLER
#define HermesConverterInterface SDL_BlitInfo
#define HermesClearInterface void
#define STACKCALL
Feb 16, 2006
Feb 16, 2006
890
891
#include "../hermes/HeadMMX.h"
#include "../hermes/HeadX86.h"
Apr 26, 2001
Apr 26, 2001
892
893
894
895
896
#else
/* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */
#define RGB888_RGB332(dst, src) { \
Feb 24, 2006
Feb 24, 2006
897
898
899
dst = (Uint8)((((src)&0x00E00000)>>16)| \
(((src)&0x0000E000)>>11)| \
(((src)&0x000000C0)>>6)); \
Apr 26, 2001
Apr 26, 2001
900
}
May 28, 2006
May 28, 2006
901
static void
May 29, 2006
May 29, 2006
902
Blit_RGB888_index8(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
903
904
{
#ifndef USE_DUFFS_LOOP
May 28, 2006
May 28, 2006
905
int c;
Apr 26, 2001
Apr 26, 2001
906
#endif
May 28, 2006
May 28, 2006
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
int width, height;
Uint32 *src;
const Uint8 *map;
Uint8 *dst;
int srcskip, dstskip;
/* Set up some basic variables */
width = info->d_width;
height = info->d_height;
src = (Uint32 *) info->s_pixels;
srcskip = info->s_skip / 4;
dst = info->d_pixels;
dstskip = info->d_skip;
map = info->table;
if (map == NULL) {
while (height--) {
Apr 26, 2001
Apr 26, 2001
924
#ifdef USE_DUFFS_LOOP
May 28, 2006
May 28, 2006
925
/* *INDENT-OFF* */
Apr 26, 2001
Apr 26, 2001
926
927
928
DUFFS_LOOP(
RGB888_RGB332(*dst++, *src);
, width);
May 28, 2006
May 28, 2006
929
/* *INDENT-ON* */
Apr 26, 2001
Apr 26, 2001
930
#else
May 28, 2006
May 28, 2006
931
932
933
for (c = width / 4; c; --c) {
/* Pack RGB into 8bit pixel */
++src;
May 29, 2006
May 29, 2006
934
RGB888_RGB332(*dst++, *src);
May 28, 2006
May 28, 2006
935
++src;
May 29, 2006
May 29, 2006
936
RGB888_RGB332(*dst++, *src);
May 28, 2006
May 28, 2006
937
++src;
May 29, 2006
May 29, 2006
938
RGB888_RGB332(*dst++, *src);
May 28, 2006
May 28, 2006
939
940
941
942
++src;
}
switch (width & 3) {
case 3:
May 29, 2006
May 29, 2006
943
RGB888_RGB332(*dst++, *src);
May 28, 2006
May 28, 2006
944
945
++src;
case 2:
May 29, 2006
May 29, 2006
946
RGB888_RGB332(*dst++, *src);
May 28, 2006
May 28, 2006
947
948
++src;
case 1:
May 29, 2006
May 29, 2006
949
RGB888_RGB332(*dst++, *src);
May 28, 2006
May 28, 2006
950
951
++src;
}
Apr 26, 2001
Apr 26, 2001
952
#endif /* USE_DUFFS_LOOP */
May 28, 2006
May 28, 2006
953
954
955
956
957
src += srcskip;
dst += dstskip;
}
} else {
int Pixel;
Apr 26, 2001
Apr 26, 2001
958
May 28, 2006
May 28, 2006
959
while (height--) {
Apr 26, 2001
Apr 26, 2001
960
#ifdef USE_DUFFS_LOOP
May 28, 2006
May 28, 2006
961
/* *INDENT-OFF* */
Apr 26, 2001
Apr 26, 2001
962
DUFFS_LOOP(
Oct 20, 2005
Oct 20, 2005
963
964
RGB888_RGB332(Pixel, *src);
*dst++ = map[Pixel];
Apr 26, 2001
Apr 26, 2001
965
966
++src;
, width);
May 28, 2006
May 28, 2006
967
/* *INDENT-ON* */
Apr 26, 2001
Apr 26, 2001
968
#else
May 28, 2006
May 28, 2006
969
970
for (c = width / 4; c; --c) {
/* Pack RGB into 8bit pixel */
May 29, 2006
May 29, 2006
971
RGB888_RGB332(Pixel, *src);
May 28, 2006
May 28, 2006
972
973
*dst++ = map[Pixel];
++src;
May 29, 2006
May 29, 2006
974
RGB888_RGB332(Pixel, *src);
May 28, 2006
May 28, 2006
975
976
*dst++ = map[Pixel];
++src;
May 29, 2006
May 29, 2006
977
RGB888_RGB332(Pixel, *src);
May 28, 2006
May 28, 2006
978
979
*dst++ = map[Pixel];
++src;
May 29, 2006
May 29, 2006
980
RGB888_RGB332(Pixel, *src);
May 28, 2006
May 28, 2006
981
982
983
984
985
*dst++ = map[Pixel];
++src;
}
switch (width & 3) {
case 3:
May 29, 2006
May 29, 2006
986
RGB888_RGB332(Pixel, *src);
May 28, 2006
May 28, 2006
987
988
989
*dst++ = map[Pixel];
++src;
case 2:
May 29, 2006
May 29, 2006
990
RGB888_RGB332(Pixel, *src);
May 28, 2006
May 28, 2006
991
992
993
*dst++ = map[Pixel];
++src;
case 1:
May 29, 2006
May 29, 2006
994
RGB888_RGB332(Pixel, *src);
May 28, 2006
May 28, 2006
995
996
997
*dst++ = map[Pixel];
++src;
}
Apr 26, 2001
Apr 26, 2001
998
#endif /* USE_DUFFS_LOOP */
May 28, 2006
May 28, 2006
999
1000
src += srcskip;
dst += dstskip;