/*
 *  Copyright 2000-2011 Intel Corporation All Rights Reserved
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
//   33    // Total instruction count
//    1    // Total kernel count


// Module name: common.inc
//
// Common header file for all Video-Processing kernels
//

.default_execution_size (16)
.default_register_type  :ub

.reg_count_total        128
.reg_count_payload      7

//========== Common constants ==========


//========== Macros ==========


//Fast Jump, For more details see "Set_Layer_N.asm"


//========== Defines ====================

//========== Static Parameters (Common To All) ==========
//r1


//r2

                                    //  e.g.            byte0   byte1  byte2
                                    // YUYV               0       1      3
                                    // YVYU               0       3      1

//Color Pipe (IECP) parameters


//r4

                                    //  e.g.              byte0           byte1           byte2
                                    // YUYV                 0               1               3
                                    // YVYU                 0               3               1


//========== Inline parameters (Common To All) ===========


//============== Binding Index Table===========
//Common between DNDI and DNUV


//================= Common Message Descriptor =====
// Message descriptor for thread spawning
// Message Descriptors
//                = 000 0001 (min message len 1 ) 0,0000 (resp len 0   -add later)
//                  0000,0000,0000
//                  0001(Spawn a root thread),0001 (Root thread spawn thread)
//                = 0x02000011
// Thread Spawner Message Descriptor


// Message descriptor for atomic operation add
// Message Descriptors
//                = 000 0110 (min message len 6 ) 0,0000 (resp len 0   -add later)
//                  1(header present)001,10(typed atomic operation)0(return enabled)0(slot group, low 8 bits),0111 (AOP_Add)
//                  0000,0000 (Binding table index, added later)
//                = 0x02000011

// Atomic Operation Add Message Descriptor


// Message descriptor for dataport media write
        // Message Descriptors
                //                = 000 0001 (min message len 1 - add later) 00000 (resp len 0)
                //                  1 (header present 1) 0 1010 (media block write) 000000
                //                  00000000 (binding table index - set later)
                //                = 0x020A8000


// Message Length defines


// Response Length defines


// Block Width and Height Size defines


// Extended Message Descriptors


// Common message descriptors:


//===================== Math Function Control ===================================


//============ Message Registers ===============
                             // buf4 starts from r28


//#define mMSGHDR_EOT  r43    // Dummy Message Register for EOT


.declare    mubMSGPAYLOAD  Base=r30 ElementSize=1 SrcRegion=<16;16,1> Type=ub
.declare    muwMSGPAYLOAD  Base=r30 ElementSize=2 SrcRegion=<16;16,1> Type=uw
.declare    mudMSGPAYLOAD  Base=r30 ElementSize=4 SrcRegion=<8;8,1> Type=ud
.declare    mfMSGPAYLOAD   Base=r30 ElementSize=4 SrcRegion=<8;8,1> Type=f

//=================== End of thread instruction ===========================


//=====================Pointers Used=====================================


//=======================================================================


//r9-r17
// Define temp space for any usages


// Common Buffers


// End of common.inc

// FileName:    DI_Save_PA_16x4.asm
// Author:      Vivek Kumar
// Description: Save two 16x4 blocks of DI output in Packed format


// FileName:    DNDI.inc
// Author:      Vivek Kumar
// Description: Include file for DN, DI and DNDI
// Inputs:      DI_ENABLE, DN_ENABLE, DN_PLANAR, DN_PACKED


// End of common.inc


//Interface:
//Static Parameters:
//r1


//====================== Binding table (Explicit To DNDI)=========================================


.declare mudMSGHDR_DNDI     Base=r18      ElementSize=4    Type=ud
.declare mdMSGHDR_DNDI      Base=r18      ElementSize=4    Type=d
.declare mwMSGHDR_DNDI      Base=r18      ElementSize=2    Type=w


.declare mudMSGHDR_STMM     Base=r20      ElementSize=4    Type=ud


.declare mudMSGHDR_HIST     Base=r22      ElementSize=4    Type=ud


.declare mudMSGHDR_ENC_STATS Base=r24 ElementSize=4   Type=ud
.declare muwMSGHDR_ENC_STATS Base=r24 ElementSize=2   Type=uw
.declare mubMSGHDR_ENC_STATS Base=r24 ElementSize=1   Type=ub


.declare mudMSGHDR_DN_OUT   Base=r31.0      ElementSize=4  Type=ud
.declare mdMSGHDR_DN_OUT    Base=r31.0      ElementSize=4  Type=d
.declare mubMSGHDR_DN_OUT   Base=r31.0      ElementSize=1  Type=ub


.declare mudMSGHDR_UVCOPY   Base=r36      ElementSize=4  Type=ud
.declare mdMSGHDR_UVCOPY    Base=r36      ElementSize=4  Type=d
.declare mudMSGHDR_UCOPY    Base=r36       ElementSize=4  Type=ud
.declare mudMSGHDR_VCOPY    Base=r38       ElementSize=4  Type=ud


.declare mudMSGHDR_DI_OUT1  Base=r18.0      ElementSize=4     Type=ud
.declare mubMSGHDR_DI_OUT1  Base=r18.0      ElementSize=1     Type=ub


.declare mudMSGHDR_DI_OUT2  Base=r23.0      ElementSize=4     Type=ud
.declare mubMSGHDR_DI_OUT2  Base=r23.0      ElementSize=1     Type=ub

//r45
//Use r45 as message header, so no need to "mov" the data.

.declare mudDN_Y_OUT        Base=r45.0 ElementSize=4 SrcRegion=<8;8,1>   DstRegion=<1> Type=ud

// Message response (Denoised & DI-ed pixels & statistics); Use buffer 5
.declare udDNDI_RESP        Base=r46.0 ElementSize=4 SrcRegion=<8;8,1>   DstRegion=<1> Type=ud
.declare uwDNDI_RESP        Base=r46.0 ElementSize=2 SrcRegion=<16;16,1> DstRegion=<1> Type=uw
.declare ubDNDI_RESP        Base=r46.0 ElementSize=1 SrcRegion=<16;16,1> DstRegion=<1> Type=ub

// Message response (UV Copy); Use buffer 5
.declare udDNDI_UV_RESP     Base=r58.0 ElementSize=4 SrcRegion=<8;8,1>  DstRegion=<1> Type=ud
.declare ubDNDI_UV_RESP     Base=r58.0 ElementSize=1 SrcRegion=<16;16,1>    DstRegion=<1> Type=ub

//Temp GRFs: For 42X to 422 Conversion
.declare uwDNDI_UVCOPY_TEMP Base=r10.0 ElementSize=2 SrcRegion=<16;16,1>    DstRegion=<1> Type=uw       //8 GRFs
.declare ubDNDI_UVCOPY_TEMP Base=r10.0 ElementSize=1 SrcRegion=<16;16,1>    DstRegion=<1> Type=ub       //8 GRFs
//---------------------------------------------------------------------------
// Message descriptors
//---------------------------------------------------------------------------
// Extended message descriptor
    // Message descriptor   for sampler read
    //                    = 000 0010 (message len 2) 00000 (resp len - set later, 12 or 5 or 11)
    //                      1 (header present 1) 0 11 (SIMD32/64 mode)
    //                      1000 (message type) 0000 (DI state index)
    //                      00000000 (binding table index - set later)
    //                    = 0x040b8000


// Attention: The Message Length is The Number of GRFs with Data Only, without the Header


//---------------------------------------------------------------------------
// VDI Return Data format
//---------------------------------------------------------------------------
// Defines for DI enabled


// Defines for DI disabled


add (4) a0.4<1>:uw   r2.28<4;4,1>:ub   608:w               // Initial Y,U,V offset in YUV422 block; it starts at m20

mov (8) r27.0<1>:ud     r0.0<8;8,1>:ud
shl (1) r27.0<1>:d      r7.0<0;1,0>:w            1:w  { NoDDClr }          // H. block origin need to be doubled
mov (1) r27.1<1>:d      r7.1<0;1,0>:w                 { NoDDClr, NoDDChk }       // Block origin
mov (1) r27.2<1>:ud     0x3001F:ud          { NoDDChk }          // Block width and height (32x8)

//prepare the message headers
mov (8) r18.0<1>:ud       r27<8;8,1>:ud
mov (8) r23.0<1>:ud       r27<8;8,1>:ud

// Pack 2nd field Y
    mov (16)    r[a0.4, 0]<2>      ubDNDI_RESP(0,0)               { NoDDClr }
    mov (16)    r[a0.4, 32]<2>      ubDNDI_RESP(0,16)               { NoDDClr }
    mov (16)    r[a0.4, 64]<2>      ubDNDI_RESP(0,32)               { NoDDClr }
    mov (16)    r[a0.4, 96]<2>      ubDNDI_RESP(0,48)               { NoDDClr }
// Pack 2nd field U
    mov (8)     r[a0.5, 0]<4>      ubDNDI_RESP(2,1)<16;8,2>   { NoDDClr, NoDDChk }  //U pixels
    mov (8)     r[a0.5, 32]<4>      ubDNDI_RESP(2,17)<16;8,2>   { NoDDClr, NoDDChk }  //U pixels
    mov (8)     r[a0.5, 64]<4>      ubDNDI_RESP(2,33)<16;8,2>   { NoDDClr, NoDDChk }  //U pixels
    mov (8)     r[a0.5, 96]<4>      ubDNDI_RESP(2,49)<16;8,2>   { NoDDClr, NoDDChk }  //U pixels
// Pack 2nd field V
    mov (8)     r[a0.6, 0]<4>      ubDNDI_RESP(2,0)<16;8,2>     { NoDDChk }     //Vpixels
    mov (8)     r[a0.6, 32]<4>      ubDNDI_RESP(2,16)<16;8,2>     { NoDDChk }     //Vpixels
    mov (8)     r[a0.6, 64]<4>      ubDNDI_RESP(2,32)<16;8,2>     { NoDDChk }     //Vpixels
    mov (8)     r[a0.6, 96]<4>      ubDNDI_RESP(2,48)<16;8,2>     { NoDDChk }     //Vpixels

// Pack 1st field Y
    mov (16)    r[a0.4, 160]<2>    ubDNDI_RESP(4,0)               { NoDDClr }
    mov (16)    r[a0.4, 192]<2>    ubDNDI_RESP(4,16)               { NoDDClr }
    mov (16)    r[a0.4, 224]<2>    ubDNDI_RESP(4,32)               { NoDDClr }
    mov (16)    r[a0.4, 256]<2>    ubDNDI_RESP(4,48)               { NoDDClr }
// Pack 1st field U
    mov (8)     r[a0.5, 160]<4>    ubDNDI_RESP(6,1)<16;8,2>   { NoDDClr, NoDDChk }  //U pixels
    mov (8)     r[a0.5, 192]<4>    ubDNDI_RESP(6,17)<16;8,2>   { NoDDClr, NoDDChk }  //U pixels
    mov (8)     r[a0.5, 224]<4>    ubDNDI_RESP(6,33)<16;8,2>   { NoDDClr, NoDDChk }  //U pixels
    mov (8)     r[a0.5, 256]<4>    ubDNDI_RESP(6,49)<16;8,2>   { NoDDClr, NoDDChk }  //U pixels
// Pack 1st field V
    mov (8)     r[a0.6, 160]<4>    ubDNDI_RESP(6,0)<16;8,2>     { NoDDChk }     //Vpixels
    mov (8)     r[a0.6, 192]<4>    ubDNDI_RESP(6,16)<16;8,2>     { NoDDChk }     //Vpixels
    mov (8)     r[a0.6, 224]<4>    ubDNDI_RESP(6,32)<16;8,2>     { NoDDChk }     //Vpixels
    mov (8)     r[a0.6, 256]<4>    ubDNDI_RESP(6,48)<16;8,2>     { NoDDChk }     //Vpixels

//save the previous frame
send (8)    null<1>:d    r18.0     0x5     0xA0A801B:ud

//save the current frame
send (8)    null<1>:d    r23.0     0x5     0xA0A801E:ud
