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
|
; PowerPC optimized zoom for Goom
; © 2001-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., 59 Temple Place - Suite 330,
; Boston, MA 02111-1307, USA.
; Change log :
; 21 Dec 2003 : Use of altivec is now determined with a parameter
; Section definition : We use a read only section
.text
; name of the function to call by C program : ppc_zoom
; We declare this label as a global to extend its scope outside this file
.globl _ppc_zoom_generic
.globl _ppc_zoom_G4
; Description :
; This routine dynamically computes and applies a zoom filter
; parameters :
; r3 <=> unsigned int sizeX (in pixels)
; r4 <=> unsigned int sizeY (in pixels)
; r5 <=> unsigned int * frompixmap
; r6 <=> unsigned int * topixmap
; r7 <=> unsigned int * brutS
; r8 <=> unsigned int * brutD
; r9 <=> unsigned int buffratio
; r10 <=> int [16][16] precalccoeffs
; globals after init
; r5 <=> frompixmap - 1 byte needed for preincremental fetch (replaces r5)
; r6 <=> topixmap - 1 byte needed for preincremental fetch (replaces r6)
; r3 <=> ax = x max in 16th of pixels (replaces old r3)
; r4 <=> ay = y max in 16th of pixels (replaces old r4)
; r20 <=> row size in bytes
; r12 <=> 0xFF00FF (mask for parallel 32 bits pixs computing)
; r30 <=> brutS - 1 byte needed for preincremental fetch (replaces r7)
; r31 <=> brutD - 1 byte needed for preincremental fetch (replaces r8)
; ABI notes :
; r1 is the Stack Pointer (SP) => Do not use
; r13..r31 are non-volatiles => Do not use
_ppc_zoom_generic:
; Saves the used non volatile registers in the Mach-O stack s Red-Zone
stmw r18,-56(r1)
; init
li r18,0 ; Default value if out of range : 0 (Black)
mr r11,r10
lis r12,0xFF
mullw r2,r3,r4 ; Number of pixels to compute
subi r30,r8,0
slwi r20,r3,2
srawi r19,r20,2
ori r12,r12,0xFF
subi r3,r3,1
subi r4,r4,1
mtspr ctr,r2 ; Init the loop count (one loop per pixel computed)
subi r31,r7,0
subi r6,r6,4
slwi r3,r3,4
slwi r4,r4,4
;pre init for loop
lwz r2,0(r31) ; px
lwz r29,4(r31) ; py
lwz r8,0(r30) ; px2
lwz r10,4(r30) ; py2
b L1
.align 5
L1:
; computes dynamically the position to fetch
sub r8,r8,r2
sub r10,r10,r29
mullw r8,r8,r9
addi r31,r31,8
mullw r10,r10,r9
addi r30,r30,8
srawi r8,r8,16
srawi r10,r10,16
add r2,r2,r8
add r29,r29,r10
; if px>ax or py>ay goto outofrange
; computes the attenuation coeffs and the original point address
rlwinm r10,r2,6,28-6,31-6 ; r10 <- (r2 << 2) & 0x000002D0 (r10=(r2%16)*4*16)
cmpl cr4,0,r2,r3
rlwimi r10, r29, 2, 28-2, 31-2 ; r10 <- ((r29 << 2) & 0x0000002D) | (r10 & !0x0000002D) (r10=(r10%16)*4 | r10)
cmpl cr7,0,r29,r4
srawi r29,r29,4 ; pos computing
bge- cr4,L4
srawi r2,r2,4 ; pos computing
mullw r29, r29,r19 ; pos computing
bge- cr7,L4
; Channels notation : 00112233 (AARRVVBB)
add r2,r2,r29 ; pos computing
lwzx r10,r11,r10 ; Loads coefs
slwi r2,r2,2 ; pos computing
add r2,r2,r5 ; pos computing
rlwinm r21,r10,0,24,31 ; Isolates coef1 (??????11 -> 00000011)
lwz r25,0(r2) ; Loads col1 -> r25
lwz r26,4(r2) ; Loads col2 -> r26
rlwinm r22,r10,24,24,31 ; Isolates coef2 (????22?? -> 00000022)
rlwinm r23,r10,16,24,31 ; Isolates coef3 (??33???? -> 00000033)
add r2,r2,r20 ; Adds one line for future load of col3 and col4
and r8, r25,r12 ; Masks col1 channels 1 & 3 : 0x00XX00XX
rlwinm r24,r10,8,24,31 ; Isolates coef4 (44?????? -> 00000044)
andi. r25,r25,0xFF00 ; Masks col1 channel 2 : 0x0000XX00
mullw r8, r8, r21 ; Applies coef1 on col1 channels 1 & 3
; computes final pixel color
and r10,r26,r12 ; Masks col2 channels 1 & 3 : 0x00XX00XX
lwz r27,0(r2) ; Loads col3 -> r27
mullw r10,r10,r22 ; Applies coef2 on col2 channels 1 & 3
mullw r25,r25,r21 ; Applies coef1 on col1 channel 2
andi. r29,r26,0xFF00 ; Masks col2 channel 2 : 0x0000XX00
mullw r29,r29,r22 ; Applies coef2 on col2 channel 2
lwz r28,4(r2) ; Loads col4 -> r28
add r8 ,r8 ,r10 ; Adds col1 & col2 channels 1 & 3
and r10,r27,r12 ; Masks col3 channels 1 & 3 : 0x00XX00XX
add r25,r25,r29 ; Adds col1 & col2 channel 2
mullw r10,r10,r23 ; Applies coef3 on col3 channels 1 & 3
andi. r29,r27,0xFF00 ; Masks col3 channel 2 : 0x0000XX00
mullw r29,r29,r23 ; Applies coef3 on col3 channel 2
lwz r2,0(r31) ; px
add r7 ,r8 ,r10 ; Adds col3 to (col1 + col2) channels 1 & 3
and r10,r28,r12 ; Masks col4 channels 1 & 3 : 0x00XX00XX
mullw r10,r10,r24 ; Applies coef4 on col4 channels 1 & 3
add r25,r25,r29 ; Adds col 3 to (col1 + col2) channel 2
lwz r8,0(r30) ; px2
andi. r28,r28,0xFF00 ; Masks col4 channel 2 : 0x0000XX00
add r7 ,r7 ,r10 ; Adds col4 to (col1 + col2 + col3) channels 1 & 3
lwz r10,4(r30) ; py2
mullw r28,r28,r24 ; Applies coef4 on col4 channel 2
srawi r7, r7, 8 ; (sum of channels 1 & 3) >> 8
lwz r29,4(r31) ; py
add r25,r25,r28 ; Adds col 4 to (col1 + col2 + col3) channel 2
rlwimi r7, r25, 24, 16, 23 ; (((sum of channels 2) >> 8 ) & 0x0000FF00) | ((sum of channels 1 and 3) & 0xFFFF00FF)
stwu r7,4(r6) ; Stores the computed pixel
bdnz L1 ; Iterate again if needed
b L3 ;goto end ; If not, returns from the function
; if out of range
L4:
stwu r18,4(r6)
lwz r8,0(r30) ; px2
lwz r10,4(r30) ; py2
lwz r2,0(r31) ; px
lwz r29,4(r31) ; py
bdnz L1
L3:
; Restore saved registers and return
lmw r18,-56(r1)
blr
_ppc_zoom_G4:
; Saves the used non volatile registers in the Mach-O stack s Red-Zone
stmw r17,-60(r1)
; init
li r18,0 ; Default value if out of range : 0 (Black)
mr r11,r10
lis r12,0xFF
mullw r2,r3,r4 ; Number of pixels to compute
subi r30,r8,0
slwi r20,r3,2
srawi r19,r20,2
ori r12,r12,0xFF
subi r3,r3,1
subi r4,r4,1
mtspr ctr,r2 ; Init the loop count (one loop per pixel computed)
subi r31,r7,0
subi r6,r6,4
slwi r3,r3,4
slwi r4,r4,4
;pre init for loop
lwz r2,0(r31) ; px
lwz r29,4(r31) ; py
lwz r8,0(r30) ; px2
lwz r10,4(r30) ; py2
;*********************
lis r17,0x0F01
b L100
.align 5
L100:
addi r6,r6,4
; Optimization to ensure the destination buffer
; won't be loaded into the data cache
rlwinm. r0,r6,0,27,31
bne+ L500
dcbz 0,r6
;dcba 0,r6
L500:
; computes dynamically the position to fetch
;mullw r8,r8,r29
;mullw r2,r2,r29
;add r2,r8,r2
;srawi r2,r2,17
sub r8,r8,r2
sub r10,r10,r29
mullw r8,r8,r9
addi r31,r31,8
mullw r10,r10,r9
addi r30,r30,8
dst r30,r17,0
srawi r8,r8,16
srawi r10,r10,16
add r2,r2,r8
add r29,r29,r10
dst r31,r17,1
; if px>ax or py>ay goto outofrange
; computes the attenuation coeffs and the original point address
rlwinm r10,r2,6,28-6,31-6 ; r10 <- (r2 << 2) & 0x000002D0 (r10=(r2%16)*4*16)
cmpl cr4,0,r2,r3
rlwimi r10, r29, 2, 28-2, 31-2 ; r10 <- ((r29 << 2) & 0x0000002D) | (r10 & !0x0000002D) (r10=(r29%16)*4 | r10)
cmpl cr7,0,r29,r4
srawi r29,r29,4 ; pos computing
bge- cr4,L400
srawi r2,r2,4 ; pos computing
mullw r29, r29,r19 ; pos computing
bge- cr7,L400
; Channels notation : 00112233 (AARRVVBB)
add r2,r2,r29 ; pos computing
lwzx r10,r11,r10 ; Loads coefs
slwi r2,r2,2 ; pos computing
add r2,r2,r5 ; pos computing
rlwinm r21,r10,0,24,31 ; Isolates coef1 (??????11 -> 00000011)
lwz r25,0(r2) ; Loads col1 -> r25
lwz r26,4(r2) ; Loads col2 -> r26
rlwinm r22,r10,24,24,31 ; Isolates coef2 (????22?? -> 00000022)
rlwinm r23,r10,16,24,31 ; Isolates coef3 (??33???? -> 00000033)
add r2,r2,r20 ; Adds one line for future load of col3 and col4
and r8, r25,r12 ; Masks col1 channels 1 & 3 : 0x00XX00XX
rlwinm r24,r10,8,24,31 ; Isolates coef4 (44?????? -> 00000044)
dst r2,r17,2
rlwinm r25,r25,0,16,23 ; Masks col1 channel 2 : 0x0000XX00
;andi. r25,r25,0xFF00 ; Masks col1 channel 2 : 0x0000XX00
mullw r8, r8, r21 ; Applies coef1 on col1 channels 1 & 3
; computes final pixel color
and r10,r26,r12 ; Masks col2 channels 1 & 3 : 0x00XX00XX
lwz r27,0(r2) ; Loads col3 -> r27
mullw r10,r10,r22 ; Applies coef2 on col2 channels 1 & 3
mullw r25,r25,r21 ; Applies coef1 on col1 channel 2
rlwinm r29,r26,0,16,23 ; Masks col2 channel 2 : 0x0000XX00
;andi. r29,r26,0xFF00 ; Masks col2 channel 2 : 0x0000XX00
mullw r29,r29,r22 ; Applies coef2 on col2 channel 2
lwz r28,4(r2) ; Loads col4 -> r28
add r8 ,r8 ,r10 ; Adds col1 & col2 channels 1 & 3
and r10,r27,r12 ; Masks col3 channels 1 & 3 : 0x00XX00XX
add r25,r25,r29 ; Adds col1 & col2 channel 2
mullw r10,r10,r23 ; Applies coef3 on col3 channels 1 & 3
rlwinm r29,r27,0,16,23 ; Masks col3 channel 2 : 0x0000XX00
;andi. r29,r27,0xFF00 ; Masks col3 channel 2 : 0x0000XX00
mullw r29,r29,r23 ; Applies coef3 on col3 channel 2
lwz r2,0(r31) ; px
add r7 ,r8 ,r10 ; Adds col3 to (col1 + col2) channels 1 & 3
and r10,r28,r12 ; Masks col4 channels 1 & 3 : 0x00XX00XX
mullw r10,r10,r24 ; Applies coef4 on col4 channels 1 & 3
add r25,r25,r29 ; Adds col 3 to (col1 + col2) channel 2
lwz r8,0(r30) ; px2
rlwinm r28,r28,0,16,23 ; Masks col4 channel 2 : 0x0000XX00
;andi. r28,r28,0xFF00 ; Masks col4 channel 2 : 0x0000XX00
add r7 ,r7 ,r10 ; Adds col4 to (col1 + col2 + col3) channels 1 & 3
lwz r10,4(r30) ; py2
mullw r28,r28,r24 ; Applies coef4 on col4 channel 2
srawi r7, r7, 8 ; (sum of channels 1 & 3) >> 8
lwz r29,4(r31) ; py
add r25,r25,r28 ; Adds col 4 to (col1 + col2 + col3) channel 2
rlwimi r7, r25, 24, 16, 23 ; (((sum of channels 2) >> 8 ) & 0x0000FF00) | ((sum of channels 1 and 3) & 0xFFFF00FF)
stw r7,0(r6) ; Stores the computed pixel
bdnz L100 ; Iterate again if needed
b L300 ;goto end ; If not, returns from the function
; if out of range
L400:
stw r18,0(r6)
lwz r8,0(r30) ; px2
lwz r10,4(r30) ; py2
lwz r2,0(r31) ; px
lwz r29,4(r31) ; py
bdnz L100
L300:
; Restore saved registers and return
lmw r17,-60(r1)
blr
|