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 "GammaC.h"
24 
25 const uchar R[16] = {
26     0, 0, 0, 0,
27     0, 0, 0, 0,
28     0, 0, 0, 0,
29     0, 0, 0, 0
30 };
31 
GammaC(CURBE_INPUT_OUTPUT,GLOBAL_BUFFER_INPUT_OUTPUT)32 _GENX_MAIN_ _CM_CALLABLE_ void GammaC(
33     CURBE_INPUT_OUTPUT,
34     GLOBAL_BUFFER_INPUT_OUTPUT)
35 {
36     /*
37     Buffer layout after shuffle
38     _________________________________________________
39     |_______Block0__________|_______Block1__________|
40     |_______Block2__________|_______Block3__________|
41     |_______Block4__________|_______Block5__________|
42     |_______Block6__________|_______Block7__________|
43 
44     Write back buffer layout correlate to the block number#, each box stands for 1 GRF
45     _______________________________________________
46     |____R0_________R1_____|____R2_________R3_____|
47     |____G0_________G1_____|____G2_________G3_____|
48     |____B0_________B1_____|____B2_________B3_____|
49     |____A0_________A1_____|____A2_________A3_____|
50     |____R4_________R5_____|____R6_________R7_____|
51     |____G4_________G5_____|____G6_________G7_____|
52     |____B4_________B5_____|____B6_________B7_____|
53     |____A4_________A5_____|____A6_________A7_____|
54     */
55     matrix_ref<ushort, 16, 16> WriteBackBuffer = DataBuffer.select<4, 1, 64, 1>(Buffer_Index << 2, 0).format<ushort, 16, 16>();
56     matrix<uchar, 1, 256> GammaC_Lut_Linear = GammaC_Lut.format<uchar, 1, 256>();
57     vector<uchar, 16> row(R);
58     matrix<ushort, 2, 16> Temp;
59 
60 #pragma unroll
61     for (uchar i = 0; i < 3; i++)
62     {
63         Temp = WriteBackBuffer.select<2, 1, 16, 1>(2 * i, 0);
64         vector<uchar, 16> LutCoordinate;
65         vector<uchar, 16> LutCoordinate1;
66 
67         Temp = cm_add<ushort>(Temp, 0x80, SAT);
68 
69         LutCoordinate = Temp.row(0).format<uchar>().select<16, 2>(1);
70         LutCoordinate1 = Temp.row(1).format<uchar>().select<16, 2>(1);
71 
72         WriteBackBuffer.select<1, 1, 16, 1>(2 * i, 0)     = GammaC_Lut_Linear.iselect(row, LutCoordinate);
73         WriteBackBuffer.select<1, 1, 16, 1>(2 * i + 1, 0) = GammaC_Lut_Linear.iselect(row, LutCoordinate1);
74 
75         WriteBackBuffer.select<2, 1, 16, 1>(2 * i, 0) = cm_shl<ushort>(WriteBackBuffer.select<2, 1, 16, 1>(2 * i, 0), 8, SAT);
76     }
77 
78 #pragma unroll
79     for (uchar i = 0; i < 3; i++)
80     {
81         Temp = WriteBackBuffer.select<2, 1, 16, 1>(2 * i + 8, 0);
82         vector<uchar, 16> LutCoordinate;
83         vector<uchar, 16> LutCoordinate1;
84 
85         Temp = cm_add<ushort>(Temp, 0x80, SAT);
86 
87         LutCoordinate = Temp.row(0).format<uchar>().select<16, 2>(1);
88         LutCoordinate1 = Temp.row(1).format<uchar>().select<16, 2>(1);
89 
90         WriteBackBuffer.select<1, 1, 16, 1>(2 * i + 8, 0) = GammaC_Lut_Linear.iselect(row, LutCoordinate);
91         WriteBackBuffer.select<1, 1, 16, 1>(2 * i + 9, 0) = GammaC_Lut_Linear.iselect(row, LutCoordinate1);
92 
93         WriteBackBuffer.select<2, 1, 16, 1>(2 * i + 8, 0) = cm_shl<ushort>(WriteBackBuffer.select<2, 1, 16, 1>(2 * i + 8, 0), 8, SAT);
94     }
95 }
96