| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Author: Siarhei Siamashka (siarhei.siamashka@nokia.com) |
| 24 | */ |
| 25 |
| 26 | /* |
| 27 | * This file contains a macro ('generate_composite_function') which can |
| 28 | * construct 2D image processing functions, based on a common template. |
| 29 | * Any combinations of source, destination and mask images with 8bpp, |
| 30 | * 16bpp, 24bpp, 32bpp color formats are supported. |
| 31 | * |
| 32 | * This macro takes care of: |
| 33 | * - handling of leading and trailing unaligned pixels |
| 34 | * - doing most of the work related to L2 cache preload |
| 35 | * - encourages the use of software pipelining for better instructions |
| 36 | * scheduling |
| 37 | * |
| 38 | * The user of this macro has to provide some configuration parameters |
| 39 | * (bit depths for the images, prefetch distance, etc.) and a set of |
| 40 | * macros, which should implement basic code chunks responsible for |
| 41 | * pixels processing. See 'pixman-armv8-neon-asm.S' file for the usage |
| 42 | * examples. |
| 43 | * |
| 44 | * TODO: |
| 45 | * - try overlapped pixel method (from Ian Rickards) when processing |
| 46 | * exactly two blocks of pixels |
| 47 | * - maybe add an option to do reverse scanline processing |
| 48 | */ |
| 49 |
| 50 | /* |
| 51 | * Bit flags for 'generate_composite_function' macro which are used |
| 52 | * to tune generated functions behavior. |
| 53 | */ |
| 54 | .set FLAG_DST_WRITEONLY, 0 |
| 55 | .set FLAG_DST_READWRITE, 1 |
| 56 | .set FLAG_DEINTERLEAVE_32BPP, 2 |
| 57 |
| 58 | /* |
| 59 | * Constants for selecting preferable prefetch type. |
| 60 | */ |
| 61 | .set PREFETCH_TYPE_NONE, 0 /* No prefetch at all */ |
| 62 | .set PREFETCH_TYPE_SIMPLE, 1 /* A simple, fixed-distance-ahead prefetch */ |
| 63 | .set PREFETCH_TYPE_ADVANCED, 2 /* Advanced fine-grained prefetch */ |
| 64 |
| 65 | /* |
| 66 | * prefetch mode |
| 67 | * available modes are: |
| 68 | * pldl1keep |
| 69 | * pldl1strm |
| 70 | * pldl2keep |
| 71 | * pldl2strm |
| 72 | * pldl3keep |
| 73 | * pldl3strm |
| 74 | */ |
| 75 | #define PREFETCH_MODE pldl1keep |
| 76 |
| 77 | /* |
| 78 | * Definitions of supplementary pixld/pixst macros (for partial load/store of |
| 79 | * pixel data). |
| 80 | */ |
| 81 |
| 82 | .macro pixldst1 op, elem_size, reg1, mem_operand, abits |
| 83 | op {v®1&.&elem_size}, [&mem_operand&], #8 |
| 84 | .endm |
| 85 |
| 86 | .macro pixldst2 op, elem_size, reg1, reg2, mem_operand, abits |
| 87 | op {v®1&.&elem_size, v®2&.&elem_size}, [&mem_operand&], #16 |
| 88 | .endm |
| 89 |
| 90 | .macro pixldst4 op, elem_size, reg1, reg2, reg3, reg4, mem_operand, abits |
| 91 | op {v®1&.&elem_size, v®2&.&elem_size, v®3&.&elem_size, v®4&.&elem_size}, [&mem_operand&], #32 |
| 92 | .endm |
| 93 |
| 94 | .macro pixldst0 op, elem_size, reg1, idx, mem_operand, abits, bytes |
| 95 | op {v®1&.&elem_size}[idx], [&mem_operand&], #&bytes& |
| 96 | .endm |
| 97 |
| 98 | .macro pixldst3 op, elem_size, reg1, reg2, reg3, mem_operand |
| 99 | op {v®1&.&elem_size, v®2&.&elem_size, v®3&.&elem_size}, [&mem_operand&], #24 |
| 100 | .endm |
| 101 |
| 102 | .macro pixldst30 op, elem_size, reg1, reg2, reg3, idx, mem_operand |
| 103 | op {v®1&.&elem_size, v®2&.&elem_size, v®3&.&elem_size}[idx], [&mem_operand&], #3 |
| 104 | .endm |
| 105 |
| 106 | .macro pixldst numbytes, op, elem_size, basereg, mem_operand, abits |
| 107 | .if numbytes == 32 |
| 108 | .if elem_size==32 |
| 109 | pixldst4 op, 2s, %(basereg+4), %(basereg+5), \ |
| 110 | %(basereg+6), %(basereg+7), mem_operand, abits |
| 111 | .elseif elem_size==16 |
| 112 | pixldst4 op, 4h, %(basereg+4), %(basereg+5), \ |
| 113 | %(basereg+6), %(basereg+7), mem_operand, abits |
| 114 | .else |
| 115 | pixldst4 op, 8b, %(basereg+4), %(basereg+5), \ |
| 116 | %(basereg+6), %(basereg+7), mem_operand, abits |
| 117 | .endif |
| 118 | .elseif numbytes == 16 |
| 119 | .if elem_size==32 |
| 120 | pixldst2 op, 2s, %(basereg+2), %(basereg+3), mem_operand, abits |
| 121 | .elseif elem_size==16 |
| 122 | pixldst2 op, 4h, %(basereg+2), %(basereg+3), mem_operand, abits |
| 123 | .else |
| 124 | pixldst2 op, 8b, %(basereg+2), %(basereg+3), mem_operand, abits |
| 125 | .endif |
| 126 | .elseif numbytes == 8 |
| 127 | .if elem_size==32 |
| 128 | pixldst1 op, 2s, %(basereg+1), mem_operand, abits |
| 129 | .elseif elem_size==16 |
| 130 | pixldst1 op, 4h, %(basereg+1), mem_operand, abits |
| 131 | .else |
| 132 | pixldst1 op, 8b, %(basereg+1), mem_operand, abits |
| 133 | .endif |
| 134 | .elseif numbytes == 4 |
| 135 | .if !RESPECT_STRICT_ALIGNMENT || (elem_size == 32) |
| 136 | pixldst0 op, s, %(basereg+0), 1, mem_operand, abits, 4 |
| 137 | .elseif elem_size == 16 |
| 138 | pixldst0 op, h, %(basereg+0), 2, mem_operand, abits, 2 |
| 139 | pixldst0 op, h, %(basereg+0), 3, mem_operand, abits, 2 |
| 140 | .else |
| 141 | pixldst0 op, b, %(basereg+0), 4, mem_operand, abits, 1 |
| 142 | pixldst0 op, b, %(basereg+0), 5, mem_operand, abits, 1 |
| 143 | pixldst0 op, b, %(basereg+0), 6, mem_operand, abits, 1 |
| 144 | pixldst0 op, b, %(basereg+0), 7, mem_operand, abits, 1 |
| 145 | .endif |
| 146 | .elseif numbytes == 2 |
| 147 | .if !RESPECT_STRICT_ALIGNMENT || (elem_size == 16) |
| 148 | pixldst0 op, h, %(basereg+0), 1, mem_operand, abits, 2 |
| 149 | .else |
| 150 | pixldst0 op, b, %(basereg+0), 2, mem_operand, abits, 1 |
| 151 | pixldst0 op, b, %(basereg+0), 3, mem_operand, abits, 1 |
| 152 | .endif |
| 153 | .elseif numbytes == 1 |
| 154 | pixldst0 op, b, %(basereg+0), 1, mem_operand, abits, 1 |
| 155 | .else |
| 156 | .error "unsupported size: numbytes" |
| 157 | .endif |
| 158 | .endm |
| 159 |
| 160 | .macro pixld numpix, bpp, basereg, mem_operand, abits=0 |
| 161 | .if bpp > 0 |
| 162 | .if (bpp == 32) && (numpix == 8) && (DEINTERLEAVE_32BPP_ENABLED != 0) |
| 163 | pixldst4 ld4, 8b, %(basereg+4), %(basereg+5), \ |
| 164 | %(basereg+6), %(basereg+7), mem_operand, abits |
| 165 | .elseif (bpp == 24) && (numpix == 8) |
| 166 | pixldst3 ld3, 8b, %(basereg+3), %(basereg+4), %(basereg+5), mem_operand |
| 167 | .elseif (bpp == 24) && (numpix == 4) |
| 168 | pixldst30 ld3, b, %(basereg+0), %(basereg+1), %(basereg+2), 4, mem_operand |
| 169 | pixldst30 ld3, b, %(basereg+0), %(basereg+1), %(basereg+2), 5, mem_operand |
| 170 | pixldst30 ld3, b, %(basereg+0), %(basereg+1), %(basereg+2), 6, mem_operand |
| 171 | pixldst30 ld3, b, %(basereg+0), %(basereg+1), %(basereg+2), 7, mem_operand |
| 172 | .elseif (bpp == 24) && (numpix == 2) |
| 173 | pixldst30 ld3, b, %(basereg+0), %(basereg+1), %(basereg+2), 2, mem_operand |
| 174 | pixldst30 ld3, b, %(basereg+0), %(basereg+1), %(basereg+2), 3, mem_operand |
| 175 | .elseif (bpp == 24) && (numpix == 1) |
| 176 | pixldst30 ld3, b, %(basereg+0), %(basereg+1), %(basereg+2), 1, mem_operand |
| 177 | .else |
| 178 | pixldst %(numpix * bpp / 8), ld1, %(bpp), basereg, mem_operand, abits |
| 179 | .endif |
| 180 | .endif |
| 181 | .endm |
| 182 |
| 183 | .macro pixst numpix, bpp, basereg, mem_operand, abits=0 |
| 184 | .if bpp > 0 |
| 185 | .if (bpp == 32) && (numpix == 8) && (DEINTERLEAVE_32BPP_ENABLED != 0) |
| 186 | pixldst4 st4, 8b, %(basereg+4), %(basereg+5), \ |
| 187 | %(basereg+6), %(basereg+7), mem_operand, abits |
| 188 | .elseif (bpp == 24) && (numpix == 8) |
| 189 | pixldst3 st3, 8b, %(basereg+3), %(basereg+4), %(basereg+5), mem_operand |
| 190 | .elseif (bpp == 24) && (numpix == 4) |
| 191 | pixldst30 st3, b, %(basereg+0), %(basereg+1), %(basereg+2), 4, mem_operand |
| 192 | pixldst30 st3, b, %(basereg+0), %(basereg+1), %(basereg+2), 5, mem_operand |
| 193 | pixldst30 st3, b, %(basereg+0), %(basereg+1), %(basereg+2), 6, mem_operand |
| 194 | pixldst30 st3, b, %(basereg+0), %(basereg+1), %(basereg+2), 7, mem_operand |
| 195 | .elseif (bpp == 24) && (numpix == 2) |
| 196 | pixldst30 st3, b, %(basereg+0), %(basereg+1), %(basereg+2), 2, mem_operand |
| 197 | pixldst30 st3, b, %(basereg+0), %(basereg+1), %(basereg+2), 3, mem_operand |
| 198 | .elseif (bpp == 24) && (numpix == 1) |
| 199 | pixldst30 st3, b, %(basereg+0), %(basereg+1), %(basereg+2), 1, mem_operand |
| 200 | .else |
| 201 | pixldst %(numpix * bpp / 8), st1, %(bpp), basereg, mem_operand, abits |
| 202 | .endif |
| 203 | .endif |
| 204 | .endm |
| 205 |
| 206 | .macro pixld_a numpix, bpp, basereg, mem_operand |
| 207 | .if (bpp * numpix) <= 128 |
| 208 | pixld numpix, bpp, basereg, mem_operand, %(bpp * numpix) |
| 209 | .else |
| 210 | pixld numpix, bpp, basereg, mem_operand, 128 |
| 211 | .endif |
| 212 | .endm |
| 213 |
| 214 | .macro pixst_a numpix, bpp, basereg, mem_operand |
| 215 | .if (bpp * numpix) <= 128 |
| 216 | pixst numpix, bpp, basereg, mem_operand, %(bpp * numpix) |
| 217 | .else |
| 218 | pixst numpix, bpp, basereg, mem_operand, 128 |
| 219 | .endif |
| 220 | .endm |
| 221 |
| 222 | /* |
| 223 | * Pixel fetcher for nearest scaling (needs TMP1, TMP2, VX, UNIT_X register |
| 224 | * aliases to be defined) |
| 225 | */ |
| 226 | .macro pixld1_s elem_size, reg1, mem_operand |
| 227 | .if elem_size == 16 |
| 228 | asr TMP1, VX, #16 |
| 229 | adds VX, VX, UNIT_X |
| 230 | bmi 55f |
| 231 | 5: subs VX, VX, SRC_WIDTH_FIXED |
| 232 | bpl 5b |
| 233 | 55: |
| 234 | add TMP1, mem_operand, TMP1, lsl #1 |
| 235 | asr TMP2, VX, #16 |
| 236 | adds VX, VX, UNIT_X |
| 237 | bmi 55f |
| 238 | 5: subs VX, VX, SRC_WIDTH_FIXED |
| 239 | bpl 5b |
| 240 | 55: |
| 241 | add TMP2, mem_operand, TMP2, lsl #1 |
| 242 | ld1 {v®1&.h}[0], [TMP1] |
| 243 | asr TMP1, VX, #16 |
| 244 | adds VX, VX, UNIT_X |
| 245 | bmi 55f |
| 246 | 5: subs VX, VX, SRC_WIDTH_FIXED |
| 247 | bpl 5b |
| 248 | 55: |
| 249 | add TMP1, mem_operand, TMP1, lsl #1 |
| 250 | ld1 {v®1&.h}[1], [TMP2] |
| 251 | asr TMP2, VX, #16 |
| 252 | adds VX, VX, UNIT_X |
| 253 | bmi 55f |
| 254 | 5: subs VX, VX, SRC_WIDTH_FIXED |
| 255 | bpl 5b |
| 256 | 55: |
| 257 | add TMP2, mem_operand, TMP2, lsl #1 |
| 258 | ld1 {v®1&.h}[2], [TMP1] |
| 259 | ld1 {v®1&.h}[3], [TMP2] |
| 260 | .elseif elem_size == 32 |
| 261 | asr TMP1, VX, #16 |
| 262 | adds VX, VX, UNIT_X |
| 263 | bmi 55f |
| 264 | 5: subs VX, VX, SRC_WIDTH_FIXED |
| 265 | bpl 5b |
| 266 | 55: |
| 267 | add TMP1, mem_operand, TMP1, lsl #2 |
| 268 | asr TMP2, VX, #16 |
| 269 | adds VX, VX, UNIT_X |
| 270 | bmi 55f |
| 271 | 5: subs VX, VX, SRC_WIDTH_FIXED |
| 272 | bpl 5b |
| 273 | 55: |
| 274 | add TMP2, mem_operand, TMP2, lsl #2 |
| 275 | ld1 {v®1&.s}[0], [TMP1] |
| 276 | ld1 {v®1&.s}[1], [TMP2] |
| 277 | .else |
| 278 | .error "unsupported" |
| 279 | .endif |
| 280 | .endm |
| 281 |
| 282 | .macro pixld2_s elem_size, reg1, reg2, mem_operand |
| 283 | .if 0 /* elem_size == 32 */ |
| 284 | mov TMP1, VX, asr #16 |
| 285 | add VX, VX, UNIT_X, asl #1 |
| 286 | add TMP1, mem_operand, TMP1, asl #2 |
| 287 | mov TMP2, VX, asr #16 |
| 288 | sub VX, VX, UNIT_X |
| 289 | add TMP2, mem_operand, TMP2, asl #2 |
| 290 | ld1 {v®1&.s}[0], [TMP1] |
| 291 | mov TMP1, VX, asr #16 |
| 292 | add VX, VX, UNIT_X, asl #1 |
| 293 | add TMP1, mem_operand, TMP1, asl #2 |
| 294 | ld1 {v®2&.s}[0], [TMP2, :32] |
| 295 | mov TMP2, VX, asr #16 |
| 296 | add VX, VX, UNIT_X |
| 297 | add TMP2, mem_operand, TMP2, asl #2 |
| 298 | ld1 {v®1&.s}[1], [TMP1] |
| 299 | ld1 {v®2&.s}[1], [TMP2] |
| 300 | .else |
| 301 | pixld1_s elem_size, reg1, mem_operand |
| 302 | pixld1_s elem_size, reg2, mem_operand |
| 303 | .endif |
| 304 | .endm |
| 305 |
| 306 | .macro pixld0_s elem_size, reg1, idx, mem_operand |
| 307 | .if elem_size == 16 |
| 308 | asr TMP1, VX, #16 |
| 309 | adds VX, VX, UNIT_X |
| 310 | bmi 55f |
| 311 | 5: subs VX, VX, SRC_WIDTH_FIXED |
| 312 | bpl 5b |
| 313 | 55: |
| 314 | add TMP1, mem_operand, TMP1, lsl #1 |
| 315 | ld1 {v®1&.h}[idx], [TMP1] |
| 316 | .elseif elem_size == 32 |
| 317 | asr DUMMY, VX, #16 |
| 318 | mov TMP1, DUMMY |
| 319 | adds VX, VX, UNIT_X |
| 320 | bmi 55f |
| 321 | 5: subs VX, VX, SRC_WIDTH_FIXED |
| 322 | bpl 5b |
| 323 | 55: |
| 324 | add TMP1, mem_operand, TMP1, lsl #2 |
| 325 | ld1 {v®1&.s}[idx], [TMP1] |
| 326 | .endif |
| 327 | .endm |
| 328 |
| 329 | .macro pixld_s_internal numbytes, elem_size, basereg, mem_operand |
| 330 | .if numbytes == 32 |
| 331 | pixld2_s elem_size, %(basereg+4), %(basereg+5), mem_operand |
| 332 | pixld2_s elem_size, %(basereg+6), %(basereg+7), mem_operand |
| 333 | pixdeinterleave elem_size, %(basereg+4) |
| 334 | .elseif numbytes == 16 |
| 335 | pixld2_s elem_size, %(basereg+2), %(basereg+3), mem_operand |
| 336 | .elseif numbytes == 8 |
| 337 | pixld1_s elem_size, %(basereg+1), mem_operand |
| 338 | .elseif numbytes == 4 |
| 339 | .if elem_size == 32 |
| 340 | pixld0_s elem_size, %(basereg+0), 1, mem_operand |
| 341 | .elseif elem_size == 16 |
| 342 | pixld0_s elem_size, %(basereg+0), 2, mem_operand |
| 343 | pixld0_s elem_size, %(basereg+0), 3, mem_operand |
| 344 | .else |
| 345 | pixld0_s elem_size, %(basereg+0), 4, mem_operand |
| 346 | pixld0_s elem_size, %(basereg+0), 5, mem_operand |
| 347 | pixld0_s elem_size, %(basereg+0), 6, mem_operand |
| 348 | pixld0_s elem_size, %(basereg+0), 7, mem_operand |
| 349 | .endif |
| 350 | .elseif numbytes == 2 |
| 351 | .if elem_size == 16 |
| 352 | pixld0_s elem_size, %(basereg+0), 1, mem_operand |
| 353 | .else |
| 354 | pixld0_s elem_size, %(basereg+0), 2, mem_operand |
| 355 | pixld0_s elem_size, %(basereg+0), 3, mem_operand |
| 356 | .endif |
| 357 | .elseif numbytes == 1 |
| 358 | pixld0_s elem_size, %(basereg+0), 1, mem_operand |
| 359 | .else |
| 360 | .error "unsupported size: numbytes" |
| 361 | .endif |
| 362 | .endm |
| 363 |
| 364 | .macro pixld_s numpix, bpp, basereg, mem_operand |
| 365 | .if bpp > 0 |
| 366 | pixld_s_internal %(numpix * bpp / 8), %(bpp), basereg, mem_operand |
| 367 | .endif |
| 368 | .endm |
| 369 |
| 370 | .macro vuzp8 reg1, reg2 |
| 371 | umov DUMMY, v16.d[0] |
| 372 | uzp1 v16.8b, v®1&.8b, v®2&.8b |
| 373 | uzp2 v®2&.8b, v®1&.8b, v®2&.8b |
| 374 | mov v®1&.8b, v16.8b |
| 375 | mov v16.d[0], DUMMY |
| 376 | .endm |
| 377 |
| 378 | .macro vzip8 reg1, reg2 |
| 379 | umov DUMMY, v16.d[0] |
| 380 | zip1 v16.8b, v®1&.8b, v®2&.8b |
| 381 | zip2 v®2&.8b, v®1&.8b, v®2&.8b |
| 382 | mov v®1&.8b, v16.8b |
| 383 | mov v16.d[0], DUMMY |
| 384 | .endm |
| 385 |
| 386 | /* deinterleave B, G, R, A channels for eight 32bpp pixels in 4 registers */ |
| 387 | .macro pixdeinterleave bpp, basereg |
| 388 | .if (bpp == 32) && (DEINTERLEAVE_32BPP_ENABLED != 0) |
| 389 | vuzp8 %(basereg+0), %(basereg+1) |
| 390 | vuzp8 %(basereg+2), %(basereg+3) |
| 391 | vuzp8 %(basereg+1), %(basereg+3) |
| 392 | vuzp8 %(basereg+0), %(basereg+2) |
| 393 | .endif |
| 394 | .endm |
| 395 |
| 396 | /* interleave B, G, R, A channels for eight 32bpp pixels in 4 registers */ |
| 397 | .macro pixinterleave bpp, basereg |
| 398 | .if (bpp == 32) && (DEINTERLEAVE_32BPP_ENABLED != 0) |
| 399 | vzip8 %(basereg+0), %(basereg+2) |
| 400 | vzip8 %(basereg+1), %(basereg+3) |
| 401 | vzip8 %(basereg+2), %(basereg+3) |
| 402 | vzip8 %(basereg+0), %(basereg+1) |
| 403 | .endif |
| 404 | .endm |
| 405 |
| 406 | /* |
| 407 | * This is a macro for implementing cache preload. The main idea is that |
| 408 | * cache preload logic is mostly independent from the rest of pixels |
| 409 | * processing code. It starts at the top left pixel and moves forward |
| 410 | * across pixels and can jump across scanlines. Prefetch distance is |
| 411 | * handled in an 'incremental' way: it starts from 0 and advances to the |
| 412 | * optimal distance over time. After reaching optimal prefetch distance, |
| 413 | * it is kept constant. There are some checks which prevent prefetching |
| 414 | * unneeded pixel lines below the image (but it still can prefetch a bit |
| 415 | * more data on the right side of the image - not a big issue and may |
| 416 | * be actually helpful when rendering text glyphs). Additional trick is |
| 417 | * the use of LDR instruction for prefetch instead of PLD when moving to |
| 418 | * the next line, the point is that we have a high chance of getting TLB |
| 419 | * miss in this case, and PLD would be useless. |
| 420 | * |
| 421 | * This sounds like it may introduce a noticeable overhead (when working with |
| 422 | * fully cached data). But in reality, due to having a separate pipeline and |
| 423 | * instruction queue for NEON unit in ARM Cortex-A8, normal ARM code can |
| 424 | * execute simultaneously with NEON and be completely shadowed by it. Thus |
| 425 | * we get no performance overhead at all (*). This looks like a very nice |
| 426 | * feature of Cortex-A8, if used wisely. We don't have a hardware prefetcher, |
| 427 | * but still can implement some rather advanced prefetch logic in software |
| 428 | * for almost zero cost! |
| 429 | * |
| 430 | * (*) The overhead of the prefetcher is visible when running some trivial |
| 431 | * pixels processing like simple copy. Anyway, having prefetch is a must |
| 432 | * when working with the graphics data. |
| 433 | */ |
| 434 | .macro PF a, x:vararg |
| 435 | .if (PREFETCH_TYPE_CURRENT == PREFETCH_TYPE_ADVANCED) |
| 436 | a x |
| 437 | .endif |
| 438 | .endm |
| 439 |
| 440 | .macro cache_preload std_increment, boost_increment |
| 441 | .if (src_bpp_shift >= 0) || (dst_r_bpp != 0) || (mask_bpp_shift >= 0) |
| 442 | .if std_increment != 0 |
| 443 | PF add PF_X, PF_X, #std_increment |
| 444 | .endif |
| 445 | PF tst PF_CTL, #0xF |
| 446 | PF beq 71f |
| 447 | PF add PF_X, PF_X, #boost_increment |
| 448 | PF sub PF_CTL, PF_CTL, #1 |
| 449 | 71: |
| 450 | PF cmp PF_X, ORIG_W |
| 451 | .if src_bpp_shift >= 0 |
| 452 | PF lsl DUMMY, PF_X, #src_bpp_shift |
| 453 | PF prfm PREFETCH_MODE, [PF_SRC, DUMMY] |
| 454 | .endif |
| 455 | .if dst_r_bpp != 0 |
| 456 | PF lsl DUMMY, PF_X, #dst_bpp_shift |
| 457 | PF prfm PREFETCH_MODE, [PF_DST, DUMMY] |
| 458 | .endif |
| 459 | .if mask_bpp_shift >= 0 |
| 460 | PF lsl DUMMY, PF_X, #mask_bpp_shift |
| 461 | PF prfm PREFETCH_MODE, [PF_MASK, DUMMY] |
| 462 | .endif |
| 463 | PF ble 71f |
| 464 | PF sub PF_X, PF_X, ORIG_W |
| 465 | PF subs PF_CTL, PF_CTL, #0x10 |
| 466 | 71: |
| 467 | PF ble 72f |
| 468 | .if src_bpp_shift >= 0 |
| 469 | PF lsl DUMMY, SRC_STRIDE, #src_bpp_shift |
| 470 | PF ldrsb DUMMY, [PF_SRC, DUMMY] |
| 471 | PF add PF_SRC, PF_SRC, #1 |
| 472 | .endif |
| 473 | .if dst_r_bpp != 0 |
| 474 | PF lsl DUMMY, DST_STRIDE, #dst_bpp_shift |
| 475 | PF ldrsb DUMMY, [PF_DST, DUMMY] |
| 476 | PF add PF_DST, PF_DST, #1 |
| 477 | .endif |
| 478 | .if mask_bpp_shift >= 0 |
| 479 | PF lsl DUMMY, MASK_STRIDE, #mask_bpp_shift |
| 480 | PF ldrsb DUMMY, [PF_MASK, DUMMY] |
| 481 | PF add PF_MASK, PF_MASK, #1 |
| 482 | .endif |
| 483 | 72: |
| 484 | .endif |
| 485 | .endm |
| 486 |
| 487 | .macro cache_preload_simple |
| 488 | .if (PREFETCH_TYPE_CURRENT == PREFETCH_TYPE_SIMPLE) |
| 489 | .if src_bpp > 0 |
| 490 | prfm PREFETCH_MODE, [SRC, #(PREFETCH_DISTANCE_SIMPLE * src_bpp / 8)] |
| 491 | .endif |
| 492 | .if dst_r_bpp > 0 |
| 493 | prfm PREFETCH_MODE, [DST_R, #(PREFETCH_DISTANCE_SIMPLE * dst_r_bpp / 8)] |
| 494 | .endif |
| 495 | .if mask_bpp > 0 |
| 496 | prfm PREFETCH_MODE, [MASK, #(PREFETCH_DISTANCE_SIMPLE * mask_bpp / 8)] |
| 497 | .endif |
| 498 | .endif |
| 499 | .endm |
| 500 |
| 501 | .macro fetch_mask_pixblock |
| 502 | pixld pixblock_size, mask_bpp, \ |
| 503 | (mask_basereg - pixblock_size * mask_bpp / 64), MASK |
| 504 | .endm |
| 505 |
| 506 | /* |
| 507 | * Macro which is used to process leading pixels until destination |
| 508 | * pointer is properly aligned (at 16 bytes boundary). When destination |
| 509 | * buffer uses 16bpp format, this is unnecessary, or even pointless. |
| 510 | */ |
| 511 | .macro ensure_destination_ptr_alignment process_pixblock_head, \ |
| 512 | process_pixblock_tail, \ |
| 513 | process_pixblock_tail_head |
| 514 | .if dst_w_bpp != 24 |
| 515 | tst DST_R, #0xF |
| 516 | beq 52f |
| 517 | .irp lowbit, 1, 2, 4, 8, 16 |
| 518 | local skip1 |
| 519 | .if (dst_w_bpp <= (lowbit * 8)) && ((lowbit * 8) < (pixblock_size * dst_w_bpp)) |
| 520 | .if lowbit < 16 /* we don't need more than 16-byte alignment */ |
| 521 | tst DST_R, #lowbit |
| 522 | beq 51f |
| 523 | .endif |
| 524 | pixld_src (lowbit * 8 / dst_w_bpp), src_bpp, src_basereg, SRC |
| 525 | pixld (lowbit * 8 / dst_w_bpp), mask_bpp, mask_basereg, MASK |
| 526 | .if dst_r_bpp > 0 |
| 527 | pixld_a (lowbit * 8 / dst_r_bpp), dst_r_bpp, dst_r_basereg, DST_R |
| 528 | .else |
| 529 | add DST_R, DST_R, #lowbit |
| 530 | .endif |
| 531 | PF add PF_X, PF_X, #(lowbit * 8 / dst_w_bpp) |
| 532 | sub W, W, #(lowbit * 8 / dst_w_bpp) |
| 533 | 51: |
| 534 | .endif |
| 535 | .endr |
| 536 | pixdeinterleave src_bpp, src_basereg |
| 537 | pixdeinterleave mask_bpp, mask_basereg |
| 538 | pixdeinterleave dst_r_bpp, dst_r_basereg |
| 539 |
| 540 | process_pixblock_head |
| 541 | cache_preload 0, pixblock_size |
| 542 | cache_preload_simple |
| 543 | process_pixblock_tail |
| 544 |
| 545 | pixinterleave dst_w_bpp, dst_w_basereg |
| 546 |
| 547 | .irp lowbit, 1, 2, 4, 8, 16 |
| 548 | .if (dst_w_bpp <= (lowbit * 8)) && ((lowbit * 8) < (pixblock_size * dst_w_bpp)) |
| 549 | .if lowbit < 16 /* we don't need more than 16-byte alignment */ |
| 550 | tst DST_W, #lowbit |
| 551 | beq 51f |
| 552 | .endif |
| 553 | pixst_a (lowbit * 8 / dst_w_bpp), dst_w_bpp, dst_w_basereg, DST_W |
| 554 | 51: |
| 555 | .endif |
| 556 | .endr |
| 557 | .endif |
| 558 | 52: |
| 559 | .endm |
| 560 |
| 561 | /* |
| 562 | * Special code for processing up to (pixblock_size - 1) remaining |
| 563 | * trailing pixels. As SIMD processing performs operation on |
| 564 | * pixblock_size pixels, anything smaller than this has to be loaded |
| 565 | * and stored in a special way. Loading and storing of pixel data is |
| 566 | * performed in such a way that we fill some 'slots' in the NEON |
| 567 | * registers (some slots naturally are unused), then perform compositing |
| 568 | * operation as usual. In the end, the data is taken from these 'slots' |
| 569 | * and saved to memory. |
| 570 | * |
| 571 | * cache_preload_flag - allows to suppress prefetch if |
| 572 | * set to 0 |
| 573 | * dst_aligned_flag - selects whether destination buffer |
| 574 | * is aligned |
| 575 | */ |
| 576 | .macro process_trailing_pixels cache_preload_flag, \ |
| 577 | dst_aligned_flag, \ |
| 578 | process_pixblock_head, \ |
| 579 | process_pixblock_tail, \ |
| 580 | process_pixblock_tail_head |
| 581 | tst W, #(pixblock_size - 1) |
| 582 | beq 52f |
| 583 | .irp chunk_size, 16, 8, 4, 2, 1 |
| 584 | .if pixblock_size > chunk_size |
| 585 | tst W, #chunk_size |
| 586 | beq 51f |
| 587 | pixld_src chunk_size, src_bpp, src_basereg, SRC |
| 588 | pixld chunk_size, mask_bpp, mask_basereg, MASK |
| 589 | .if dst_aligned_flag != 0 |
| 590 | pixld_a chunk_size, dst_r_bpp, dst_r_basereg, DST_R |
| 591 | .else |
| 592 | pixld chunk_size, dst_r_bpp, dst_r_basereg, DST_R |
| 593 | .endif |
| 594 | .if cache_preload_flag != 0 |
| 595 | PF add PF_X, PF_X, #chunk_size |
| 596 | .endif |
| 597 | 51: |
| 598 | .endif |
| 599 | .endr |
| 600 | pixdeinterleave src_bpp, src_basereg |
| 601 | pixdeinterleave mask_bpp, mask_basereg |
| 602 | pixdeinterleave dst_r_bpp, dst_r_basereg |
| 603 |
| 604 | process_pixblock_head |
| 605 | .if cache_preload_flag != 0 |
| 606 | cache_preload 0, pixblock_size |
| 607 | cache_preload_simple |
| 608 | .endif |
| 609 | process_pixblock_tail |
| 610 | pixinterleave dst_w_bpp, dst_w_basereg |
| 611 | .irp chunk_size, 16, 8, 4, 2, 1 |
| 612 | .if pixblock_size > chunk_size |
| 613 | tst W, #chunk_size |
| 614 | beq 51f |
| 615 | .if dst_aligned_flag != 0 |
| 616 | pixst_a chunk_size, dst_w_bpp, dst_w_basereg, DST_W |
| 617 | .else |
| 618 | pixst chunk_size, dst_w_bpp, dst_w_basereg, DST_W |
| 619 | .endif |
| 620 | 51: |
| 621 | .endif |
| 622 | .endr |
| 623 | 52: |
| 624 | .endm |
| 625 |
| 626 | /* |
| 627 | * Macro, which performs all the needed operations to switch to the next |
| 628 | * scanline and start the next loop iteration unless all the scanlines |
| 629 | * are already processed. |
| 630 | */ |
| 631 | .macro advance_to_next_scanline start_of_loop_label |
| 632 | mov W, ORIG_W |
| 633 | add DST_W, DST_W, DST_STRIDE, lsl #dst_bpp_shift |
| 634 | .if src_bpp != 0 |
| 635 | add SRC, SRC, SRC_STRIDE, lsl #src_bpp_shift |
| 636 | .endif |
| 637 | .if mask_bpp != 0 |
| 638 | add MASK, MASK, MASK_STRIDE, lsl #mask_bpp_shift |
| 639 | .endif |
| 640 | .if (dst_w_bpp != 24) |
| 641 | sub DST_W, DST_W, W, lsl #dst_bpp_shift |
| 642 | .endif |
| 643 | .if (src_bpp != 24) && (src_bpp != 0) |
| 644 | sub SRC, SRC, W, lsl #src_bpp_shift |
| 645 | .endif |
| 646 | .if (mask_bpp != 24) && (mask_bpp != 0) |
| 647 | sub MASK, MASK, W, lsl #mask_bpp_shift |
| 648 | .endif |
| 649 | subs H, H, #1 |
| 650 | mov DST_R, DST_W |
| 651 | bge start_of_loop_label |
| 652 | .endm |
| 653 |
| 654 | /* |
| 655 | * Registers are allocated in the following way by default: |
| 656 | * v0, v1, v2, v3 - reserved for loading source pixel data |
| 657 | * v4, v5, v6, v7 - reserved for loading destination pixel data |
| 658 | * v24, v25, v26, v27 - reserved for loading mask pixel data |
| 659 | * v28, v29, v30, v31 - final destination pixel data for writeback to memory |
| 660 | */ |
| 661 | .macro generate_composite_function fname, \ |
| 662 | src_bpp_, \ |
| 663 | mask_bpp_, \ |
| 664 | dst_w_bpp_, \ |
| 665 | flags, \ |
| 666 | pixblock_size_, \ |
| 667 | prefetch_distance, \ |
| 668 | init, \ |
| 669 | cleanup, \ |
| 670 | process_pixblock_head, \ |
| 671 | process_pixblock_tail, \ |
| 672 | process_pixblock_tail_head, \ |
| 673 | dst_w_basereg_ = 28, \ |
| 674 | dst_r_basereg_ = 4, \ |
| 675 | src_basereg_ = 0, \ |
| 676 | mask_basereg_ = 24 |
| 677 |
| 678 | pixman_asm_function fname |
| 679 | stp x29, x30, [sp, -16]! |
| 680 | mov x29, sp |
| 681 | sub sp, sp, 232 /* push all registers */ |
| 682 | sub x29, x29, 64 |
| 683 | st1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x29], #32 |
| 684 | st1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x29], #32 |
| 685 | stp x8, x9, [x29, -80] |
| 686 | stp x10, x11, [x29, -96] |
| 687 | stp x12, x13, [x29, -112] |
| 688 | stp x14, x15, [x29, -128] |
| 689 | stp x16, x17, [x29, -144] |
| 690 | stp x18, x19, [x29, -160] |
| 691 | stp x20, x21, [x29, -176] |
| 692 | stp x22, x23, [x29, -192] |
| 693 | stp x24, x25, [x29, -208] |
| 694 | stp x26, x27, [x29, -224] |
| 695 | str x28, [x29, -232] |
| 696 |
| 697 | /* |
| 698 | * Select prefetch type for this function. If prefetch distance is |
| 699 | * set to 0 or one of the color formats is 24bpp, SIMPLE prefetch |
| 700 | * has to be used instead of ADVANCED. |
| 701 | */ |
| 702 | .set PREFETCH_TYPE_CURRENT, PREFETCH_TYPE_DEFAULT |
| 703 | .if prefetch_distance == 0 |
| 704 | .set PREFETCH_TYPE_CURRENT, PREFETCH_TYPE_NONE |
| 705 | .elseif (PREFETCH_TYPE_CURRENT > PREFETCH_TYPE_SIMPLE) && \ |
| 706 | ((src_bpp_ == 24) || (mask_bpp_ == 24) || (dst_w_bpp_ == 24)) |
| 707 | .set PREFETCH_TYPE_CURRENT, PREFETCH_TYPE_SIMPLE |
| 708 | .endif |
| 709 |
| 710 | /* |
| 711 | * Make some macro arguments globally visible and accessible |
| 712 | * from other macros |
| 713 | */ |
| 714 | .set src_bpp, src_bpp_ |
| 715 | .set mask_bpp, mask_bpp_ |
| 716 | .set dst_w_bpp, dst_w_bpp_ |
| 717 | .set pixblock_size, pixblock_size_ |
| 718 | .set dst_w_basereg, dst_w_basereg_ |
| 719 | .set dst_r_basereg, dst_r_basereg_ |
| 720 | .set src_basereg, src_basereg_ |
| 721 | .set mask_basereg, mask_basereg_ |
| 722 |
| 723 | .macro pixld_src x:vararg |
| 724 | pixld x |
| 725 | .endm |
| 726 | .macro fetch_src_pixblock |
| 727 | pixld_src pixblock_size, src_bpp, \ |
| 728 | (src_basereg - pixblock_size * src_bpp / 64), SRC |
| 729 | .endm |
| 730 | /* |
| 731 | * Assign symbolic names to registers |
| 732 | */ |
| 733 | W .req x0 /* width (is updated during processing) */ |
| 734 | H .req x1 /* height (is updated during processing) */ |
| 735 | DST_W .req x2 /* destination buffer pointer for writes */ |
| 736 | DST_STRIDE .req x3 /* destination image stride */ |
| 737 | SRC .req x4 /* source buffer pointer */ |
| 738 | SRC_STRIDE .req x5 /* source image stride */ |
| 739 | MASK .req x6 /* mask pointer */ |
| 740 | MASK_STRIDE .req x7 /* mask stride */ |
| 741 |
| 742 | DST_R .req x8 /* destination buffer pointer for reads */ |
| 743 |
| 744 | PF_CTL .req x9 /* combined lines counter and prefetch */ |
| 745 | /* distance increment counter */ |
| 746 | PF_X .req x10 /* pixel index in a scanline for current */ |
| 747 | /* pretetch position */ |
| 748 | PF_SRC .req x11 /* pointer to source scanline start */ |
| 749 | /* for prefetch purposes */ |
| 750 | PF_DST .req x12 /* pointer to destination scanline start */ |
| 751 | /* for prefetch purposes */ |
| 752 | PF_MASK .req x13 /* pointer to mask scanline start */ |
| 753 | /* for prefetch purposes */ |
| 754 |
| 755 | ORIG_W .req x14 /* saved original width */ |
| 756 | DUMMY .req x15 /* temporary register */ |
| 757 |
| 758 | sxtw x0, w0 |
| 759 | sxtw x1, w1 |
| 760 | sxtw x3, w3 |
| 761 | sxtw x5, w5 |
| 762 | sxtw x7, w7 |
| 763 |
| 764 | .set mask_bpp_shift, -1 |
| 765 | .if src_bpp == 32 |
| 766 | .set src_bpp_shift, 2 |
| 767 | .elseif src_bpp == 24 |
| 768 | .set src_bpp_shift, 0 |
| 769 | .elseif src_bpp == 16 |
| 770 | .set src_bpp_shift, 1 |
| 771 | .elseif src_bpp == 8 |
| 772 | .set src_bpp_shift, 0 |
| 773 | .elseif src_bpp == 0 |
| 774 | .set src_bpp_shift, -1 |
| 775 | .else |
| 776 | .error "requested src bpp (src_bpp) is not supported" |
| 777 | .endif |
| 778 | .if mask_bpp == 32 |
| 779 | .set mask_bpp_shift, 2 |
| 780 | .elseif mask_bpp == 24 |
| 781 | .set mask_bpp_shift, 0 |
| 782 | .elseif mask_bpp == 8 |
| 783 | .set mask_bpp_shift, 0 |
| 784 | .elseif mask_bpp == 0 |
| 785 | .set mask_bpp_shift, -1 |
| 786 | .else |
| 787 | .error "requested mask bpp (mask_bpp) is not supported" |
| 788 | .endif |
| 789 | .if dst_w_bpp == 32 |
| 790 | .set dst_bpp_shift, 2 |
| 791 | .elseif dst_w_bpp == 24 |
| 792 | .set dst_bpp_shift, 0 |
| 793 | .elseif dst_w_bpp == 16 |
| 794 | .set dst_bpp_shift, 1 |
| 795 | .elseif dst_w_bpp == 8 |
| 796 | .set dst_bpp_shift, 0 |
| 797 | .else |
| 798 | .error "requested dst bpp (dst_w_bpp) is not supported" |
| 799 | .endif |
| 800 |
| 801 | .if (((flags) & FLAG_DST_READWRITE) != 0) |
| 802 | .set dst_r_bpp, dst_w_bpp |
| 803 | .else |
| 804 | .set dst_r_bpp, 0 |
| 805 | .endif |
| 806 | .if (((flags) & FLAG_DEINTERLEAVE_32BPP) != 0) |
| 807 | .set DEINTERLEAVE_32BPP_ENABLED, 1 |
| 808 | .else |
| 809 | .set DEINTERLEAVE_32BPP_ENABLED, 0 |
| 810 | .endif |
| 811 |
| 812 | .if prefetch_distance < 0 || prefetch_distance > 15 |
| 813 | .error "invalid prefetch distance (prefetch_distance)" |
| 814 | .endif |
| 815 |
| 816 | PF mov PF_X, #0 |
| 817 | mov DST_R, DST_W |
| 818 |
| 819 | .if src_bpp == 24 |
| 820 | sub SRC_STRIDE, SRC_STRIDE, W |
| 821 | sub SRC_STRIDE, SRC_STRIDE, W, lsl #1 |
| 822 | .endif |
| 823 | .if mask_bpp == 24 |
| 824 | sub MASK_STRIDE, MASK_STRIDE, W |
| 825 | sub MASK_STRIDE, MASK_STRIDE, W, lsl #1 |
| 826 | .endif |
| 827 | .if dst_w_bpp == 24 |
| 828 | sub DST_STRIDE, DST_STRIDE, W |
| 829 | sub DST_STRIDE, DST_STRIDE, W, lsl #1 |
| 830 | .endif |
| 831 |
| 832 | /* |
| 833 | * Setup advanced prefetcher initial state |
| 834 | */ |
| 835 | PF mov PF_SRC, SRC |
| 836 | PF mov PF_DST, DST_R |
| 837 | PF mov PF_MASK, MASK |
| 838 | /* PF_CTL = prefetch_distance | ((h - 1) << 4) */ |
| 839 | PF lsl DUMMY, H, #4 |
| 840 | PF mov PF_CTL, DUMMY |
| 841 | PF add PF_CTL, PF_CTL, #(prefetch_distance - 0x10) |
| 842 |
| 843 | init |
| 844 | subs H, H, #1 |
| 845 | mov ORIG_W, W |
| 846 | blt 9f |
| 847 | cmp W, #(pixblock_size * 2) |
| 848 | blt 800f |
| 849 | /* |
| 850 | * This is the start of the pipelined loop, which if optimized for |
| 851 | * long scanlines |
| 852 | */ |
| 853 | 0: |
| 854 | ensure_destination_ptr_alignment process_pixblock_head, \ |
| 855 | process_pixblock_tail, \ |
| 856 | process_pixblock_tail_head |
| 857 |
| 858 | /* Implement "head (tail_head) ... (tail_head) tail" loop pattern */ |
| 859 | pixld_a pixblock_size, dst_r_bpp, \ |
| 860 | (dst_r_basereg - pixblock_size * dst_r_bpp / 64), DST_R |
| 861 | fetch_src_pixblock |
| 862 | pixld pixblock_size, mask_bpp, \ |
| 863 | (mask_basereg - pixblock_size * mask_bpp / 64), MASK |
| 864 | PF add PF_X, PF_X, #pixblock_size |
| 865 | process_pixblock_head |
| 866 | cache_preload 0, pixblock_size |
| 867 | cache_preload_simple |
| 868 | subs W, W, #(pixblock_size * 2) |
| 869 | blt 200f |
| 870 |
| 871 | 100: |
| 872 | process_pixblock_tail_head |
| 873 | cache_preload_simple |
| 874 | subs W, W, #pixblock_size |
| 875 | bge 100b |
| 876 |
| 877 | 200: |
| 878 | process_pixblock_tail |
| 879 | pixst_a pixblock_size, dst_w_bpp, \ |
| 880 | (dst_w_basereg - pixblock_size * dst_w_bpp / 64), DST_W |
| 881 |
| 882 | /* Process the remaining trailing pixels in the scanline */ |
| 883 | process_trailing_pixels 1, 1, \ |
| 884 | process_pixblock_head, \ |
| 885 | process_pixblock_tail, \ |
| 886 | process_pixblock_tail_head |
| 887 | advance_to_next_scanline 0b |
| 888 |
| 889 | cleanup |
| 890 | 1000: |
| 891 | /* pop all registers */ |
| 892 | sub x29, x29, 64 |
| 893 | ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x29], 32 |
| 894 | ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x29], 32 |
| 895 | ldp x8, x9, [x29, -80] |
| 896 | ldp x10, x11, [x29, -96] |
| 897 | ldp x12, x13, [x29, -112] |
| 898 | ldp x14, x15, [x29, -128] |
| 899 | ldp x16, x17, [x29, -144] |
| 900 | ldp x18, x19, [x29, -160] |
| 901 | ldp x20, x21, [x29, -176] |
| 902 | ldp x22, x23, [x29, -192] |
| 903 | ldp x24, x25, [x29, -208] |
| 904 | ldp x26, x27, [x29, -224] |
| 905 | ldr x28, [x29, -232] |
| 906 | mov sp, x29 |
| 907 | ldp x29, x30, [sp], 16 |
| 908 | ret /* exit */ |
| 909 | /* |
| 910 | * This is the start of the loop, designed to process images with small width |
| 911 | * (less than pixblock_size * 2 pixels). In this case neither pipelining |
| 912 | * nor prefetch are used. |
| 913 | */ |
| 914 | 800: |
| 915 | /* Process exactly pixblock_size pixels if needed */ |
| 916 | tst W, #pixblock_size |
| 917 | beq 100f |
| 918 | pixld pixblock_size, dst_r_bpp, \ |
| 919 | (dst_r_basereg - pixblock_size * dst_r_bpp / 64), DST_R |
| 920 | fetch_src_pixblock |
| 921 | pixld pixblock_size, mask_bpp, \ |
| 922 | (mask_basereg - pixblock_size * mask_bpp / 64), MASK |
| 923 | process_pixblock_head |
| 924 | process_pixblock_tail |
| 925 | pixst pixblock_size, dst_w_bpp, \ |
| 926 | (dst_w_basereg - pixblock_size * dst_w_bpp / 64), DST_W |
| 927 | 100: |
| 928 | /* Process the remaining trailing pixels in the scanline */ |
| 929 | process_trailing_pixels 0, 0, \ |
| 930 | process_pixblock_head, \ |
| 931 | process_pixblock_tail, \ |
| 932 | process_pixblock_tail_head |
| 933 | advance_to_next_scanline 800b |
| 934 | 9: |
| 935 | cleanup |
| 936 | /* pop all registers */ |
| 937 | sub x29, x29, 64 |
| 938 | ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x29], 32 |
| 939 | ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x29], 32 |
| 940 | ldp x8, x9, [x29, -80] |
| 941 | ldp x10, x11, [x29, -96] |
| 942 | ldp x12, x13, [x29, -112] |
| 943 | ldp x14, x15, [x29, -128] |
| 944 | ldp x16, x17, [x29, -144] |
| 945 | ldp x18, x19, [x29, -160] |
| 946 | ldp x20, x21, [x29, -176] |
| 947 | ldp x22, x23, [x29, -192] |
| 948 | ldp x24, x25, [x29, -208] |
| 949 | ldp x26, x27, [x29, -224] |
| 950 | ldr x28, [x29, -232] |
| 951 | mov sp, x29 |
| 952 | ldp x29, x30, [sp], 16 |
| 953 | ret /* exit */ |
| 954 |
| 955 | .purgem fetch_src_pixblock |
| 956 | .purgem pixld_src |
| 957 |
| 958 | .unreq SRC |
| 959 | .unreq MASK |
| 960 | .unreq DST_R |
| 961 | .unreq DST_W |
| 962 | .unreq ORIG_W |
| 963 | .unreq W |
| 964 | .unreq H |
| 965 | .unreq SRC_STRIDE |
| 966 | .unreq DST_STRIDE |
| 967 | .unreq MASK_STRIDE |
| 968 | .unreq PF_CTL |
| 969 | .unreq PF_X |
| 970 | .unreq PF_SRC |
| 971 | .unreq PF_DST |
| 972 | .unreq PF_MASK |
| 973 | .unreq DUMMY |
| 974 | .endfunc |
| 975 | .endm |
| 976 |
| 977 | /* |
| 978 | * A simplified variant of function generation template for a single |
| 979 | * scanline processing (for implementing pixman combine functions) |
| 980 | */ |
| 981 | .macro generate_composite_function_scanline use_nearest_scaling, \ |
| 982 | fname, \ |
| 983 | src_bpp_, \ |
| 984 | mask_bpp_, \ |
| 985 | dst_w_bpp_, \ |
| 986 | flags, \ |
| 987 | pixblock_size_, \ |
| 988 | init, \ |
| 989 | cleanup, \ |
| 990 | process_pixblock_head, \ |
| 991 | process_pixblock_tail, \ |
| 992 | process_pixblock_tail_head, \ |
| 993 | dst_w_basereg_ = 28, \ |
| 994 | dst_r_basereg_ = 4, \ |
| 995 | src_basereg_ = 0, \ |
| 996 | mask_basereg_ = 24 |
| 997 |
| 998 | pixman_asm_function fname |
| 999 | .set PREFETCH_TYPE_CURRENT, PREFETCH_TYPE_NONE |
| 1000 |
| 1001 | /* |
| 1002 | * Make some macro arguments globally visible and accessible |
| 1003 | * from other macros |
| 1004 | */ |
| 1005 | .set src_bpp, src_bpp_ |
| 1006 | .set mask_bpp, mask_bpp_ |
| 1007 | .set dst_w_bpp, dst_w_bpp_ |
| 1008 | .set pixblock_size, pixblock_size_ |
| 1009 | .set dst_w_basereg, dst_w_basereg_ |
| 1010 | .set dst_r_basereg, dst_r_basereg_ |
| 1011 | .set src_basereg, src_basereg_ |
| 1012 | .set mask_basereg, mask_basereg_ |
| 1013 |
| 1014 | .if use_nearest_scaling != 0 |
| 1015 | /* |
| 1016 | * Assign symbolic names to registers for nearest scaling |
| 1017 | */ |
| 1018 | W .req x0 |
| 1019 | DST_W .req x1 |
| 1020 | SRC .req x2 |
| 1021 | VX .req x3 |
| 1022 | UNIT_X .req x4 |
| 1023 | SRC_WIDTH_FIXED .req x5 |
| 1024 | MASK .req x6 |
| 1025 | TMP1 .req x8 |
| 1026 | TMP2 .req x9 |
| 1027 | DST_R .req x10 |
| 1028 | DUMMY .req x30 |
| 1029 |
| 1030 | .macro pixld_src x:vararg |
| 1031 | pixld_s x |
| 1032 | .endm |
| 1033 |
| 1034 | sxtw x0, w0 |
| 1035 | sxtw x3, w3 |
| 1036 | sxtw x4, w4 |
| 1037 | sxtw x5, w5 |
| 1038 |
| 1039 | stp x29, x30, [sp, -16]! |
| 1040 | mov x29, sp |
| 1041 | sub sp, sp, 88 |
| 1042 | sub x29, x29, 64 |
| 1043 | st1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x29], 32 |
| 1044 | st1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x29], 32 |
| 1045 | stp x8, x9, [x29, -80] |
| 1046 | str x10, [x29, -88] |
| 1047 | .else |
| 1048 | /* |
| 1049 | * Assign symbolic names to registers |
| 1050 | */ |
| 1051 | W .req x0 /* width (is updated during processing) */ |
| 1052 | DST_W .req x1 /* destination buffer pointer for writes */ |
| 1053 | SRC .req x2 /* source buffer pointer */ |
| 1054 | MASK .req x3 /* mask pointer */ |
| 1055 | DST_R .req x4 /* destination buffer pointer for reads */ |
| 1056 | DUMMY .req x30 |
| 1057 |
| 1058 | .macro pixld_src x:vararg |
| 1059 | pixld x |
| 1060 | .endm |
| 1061 |
| 1062 | sxtw x0, w0 |
| 1063 |
| 1064 | stp x29, x30, [sp, -16]! |
| 1065 | mov x29, sp |
| 1066 | sub sp, sp, 64 |
| 1067 | sub x29, x29, 64 |
| 1068 | st1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x29], 32 |
| 1069 | st1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x29], 32 |
| 1070 | .endif |
| 1071 |
| 1072 | .if (((flags) & FLAG_DST_READWRITE) != 0) |
| 1073 | .set dst_r_bpp, dst_w_bpp |
| 1074 | .else |
| 1075 | .set dst_r_bpp, 0 |
| 1076 | .endif |
| 1077 | .if (((flags) & FLAG_DEINTERLEAVE_32BPP) != 0) |
| 1078 | .set DEINTERLEAVE_32BPP_ENABLED, 1 |
| 1079 | .else |
| 1080 | .set DEINTERLEAVE_32BPP_ENABLED, 0 |
| 1081 | .endif |
| 1082 |
| 1083 | .macro fetch_src_pixblock |
| 1084 | pixld_src pixblock_size, src_bpp, \ |
| 1085 | (src_basereg - pixblock_size * src_bpp / 64), SRC |
| 1086 | .endm |
| 1087 |
| 1088 | init |
| 1089 | mov DST_R, DST_W |
| 1090 |
| 1091 | cmp W, #pixblock_size |
| 1092 | blt 800f |
| 1093 |
| 1094 | ensure_destination_ptr_alignment process_pixblock_head, \ |
| 1095 | process_pixblock_tail, \ |
| 1096 | process_pixblock_tail_head |
| 1097 |
| 1098 | subs W, W, #pixblock_size |
| 1099 | blt 700f |
| 1100 |
| 1101 | /* Implement "head (tail_head) ... (tail_head) tail" loop pattern */ |
| 1102 | pixld_a pixblock_size, dst_r_bpp, \ |
| 1103 | (dst_r_basereg - pixblock_size * dst_r_bpp / 64), DST_R |
| 1104 | fetch_src_pixblock |
| 1105 | pixld pixblock_size, mask_bpp, \ |
| 1106 | (mask_basereg - pixblock_size * mask_bpp / 64), MASK |
| 1107 | process_pixblock_head |
| 1108 | subs W, W, #pixblock_size |
| 1109 | blt 200f |
| 1110 | 100: |
| 1111 | process_pixblock_tail_head |
| 1112 | subs W, W, #pixblock_size |
| 1113 | bge 100b |
| 1114 | 200: |
| 1115 | process_pixblock_tail |
| 1116 | pixst_a pixblock_size, dst_w_bpp, \ |
| 1117 | (dst_w_basereg - pixblock_size * dst_w_bpp / 64), DST_W |
| 1118 | 700: |
| 1119 | /* Process the remaining trailing pixels in the scanline (dst aligned) */ |
| 1120 | process_trailing_pixels 0, 1, \ |
| 1121 | process_pixblock_head, \ |
| 1122 | process_pixblock_tail, \ |
| 1123 | process_pixblock_tail_head |
| 1124 |
| 1125 | cleanup |
| 1126 | .if use_nearest_scaling != 0 |
| 1127 | sub x29, x29, 64 |
| 1128 | ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x29], 32 |
| 1129 | ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x29], 32 |
| 1130 | ldp x8, x9, [x29, -80] |
| 1131 | ldr x10, [x29, -96] |
| 1132 | mov sp, x29 |
| 1133 | ldp x29, x30, [sp], 16 |
| 1134 | ret /* exit */ |
| 1135 | .else |
| 1136 | sub x29, x29, 64 |
| 1137 | ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x29], 32 |
| 1138 | ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x29], 32 |
| 1139 | mov sp, x29 |
| 1140 | ldp x29, x30, [sp], 16 |
| 1141 | ret /* exit */ |
| 1142 | .endif |
| 1143 | 800: |
| 1144 | /* Process the remaining trailing pixels in the scanline (dst unaligned) */ |
| 1145 | process_trailing_pixels 0, 0, \ |
| 1146 | process_pixblock_head, \ |
| 1147 | process_pixblock_tail, \ |
| 1148 | process_pixblock_tail_head |
| 1149 |
| 1150 | cleanup |
| 1151 | .if use_nearest_scaling != 0 |
| 1152 | sub x29, x29, 64 |
| 1153 | ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x29], 32 |
| 1154 | ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x29], 32 |
| 1155 | ldp x8, x9, [x29, -80] |
| 1156 | ldr x10, [x29, -88] |
| 1157 | mov sp, x29 |
| 1158 | ldp x29, x30, [sp], 16 |
| 1159 | ret /* exit */ |
| 1160 |
| 1161 | .unreq DUMMY |
| 1162 | .unreq DST_R |
| 1163 | .unreq SRC |
| 1164 | .unreq W |
| 1165 | .unreq VX |
| 1166 | .unreq UNIT_X |
| 1167 | .unreq TMP1 |
| 1168 | .unreq TMP2 |
| 1169 | .unreq DST_W |
| 1170 | .unreq MASK |
| 1171 | .unreq SRC_WIDTH_FIXED |
| 1172 |
| 1173 | .else |
| 1174 | sub x29, x29, 64 |
| 1175 | ld1 {v8.8b, v9.8b, v10.8b, v11.8b}, [x29], 32 |
| 1176 | ld1 {v12.8b, v13.8b, v14.8b, v15.8b}, [x29], 32 |
| 1177 | mov sp, x29 |
| 1178 | ldp x29, x30, [sp], 16 |
| 1179 | ret /* exit */ |
| 1180 |
| 1181 | .unreq DUMMY |
| 1182 | .unreq SRC |
| 1183 | .unreq MASK |
| 1184 | .unreq DST_R |
| 1185 | .unreq DST_W |
| 1186 | .unreq W |
| 1187 | .endif |
| 1188 |
| 1189 | .purgem fetch_src_pixblock |
| 1190 | .purgem pixld_src |
| 1191 |
| 1192 | .endfunc |
| 1193 | .endm |
| 1194 |
| 1195 | .macro generate_composite_function_single_scanline x:vararg |
| 1196 | generate_composite_function_scanline 0, x |
| 1197 | .endm |
| 1198 |
| 1199 | .macro generate_composite_function_nearest_scanline x:vararg |
| 1200 | generate_composite_function_scanline 1, x |
| 1201 | .endm |
| 1202 |
| 1203 | /* Default prologue/epilogue, nothing special needs to be done */ |
| 1204 |
| 1205 | .macro default_init |
| 1206 | .endm |
| 1207 |
| 1208 | .macro default_cleanup |
| 1209 | .endm |
| 1210 |
| 1211 | /* |
| 1212 | * Prologue/epilogue variant which additionally saves/restores v8-v15 |
| 1213 | * registers (they need to be saved/restored by callee according to ABI). |
| 1214 | * This is required if the code needs to use all the NEON registers. |
| 1215 | */ |
| 1216 |
| 1217 | .macro default_init_need_all_regs |
| 1218 | .endm |
| 1219 |
| 1220 | .macro default_cleanup_need_all_regs |
| 1221 | .endm |
| 1222 |
| 1223 | /******************************************************************************/ |
| 1224 |