1/*
2 * Copyright © 2008 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 *    Zhang Hua jun <huajun.zhang@intel.com>
26 *    Xing Dong sheng <dongsheng.xing@intel.com>
27 *
28 */
29
30/* shader for forward and backward predict mc
31*/
32/* (x', y') = (x, y) + (motion_vector1.x >> 1, motion_vector1.y >> 1)
33/* (x'', y'') = (x, y) + (motion_vector2.x >> 1, motion_vector2.y >> 1)
34/* f(x, y) = (motion_forward(x`, y`) + motion_backward(x'', y'') + 1) / 2 */
35
36//Save payload
37mov (8) g76.0<1>UD g1.0<8,8,1>UD {align1};
38//mov (8) g77.0<1>UD g2.0<8,8,1>UD {align1};
39include(`block_clear.g4i')
40
41mov (8) g115.0<1>UD g1.0<8,8,1>UD {align1};
42mov (1) g1.8<1>UD 0x0070007UD  {align1};
43mov (8) g2.0<1>UD g1.0<8,8,1>UD {align1};
44/* Y */
45//Forward
46asr (2) g1.14<1>W g115.14<2,2,1>W 1W {align1};
47add (2) g2.0<1>UD g115.0<2,2,1>UD g1.14<2,2,1>W {align1};
48define(`input_surface',	`4')
49define(`mv1',	`g115.14')
50define(`mv2',	`g115.16')
51include(`motion_frame_y.g4i')
52mov (16) g52.0<1>UD g28.0<16,16,1>UD {align1 compr};
53mov (16) g54.0<1>UD g30.0<16,16,1>UD {align1 compr};
54mov (16) g56.0<1>UD g32.0<16,16,1>UD {align1 compr};
55mov (16) g58.0<1>UD g34.0<16,16,1>UD {align1 compr};
56mov (16) g60.0<1>UD g36.0<16,16,1>UD {align1 compr};
57mov (16) g62.0<1>UD g38.0<16,16,1>UD {align1 compr};
58mov (16) g64.0<1>UD g40.0<16,16,1>UD {align1 compr};
59mov (16) g66.0<1>UD g42.0<16,16,1>UD {align1 compr};
60//Backward
61asr (2) g1.14<1>W g115.18<2,2,1>W 1W {align1};
62add (2) g2.0<1>UD g115.0<2,2,1>UD g1.14<2,2,1>W {align1};
63define(`input_surface',	`7')
64define(`mv1',	`g115.18')
65define(`mv2',	`g115.20')
66include(`motion_frame_y.g4i')
67
68//Average
69avg.sat (16) g28.0<1>UW g28.0<16,16,1>UW g52.0<16,16,1>UW {align1};
70avg.sat (16) g29.0<1>UW g29.0<16,16,1>UW g53.0<16,16,1>UW {align1};
71avg.sat (16) g30.0<1>UW g30.0<16,16,1>UW g54.0<16,16,1>UW {align1};
72avg.sat (16) g31.0<1>UW g31.0<16,16,1>UW g55.0<16,16,1>UW {align1};
73avg.sat (16) g32.0<1>UW g32.0<16,16,1>UW g56.0<16,16,1>UW {align1};
74avg.sat (16) g33.0<1>UW g33.0<16,16,1>UW g57.0<16,16,1>UW {align1};
75avg.sat (16) g34.0<1>UW g34.0<16,16,1>UW g58.0<16,16,1>UW {align1};
76avg.sat (16) g35.0<1>UW g35.0<16,16,1>UW g59.0<16,16,1>UW {align1};
77avg.sat (16) g36.0<1>UW g36.0<16,16,1>UW g60.0<16,16,1>UW {align1};
78avg.sat (16) g37.0<1>UW g37.0<16,16,1>UW g61.0<16,16,1>UW {align1};
79avg.sat (16) g38.0<1>UW g38.0<16,16,1>UW g62.0<16,16,1>UW {align1};
80avg.sat (16) g39.0<1>UW g39.0<16,16,1>UW g63.0<16,16,1>UW {align1};
81avg.sat (16) g40.0<1>UW g40.0<16,16,1>UW g64.0<16,16,1>UW {align1};
82avg.sat (16) g41.0<1>UW g41.0<16,16,1>UW g65.0<16,16,1>UW {align1};
83avg.sat (16) g42.0<1>UW g42.0<16,16,1>UW g66.0<16,16,1>UW {align1};
84avg.sat (16) g43.0<1>UW g43.0<16,16,1>UW g67.0<16,16,1>UW {align1};
85
86/* UV */
87//Forward
88shr (2) g1.0<1>UD g115.0<2,2,1>UD 1UD {align1};
89asr (2) g115.14<1>W g115.14<2,2,1>W 1W {align1};
90asr (2) g1.14<1>W g115.14<2,2,1>W 1W {align1};
91add (2) g2.0<1>UD g1.0<2,2,1>UD g1.14<2,2,1>W {align1};
92
93define(`input_surface1',	`5')
94define(`input_surface2',	`6')
95define(`mv1',	`g115.14')
96define(`mv2',	`g115.16')
97mov (1) g2.8<1>UD 0x007000fUD  {align1};
98include(`motion_frame_uv.g4i')
99mov (16) g122.0<1>UB g44.0<16,16,2>UB {align1};
100mov (16) g122.16<1>UB g45.0<16,16,2>UB {align1};
101mov (16) g123.0<1>UB g46.0<16,16,2>UB {align1};
102mov (16) g123.16<1>UB g47.0<16,16,2>UB {align1};
103mov (16) g124.0<1>UB g48.0<16,16,2>UB {align1};
104mov (16) g124.16<1>UB g49.0<16,16,2>UB {align1};
105mov (16) g125.0<1>UB g50.0<16,16,2>UB {align1};
106mov (16) g125.16<1>UB g51.0<16,16,2>UB {align1};
107//Backward
108asr (2) g115.18<1>W g115.18<2,2,1>W 1W {align1};
109asr (2) g1.14<1>W g115.18<2,2,1>W 1W {align1};
110add (2) g2.0<1>UD g1.0<2,2,1>UD g1.14<2,2,1>W {align1};
111define(`input_surface1',	`8')
112define(`input_surface2',	`9')
113define(`mv1',	`g115.18')
114define(`mv2',	`g115.20')
115mov (1) g2.8<1>UD 0x007000fUD  {align1};
116include(`motion_frame_uv.g4i')
117
118//Average
119avg.sat (16) g44.0<1>UW g44.0<16,16,1>UW g122.0<16,16,1>UB {align1};
120avg.sat (16) g45.0<1>UW g45.0<16,16,1>UW g122.16<16,16,1>UB {align1};
121avg.sat (16) g46.0<1>UW g46.0<16,16,1>UW g123.0<16,16,1>UB {align1};
122avg.sat (16) g47.0<1>UW g47.0<16,16,1>UW g123.16<16,16,1>UB {align1};
123avg.sat (16) g48.0<1>UW g48.0<16,16,1>UW g124.0<16,16,1>UB {align1};
124avg.sat (16) g49.0<1>UW g49.0<16,16,1>UW g124.16<16,16,1>UB {align1};
125avg.sat (16) g50.0<1>UW g50.0<16,16,1>UW g125.0<16,16,1>UB {align1};
126avg.sat (16) g51.0<1>UW g51.0<16,16,1>UW g125.16<16,16,1>UB {align1};
127
128include(`addidct.g4i')
129
130send (16) 0 acc0<1>UW g0<8,8,1>UW 
131	thread_spawner(0, 0, 0) mlen 1 rlen 0 { align1 EOT};
132