Home | History | Annotate | Download | only in arch-mips64
      1 /*
      2 ** Copyright 2015, The Android Open Source Project
      3 **
      4 ** Licensed under the Apache License, Version 2.0 (the "License");
      5 ** you may not use this file except in compliance with the License.
      6 ** You may obtain a copy of the License at
      7 **
      8 **     http://www.apache.org/licenses/LICENSE-2.0
      9 **
     10 ** Unless required by applicable law or agreed to in writing, software
     11 ** distributed under the License is distributed on an "AS IS" BASIS,
     12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 ** See the License for the specific language governing permissions and
     14 ** limitations under the License.
     15 */
     16 
     17 #ifdef DEBUG
     18 #define DBG
     19 #else
     20 #define DBG #
     21 #endif
     22 
     23 /*
     24  * blend one of 2 16bpp RGB pixels held in dreg selected by shift
     25  * with the 32bpp ABGR pixel held in src and store the result in fb
     26  *
     27  * Assumes that the dreg data is little endian and that
     28  * the the second pixel (shift==16) will be merged into
     29  * the fb result
     30  *
     31  * Uses $a4,$t2,$t3,$t8
     32  */
     33 
     34     .macro pixel dreg src fb shift
     35     /*
     36      * sA = s >> 24
     37      * f = 0x100 - (sA + (sA>>7))
     38      */
     39     srl     $t3,\src,24
     40     srl     $t2,$t3,7
     41     addu    $t3,$t2
     42     li      $t2,0x100
     43     subu    $t3,$t2,$t3
     44 
     45     /* red */
     46     ext     $t8,\dreg,\shift+6+5,5                  # dst[\shift:15..11]
     47     mul     $t2,$t8,$t3
     48     ext     $a4,\dreg,\shift+5,6                    # start green extraction dst[\shift:10..5]
     49     ext     $t8,\src,3,5                            # src[7..3]
     50     srl     $t2,8
     51     addu    $t8,$t2
     52 .if \shift!=0
     53     sll     $t8,\shift+11                           # dst[\shift:15..11]
     54     or      \fb,$t8
     55 .else
     56     sll     \fb,$t8,11
     57 .endif
     58 
     59     /* green */
     60     mul     $t8,$a4,$t3
     61     ext     $a4,\dreg,\shift,5                      # start blue extraction dst[\shift:4..0]
     62     ext     $t2,\src,2+8,6                          # src[15..10]
     63     srl     $t8,8
     64     addu    $t8,$t2
     65 
     66     /* blue */
     67     mul     $a4,$a4,$t3
     68     sll     $t8, $t8, \shift+5                  # finish green insertion dst[\shift:10..5]
     69     or      \fb, \fb, $t8
     70     ext     $t2,\src,(3+8+8),5
     71     srl     $t8,$a4,8
     72     addu    $t8,$t2
     73     sll     $t8, $t8, \shift
     74     or      \fb, \fb, $t8
     75     .endm
     76 
     77     .text
     78     .align
     79 
     80     .global scanline_t32cb16blend_mips64
     81     .ent    scanline_t32cb16blend_mips64
     82 scanline_t32cb16blend_mips64:
     83     daddiu  $sp, $sp, -40
     84 DBG li      $v0,0xffffffff
     85 DBG li      $v1,0
     86     /* Align the destination if necessary */
     87     and     $a4,$a0,3
     88     beqz    $a4,aligned
     89 
     90     /* as long as there is at least one pixel */
     91     beqz    $a2,done
     92 
     93     lw      $t0,($a1)
     94     daddu   $a0,2
     95     daddu   $a1,4
     96     beqz    $t0,1f
     97     lhu     $a7,-2($a0)
     98     pixel   $a7,$t0,$a5,0
     99     sh      $a5,-2($a0)
    100 1:  subu    $a2,1
    101 
    102 aligned:
    103     /* Check to see if its worth unrolling the loop */
    104     subu    $a2,4
    105     bltz    $a2,tail
    106 
    107     /* Process 4 pixels at a time */
    108 fourpixels:
    109     /* 1st pair of pixels */
    110     lw      $t0,0($a1)
    111     lw      $t1,4($a1)
    112     daddu   $a0,8
    113     daddu   $a1,16
    114 
    115     /* both are zero, skip this pair */
    116     or      $a7,$t0,$t1
    117     beqz    $a7,1f
    118 
    119     /* load the destination */
    120     lw      $a7,-8($a0)
    121 
    122     pixel   $a7,$t0,$a5,0
    123     andi    $a5, 0xFFFF
    124     pixel   $a7,$t1,$a5,16
    125     sw      $a5,-8($a0)
    126 
    127 1:
    128     /* 2nd pair of pixels */
    129     lw      $t0,-8($a1)
    130     lw      $t1,-4($a1)
    131 
    132     /* both are zero, skip this pair */
    133     or      $a7,$t0,$t1
    134     beqz    $a7,1f
    135 
    136     /* load the destination */
    137     lw      $a7,-4($a0)
    138 
    139     pixel   $a7,$t0,$a5,0
    140     andi    $a5, 0xFFFF
    141     pixel   $a7,$t1,$a5,16
    142     sw      $a5,-4($a0)
    143 
    144 1:  subu    $a2,4
    145     bgtz    $a2,fourpixels
    146 
    147 tail:
    148     /* the pixel count underran, restore it now */
    149     addu    $a2,4
    150 
    151     /* handle the last 0..3 pixels */
    152     beqz    $a2,done
    153 onepixel:
    154     lw      $t0,($a1)
    155     daddu   $a0,2
    156     daddu   $a1,4
    157     beqz    $t0,1f
    158     lhu     $a7,-2($a0)
    159     pixel   $a7,$t0,$a5,0
    160     sh      $a5,-2($a0)
    161 1:  subu    $a2,1
    162     bnez    $a2,onepixel
    163 done:
    164 DBG .set    push
    165 DBG .set    mips32r2
    166 DBG rdhwr   $a0,$3
    167 DBG mul     $v0,$a0
    168 DBG mul     $v1,$a0
    169 DBG .set    pop
    170     daddiu  $sp, $sp, 40
    171     j       $ra
    172     .end    scanline_t32cb16blend_mips64
    173