Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Weighted prediction of luminance and chrominance
  3.  * Copyright © <2010>, Intel Corporation.
  4.  *
  5.  * Permission is hereby granted, free of charge, to any person obtaining a
  6.  * copy of this software and associated documentation files (the
  7.  * "Software"), to deal in the Software without restriction, including
  8.  * without limitation the rights to use, copy, modify, merge, publish,
  9.  * distribute, sub license, and/or sell copies of the Software, and to
  10.  * permit persons to whom the Software is furnished to do so, subject to
  11.  * the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice (including the
  14.  * next paragraph) shall be included in all copies or substantial portions
  15.  * of the Software.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  20.  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
  21.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24.  *
  25.  * This file was originally licensed under the following license
  26.  *
  27.  *  Licensed under the Apache License, Version 2.0 (the "License");
  28.  *  you may not use this file except in compliance with the License.
  29.  *  You may obtain a copy of the License at
  30.  *
  31.  *      http://www.apache.org/licenses/LICENSE-2.0
  32.  *
  33.  *  Unless required by applicable law or agreed to in writing, software
  34.  *  distributed under the License is distributed on an "AS IS" BASIS,
  35.  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36.  *  See the License for the specific language governing permissions and
  37.  *  limitations under the License.
  38.  *
  39.  */
  40. // Kernel name: WeightedPred.asm
  41. //
  42. // Weighted prediction of luminance and chrominance
  43. //
  44.  
  45.  
  46. //#if !defined(__WeightedPred__)                // Make sure this is only included once
  47. //#define __WeightedPred__
  48.  
  49.  
  50.         and.z.f0.0 (1) gWEIGHTFLAG:w    gWPREDFLAG:ub                                   nWBIDIR_MASK:w
  51.         cmp.e.f0.1 (1) null:w                   gPREDFLAG:w                                             2:w
  52.         (-f0.0) jmpi INTERLABEL(WeightedPred)
  53.         (f0.1) jmpi INTERLABEL(DefaultWeightedPred_BiPred)
  54.        
  55. INTERLABEL(DefaultWeightedPred_UniPred):
  56.  
  57.         cmp.e.f0.0 (1) null:w                   gPREDFLAG:w                                             0:w
  58.         (f0.0) jmpi INTERLABEL(Return_WeightedPred)
  59.  
  60.         // luma
  61.         mov (32)        gubYPRED(0)<2>          gubINTPY1(0)    {Compr}
  62.         mov (32)        gubYPRED(2)<2>          gubINTPY1(2)    {Compr}
  63.  
  64. #ifndef MONO
  65.         // chroma      
  66.         mov (32)        gubCPRED(0)<2>          gubINTPC1(0)    {Compr}
  67. #endif
  68.  
  69.         jmpi INTERLABEL(Return_WeightedPred)
  70.        
  71. INTERLABEL(DefaultWeightedPred_BiPred):
  72.  
  73.         // luma
  74.         avg.sat (32) gubYPRED(0)<2>             gubINTPY0(0)                                    gubINTPY1(0)    {Compr}
  75.         avg.sat (32) gubYPRED(2)<2>             gubINTPY0(2)                                    gubINTPY1(2)    {Compr}
  76.        
  77. #ifndef MONO
  78.         // chroma
  79.         avg.sat (32) gubCPRED(0)<2>             gubINTPC0(0)                                    gubINTPC1(0)    {Compr}
  80. #endif
  81.        
  82.         jmpi INTERLABEL(Return_WeightedPred)
  83.        
  84. INTERLABEL(WeightedPred):
  85.         cmp.e.f0.1 (1) null:w                   gWEIGHTFLAG:w                                   0x80:w
  86.         (-f0.1) jmpi INTERLABEL(WeightedPred_Explicit)
  87.        
  88.         cmp.e.f0.0 (1) null:w                   gPREDFLAG:w                                             2:w
  89.         (-f0.0) jmpi INTERLABEL(DefaultWeightedPred_UniPred)
  90.  
  91.         mov (2)         gYADD<1>:w                      32:w                                                            {NoDDClr}      
  92.         mov (2)         gYSHIFT<1>:w            6:w                                                                     {NoDDChk}
  93.         mov (4)         gOFFSET<1>:w            0:w
  94.         mov (8)         gWT0<2>:w                       r[pWGT,0]<0;2,1>:w
  95.        
  96.         jmpi INTERLABEL(WeightedPred_LOOP)
  97.        
  98.         // Explicit Prediction
  99. INTERLABEL(WeightedPred_Explicit):
  100.        
  101.         // WA for weighted prediction - 2007/09/06     
  102. #ifdef  SW_W_128                // CTG SW WA
  103.         cmp.e.f0.1 (8) null:ud                  r[pWGT,0]<8;8,1>:uw                             gudW128(0)<0;1,0>
  104. #else                                   // ILK HW solution
  105.         and.ne.f0.1 (8) null:uw                 r[pWGT,12]<0;1,0>:ub                    0x88848421:v    // Expand W=128 flag to all components. 2 MSB are don't care
  106. #endif 
  107.         asr.nz.f0.0 (2) gBIPRED<1>:w    gPREDFLAG<0;1,0>:w                              1:w
  108.         asr (1)         gWEIGHTFLAG:w           gWEIGHTFLAG:w                                   6:w    
  109.         (-f0.0) mov (2) gPREDFLAG1<1>:w gPREDFLAG<0;1,0>:w                                                             
  110.         (f0.0) mov (2)  gPREDFLAG0<1>:ud 0x00010001:ud
  111.         (-f0.0) add (2) gPREDFLAG0<1>:w -gPREDFLAG1<2;2,1>:w                    1:w
  112.        
  113.         // WA for weighted prediction - 2007/09/06     
  114.         (f0.1) mov (8)  gWT0<1>:ud              0x00000080:ud
  115.         (-f0.1) mov (8) gWT0<2>:w               r[pWGT,0]<16;8,2>:b
  116.         (-f0.1) mov (8) gO0<2>:w                r[pWGT,1]<16;8,2>:b
  117.         mul (16)                gWT0<1>:w               gWT0<16;16,1>:w                                 gPREDFLAG0<0;4,1>:w
  118.  
  119.         // Compute addition
  120.         cmp.e.f0.1 (2) null<1>:w                gYWDENOM<2;2,1>:ub                              0:w
  121.         (-f0.1) shl (2) gW0<1>:w                gWEIGHTFLAG<0;1,0>:w                    gYWDENOM<2;2,1>:ub
  122.         (f0.1) mov (2) gW0<1>:w                 0:w
  123.         (-f0.1) asr (2) gW0<1>:w                gW0<2;2,1>:w                                    1:w
  124.         shl (2)         gYADD<1>:w                      gW0<2;2,1>:w                                    gBIPRED<0;1,0>:w
  125.         (f0.1) add (2)  gYADD<1>:w              gYADD<2;2,1>:w                                  gBIPRED<0;1,0>:w
  126.        
  127.         // Compute shift
  128.         add (2)         gYSHIFT<1>:w            gYWDENOM<2;2,1>:ub                              gBIPRED<0;1,0>:w
  129.        
  130.         // Compute offset
  131.         add (4)         acc0<1>:w                       gO0<16;4,4>:w                                   gO1<16;4,4>:w
  132.         add (4)         acc0<1>:w                       acc0<4;4,1>:w                                   gBIPRED<0;1,0>:w
  133.         asr (4)         gOFFSET<1>:w            acc0<4;4,1>:w                                   gBIPRED<0;1,0>:w
  134.  
  135. INTERLABEL(WeightedPred_LOOP): 
  136.         // luma
  137.         $for(0;<4;2) { 
  138.         mul (16)        acc0<1>:w                       gubINTPY0(%1)                                   gWT0<0;1,0>:w
  139.         mul (16)        acc1<1>:w                       gubINTPY0(%1+1)                                 gWT0<0;1,0>:w
  140.         mac (16)        acc0<1>:w                       gubINTPY1(%1)                                   gWT1<0;1,0>:w
  141.         mac (16)        acc1<1>:w                       gubINTPY1(%1+1)                                 gWT1<0;1,0>:w
  142.         add (16)        acc0<1>:w                       acc0<16;16,1>:w                                 gYADD:w
  143.         add (16)        acc1<1>:w                       acc1<16;16,1>:w                                 gYADD:w
  144.         // Accumulator cannot be used as destination for ASR
  145.         asr (16)        gwINTERIM_BUF3(0)<1> acc0<16;16,1>:w                            gYSHIFT:w
  146.         asr (16)        gwINTERIM_BUF3(1)<1> acc1<16;16,1>:w                            gYSHIFT:w
  147.         add.sat (16) gubYPRED(%1)<2>    gwINTERIM_BUF3(0)                               gOFFSET:w
  148.         add.sat (16) gubYPRED(%1+1)<2>  gwINTERIM_BUF3(1)                               gOFFSET:w
  149.         }      
  150.  
  151. #ifndef MONO
  152.         // chroma
  153.         mul (16)        acc0<1>:w                       gubINTPC0(0)                                    gUW0<0;2,4>:w
  154.         mul (16)        acc1<1>:w                       gubINTPC0(1)                                    gUW0<0;2,4>:w
  155.         mac (16)        acc0<1>:w                       gubINTPC1(0)                                    gUW1<0;2,4>:w
  156.         mac (16)        acc1<1>:w                       gubINTPC1(1)                                    gUW1<0;2,4>:w
  157.         add (16)        acc0<1>:w                       acc0<16;16,1>:w                                 gCADD:w
  158.         add (16)        acc1<1>:w                       acc1<16;16,1>:w                                 gCADD:w
  159.         // Accumulator cannot be used as destination for ASR
  160.         asr (16)        gwINTERIM_BUF3(0)<1> acc0<16;16,1>:w                            gCSHIFT:w
  161.         asr (16)        gwINTERIM_BUF3(1)<1> acc1<16;16,1>:w                            gCSHIFT:w
  162.         add.sat (16) gubCPRED(0)<2>             gwINTERIM_BUF3(0)                               gUOFFSET<0;2,1>:w
  163.         add.sat (16) gubCPRED(1)<2>             gwINTERIM_BUF3(1)                               gUOFFSET<0;2,1>:w
  164. #endif
  165.  
  166.  
  167. INTERLABEL(Return_WeightedPred):
  168.  
  169.        
  170. //#endif        // !defined(__WeightedPred__)
  171.