1/*
2 * Copyright © 2009 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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Author:
24 *    Zou Nan hai <nanhai.zou@intel.com>
25 *    Yan Li <li.l.yan@intel.com>
26 *    Liu Xi bin<xibin.liu@intel.com>
27 */
28/*
29   GRF allocation:
30   g1~g30: constant buffer
31           g1~g2:intra IQ matrix
32           g3~g4:non intra IQ matrix
33           g5~g20:IDCT tab
34   g31:    read and write message descriptor
35   g32~g55:DCT data
36   g58~g81:reference data
37   g82:    thread payload 
38   g83~g106:IDCT data 
39*/
40mov (8) g82.0<1>UD g31.0<8,8,1>UD {align1};
41mov (2) g31.0<1>UD g82.12<2,2,1>UW {align1};
42
43include(`iq_intra.g4i')
44
45//defined for idct
46define(`ROW_SHIFT', `11UD') 
47define(`ROW_ADD', `0x400UD')          
48define(`COL_SHIFT', `20UD') 
49define(`COL_ADD', `0x80000UD')          
50
51mov (1) a0.0<1>UD 0x06F006E0UD {align1};      //0x06F006E0UD+0x00200020UD=0x07100700UD (g56.0 and g56.16)
52
53//Y0
54mov (1) g125.0<1>UD ip {align1};
55jmpi IDCT_START;
56add (8) g83.0<1>W g32.0<16,8,2>W 128UW {align1};
57add (8) g84.0<1>W g33.0<16,8,2>W 128UW {align1};
58add (8) g85.0<1>W g34.0<16,8,2>W 128UW {align1};
59add (8) g86.0<1>W g35.0<16,8,2>W 128UW {align1};
60add (8) g87.0<1>W g36.0<16,8,2>W 128UW {align1};
61add (8) g88.0<1>W g37.0<16,8,2>W 128UW {align1};
62add (8) g89.0<1>W g38.0<16,8,2>W 128UW {align1};
63add (8) g90.0<1>W g39.0<16,8,2>W 128UW {align1};
64
65//Y1
66mov (1) g125.0<1>UD ip {align1};
67jmpi IDCT_START;
68add (8) g83.16<1>W g32.0<16,8,2>W 128UW {align1};
69add (8) g84.16<1>W g33.0<16,8,2>W 128UW {align1};
70add (8) g85.16<1>W g34.0<16,8,2>W 128UW {align1};
71add (8) g86.16<1>W g35.0<16,8,2>W 128UW {align1};
72add (8) g87.16<1>W g36.0<16,8,2>W 128UW {align1};
73add (8) g88.16<1>W g37.0<16,8,2>W 128UW {align1};
74add (8) g89.16<1>W g38.0<16,8,2>W 128UW {align1};
75add (8) g90.16<1>W g39.0<16,8,2>W 128UW {align1};
76
77//Y2
78mov (1) g125.0<1>UD ip {align1};
79jmpi IDCT_START;
80add (8) g91.0<1>W g32.0<16,8,2>W 128UW {align1};
81add (8) g92.0<1>W g33.0<16,8,2>W 128UW {align1};
82add (8) g93.0<1>W g34.0<16,8,2>W 128UW {align1};
83add (8) g94.0<1>W g35.0<16,8,2>W 128UW {align1};
84add (8) g95.0<1>W g36.0<16,8,2>W 128UW {align1};
85add (8) g96.0<1>W g37.0<16,8,2>W 128UW {align1};
86add (8) g97.0<1>W g38.0<16,8,2>W 128UW {align1};
87add (8) g98.0<1>W g39.0<16,8,2>W 128UW {align1};
88
89//Y3
90mov (1) g125.0<1>UD ip {align1};
91jmpi IDCT_START;
92add (8) g91.16<1>W g32.0<16,8,2>W 128UW {align1};
93add (8) g92.16<1>W g33.0<16,8,2>W 128UW {align1};
94add (8) g93.16<1>W g34.0<16,8,2>W 128UW {align1};
95add (8) g94.16<1>W g35.0<16,8,2>W 128UW {align1};
96add (8) g95.16<1>W g36.0<16,8,2>W 128UW {align1};
97add (8) g96.16<1>W g37.0<16,8,2>W 128UW {align1};
98add (8) g97.16<1>W g38.0<16,8,2>W 128UW {align1};
99add (8) g98.16<1>W g39.0<16,8,2>W 128UW {align1};
100
101//U
102mov (1) g125.0<1>UD ip {align1};
103jmpi IDCT_START;
104add (16) g99.0<1>W g32.0<16,8,2>W 128UW {align1};
105add (16) g100.0<1>W g34.0<16,8,2>W 128UW {align1};
106add (16) g101.0<1>W g36.0<16,8,2>W 128UW {align1};
107add (16) g102.0<1>W g38.0<16,8,2>W 128UW {align1};
108
109//V
110mov (1) g125.0<1>UD ip {align1};
111jmpi IDCT_START;
112add (16) g103.0<1>W g32.0<16,8,2>W 128UW {align1};
113add (16) g104.0<1>W g34.0<16,8,2>W 128UW {align1};
114add (16) g105.0<1>W g36.0<16,8,2>W 128UW {align1};
115add (16) g106.0<1>W g38.0<16,8,2>W 128UW {align1};
116
117/******************* MC ************************/
118mov (1) g31.8<1>UD 0x00F000FUD {align1};
119mov.sat (16) g83.0<2>UB g83.0<16,16,1>W {align1};
120mov.sat (16) g84.0<2>UB g84.0<16,16,1>W {align1};
121mov.sat (16) g85.0<2>UB g85.0<16,16,1>W {align1};
122mov.sat (16) g86.0<2>UB g86.0<16,16,1>W {align1};
123mov.sat (16) g87.0<2>UB g87.0<16,16,1>W {align1};
124mov.sat (16) g88.0<2>UB g88.0<16,16,1>W {align1};
125mov.sat (16) g89.0<2>UB g89.0<16,16,1>W {align1};
126mov.sat (16) g90.0<2>UB g90.0<16,16,1>W {align1};
127mov.sat (16) g91.0<2>UB g91.0<16,16,1>W {align1};
128mov.sat (16) g92.0<2>UB g92.0<16,16,1>W {align1};
129mov.sat (16) g93.0<2>UB g93.0<16,16,1>W {align1};
130mov.sat (16) g94.0<2>UB g94.0<16,16,1>W {align1};
131mov.sat (16) g95.0<2>UB g95.0<16,16,1>W {align1};
132mov.sat (16) g96.0<2>UB g96.0<16,16,1>W {align1};
133mov.sat (16) g97.0<2>UB g97.0<16,16,1>W {align1};
134mov.sat (16) g98.0<2>UB g98.0<16,16,1>W {align1};
135
136and.nz (1) null g82.2<1,1,1>UW 0x20UW{align1};
137(f0) jmpi field_dct;
138
139mov (16) m1.0<1>UB  g83.0<16,16,2>UB {align1};
140mov (16) m1.16<1>UB g84.0<16,16,2>UB {align1};
141mov (16) m2.0<1>UB  g85.0<16,16,2>UB {align1};
142mov (16) m2.16<1>UB g86.0<16,16,2>UB {align1};
143mov (16) m3.0<1>UB  g87.0<16,16,2>UB {align1};
144mov (16) m3.16<1>UB g88.0<16,16,2>UB {align1};
145mov (16) m4.0<1>UB  g89.0<16,16,2>UB {align1};
146mov (16) m4.16<1>UB g90.0<16,16,2>UB {align1};
147mov (16) m5.0<1>UB  g91.0<16,16,2>UB {align1};
148mov (16) m5.16<1>UB g92.0<16,16,2>UB {align1};
149mov (16) m6.0<1>UB  g93.0<16,16,2>UB {align1};
150mov (16) m6.16<1>UB g94.0<16,16,2>UB {align1};
151mov (16) m7.0<1>UB  g95.0<16,16,2>UB {align1};
152mov (16) m7.16<1>UB g96.0<16,16,2>UB {align1};
153mov (16) m8.0<1>UB  g97.0<16,16,2>UB {align1};
154mov (16) m8.16<1>UB g98.0<16,16,2>UB {align1};
155jmpi write_back;
156
157field_dct:
158mov (16) m1.0<1>UB  g83.0<16,16,2>UB {align1};
159mov (16) m1.16<1>UB g91.0<16,16,2>UB {align1};
160mov (16) m2.0<1>UB  g84.0<16,16,2>UB {align1};
161mov (16) m2.16<1>UB g92.0<16,16,2>UB {align1};
162mov (16) m3.0<1>UB  g85.0<16,16,2>UB {align1};
163mov (16) m3.16<1>UB g93.0<16,16,2>UB {align1};
164mov (16) m4.0<1>UB  g86.0<16,16,2>UB {align1};
165mov (16) m4.16<1>UB g94.0<16,16,2>UB {align1};
166mov (16) m5.0<1>UB  g87.0<16,16,2>UB {align1};
167mov (16) m5.16<1>UB g95.0<16,16,2>UB {align1};
168mov (16) m6.0<1>UB  g88.0<16,16,2>UB {align1};
169mov (16) m6.16<1>UB g96.0<16,16,2>UB {align1};
170mov (16) m7.0<1>UB  g89.0<16,16,2>UB {align1};
171mov (16) m7.16<1>UB g97.0<16,16,2>UB {align1};
172mov (16) m8.0<1>UB  g90.0<16,16,2>UB {align1};
173mov (16) m8.16<1>UB g98.0<16,16,2>UB {align1};
174
175write_back:
176send (16) 0 acc0<1>UW g31<8,8,1>UW write(0,0,2,0) mlen 9 rlen 0 {align1};
177
178//U
179mov (1) g31.8<1>UD 0x0070007UD  { align1 };
180shr (2) g31.0<1>UD g82.12<2,2,1>UW 1D {align1};
181mov.sat (16) g99.0<2>UB g99.0<16,16,1>W {align1};
182mov.sat (16) g100.0<2>UB g100.0<16,16,1>W {align1};
183mov.sat (16) g101.0<2>UB g101.0<16,16,1>W {align1};
184mov.sat (16) g102.0<2>UB g102.0<16,16,1>W {align1};
185
186mov (16) m1.0<1>UB  g99.0<16,16,2>UB {align1};
187mov (16) m1.16<1>UB g100.0<16,16,2>UB {align1};
188mov (16) m2.0<1>UB  g101.0<16,16,2>UB {align1};
189mov (16) m2.16<1>UB g102.0<16,16,2>UB {align1};
190send (16) 0 acc0<1>UW g31<8,8,1>UW write(1, 0, 2, 0) mlen 3 rlen 0 { align1 };
191
192//V
193mov.sat (16) g103.0<2>UB g103.0<16,16,1>W {align1};
194mov.sat (16) g104.0<2>UB g104.0<16,16,1>W {align1};
195mov.sat (16) g105.0<2>UB g105.0<16,16,1>W {align1};
196mov.sat (16) g106.0<2>UB g106.0<16,16,1>W {align1};
197
198mov (16) m1.0<1>UB  g103.0<16,16,2>UB {align1};
199mov (16) m1.16<1>UB g104.0<16,16,2>UB {align1};
200mov (16) m2.0<1>UB  g105.0<16,16,2>UB {align1};
201mov (16) m2.16<1>UB g106.0<16,16,2>UB {align1};
202send (16) 0 acc0<1>UW g31<8,8,1>UW write(2, 0, 2, 0) mlen 3 rlen 0 { align1 };
203
204OUT:
205send (16) 0 acc0<1>UW g0<8,8,1>UW
206        thread_spawner(0, 0, 0) mlen 1 rlen 0 { align1 EOT};
207
208include(`do_iq_intra.g4i')
209include(`idct.g4i')
210