1 /*
2 * Copyright (c) 2019, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
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 shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 
23 #include "CSC_444_16.h"
24 
CSC_444_16(CURBE_INPUT_OUTPUT,GLOBAL_BUFFER_INPUT_OUTPUT)25 _GENX_MAIN_ _CM_CALLABLE_ void CSC_444_16(
26     CURBE_INPUT_OUTPUT,
27     GLOBAL_BUFFER_INPUT_OUTPUT)
28 {
29     /*
30     Buffer layout after shuffle
31     _________________________________________________
32     |_______Block0__________|_______Block1__________|
33     |_______Block2__________|_______Block3__________|
34     |_______Block4__________|_______Block5__________|
35     |_______Block6__________|_______Block7__________|
36 
37     Write back buffer layout correlate to the block number#, each box stands for 1 GRF
38     _______________________________________________
39     |____R0_________R1_____|____R2_________R3_____|
40     |____G0_________G1_____|____G2_________G3_____|
41     |____B0_________B1_____|____B2_________B3_____|
42     |____A0_________A1_____|____A2_________A3_____|
43     |____R4_________R5_____|____R6_________R7_____|
44     |____G4_________G5_____|____G6_________G7_____|
45     |____B4_________B5_____|____B6_________B7_____|
46     |____A4_________A5_____|____A6_________A7_____|
47     */
48 
49     uchar CSCShift = (uchar)((WAFlag & 0xe0) >> 5);
50     CSCShift = CSCShift + 7;
51 
52     matrix_ref<ushort, 4, 64> WriteBackBuffer = DataBuffer.select<4, 1, 64, 1>(Buffer_Index << 2, 0);
53 
54     matrix<ushort, 1, 16> tempR = WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(0, 0);
55     matrix<ushort, 1, 16> tempG = WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(2, 0);
56 
57     unsigned short tempMul = 0xFFFF;
58 
59     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(0, 0) = cm_shr<ushort>(tempR * CscCoeff[0][2] + tempG * CscCoeff[0][0] + WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(4, 0) * CscCoeff[0][1] + CscCoeff[0][3] * tempMul, CSCShift, SAT);
60     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(2, 0) = cm_shr<ushort>(tempR * CscCoeff[0][6] + tempG * CscCoeff[0][4] + WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(4, 0) * CscCoeff[0][5] + CscCoeff[0][7] * tempMul, CSCShift, SAT);
61     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(4, 0) = cm_shr<ushort>(WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(4, 0) * CscCoeff[0][9] + tempR * CscCoeff[0][10] + tempG * CscCoeff[0][8] + CscCoeff[0][11] * tempMul, CSCShift, SAT);
62 
63     tempR = WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(1, 0);
64     tempG = WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(3, 0);
65 
66     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(1, 0) = cm_shr<ushort>(tempR * CscCoeff[0][2] + tempG * CscCoeff[0][0] + WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(5, 0)  * CscCoeff[0][1] + CscCoeff[0][3] * tempMul, CSCShift, SAT);
67     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(3, 0) = cm_shr<ushort>(tempR * CscCoeff[0][6] + tempG * CscCoeff[0][4] + WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(5, 0)  * CscCoeff[0][5] + CscCoeff[0][7] * tempMul, CSCShift, SAT);
68     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(5, 0) = cm_shr<ushort>(WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(5, 0) * CscCoeff[0][9] + tempR * CscCoeff[0][10] + tempG * CscCoeff[0][8] + CscCoeff[0][11] * tempMul, CSCShift, SAT);
69 
70     tempR = WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(8, 0);
71     tempG = WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(10, 0);
72 
73     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(8, 0) = cm_shr<ushort>(tempR * CscCoeff[0][2] + tempG * CscCoeff[0][0] + WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(12, 0) * CscCoeff[0][1] + CscCoeff[0][3] * tempMul, CSCShift, SAT);
74     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(10, 0) = cm_shr<ushort>(tempR * CscCoeff[0][6] + tempG * CscCoeff[0][4] + WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(12, 0) * CscCoeff[0][5] + CscCoeff[0][7] * tempMul, CSCShift, SAT);
75     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(12, 0) = cm_shr<ushort>(WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(12, 0) * CscCoeff[0][9] + tempR * CscCoeff[0][10] + tempG * CscCoeff[0][8] + CscCoeff[0][11] * tempMul, CSCShift, SAT);
76 
77     tempR = WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(9, 0);
78     tempG = WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(11, 0);
79 
80     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(9, 0) = cm_shr<ushort>(tempR * CscCoeff[0][2] + tempG * CscCoeff[0][0] + WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(13, 0) * CscCoeff[0][1] + CscCoeff[0][3] * tempMul, CSCShift, SAT);
81     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(11, 0) = cm_shr<ushort>(tempR * CscCoeff[0][6] + tempG * CscCoeff[0][4] + WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(13, 0) * CscCoeff[0][5] + CscCoeff[0][7] * tempMul, CSCShift, SAT);
82     WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(13, 0) = cm_shr<ushort>(WriteBackBuffer.format<ushort, 16, 16>().select<1, 1, 16, 1>(13, 0) * CscCoeff[0][9] + tempR * CscCoeff[0][10] + tempG * CscCoeff[0][8] + CscCoeff[0][11] * tempMul, CSCShift, SAT);
83 }
84