1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
; PowerPC optimized drawing methods for Goom
; © 2003 Guillaume Borios
; This library is free software; you can redistribute it and/or
; modify it under the terms of the GNU Library General Public
; License as published by the Free Software Foundation; either
; version 2 of the License, or (at your option) any later version.
;
; 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
; Library General Public License for more details.
;
; You should have received a copy of the GNU Library 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.
; Change log :
; 30 May 2003 : File creation
; Section definition : We use a read only code section for the whole file
.section __TEXT,__text,regular,pure_instructions
; --------------------------------------------------------------------------------------
; Single 32b pixel drawing macros
; Usage :
; DRAWMETHOD_XXXX_MACRO *pixelIN, *pixelOUT, COLOR, WR1, WR2, WR3, WR4
; Only the work registers (WR) can be touched by the macros
;
; Available methods :
; DRAWMETHOD_DFLT_MACRO : Default drawing method (Actually OVRW)
; DRAWMETHOD_PLUS_MACRO : RVB Saturated per channel addition (SLOWEST)
; DRAWMETHOD_HALF_MACRO : 50% Transparency color drawing
; DRAWMETHOD_OVRW_MACRO : Direct COLOR drawing (FASTEST)
; DRAWMETHOD_B_OR_MACRO : Bitwise OR
; DRAWMETHOD_BAND_MACRO : Bitwise AND
; DRAWMETHOD_BXOR_MACRO : Bitwise XOR
; DRAWMETHOD_BNOT_MACRO : Bitwise NOT
; --------------------------------------------------------------------------------------
.macro DRAWMETHOD_OVRW_MACRO
stw $2,0($1) ;; *$1 <- $2
.endmacro
.macro DRAWMETHOD_B_OR_MACRO
lwz $3,0($0) ;; $3 <- *$0
or $3,$3,$2 ;; $3 <- $3 | $2
stw $3,0($1) ;; *$1 <- $3
.endmacro
.macro DRAWMETHOD_BAND_MACRO
lwz $3,0($0) ;; $3 <- *$0
and $3,$3,$2 ;; $3 <- $3 & $2
stw $3,0($1) ;; *$1 <- $3
.endmacro
.macro DRAWMETHOD_BXOR_MACRO
lwz $3,0($0) ;; $3 <- *$0
xor $3,$3,$2 ;; $3 <- $3 ^ $2
stw $3,0($1) ;; *$1 <- $3
.endmacro
.macro DRAWMETHOD_BNOT_MACRO
lwz $3,0($0) ;; $3 <- *$0
nand $3,$3,$3 ;; $3 <- ~$3
stw $3,0($1) ;; *$1 <- $3
.endmacro
.macro DRAWMETHOD_PLUS_MACRO
lwz $4,0($0) ;; $4 <- *$0
andi. $3,$4,0xFF00 ;; $3 <- $4 & 0x0000FF00
andi. $5,$2,0xFF00 ;; $5 <- $2 & 0x0000FF00
add $3,$3,$5 ;; $3 <- $3 + $5
rlwinm $5,$3,15,0,0 ;; $5 <- 0 | ($3[15] << 15)
srawi $5,$5,23 ;; $5 <- $5 >> 23 (algebraic for sign extension)
or $3,$3,$5 ;; $3 <- $3 | $5
lis $5,0xFF ;; $5 <- 0x00FF00FF
addi $5,$5,0xFF
and $4,$4,$5 ;; $4 <- $4 & $5
and $6,$2,$5 ;; $6 <- $2 & $5
add $4,$4,$6 ;; $4 <- $4 + $6
rlwinm $6,$4,7,0,0 ;; $6 <- 0 | ($4[7] << 7)
srawi $6,$6,15 ;; $6 <- $6 >> 15 (algebraic for sign extension)
rlwinm $5,$4,23,0,0 ;; $5 <- 0 | ($4[23] << 23)
srawi $5,$5,31 ;; $5 <- $5 >> 31 (algebraic for sign extension)
rlwimi $6,$5,0,24,31 ;; $6[24..31] <- $5[24..31]
or $4,$4,$6 ;; $4 <- $4 | $6
rlwimi $4,$3,0,16,23 ;; $4[16..23] <- $3[16..23]
stw $4,0($1) ;; *$1 <- $4
.endmacro
.macro DRAWMETHOD_HALF_MACRO
lwz $4,0($0) ;; $4 <- *$0
andi. $3,$4,0xFF00 ;; $3 <- $4 & 0x0000FF00
andi. $5,$2,0xFF00 ;; $5 <- $2 & 0x0000FF00
add $3,$3,$5 ;; $3 <- $3 + $5
lis $5,0xFF ;; $5 <- 0x00FF00FF
addi $5,$5,0xFF
and $4,$4,$5 ;; $4 <- $4 & $5
and $5,$2,$5 ;; $5 <- $2 & $5
add $4,$4,$5 ;; $4 <- $4 + $5
srwi $4,$4,1 ;; $4 <- $4 >> 1
rlwimi $4,$3,31,16,23 ;; $4[16..23] <- $3[15..22]
stw $4,0($1) ;; *$1 <- $4
.endmacro
.macro DRAWMETHOD_DFLT_MACRO
DRAWMETHOD_PLUS_MACRO
.endmacro
; --------------------------------------------------------------------------------------
; **************************************************************************************
; void DRAWMETHOD_PLUS_PPC(unsigned int * buf, unsigned int _col);
; void DRAWMETHOD_PLUS_2_PPC(unsigned * in, unsigned int * out, unsigned int _col);
; **************************************************************************************
.globl _DRAWMETHOD_PLUS_2_PPC
.align 3
_DRAWMETHOD_PLUS_2_PPC:
DRAWMETHOD_PLUS_MACRO r3,r4,r5,r6,r7,r8,r9
blr ;; return
.globl _DRAWMETHOD_PLUS_PPC
.align 3
_DRAWMETHOD_PLUS_PPC:
DRAWMETHOD_PLUS_MACRO r3,r3,r4,r5,r6,r7,r9
blr ;; return
; **************************************************************************************
; void DRAWMETHOD_HALF_PPC(unsigned int * buf, unsigned int _col);
; void DRAWMETHOD_HALF_2_PPC(unsigned * in, unsigned int * out, unsigned int _col);
; **************************************************************************************
.globl _DRAWMETHOD_HALF_2_PPC
.align 3
_DRAWMETHOD_HALF_2_PPC:
DRAWMETHOD_HALF_MACRO r3,r4,r5,r6,r7,r8
blr ;; return
.globl _DRAWMETHOD_HALF_PPC
.align 3
_DRAWMETHOD_HALF_PPC:
DRAWMETHOD_HALF_MACRO r3,r3,r4,r5,r6,r7
blr ;; return
; **************************************************************************************
; void DRAW_LINE_PPC(unsigned int *data, int x1, int y1, int x2, int y2, unsigned int col,
; unsigned int screenx, unsigned int screeny)
; **************************************************************************************
.globl _DRAW_LINE_PPC
.align 3
_DRAW_LINE_PPC:
;; NOT IMPLEMENTED YET
blr ;; return
; **************************************************************************************
; void _ppc_brightness(Pixel * src, Pixel * dest, unsigned int size, unsigned int coeff)
; **************************************************************************************
.const
.align 4
vectorZERO:
.long 0,0,0,0
.long 0x10101000, 0x10101001, 0x10101002, 0x10101003
.long 0x10101004, 0x10101005, 0x10101006, 0x10101007
.long 0x10101008, 0x10101009, 0x1010100A, 0x1010100B
.long 0x1010100C, 0x1010100D, 0x1010100E, 0x1010100F
.section __TEXT,__text,regular,pure_instructions
.globl _ppc_brightness_G4
.align 3
_ppc_brightness_G4:
;; PowerPC Altivec code
srwi r5,r5,2
mtctr r5
;;vrsave
mfspr r11,256
lis r12,0xCFFC
mtspr 256,r12
mflr r0
bcl 20,31,"L00000000001$pb"
"L00000000001$pb":
mflr r10
mtlr r0
addis r9,r10,ha16(vectorZERO-"L00000000001$pb")
addi r9,r9,lo16(vectorZERO-"L00000000001$pb")
vxor v0,v0,v0 ;; V0 = NULL vector
addi r9,r9,16
lvx v10,0,r9
addi r9,r9,16
lvx v11,0,r9
addi r9,r9,16
lvx v12,0,r9
addi r9,r9,16
lvx v13,0,r9
addis r9,r10,ha16(vectortmpwork-"L00000000001$pb")
addi r9,r9,lo16(vectortmpwork-"L00000000001$pb")
stw r6,0(r9)
li r6,8
stw r6,4(r9)
lvx v9,0,r9
li r9,128
vspltw v8,v9,0
vspltw v9,v9,1
;; elt counter
li r9,0
lis r7,0x0F01
b L7
.align 4
L7:
lvx v1,r9,r3
vperm v4,v1,v0,v10
;*********************
add r10,r9,r3
;*********************
vperm v5,v1,v0,v11
vperm v6,v1,v0,v12
vperm v7,v1,v0,v13
vmulouh v4,v4,v8
;*********************
dst r10,r7,3
;*********************
vmulouh v5,v5,v8
vmulouh v6,v6,v8
vmulouh v7,v7,v8
vsrw v4,v4,v9
vsrw v5,v5,v9
vsrw v6,v6,v9
vsrw v7,v7,v9
vpkuwus v4,v4,v5
vpkuwus v6,v6,v7
vpkuhus v1,v4,v6
stvx v1,r9,r4
addi r9,r9,16
bdnz L7
mtspr 256,r11
blr
.globl _ppc_brightness_G5
.align 3
_ppc_brightness_G5:
;; PowerPC Altivec G5 code
srwi r5,r5,2
mtctr r5
;;vrsave
mfspr r11,256
lis r12,0xCFFC
mtspr 256,r12
mflr r0
bcl 20,31,"L00000000002$pb"
"L00000000002$pb":
mflr r10
mtlr r0
addis r9,r10,ha16(vectorZERO-"L00000000002$pb")
addi r9,r9,lo16(vectorZERO-"L00000000002$pb")
vxor v0,v0,v0 ;; V0 = NULL vector
addi r9,r9,16
lvx v10,0,r9
addi r9,r9,16
lvx v11,0,r9
addi r9,r9,16
lvx v12,0,r9
addi r9,r9,16
lvx v13,0,r9
addis r9,r10,ha16(vectortmpwork-"L00000000002$pb")
addi r9,r9,lo16(vectortmpwork-"L00000000002$pb")
stw r6,0(r9)
li r6,8
stw r6,4(r9)
lvx v9,0,r9
li r9,128
vspltw v8,v9,0
vspltw v9,v9,1
;; elt counter
li r9,0
lis r7,0x0F01
b L6
.align 4
L6:
lvx v1,r9,r3
vperm v4,v1,v0,v10
;*********************
add r10,r9,r3
;*********************
vperm v5,v1,v0,v11
vperm v6,v1,v0,v12
vperm v7,v1,v0,v13
vmulouh v4,v4,v8
vmulouh v5,v5,v8
vmulouh v6,v6,v8
vmulouh v7,v7,v8
vsrw v4,v4,v9
vsrw v5,v5,v9
vsrw v6,v6,v9
vsrw v7,v7,v9
vpkuwus v4,v4,v5
vpkuwus v6,v6,v7
vpkuhus v1,v4,v6
stvx v1,r9,r4
addi r9,r9,16
bdnz L6
mtspr 256,r11
blr
.globl _ppc_brightness_generic
.align 3
_ppc_brightness_generic:
lis r12,0x00FF
ori r12,r12,0x00FF
subi r3,r3,4
subi r4,r4,4
mtctr r5
b L1
.align 4
L1:
lwzu r7,4(r3)
rlwinm r8,r7,16,24,31
rlwinm r9,r7,24,24,31
mullw r8,r8,r6
rlwinm r10,r7,0,24,31
mullw r9,r9,r6
srwi r8,r8,8
mullw r10,r10,r6
srwi r9,r9,8
rlwinm. r11,r8,0,0,23
beq L2
li r8,0xFF
L2:
srwi r10,r10,8
rlwinm. r11,r9,0,0,23
beq L3
li r9,0xFF
L3:
rlwinm r7,r8,16,8,15
rlwinm. r11,r10,0,0,23
beq L4
li r10,0xFF
L4:
rlwimi r7,r9,8,16,23
rlwimi r7,r10,0,24,31
stwu r7,4(r4)
bdnz L1
blr
.static_data
.align 4
vectortmpwork:
.long 0,0,0,0
|