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/* GRF allocation:
29   g1~g30: constant buffer
30           g1~g2:intra IQ matrix in UB format
31           g3~g4:non intra IQ matrix in UB format
32           g5~g20:IDCT table
33   g32~g55:DCT data before IQ
34   g56~g79:DCT data after IQ
35   g82:    thread payload backup
36   g109:   q_scale_code
37   g110:   q_scale_code
38   g112~g115: non intra IQ matrix in UW format (in order to use instruction compress), copys from g3~g4
39   g125:   ip before jump
40*/
41and (1) g109.0<1>UW g82.8<1,1,1>UW 0x1fUW {align1}; //q_scale_code
42
43and.z (1) null g82.8<1,1,1>UW 0x20UW {align1};   //if(q_scale_type==0) q_scale=q_scale_code*2;
44(f0) jmpi Q_SCALE_TYPE_0;
45
46cmp.l (1) null g109.0<1,1,1>UW 9UW {align1};      //if(q_scale_type!=0) calculate q_scale
47(f0) jmpi DO_IQ;
48cmp.l (1) null g109.0<1,1,1>UW 17UW {align1};
49(f0) jmpi RANG_9_16;
50cmp.l (1) null g109.0<1,1,1>UW 25UW {align1};
51(f0) jmpi RANG_17_24;
52
53RANG_25_31:
54add (1) g109.0<1>UW g109.0<1,1,1>UW -25W {align1};
55shl (1) g109.0<1>UW g109.0<1,1,1>UW 3UW {align1};
56add (1) g109.0<1>UW g109.0<1,1,1>UW 64UW {align1};
57jmpi DO_IQ;
58
59RANG_9_16:
60add (1) g109.0<1>UW g109.0<1,1,1>UW -9W {align1};
61shl (1) g109.0<1>UW g109.0<1,1,1>UW 1UW {align1};
62add (1) g109.0<1>UW g109.0<1,1,1>UW 10UW {align1};
63jmpi DO_IQ;
64
65RANG_17_24:
66add (1) g109.0<1>UW g109.0<1,1,1>UW -17W {align1};
67shl (1) g109.0<1>UW g109.0<1,1,1>UW 2UW {align1};
68add (1) g109.0<1>UW g109.0<1,1,1>UW 28UW {align1};
69jmpi DO_IQ;
70
71Q_SCALE_TYPE_0:
72shl (1) g109.0<1>UW g109.0<1,1,1>UW 1UD {align1};
73
74DO_IQ:
75mov (1) g110.0<1>UW g109.0<1,1,1>UW {align1};
76
77mov (16) g112.0<1>UW g3.0<16,16,1>UB {align1};
78mov (16) g113.0<1>UW g3.16<16,16,1>UB {align1};
79mov (16) g114.0<1>UW g4.0<16,16,1>UB {align1};
80mov (16) g115.0<1>UW g4.16<16,16,1>UB {align1};
81
82mov (1) a0.0<1>UD 0x03F003E0UD {align1};
83
84//Y0
85iq_non_intra_y0:
86and.z (1) null g82.8<1,1,1>UW 0x800UW {align1};
87(f0) jmpi iq_non_intra_y1;
88mov (1) g125.0<1>UD ip {align1};
89jmpi DO_IQ_NON_INTRA;
90mov (16) g56.0<1>W g116.0<16,8,2>W {align1};
91mov (16) g57.0<1>W g118.0<16,8,2>W {align1};
92mov (16) g58.0<1>W g120.0<16,8,2>W {align1};
93mov (16) g59.0<1>W g122.0<16,8,2>W {align1};
94
95//Y1
96iq_non_intra_y1:
97and.z (1) null g82.8<1,1,1>UW 0x400UW {align1};
98(f0) jmpi iq_non_intra_y2;
99mov (1) g125.0<1>UD ip {align1};
100jmpi DO_IQ_NON_INTRA;
101mov (16) g60.0<1>W g116.0<16,8,2>W {align1};
102mov (16) g61.0<1>W g118.0<16,8,2>W {align1};
103mov (16) g62.0<1>W g120.0<16,8,2>W {align1};
104mov (16) g63.0<1>W g122.0<16,8,2>W {align1};
105
106//Y2
107iq_non_intra_y2:
108and.z (1) null g82.8<1,1,1>UW 0x200UW {align1};
109(f0) jmpi iq_non_intra_y3;
110mov (1) g125.0<1>UD ip {align1};
111jmpi DO_IQ_NON_INTRA;
112mov (16) g64.0<1>W g116.0<16,8,2>W {align1};
113mov (16) g65.0<1>W g118.0<16,8,2>W {align1};
114mov (16) g66.0<1>W g120.0<16,8,2>W {align1};
115mov (16) g67.0<1>W g122.0<16,8,2>W {align1};
116
117//Y3
118iq_non_intra_y3:
119and.z (1) null g82.8<1,1,1>UW 0x100UW {align1};
120(f0) jmpi iq_non_intra_u;
121mov (1) g125.0<1>UD ip {align1};
122jmpi DO_IQ_NON_INTRA;
123mov (16) g68.0<1>W g116.0<16,8,2>W {align1};
124mov (16) g69.0<1>W g118.0<16,8,2>W {align1};
125mov (16) g70.0<1>W g120.0<16,8,2>W {align1};
126mov (16) g71.0<1>W g122.0<16,8,2>W {align1};
127
128//U
129iq_non_intra_u:
130and.z (1) null g82.8<1,1,1>UW 0x80UW {align1};
131(f0) jmpi iq_non_intra_v;
132mov (1) g125.0<1>UD ip {align1};
133jmpi DO_IQ_NON_INTRA;
134mov (16) g72.0<1>W g116.0<16,8,2>W {align1};
135mov (16) g73.0<1>W g118.0<16,8,2>W {align1};
136mov (16) g74.0<1>W g120.0<16,8,2>W {align1};
137mov (16) g75.0<1>W g122.0<16,8,2>W {align1};
138
139//V
140iq_non_intra_v:
141and.z (1) null g82.8<1,1,1>UW 0x40UW {align1};
142(f0) jmpi iq_non_intra_end;
143mov (1) g125.0<1>UD ip {align1};
144jmpi DO_IQ_NON_INTRA;
145mov (16) g76.0<1>W g116.0<16,8,2>W {align1};
146mov (16) g77.0<1>W g118.0<16,8,2>W {align1};
147mov (16) g78.0<1>W g120.0<16,8,2>W {align1};
148mov (16) g79.0<1>W g122.0<16,8,2>W {align1};
149
150iq_non_intra_end:
151