blob: c911fbba20628395f64f3ffde125eee2731dd42e [file] [log] [blame]
Duane Sand068f9f32012-05-24 22:09:24 -07001/* libs/pixelflinger/t32cb16blend.S
2**
3** Copyright 2010, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifdef DEBUG
19#define DBG
20#else
21#define DBG #
22#endif
23
24/*
25 * blend one of 2 16bpp RGB pixels held in dreg selected by shift
26 * with the 32bpp ABGR pixel held in src and store the result in fb
27 *
28 * Assumes that the dreg data is little endian and that
29 * the the second pixel (shift==16) will be merged into
30 * the fb result
31 *
32 * Uses $t0,$t6,$t7,$t8
33 */
34
35#if __mips==32 && __mips_isa_rev>=2
Elliott Hughes7fd12172015-11-05 18:54:11 +000036 .macro pixel dreg src fb shift
37 /*
38 * sA = s >> 24
39 * f = 0x100 - (sA + (sA>>7))
40 */
41DBG .set noat
42DBG rdhwr $at,$2
43DBG .set at
Duane Sand068f9f32012-05-24 22:09:24 -070044
Elliott Hughes7fd12172015-11-05 18:54:11 +000045 srl $t7,\src,24
46 srl $t6,$t7,7
47 addu $t7,$t6
48 li $t6,0x100
49 subu $t7,$t6,$t7
Duane Sand068f9f32012-05-24 22:09:24 -070050
Elliott Hughes7fd12172015-11-05 18:54:11 +000051 /* red */
52 ext $t8,\dreg,\shift+6+5,5 # dst[\shift:15..11]
53 mul $t6,$t8,$t7
54 ext $t0,\dreg,\shift+5,6 # start green extraction dst[\shift:10..5]
55 ext $t8,\src,3,5 # src[7..3]
56 srl $t6,8
57 addu $t8,$t6
58 ins \fb,$t8,\shift+6+5,5 # dst[\shift:15..11]
Duane Sand068f9f32012-05-24 22:09:24 -070059
Elliott Hughes7fd12172015-11-05 18:54:11 +000060 /* green */
61 mul $t8,$t0,$t7
62 ext $t0,\dreg,\shift,5 # start blue extraction dst[\shift:4..0]
63 ext $t6,\src,2+8,6 # src[15..10]
64 srl $t8,8
65 addu $t8,$t6
Duane Sand068f9f32012-05-24 22:09:24 -070066
Elliott Hughes7fd12172015-11-05 18:54:11 +000067 /* blue */
68 mul $t0,$t0,$t7
69 ins \fb,$t8,\shift+5,6 # finish green insertion dst[\shift:10..5]
70 ext $t6,\src,(3+8+8),5
71 srl $t8,$t0,8
72 addu $t8,$t6
73 ins \fb,$t8,\shift,5
Duane Sand068f9f32012-05-24 22:09:24 -070074
Elliott Hughes7fd12172015-11-05 18:54:11 +000075DBG .set noat
76DBG rdhwr $t8,$2
77DBG subu $t8,$at
78DBG sltu $at,$t8,$v0
79DBG movn $v0,$t8,$at
80DBG sgtu $at,$t8,$v1
81DBG movn $v1,$t8,$at
82DBG .set at
83 .endm
Duane Sand068f9f32012-05-24 22:09:24 -070084
85#else
86
Elliott Hughes7fd12172015-11-05 18:54:11 +000087 .macro pixel dreg src fb shift
88 /*
89 * sA = s >> 24
90 * f = 0x100 - (sA + (sA>>7))
91 */
92DBG .set push
93DBG .set noat
94DBG .set mips32r2
95DBG rdhwr $at,$2
96DBG .set pop
Duane Sand068f9f32012-05-24 22:09:24 -070097
Elliott Hughes7fd12172015-11-05 18:54:11 +000098 srl $t7,\src,24
99 srl $t6,$t7,7
100 addu $t7,$t6
101 li $t6,0x100
102 subu $t7,$t6,$t7
Duane Sand068f9f32012-05-24 22:09:24 -0700103
Elliott Hughes7fd12172015-11-05 18:54:11 +0000104 /*
105 * red
106 * dR = (d >> (6 + 5)) & 0x1f;
107 * dR = (f*dR)>>8
108 * sR = (s >> ( 3)) & 0x1f;
109 * sR += dR
110 * fb |= sR << 11
111 */
112 srl $t8,\dreg,\shift+6+5
Duane Sand068f9f32012-05-24 22:09:24 -0700113.if \shift==0
Elliott Hughes7fd12172015-11-05 18:54:11 +0000114 and $t8,0x1f
Duane Sand068f9f32012-05-24 22:09:24 -0700115.endif
Elliott Hughes7fd12172015-11-05 18:54:11 +0000116 mul $t8,$t8,$t7
117 srl $t6,\src,3
118 and $t6,0x1f
119 srl $t8,8
120 addu $t8,$t6
Duane Sand068f9f32012-05-24 22:09:24 -0700121.if \shift!=0
Elliott Hughes7fd12172015-11-05 18:54:11 +0000122 sll $t8,\shift+11
123 or \fb,$t8
Duane Sand068f9f32012-05-24 22:09:24 -0700124.else
Elliott Hughes7fd12172015-11-05 18:54:11 +0000125 sll \fb,$t8,11
Duane Sand068f9f32012-05-24 22:09:24 -0700126.endif
127
128 /*
Elliott Hughes7fd12172015-11-05 18:54:11 +0000129 * green
130 * dG = (d >> 5) & 0x3f
131 * dG = (f*dG) >> 8
132 * sG = (s >> ( 8+2))&0x3F;
133 */
134 srl $t8,\dreg,\shift+5
135 and $t8,0x3f
136 mul $t8,$t8,$t7
137 srl $t6,\src,8+2
138 and $t6,0x3f
139 srl $t8,8
140 addu $t8,$t6
141 sll $t8,\shift + 5
142 or \fb,$t8
Duane Sand068f9f32012-05-24 22:09:24 -0700143
Elliott Hughes7fd12172015-11-05 18:54:11 +0000144 /* blue */
Duane Sand068f9f32012-05-24 22:09:24 -0700145.if \shift!=0
Elliott Hughes7fd12172015-11-05 18:54:11 +0000146 srl $t8,\dreg,\shift
147 and $t8,0x1f
Duane Sand068f9f32012-05-24 22:09:24 -0700148.else
Elliott Hughes7fd12172015-11-05 18:54:11 +0000149 and $t8,\dreg,0x1f
Duane Sand068f9f32012-05-24 22:09:24 -0700150.endif
Elliott Hughes7fd12172015-11-05 18:54:11 +0000151 mul $t8,$t8,$t7
152 srl $t6,\src,(8+8+3)
153 and $t6,0x1f
154 srl $t8,8
155 addu $t8,$t6
Duane Sand068f9f32012-05-24 22:09:24 -0700156.if \shift!=0
Elliott Hughes7fd12172015-11-05 18:54:11 +0000157 sll $t8,\shift
Duane Sand068f9f32012-05-24 22:09:24 -0700158.endif
Elliott Hughes7fd12172015-11-05 18:54:11 +0000159 or \fb,$t8
160DBG .set push
161DBG .set noat
162DBG .set mips32r2
163DBG rdhwr $t8,$2
164DBG subu $t8,$at
165DBG sltu $at,$t8,$v0
166DBG movn $v0,$t8,$at
167DBG sgtu $at,$t8,$v1
168DBG movn $v1,$t8,$at
169DBG .set pop
170 .endm
Duane Sand068f9f32012-05-24 22:09:24 -0700171#endif
172
Elliott Hughes7fd12172015-11-05 18:54:11 +0000173 .text
174 .align
Duane Sand068f9f32012-05-24 22:09:24 -0700175
Elliott Hughes7fd12172015-11-05 18:54:11 +0000176 .global scanline_t32cb16blend_mips
177 .ent scanline_t32cb16blend_mips
Duane Sand068f9f32012-05-24 22:09:24 -0700178scanline_t32cb16blend_mips:
Elliott Hughes7fd12172015-11-05 18:54:11 +0000179DBG li $v0,0xffffffff
180DBG li $v1,0
181 /* Align the destination if necessary */
182 and $t0,$a0,3
183 beqz $t0,aligned
Duane Sand068f9f32012-05-24 22:09:24 -0700184
Elliott Hughes7fd12172015-11-05 18:54:11 +0000185 /* as long as there is at least one pixel */
186 beqz $a2,done
Duane Sand068f9f32012-05-24 22:09:24 -0700187
Elliott Hughes7fd12172015-11-05 18:54:11 +0000188 lw $t4,($a1)
189 addu $a0,2
190 addu $a1,4
191 beqz $t4,1f
192 lhu $t3,-2($a0)
193 pixel $t3,$t4,$t1,0
194 sh $t1,-2($a0)
1951: subu $a2,1
Duane Sand068f9f32012-05-24 22:09:24 -0700196
197aligned:
Elliott Hughes7fd12172015-11-05 18:54:11 +0000198 /* Check to see if its worth unrolling the loop */
199 subu $a2,4
200 bltz $a2,tail
Duane Sand068f9f32012-05-24 22:09:24 -0700201
Elliott Hughes7fd12172015-11-05 18:54:11 +0000202 /* Process 4 pixels at a time */
Duane Sand068f9f32012-05-24 22:09:24 -0700203fourpixels:
Elliott Hughes7fd12172015-11-05 18:54:11 +0000204 /* 1st pair of pixels */
205 lw $t4,0($a1)
206 lw $t5,4($a1)
207 addu $a0,8
208 addu $a1,16
Duane Sand068f9f32012-05-24 22:09:24 -0700209
Elliott Hughes7fd12172015-11-05 18:54:11 +0000210 /* both are zero, skip this pair */
211 or $t3,$t4,$t5
212 beqz $t3,1f
Duane Sand068f9f32012-05-24 22:09:24 -0700213
Elliott Hughes7fd12172015-11-05 18:54:11 +0000214 /* load the destination */
215 lw $t3,-8($a0)
Duane Sand068f9f32012-05-24 22:09:24 -0700216
Elliott Hughes7fd12172015-11-05 18:54:11 +0000217 pixel $t3,$t4,$t1,0
218 pixel $t3,$t5,$t1,16
219 sw $t1,-8($a0)
Duane Sand068f9f32012-05-24 22:09:24 -0700220
2211:
Elliott Hughes7fd12172015-11-05 18:54:11 +0000222 /* 2nd pair of pixels */
223 lw $t4,-8($a1)
224 lw $t5,-4($a1)
Duane Sand068f9f32012-05-24 22:09:24 -0700225
Elliott Hughes7fd12172015-11-05 18:54:11 +0000226 /* both are zero, skip this pair */
227 or $t3,$t4,$t5
228 beqz $t3,1f
Duane Sand068f9f32012-05-24 22:09:24 -0700229
Elliott Hughes7fd12172015-11-05 18:54:11 +0000230 /* load the destination */
231 lw $t3,-4($a0)
Duane Sand068f9f32012-05-24 22:09:24 -0700232
Elliott Hughes7fd12172015-11-05 18:54:11 +0000233 pixel $t3,$t4,$t1,0
234 pixel $t3,$t5,$t1,16
235 sw $t1,-4($a0)
Duane Sand068f9f32012-05-24 22:09:24 -0700236
Elliott Hughes7fd12172015-11-05 18:54:11 +00002371: subu $a2,4
238 bgtz $a2,fourpixels
Duane Sand068f9f32012-05-24 22:09:24 -0700239
240tail:
Elliott Hughes7fd12172015-11-05 18:54:11 +0000241 /* the pixel count underran, restore it now */
242 addu $a2,4
Duane Sand068f9f32012-05-24 22:09:24 -0700243
Elliott Hughes7fd12172015-11-05 18:54:11 +0000244 /* handle the last 0..3 pixels */
245 beqz $a2,done
Duane Sand068f9f32012-05-24 22:09:24 -0700246onepixel:
Elliott Hughes7fd12172015-11-05 18:54:11 +0000247 lw $t4,($a1)
248 addu $a0,2
249 addu $a1,4
250 beqz $t4,1f
251 lhu $t3,-2($a0)
252 pixel $t3,$t4,$t1,0
253 sh $t1,-2($a0)
2541: subu $a2,1
255 bnez $a2,onepixel
Duane Sand068f9f32012-05-24 22:09:24 -0700256done:
Elliott Hughes7fd12172015-11-05 18:54:11 +0000257DBG .set push
258DBG .set mips32r2
259DBG rdhwr $a0,$3
260DBG mul $v0,$a0
261DBG mul $v1,$a0
262DBG .set pop
263 j $ra
264 .end scanline_t32cb16blend_mips