Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 1 | /* 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 Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 36 | .macro pixel dreg src fb shift |
| 37 | /* |
| 38 | * sA = s >> 24 |
| 39 | * f = 0x100 - (sA + (sA>>7)) |
| 40 | */ |
| 41 | DBG .set noat |
| 42 | DBG rdhwr $at,$2 |
| 43 | DBG .set at |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 44 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 45 | srl $t7,\src,24 |
| 46 | srl $t6,$t7,7 |
| 47 | addu $t7,$t6 |
| 48 | li $t6,0x100 |
| 49 | subu $t7,$t6,$t7 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 50 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 51 | /* 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 | .if \shift!=0 |
| 59 | sll $t8,\shift+11 |
| 60 | or \fb,$t8 |
| 61 | .else |
| 62 | sll \fb,$t8,11 |
| 63 | .endif |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 64 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 65 | /* green */ |
| 66 | mul $t8,$t0,$t7 |
| 67 | ext $t0,\dreg,\shift,5 # start blue extraction dst[\shift:4..0] |
| 68 | ext $t6,\src,2+8,6 # src[15..10] |
| 69 | srl $t8,8 |
| 70 | addu $t8,$t6 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 71 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 72 | /* blue */ |
| 73 | mul $t0,$t0,$t7 |
| 74 | sll $t8, $t8, \shift+5 |
| 75 | or \fb, \fb, $t8 |
| 76 | ext $t6,\src,(3+8+8),5 |
| 77 | srl $t8,$t0,8 |
| 78 | addu $t8,$t6 |
| 79 | sll $t8, $t8, \shift |
| 80 | or \fb, \fb, $t8 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 81 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 82 | DBG .set noat |
| 83 | DBG rdhwr $t8,$2 |
| 84 | DBG subu $t8,$at |
| 85 | DBG sltu $at,$t8,$v0 |
| 86 | DBG movn $v0,$t8,$at |
| 87 | DBG sgtu $at,$t8,$v1 |
| 88 | DBG movn $v1,$t8,$at |
| 89 | DBG .set at |
| 90 | .endm |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 91 | |
| 92 | #else |
| 93 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 94 | .macro pixel dreg src fb shift |
| 95 | /* |
| 96 | * sA = s >> 24 |
| 97 | * f = 0x100 - (sA + (sA>>7)) |
| 98 | */ |
| 99 | DBG .set push |
| 100 | DBG .set noat |
| 101 | DBG .set mips32r2 |
| 102 | DBG rdhwr $at,$2 |
| 103 | DBG .set pop |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 104 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 105 | srl $t7,\src,24 |
| 106 | srl $t6,$t7,7 |
| 107 | addu $t7,$t6 |
| 108 | li $t6,0x100 |
| 109 | subu $t7,$t6,$t7 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 110 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 111 | /* |
| 112 | * red |
| 113 | * dR = (d >> (6 + 5)) & 0x1f; |
| 114 | * dR = (f*dR)>>8 |
| 115 | * sR = (s >> ( 3)) & 0x1f; |
| 116 | * sR += dR |
| 117 | * fb |= sR << 11 |
| 118 | */ |
| 119 | srl $t8,\dreg,\shift+6+5 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 120 | .if \shift==0 |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 121 | and $t8,0x1f |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 122 | .endif |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 123 | mul $t8,$t8,$t7 |
| 124 | srl $t6,\src,3 |
| 125 | and $t6,0x1f |
| 126 | srl $t8,8 |
| 127 | addu $t8,$t6 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 128 | .if \shift!=0 |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 129 | sll $t8,\shift+11 |
| 130 | or \fb,$t8 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 131 | .else |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 132 | sll \fb,$t8,11 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 133 | .endif |
| 134 | |
| 135 | /* |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 136 | * green |
| 137 | * dG = (d >> 5) & 0x3f |
| 138 | * dG = (f*dG) >> 8 |
| 139 | * sG = (s >> ( 8+2))&0x3F; |
| 140 | */ |
| 141 | srl $t8,\dreg,\shift+5 |
| 142 | and $t8,0x3f |
| 143 | mul $t8,$t8,$t7 |
| 144 | srl $t6,\src,8+2 |
| 145 | and $t6,0x3f |
| 146 | srl $t8,8 |
| 147 | addu $t8,$t6 |
| 148 | sll $t8,\shift + 5 |
| 149 | or \fb,$t8 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 150 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 151 | /* blue */ |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 152 | .if \shift!=0 |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 153 | srl $t8,\dreg,\shift |
| 154 | and $t8,0x1f |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 155 | .else |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 156 | and $t8,\dreg,0x1f |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 157 | .endif |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 158 | mul $t8,$t8,$t7 |
| 159 | srl $t6,\src,(8+8+3) |
| 160 | and $t6,0x1f |
| 161 | srl $t8,8 |
| 162 | addu $t8,$t6 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 163 | .if \shift!=0 |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 164 | sll $t8,\shift |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 165 | .endif |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 166 | or \fb,$t8 |
| 167 | DBG .set push |
| 168 | DBG .set noat |
| 169 | DBG .set mips32r2 |
| 170 | DBG rdhwr $t8,$2 |
| 171 | DBG subu $t8,$at |
| 172 | DBG sltu $at,$t8,$v0 |
| 173 | DBG movn $v0,$t8,$at |
| 174 | DBG sgtu $at,$t8,$v1 |
| 175 | DBG movn $v1,$t8,$at |
| 176 | DBG .set pop |
| 177 | .endm |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 178 | #endif |
| 179 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 180 | .text |
Nikola Veljkovic | 1109f11 | 2016-07-13 22:08:18 +0200 | [diff] [blame] | 181 | .balign 4 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 182 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 183 | .global scanline_t32cb16blend_mips |
| 184 | .ent scanline_t32cb16blend_mips |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 185 | scanline_t32cb16blend_mips: |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 186 | DBG li $v0,0xffffffff |
| 187 | DBG li $v1,0 |
| 188 | /* Align the destination if necessary */ |
| 189 | and $t0,$a0,3 |
| 190 | beqz $t0,aligned |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 191 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 192 | /* as long as there is at least one pixel */ |
| 193 | beqz $a2,done |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 194 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 195 | lw $t4,($a1) |
| 196 | addu $a0,2 |
| 197 | addu $a1,4 |
| 198 | beqz $t4,1f |
| 199 | lhu $t3,-2($a0) |
| 200 | pixel $t3,$t4,$t1,0 |
| 201 | sh $t1,-2($a0) |
| 202 | 1: subu $a2,1 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 203 | |
| 204 | aligned: |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 205 | /* Check to see if its worth unrolling the loop */ |
| 206 | subu $a2,4 |
| 207 | bltz $a2,tail |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 208 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 209 | /* Process 4 pixels at a time */ |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 210 | fourpixels: |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 211 | /* 1st pair of pixels */ |
| 212 | lw $t4,0($a1) |
| 213 | lw $t5,4($a1) |
| 214 | addu $a0,8 |
| 215 | addu $a1,16 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 216 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 217 | /* both are zero, skip this pair */ |
| 218 | or $t3,$t4,$t5 |
| 219 | beqz $t3,1f |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 220 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 221 | /* load the destination */ |
| 222 | lw $t3,-8($a0) |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 223 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 224 | pixel $t3,$t4,$t1,0 |
| 225 | andi $t1, 0xFFFF |
| 226 | pixel $t3,$t5,$t1,16 |
| 227 | sw $t1,-8($a0) |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 228 | |
| 229 | 1: |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 230 | /* 2nd pair of pixels */ |
| 231 | lw $t4,-8($a1) |
| 232 | lw $t5,-4($a1) |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 233 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 234 | /* both are zero, skip this pair */ |
| 235 | or $t3,$t4,$t5 |
| 236 | beqz $t3,1f |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 237 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 238 | /* load the destination */ |
| 239 | lw $t3,-4($a0) |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 240 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 241 | pixel $t3,$t4,$t1,0 |
| 242 | andi $t1, 0xFFFF |
| 243 | pixel $t3,$t5,$t1,16 |
| 244 | sw $t1,-4($a0) |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 245 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 246 | 1: subu $a2,4 |
| 247 | bgtz $a2,fourpixels |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 248 | |
| 249 | tail: |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 250 | /* the pixel count underran, restore it now */ |
| 251 | addu $a2,4 |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 252 | |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 253 | /* handle the last 0..3 pixels */ |
| 254 | beqz $a2,done |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 255 | onepixel: |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 256 | lw $t4,($a1) |
| 257 | addu $a0,2 |
| 258 | addu $a1,4 |
| 259 | beqz $t4,1f |
| 260 | lhu $t3,-2($a0) |
| 261 | pixel $t3,$t4,$t1,0 |
| 262 | sh $t1,-2($a0) |
| 263 | 1: subu $a2,1 |
| 264 | bnez $a2,onepixel |
Duane Sand | 068f9f3 | 2012-05-24 22:09:24 -0700 | [diff] [blame] | 265 | done: |
Elliott Hughes | 606d4ae | 2015-11-05 18:55:20 +0000 | [diff] [blame] | 266 | DBG .set push |
| 267 | DBG .set mips32r2 |
| 268 | DBG rdhwr $a0,$3 |
| 269 | DBG mul $v0,$a0 |
| 270 | DBG mul $v1,$a0 |
| 271 | DBG .set pop |
| 272 | j $ra |
| 273 | .end scanline_t32cb16blend_mips |