simple_idct_mmx.c 52.1 KB
Newer Older
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * Simple IDCT MMX
 *
 * Copyright (c) 2001, 2002 Michael Niedermayer <michaelni@gmx.at>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
20
#include "../dsputil.h"
21

Michael Niedermayer's avatar
Michael Niedermayer committed
22 23 24 25 26 27 28 29 30 31
/*
23170.475006
22725.260826
21406.727617
19265.545870
16384.000000
12872.826198
8866.956905
4520.335430
*/
32 33 34 35
#define C0 23170 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
#define C1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
#define C2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
#define C3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
Michael Niedermayer's avatar
Michael Niedermayer committed
36
#if 0
37
#define C4 16384 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
Michael Niedermayer's avatar
Michael Niedermayer committed
38 39 40
#else
#define C4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) - 0.5
#endif
41 42 43 44 45 46 47
#define C5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
#define C6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
#define C7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5

#define ROW_SHIFT 11
#define COL_SHIFT 20 // 6

48 49
static const uint64_t __attribute__((aligned(8))) wm1010= 0xFFFF0000FFFF0000ULL;
static const uint64_t __attribute__((aligned(8))) d40000= 0x0000000000040000ULL;
50 51 52 53 54 55 56 57 58 59
static int16_t __attribute__((aligned(8))) temp[64];
static int16_t __attribute__((aligned(8))) coeffs[]= {
	1<<(ROW_SHIFT-1), 0, 1<<(ROW_SHIFT-1), 0,
//	1<<(COL_SHIFT-1), 0, 1<<(COL_SHIFT-1), 0,
//	0, 1<<(COL_SHIFT-1-16), 0, 1<<(COL_SHIFT-1-16),
	1<<(ROW_SHIFT-1), 1, 1<<(ROW_SHIFT-1), 0,
	// the 1 = ((1<<(COL_SHIFT-1))/C4)<<ROW_SHIFT :)
//	0, 0, 0, 0,
//	0, 0, 0, 0,

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
 C4,  C4,  C4,  C4,
 C4, -C4,  C4, -C4,
 
 C2,  C6,  C2,  C6,
 C6, -C2,  C6, -C2,
 
 C1,  C3,  C1,  C3,
 C5,  C7,  C5,  C7,
 
 C3, -C7,  C3, -C7,
-C1, -C5, -C1, -C5,
 
 C5, -C1,  C5, -C1,
 C7,  C3,  C7,  C3,
 
 C7, -C5,  C7, -C5,
 C3, -C1,  C3, -C1
};

79
#if 0
80 81 82 83 84
static void unused_var_killer(){
	int a= wm1010 + d40000;
	temp[0]=a;
}

85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
static void inline idctCol (int16_t * col, int16_t *input)
{
#undef C0
#undef C1
#undef C2
#undef C3
#undef C4
#undef C5
#undef C6
#undef C7
	int a0, a1, a2, a3, b0, b1, b2, b3;
	const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
100
	const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
	const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C6 = 8867; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C7 = 4520; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
/*
	if( !(col[8*1] | col[8*2] |col[8*3] |col[8*4] |col[8*5] |col[8*6] | col[8*7])) {
		col[8*0] = col[8*1] = col[8*2] = col[8*3] = col[8*4] =
			col[8*5] = col[8*6] = col[8*7] = col[8*0]<<3;
		return;
	}*/

col[8*0] = input[8*0 + 0];
col[8*1] = input[8*2 + 0];
col[8*2] = input[8*0 + 1];
col[8*3] = input[8*2 + 1];
col[8*4] = input[8*4 + 0];
col[8*5] = input[8*6 + 0];
col[8*6] = input[8*4 + 1];
col[8*7] = input[8*6 + 1];

	a0 = C4*col[8*0] + C2*col[8*2] + C4*col[8*4] + C6*col[8*6] + (1<<(COL_SHIFT-1));
	a1 = C4*col[8*0] + C6*col[8*2] - C4*col[8*4] - C2*col[8*6] + (1<<(COL_SHIFT-1));
	a2 = C4*col[8*0] - C6*col[8*2] - C4*col[8*4] + C2*col[8*6] + (1<<(COL_SHIFT-1));
	a3 = C4*col[8*0] - C2*col[8*2] + C4*col[8*4] - C6*col[8*6] + (1<<(COL_SHIFT-1));

	b0 = C1*col[8*1] + C3*col[8*3] + C5*col[8*5] + C7*col[8*7];
	b1 = C3*col[8*1] - C7*col[8*3] - C1*col[8*5] - C5*col[8*7];
	b2 = C5*col[8*1] - C1*col[8*3] + C7*col[8*5] + C3*col[8*7];
	b3 = C7*col[8*1] - C5*col[8*3] + C3*col[8*5] - C1*col[8*7];

	col[8*0] = (a0 + b0) >> COL_SHIFT;
	col[8*1] = (a1 + b1) >> COL_SHIFT;
	col[8*2] = (a2 + b2) >> COL_SHIFT;
	col[8*3] = (a3 + b3) >> COL_SHIFT;
	col[8*4] = (a3 - b3) >> COL_SHIFT;
	col[8*5] = (a2 - b2) >> COL_SHIFT;
	col[8*6] = (a1 - b1) >> COL_SHIFT;
	col[8*7] = (a0 - b0) >> COL_SHIFT;
}

static void inline idctRow (int16_t * output, int16_t * input)
{
	int16_t row[8];

	int a0, a1, a2, a3, b0, b1, b2, b3;
	const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
149
	const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
	const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C6 = 8867; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5
	const int C7 = 4520; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5

row[0] = input[0];
row[2] = input[1];
row[4] = input[4];
row[6] = input[5];
row[1] = input[8];
row[3] = input[9];
row[5] = input[12];
row[7] = input[13];

	if( !(row[1] | row[2] |row[3] |row[4] |row[5] |row[6] | row[7]) ) {
		row[0] = row[1] = row[2] = row[3] = row[4] =
			row[5] = row[6] = row[7] = row[0]<<3;
	output[0] = row[0];
	output[2] = row[1];
	output[4] = row[2];
	output[6] = row[3];
	output[8] = row[4];
	output[10] = row[5];
	output[12] = row[6];
	output[14] = row[7];
		return;
	}

	a0 = C4*row[0] + C2*row[2] + C4*row[4] + C6*row[6] + (1<<(ROW_SHIFT-1));
	a1 = C4*row[0] + C6*row[2] - C4*row[4] - C2*row[6] + (1<<(ROW_SHIFT-1));
	a2 = C4*row[0] - C6*row[2] - C4*row[4] + C2*row[6] + (1<<(ROW_SHIFT-1));
	a3 = C4*row[0] - C2*row[2] + C4*row[4] - C6*row[6] + (1<<(ROW_SHIFT-1));

	b0 = C1*row[1] + C3*row[3] + C5*row[5] + C7*row[7];
	b1 = C3*row[1] - C7*row[3] - C1*row[5] - C5*row[7];
	b2 = C5*row[1] - C1*row[3] + C7*row[5] + C3*row[7];
	b3 = C7*row[1] - C5*row[3] + C3*row[5] - C1*row[7];

	row[0] = (a0 + b0) >> ROW_SHIFT;
	row[1] = (a1 + b1) >> ROW_SHIFT;
	row[2] = (a2 + b2) >> ROW_SHIFT;
	row[3] = (a3 + b3) >> ROW_SHIFT;
	row[4] = (a3 - b3) >> ROW_SHIFT;
	row[5] = (a2 - b2) >> ROW_SHIFT;
	row[6] = (a1 - b1) >> ROW_SHIFT;
	row[7] = (a0 - b0) >> ROW_SHIFT;

	output[0] = row[0];
	output[2] = row[1];
	output[4] = row[2];
	output[6] = row[3];
	output[8] = row[4];
	output[10] = row[5];
	output[12] = row[6];
	output[14] = row[7];
}
#endif

static inline void idct(int16_t *block)
{
	asm volatile(
#if 0 //Alternative, simpler variant
211 212 213 214

#define ROW_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
215 216
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
217 218 219 220 221 222 223 224 225 226
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
227
	#rounder ", %%mm4			\n\t"\
228 229 230 231 232 233 234 235 236 237 238 239 240 241
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq 56(%2), %%mm5			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
	#rounder ", %%mm0			\n\t"\
	"paddd %%mm0, %%mm1			\n\t" /* A1		a1 */\
	"paddd %%mm0, %%mm0			\n\t" \
	"psubd %%mm1, %%mm0			\n\t" /* A2		a2 */\
	"pmaddwd 64(%2), %%mm2			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm5, %%mm7			\n\t" /* B0		b0 */\
	"movq 72(%2), %%mm5			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
242
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"paddd %%mm2, %%mm5			\n\t" /* B1		b1 */\
	"psrad $" #shift ", %%mm7		\n\t"\
	"psrad $" #shift ", %%mm4		\n\t"\
	"movq %%mm1, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm5, %%mm1			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm5, %%mm2			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm1		\n\t"\
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm1, %%mm7			\n\t" /* A1+B1	a1+b1	A0+B0	a0+b0 */\
	"packssdw %%mm4, %%mm2			\n\t" /* A0-B0	a0-b0	A1-B1	a1-b1 */\
	"movq %%mm7, " #dst "			\n\t"\
	"movq " #src1 ", %%mm1			\n\t" /* R3	R1	r3	r1 */\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"movq %%mm2, 24+" #dst "		\n\t"\
	"pmaddwd %%mm1, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"movq 88(%2), %%mm7			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd 96(%2), %%mm1			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
	"pmaddwd %%mm3, %%mm7			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
	"movq %%mm0, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm7, %%mm4			\n\t" /* B2		b2 */\
	"paddd %%mm4, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm0			\n\t" /* a2-B2		a2-b2 */\
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm0		\n\t"\
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm1, %%mm3			\n\t" /* B3		b3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm4			\n\t" /* a3-B3		a3-b3 */\
273
	"psrad $" #shift ", %%mm6		\n\t"\
274 275
	"packssdw %%mm6, %%mm2			\n\t" /* A3+B3	a3+b3	A2+B2	a2+b2 */\
	"movq %%mm2, 8+" #dst "			\n\t"\
276
	"psrad $" #shift ", %%mm4		\n\t"\
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
	"packssdw %%mm0, %%mm4			\n\t" /* A2-B2	a2-b2	A3-B3	a3-b3 */\
	"movq %%mm4, 16+" #dst "		\n\t"\

#define COL_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
293
	#rounder ", %%mm4			\n\t"\
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	#rounder ", %%mm0			\n\t"\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq %%mm0, %%mm5			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"paddd %%mm1, %%mm0			\n\t" /* A1		a1 */\
	"psubd %%mm1, %%mm5			\n\t" /* A2		a2 */\
	"movq 56(%2), %%mm1			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
	"pmaddwd 64(%2), %%mm2			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm1, %%mm7			\n\t" /* B0		b0 */\
	"movq 72(%2), %%mm1			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"paddd %%mm2, %%mm1			\n\t" /* B1		b1 */\
	"psrad $" #shift ", %%mm7		\n\t"\
314
	"psrad $" #shift ", %%mm4		\n\t"\
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
	"movq %%mm0, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm1, %%mm0			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm1, %%mm2			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm0		\n\t"\
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm7, %%mm7			\n\t" /* A0+B0	a0+b0 */\
	"movd %%mm7, " #dst "			\n\t"\
	"packssdw %%mm0, %%mm0			\n\t" /* A1+B1	a1+b1 */\
	"movd %%mm0, 16+" #dst "		\n\t"\
	"packssdw %%mm2, %%mm2			\n\t" /* A1-B1	a1-b1 */\
	"movd %%mm2, 96+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A0-B0	a0-b0 */\
	"movd %%mm4, 112+" #dst "		\n\t"\
	"movq " #src1 ", %%mm0			\n\t" /* R3	R1	r3	r1 */\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"movq 88(%2), %%mm7			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd 96(%2), %%mm0			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
333
	"pmaddwd %%mm3, %%mm7			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
334 335 336 337 338 339 340 341 342 343 344
	"movq %%mm5, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm7, %%mm4			\n\t" /* B2		b2 */\
	"paddd %%mm4, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm5			\n\t" /* a2-B2		a2-b2 */\
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm5		\n\t"\
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm0, %%mm3			\n\t" /* B3		b3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm4			\n\t" /* a3-B3		a3-b3 */\
345 346
	"psrad $" #shift ", %%mm6		\n\t"\
	"psrad $" #shift ", %%mm4		\n\t"\
347 348 349 350 351 352 353 354 355 356 357 358 359
	"packssdw %%mm2, %%mm2			\n\t" /* A2+B2	a2+b2 */\
	"packssdw %%mm6, %%mm6			\n\t" /* A3+B3	a3+b3 */\
	"movd %%mm2, 32+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A3-B3	a3-b3 */\
	"packssdw %%mm5, %%mm5			\n\t" /* A2-B2	a2-b2 */\
	"movd %%mm6, 48+" #dst "		\n\t"\
	"movd %%mm4, 64+" #dst "		\n\t"\
	"movd %%mm5, 80+" #dst "		\n\t"\

	
#define DC_COND_ROW_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
360 361
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
362
	"movq "MANGLE(wm1010)", %%mm4		\n\t"\
363 364 365 366 367 368 369 370
	"pand %%mm0, %%mm4			\n\t"\
	"por %%mm1, %%mm4			\n\t"\
	"por %%mm2, %%mm4			\n\t"\
	"por %%mm3, %%mm4			\n\t"\
	"packssdw %%mm4,%%mm4			\n\t"\
	"movd %%mm4, %%eax			\n\t"\
	"orl %%eax, %%eax			\n\t"\
	"jz 1f					\n\t"\
371 372 373 374 375 376 377 378 379 380
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
381
	#rounder ", %%mm4			\n\t"\
382 383 384 385 386 387 388 389 390 391 392 393 394 395
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq 56(%2), %%mm5			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
	#rounder ", %%mm0			\n\t"\
	"paddd %%mm0, %%mm1			\n\t" /* A1		a1 */\
	"paddd %%mm0, %%mm0			\n\t" \
	"psubd %%mm1, %%mm0			\n\t" /* A2		a2 */\
	"pmaddwd 64(%2), %%mm2			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm5, %%mm7			\n\t" /* B0		b0 */\
	"movq 72(%2), %%mm5			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
396
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
397 398 399
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"paddd %%mm2, %%mm5			\n\t" /* B1		b1 */\
	"psrad $" #shift ", %%mm7		\n\t"\
400
	"psrad $" #shift ", %%mm4		\n\t"\
401 402 403 404 405 406 407 408 409 410 411 412 413 414
	"movq %%mm1, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm5, %%mm1			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm5, %%mm2			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm1		\n\t"\
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm1, %%mm7			\n\t" /* A1+B1	a1+b1	A0+B0	a0+b0 */\
	"packssdw %%mm4, %%mm2			\n\t" /* A0-B0	a0-b0	A1-B1	a1-b1 */\
	"movq %%mm7, " #dst "			\n\t"\
	"movq " #src1 ", %%mm1			\n\t" /* R3	R1	r3	r1 */\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"movq %%mm2, 24+" #dst "		\n\t"\
	"pmaddwd %%mm1, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"movq 88(%2), %%mm7			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd 96(%2), %%mm1			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
415
	"pmaddwd %%mm3, %%mm7			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
416 417 418 419 420
	"movq %%mm0, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm7, %%mm4			\n\t" /* B2		b2 */\
	"paddd %%mm4, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm0			\n\t" /* a2-B2		a2-b2 */\
421 422
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm0		\n\t"\
423 424 425 426 427 428 429 430 431 432
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm1, %%mm3			\n\t" /* B3		b3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm4			\n\t" /* a3-B3		a3-b3 */\
	"psrad $" #shift ", %%mm6		\n\t"\
	"packssdw %%mm6, %%mm2			\n\t" /* A3+B3	a3+b3	A2+B2	a2+b2 */\
	"movq %%mm2, 8+" #dst "			\n\t"\
	"psrad $" #shift ", %%mm4		\n\t"\
	"packssdw %%mm0, %%mm4			\n\t" /* A2-B2	a2-b2	A3-B3	a3-b3 */\
	"movq %%mm4, 16+" #dst "		\n\t"\
433 434
	"jmp 2f					\n\t"\
	"1:					\n\t"\
435
	"pslld $16, %%mm0			\n\t"\
436
	"#paddd "MANGLE(d40000)", %%mm0		\n\t"\
437 438 439 440 441 442 443
	"psrad $13, %%mm0			\n\t"\
	"packssdw %%mm0, %%mm0			\n\t"\
	"movq %%mm0, " #dst "			\n\t"\
	"movq %%mm0, 8+" #dst "			\n\t"\
	"movq %%mm0, 16+" #dst "		\n\t"\
	"movq %%mm0, 24+" #dst "		\n\t"\
	"2:					\n\t"
444 445


446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
//IDCT(      src0,   src4,   src1,   src5,    dst,    rounder, shift)
ROW_IDCT(    (%0),  8(%0), 16(%0), 24(%0),  0(%1),paddd 8(%2), 11)
/*ROW_IDCT(  32(%0), 40(%0), 48(%0), 56(%0), 32(%1), paddd (%2), 11)
ROW_IDCT(  64(%0), 72(%0), 80(%0), 88(%0), 64(%1), paddd (%2), 11)
ROW_IDCT(  96(%0),104(%0),112(%0),120(%0), 96(%1), paddd (%2), 11)*/

DC_COND_ROW_IDCT(  32(%0), 40(%0), 48(%0), 56(%0), 32(%1),paddd (%2), 11)
DC_COND_ROW_IDCT(  64(%0), 72(%0), 80(%0), 88(%0), 64(%1),paddd (%2), 11)
DC_COND_ROW_IDCT(  96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11)


//IDCT(      src0,   src4,   src1,    src5,    dst, rounder, shift)
COL_IDCT(    (%1), 64(%1), 32(%1),  96(%1),  0(%0),/nop, 20)
COL_IDCT(   8(%1), 72(%1), 40(%1), 104(%1),  4(%0),/nop, 20)
COL_IDCT(  16(%1), 80(%1), 48(%1), 112(%1),  8(%0),/nop, 20)
COL_IDCT(  24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
462

463 464 465 466 467
#else

#define DC_COND_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
468 469
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
470
	"movq "MANGLE(wm1010)", %%mm4		\n\t"\
471 472 473 474 475 476 477 478
	"pand %%mm0, %%mm4			\n\t"\
	"por %%mm1, %%mm4			\n\t"\
	"por %%mm2, %%mm4			\n\t"\
	"por %%mm3, %%mm4			\n\t"\
	"packssdw %%mm4,%%mm4			\n\t"\
	"movd %%mm4, %%eax			\n\t"\
	"orl %%eax, %%eax			\n\t"\
	"jz 1f					\n\t"\
479 480 481 482 483 484 485 486 487 488
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
489
	#rounder ", %%mm4			\n\t"\
490 491 492 493 494 495 496 497 498 499 500 501 502 503
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq 56(%2), %%mm5			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
	#rounder ", %%mm0			\n\t"\
	"paddd %%mm0, %%mm1			\n\t" /* A1		a1 */\
	"paddd %%mm0, %%mm0			\n\t" \
	"psubd %%mm1, %%mm0			\n\t" /* A2		a2 */\
	"pmaddwd 64(%2), %%mm2			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm5, %%mm7			\n\t" /* B0		b0 */\
	"movq 72(%2), %%mm5			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
504
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
505 506 507
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"paddd %%mm2, %%mm5			\n\t" /* B1		b1 */\
	"psrad $" #shift ", %%mm7		\n\t"\
508
	"psrad $" #shift ", %%mm4		\n\t"\
509 510 511 512 513 514 515 516 517 518 519 520 521 522
	"movq %%mm1, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm5, %%mm1			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm5, %%mm2			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm1		\n\t"\
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm1, %%mm7			\n\t" /* A1+B1	a1+b1	A0+B0	a0+b0 */\
	"packssdw %%mm4, %%mm2			\n\t" /* A0-B0	a0-b0	A1-B1	a1-b1 */\
	"movq %%mm7, " #dst "			\n\t"\
	"movq " #src1 ", %%mm1			\n\t" /* R3	R1	r3	r1 */\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"movq %%mm2, 24+" #dst "		\n\t"\
	"pmaddwd %%mm1, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"movq 88(%2), %%mm7			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd 96(%2), %%mm1			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
523
	"pmaddwd %%mm3, %%mm7			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
524 525 526 527 528
	"movq %%mm0, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm7, %%mm4			\n\t" /* B2		b2 */\
	"paddd %%mm4, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm0			\n\t" /* a2-B2		a2-b2 */\
529 530
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm0		\n\t"\
531 532 533 534 535 536 537 538 539 540
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm1, %%mm3			\n\t" /* B3		b3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm4			\n\t" /* a3-B3		a3-b3 */\
	"psrad $" #shift ", %%mm6		\n\t"\
	"packssdw %%mm6, %%mm2			\n\t" /* A3+B3	a3+b3	A2+B2	a2+b2 */\
	"movq %%mm2, 8+" #dst "			\n\t"\
	"psrad $" #shift ", %%mm4		\n\t"\
	"packssdw %%mm0, %%mm4			\n\t" /* A2-B2	a2-b2	A3-B3	a3-b3 */\
	"movq %%mm4, 16+" #dst "		\n\t"\
541 542
	"jmp 2f					\n\t"\
	"1:					\n\t"\
543
	"pslld $16, %%mm0			\n\t"\
544
	"paddd "MANGLE(d40000)", %%mm0		\n\t"\
545 546 547 548 549 550 551
	"psrad $13, %%mm0			\n\t"\
	"packssdw %%mm0, %%mm0			\n\t"\
	"movq %%mm0, " #dst "			\n\t"\
	"movq %%mm0, 8+" #dst "			\n\t"\
	"movq %%mm0, 16+" #dst "		\n\t"\
	"movq %%mm0, 24+" #dst "		\n\t"\
	"2:					\n\t"
552

553 554 555
#define Z_COND_IDCT(src0, src4, src1, src5, dst, rounder, shift, bt) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
556 557 558 559 560 561
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
	"movq %%mm0, %%mm4			\n\t"\
	"por %%mm1, %%mm4			\n\t"\
	"por %%mm2, %%mm4			\n\t"\
	"por %%mm3, %%mm4			\n\t"\
562
	"packssdw %%mm4,%%mm4			\n\t"\
563 564 565
	"movd %%mm4, %%eax			\n\t"\
	"orl %%eax, %%eax			\n\t"\
	"jz " #bt "				\n\t"\
566 567 568 569 570 571 572 573 574 575
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
576
	#rounder ", %%mm4			\n\t"\
577 578 579 580 581 582 583 584 585 586 587 588 589 590
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq 56(%2), %%mm5			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
	#rounder ", %%mm0			\n\t"\
	"paddd %%mm0, %%mm1			\n\t" /* A1		a1 */\
	"paddd %%mm0, %%mm0			\n\t" \
	"psubd %%mm1, %%mm0			\n\t" /* A2		a2 */\
	"pmaddwd 64(%2), %%mm2			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm5, %%mm7			\n\t" /* B0		b0 */\
	"movq 72(%2), %%mm5			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
591
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
592 593 594
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"paddd %%mm2, %%mm5			\n\t" /* B1		b1 */\
	"psrad $" #shift ", %%mm7		\n\t"\
595
	"psrad $" #shift ", %%mm4		\n\t"\
596 597 598 599 600 601 602 603 604 605 606 607 608 609
	"movq %%mm1, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm5, %%mm1			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm5, %%mm2			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm1		\n\t"\
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm1, %%mm7			\n\t" /* A1+B1	a1+b1	A0+B0	a0+b0 */\
	"packssdw %%mm4, %%mm2			\n\t" /* A0-B0	a0-b0	A1-B1	a1-b1 */\
	"movq %%mm7, " #dst "			\n\t"\
	"movq " #src1 ", %%mm1			\n\t" /* R3	R1	r3	r1 */\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"movq %%mm2, 24+" #dst "		\n\t"\
	"pmaddwd %%mm1, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"movq 88(%2), %%mm7			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd 96(%2), %%mm1			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
610
	"pmaddwd %%mm3, %%mm7			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
611 612 613 614 615 616 617 618 619 620 621
	"movq %%mm0, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm7, %%mm4			\n\t" /* B2		b2 */\
	"paddd %%mm4, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm0			\n\t" /* a2-B2		a2-b2 */\
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm0		\n\t"\
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm1, %%mm3			\n\t" /* B3		b3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm4			\n\t" /* a3-B3		a3-b3 */\
622
	"psrad $" #shift ", %%mm6		\n\t"\
623 624
	"packssdw %%mm6, %%mm2			\n\t" /* A3+B3	a3+b3	A2+B2	a2+b2 */\
	"movq %%mm2, 8+" #dst "			\n\t"\
625
	"psrad $" #shift ", %%mm4		\n\t"\
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
	"packssdw %%mm0, %%mm4			\n\t" /* A2-B2	a2-b2	A3-B3	a3-b3 */\
	"movq %%mm4, 16+" #dst "		\n\t"\

#define ROW_IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
	#rounder ", %%mm4			\n\t"\
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq 56(%2), %%mm5			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
650
	#rounder ", %%mm0			\n\t"\
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
	"paddd %%mm0, %%mm1			\n\t" /* A1		a1 */\
	"paddd %%mm0, %%mm0			\n\t" \
	"psubd %%mm1, %%mm0			\n\t" /* A2		a2 */\
	"pmaddwd 64(%2), %%mm2			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm5, %%mm7			\n\t" /* B0		b0 */\
	"movq 72(%2), %%mm5			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm5			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"paddd %%mm2, %%mm5			\n\t" /* B1		b1 */\
	"psrad $" #shift ", %%mm7		\n\t"\
	"psrad $" #shift ", %%mm4		\n\t"\
	"movq %%mm1, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm5, %%mm1			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm5, %%mm2			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm1		\n\t"\
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm1, %%mm7			\n\t" /* A1+B1	a1+b1	A0+B0	a0+b0 */\
	"packssdw %%mm4, %%mm2			\n\t" /* A0-B0	a0-b0	A1-B1	a1-b1 */\
	"movq %%mm7, " #dst "			\n\t"\
	"movq " #src1 ", %%mm1			\n\t" /* R3	R1	r3	r1 */\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"movq %%mm2, 24+" #dst "		\n\t"\
	"pmaddwd %%mm1, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"movq 88(%2), %%mm7			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd 96(%2), %%mm1			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
	"pmaddwd %%mm3, %%mm7			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
	"movq %%mm0, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm7, %%mm4			\n\t" /* B2		b2 */\
	"paddd %%mm4, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm0			\n\t" /* a2-B2		a2-b2 */\
684 685
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm0		\n\t"\
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm1, %%mm3			\n\t" /* B3		b3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm4			\n\t" /* a3-B3		a3-b3 */\
	"psrad $" #shift ", %%mm6		\n\t"\
	"packssdw %%mm6, %%mm2			\n\t" /* A3+B3	a3+b3	A2+B2	a2+b2 */\
	"movq %%mm2, 8+" #dst "			\n\t"\
	"psrad $" #shift ", %%mm4		\n\t"\
	"packssdw %%mm0, %%mm4			\n\t" /* A2-B2	a2-b2	A3-B3	a3-b3 */\
	"movq %%mm4, 16+" #dst "		\n\t"\

//IDCT(         src0,   src4,   src1,   src5,    dst,   rounder, shift)
DC_COND_IDCT(  0(%0),  8(%0), 16(%0), 24(%0),  0(%1),paddd 8(%2), 11)
Z_COND_IDCT(  32(%0), 40(%0), 48(%0), 56(%0), 32(%1),paddd (%2), 11, 4f)
Z_COND_IDCT(  64(%0), 72(%0), 80(%0), 88(%0), 64(%1),paddd (%2), 11, 2f)
Z_COND_IDCT(  96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11, 1f)

#undef IDCT
#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
707 708
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
709 710 711 712 713 714 715 716 717 718 719 720 721
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	#rounder ", %%mm4			\n\t"\
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	#rounder ", %%mm0			\n\t"\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
722
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
723 724 725 726 727 728 729 730 731 732 733
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq %%mm0, %%mm5			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"paddd %%mm1, %%mm0			\n\t" /* A1		a1 */\
	"psubd %%mm1, %%mm5			\n\t" /* A2		a2 */\
	"movq 56(%2), %%mm1			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
	"pmaddwd 64(%2), %%mm2			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm1, %%mm7			\n\t" /* B0		b0 */\
	"movq 72(%2), %%mm1			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
734
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
735 736 737
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"paddd %%mm2, %%mm1			\n\t" /* B1		b1 */\
	"psrad $" #shift ", %%mm7		\n\t"\
738
	"psrad $" #shift ", %%mm4		\n\t"\
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
	"movq %%mm0, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm1, %%mm0			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm1, %%mm2			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm0		\n\t"\
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm7, %%mm7			\n\t" /* A0+B0	a0+b0 */\
	"movd %%mm7, " #dst "			\n\t"\
	"packssdw %%mm0, %%mm0			\n\t" /* A1+B1	a1+b1 */\
	"movd %%mm0, 16+" #dst "		\n\t"\
	"packssdw %%mm2, %%mm2			\n\t" /* A1-B1	a1-b1 */\
	"movd %%mm2, 96+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A0-B0	a0-b0 */\
	"movd %%mm4, 112+" #dst "		\n\t"\
	"movq " #src1 ", %%mm0			\n\t" /* R3	R1	r3	r1 */\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"movq 88(%2), %%mm7			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd 96(%2), %%mm0			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
757
	"pmaddwd %%mm3, %%mm7			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
758 759 760 761 762 763 764 765 766 767 768
	"movq %%mm5, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm7, %%mm4			\n\t" /* B2		b2 */\
	"paddd %%mm4, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm5			\n\t" /* a2-B2		a2-b2 */\
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm5		\n\t"\
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm0, %%mm3			\n\t" /* B3		b3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm4			\n\t" /* a3-B3		a3-b3 */\
769 770
	"psrad $" #shift ", %%mm6		\n\t"\
	"psrad $" #shift ", %%mm4		\n\t"\
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785
	"packssdw %%mm2, %%mm2			\n\t" /* A2+B2	a2+b2 */\
	"packssdw %%mm6, %%mm6			\n\t" /* A3+B3	a3+b3 */\
	"movd %%mm2, 32+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A3-B3	a3-b3 */\
	"packssdw %%mm5, %%mm5			\n\t" /* A2-B2	a2-b2 */\
	"movd %%mm6, 48+" #dst "		\n\t"\
	"movd %%mm4, 64+" #dst "		\n\t"\
	"movd %%mm5, 80+" #dst "		\n\t"


//IDCT(  src0,   src4,   src1,    src5,    dst, rounder, shift)
IDCT(    (%1), 64(%1), 32(%1),  96(%1),  0(%0),/nop, 20)
IDCT(   8(%1), 72(%1), 40(%1), 104(%1),  4(%0),/nop, 20)
IDCT(  16(%1), 80(%1), 48(%1), 112(%1),  8(%0),/nop, 20)
IDCT(  24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
786 787 788 789
	"jmp 9f					\n\t"

	"#.balign 16				\n\t"\
	"4:					\n\t"
790 791
Z_COND_IDCT(  64(%0), 72(%0), 80(%0), 88(%0), 64(%1),paddd (%2), 11, 6f)
Z_COND_IDCT(  96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11, 5f)
792

793 794 795 796
#undef IDCT
#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
797
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
798 799 800 801 802 803 804 805 806 807 808
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	#rounder ", %%mm4			\n\t"\
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	#rounder ", %%mm0			\n\t"\
809
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
810 811 812 813 814 815
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq %%mm0, %%mm5			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"paddd %%mm1, %%mm0			\n\t" /* A1		a1 */\
	"psubd %%mm1, %%mm5			\n\t" /* A2		a2 */\
	"movq 56(%2), %%mm1			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
816 817
	"movq 72(%2), %%mm7			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm7			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
818 819 820 821
	"paddd %%mm4, %%mm1			\n\t" /* A0+B0		a0+b0 */\
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
	"psubd %%mm1, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"psrad $" #shift ", %%mm1		\n\t"\
822
	"psrad $" #shift ", %%mm4		\n\t"\
823 824 825
	"movq %%mm0, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm7, %%mm0			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm7, %%mm2			\n\t" /* A1-B1		a1-b1 */\
826
	"psrad $" #shift ", %%mm0		\n\t"\
827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm1, %%mm1			\n\t" /* A0+B0	a0+b0 */\
	"movd %%mm1, " #dst "			\n\t"\
	"packssdw %%mm0, %%mm0			\n\t" /* A1+B1	a1+b1 */\
	"movd %%mm0, 16+" #dst "		\n\t"\
	"packssdw %%mm2, %%mm2			\n\t" /* A1-B1	a1-b1 */\
	"movd %%mm2, 96+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A0-B0	a0-b0 */\
	"movd %%mm4, 112+" #dst "		\n\t"\
	"movq 88(%2), %%mm1			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
	"movq %%mm5, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm1, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm1, %%mm5			\n\t" /* a2-B2		a2-b2 */\
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm5		\n\t"\
	"movq %%mm6, %%mm1			\n\t" /* A3		a3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm1			\n\t" /* a3-B3		a3-b3 */\
	"psrad $" #shift ", %%mm6		\n\t"\
	"psrad $" #shift ", %%mm1		\n\t"\
	"packssdw %%mm2, %%mm2			\n\t" /* A2+B2	a2+b2 */\
	"packssdw %%mm6, %%mm6			\n\t" /* A3+B3	a3+b3 */\
	"movd %%mm2, 32+" #dst "		\n\t"\
	"packssdw %%mm1, %%mm1			\n\t" /* A3-B3	a3-b3 */\
	"packssdw %%mm5, %%mm5			\n\t" /* A2-B2	a2-b2 */\
	"movd %%mm6, 48+" #dst "		\n\t"\
	"movd %%mm1, 64+" #dst "		\n\t"\
	"movd %%mm5, 80+" #dst "		\n\t"	

//IDCT(  src0,   src4,   src1,    src5,    dst, rounder, shift)
IDCT(    (%1), 64(%1), 32(%1),  96(%1),  0(%0),/nop, 20)
IDCT(   8(%1), 72(%1), 40(%1), 104(%1),  4(%0),/nop, 20)
IDCT(  16(%1), 80(%1), 48(%1), 112(%1),  8(%0),/nop, 20)
IDCT(  24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
863 864 865 866
	"jmp 9f					\n\t"

	"#.balign 16				\n\t"\
	"6:					\n\t"
867
Z_COND_IDCT(  96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11, 7f)
868

869 870 871
#undef IDCT
#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
872
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
873 874 875 876 877 878 879 880 881 882
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	#rounder ", %%mm4			\n\t"\
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	#rounder ", %%mm0			\n\t"\
	"movq %%mm0, %%mm5			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 56(%2), %%mm1			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
883 884
	"movq 72(%2), %%mm7			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm7			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
885 886 887 888
	"paddd %%mm4, %%mm1			\n\t" /* A0+B0		a0+b0 */\
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
	"psubd %%mm1, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"psrad $" #shift ", %%mm1		\n\t"\
889
	"psrad $" #shift ", %%mm4		\n\t"\
890 891 892
	"movq %%mm0, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm7, %%mm0			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm7, %%mm2			\n\t" /* A1-B1		a1-b1 */\
893
	"psrad $" #shift ", %%mm0		\n\t"\
894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm1, %%mm1			\n\t" /* A0+B0	a0+b0 */\
	"movd %%mm1, " #dst "			\n\t"\
	"packssdw %%mm0, %%mm0			\n\t" /* A1+B1	a1+b1 */\
	"movd %%mm0, 16+" #dst "		\n\t"\
	"packssdw %%mm2, %%mm2			\n\t" /* A1-B1	a1-b1 */\
	"movd %%mm2, 96+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A0-B0	a0-b0 */\
	"movd %%mm4, 112+" #dst "		\n\t"\
	"movq 88(%2), %%mm1			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
	"movq %%mm5, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm1, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm1, %%mm5			\n\t" /* a2-B2		a2-b2 */\
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm5		\n\t"\
	"movq %%mm6, %%mm1			\n\t" /* A3		a3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm1			\n\t" /* a3-B3		a3-b3 */\
	"psrad $" #shift ", %%mm6		\n\t"\
	"psrad $" #shift ", %%mm1		\n\t"\
	"packssdw %%mm2, %%mm2			\n\t" /* A2+B2	a2+b2 */\
	"packssdw %%mm6, %%mm6			\n\t" /* A3+B3	a3+b3 */\
	"movd %%mm2, 32+" #dst "		\n\t"\
	"packssdw %%mm1, %%mm1			\n\t" /* A3-B3	a3-b3 */\
	"packssdw %%mm5, %%mm5			\n\t" /* A2-B2	a2-b2 */\
	"movd %%mm6, 48+" #dst "		\n\t"\
	"movd %%mm1, 64+" #dst "		\n\t"\
	"movd %%mm5, 80+" #dst "		\n\t"	


//IDCT(  src0,   src4,   src1,    src5,    dst, rounder, shift)
IDCT(    (%1), 64(%1), 32(%1),  96(%1),  0(%0),/nop, 20)
IDCT(   8(%1), 72(%1), 40(%1), 104(%1),  4(%0),/nop, 20)
IDCT(  16(%1), 80(%1), 48(%1), 112(%1),  8(%0),/nop, 20)
IDCT(  24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
931 932 933 934
	"jmp 9f					\n\t"

	"#.balign 16				\n\t"\
	"2:					\n\t"
935
Z_COND_IDCT(  96(%0),104(%0),112(%0),120(%0), 96(%1),paddd (%2), 11, 3f)
936

937 938 939
#undef IDCT
#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
940 941
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
	"movq " #src5 ", %%mm3			\n\t" /* R7	R5	r7	r5 */\
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	#rounder ", %%mm4			\n\t"\
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	#rounder ", %%mm0			\n\t"\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
	"movq %%mm0, %%mm5			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 56(%2), %%mm1			\n\t" /* C7	C5	C7	C5 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* C7R7+C5R5	C7r7+C5r5 */\
	"pmaddwd 64(%2), %%mm2			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm1, %%mm7			\n\t" /* B0		b0 */\
	"movq 72(%2), %%mm1			\n\t" /* -C5	-C1	-C5	-C1 */\
	"pmaddwd %%mm3, %%mm1			\n\t" /* -C5R7-C1R5	-C5r7-C1r5 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
959
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
960 961 962
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"paddd %%mm2, %%mm1			\n\t" /* B1		b1 */\
	"psrad $" #shift ", %%mm7		\n\t"\
963
	"psrad $" #shift ", %%mm4		\n\t"\
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
	"movq %%mm0, %%mm2			\n\t" /* A1		a1 */\
	"paddd %%mm1, %%mm0			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm1, %%mm2			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm0		\n\t"\
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm7, %%mm7			\n\t" /* A0+B0	a0+b0 */\
	"movd %%mm7, " #dst "			\n\t"\
	"packssdw %%mm0, %%mm0			\n\t" /* A1+B1	a1+b1 */\
	"movd %%mm0, 16+" #dst "		\n\t"\
	"packssdw %%mm2, %%mm2			\n\t" /* A1-B1	a1-b1 */\
	"movd %%mm2, 96+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A0-B0	a0-b0 */\
	"movd %%mm4, 112+" #dst "		\n\t"\
	"movq " #src1 ", %%mm0			\n\t" /* R3	R1	r3	r1 */\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"movq 88(%2), %%mm7			\n\t" /* C3	C7	C3 	C7 */\
	"pmaddwd 96(%2), %%mm0			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
982
	"pmaddwd %%mm3, %%mm7			\n\t" /* C3R7+C7R5	C3r7+C7r5 */\
983 984 985 986 987 988 989 990 991 992 993
	"movq %%mm5, %%mm2			\n\t" /* A2		a2 */\
	"pmaddwd 104(%2), %%mm3			\n\t" /* -C1R7+C3R5	-C1r7+C3r5 */\
	"paddd %%mm7, %%mm4			\n\t" /* B2		b2 */\
	"paddd %%mm4, %%mm2			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm5			\n\t" /* a2-B2		a2-b2 */\
	"psrad $" #shift ", %%mm2		\n\t"\
	"psrad $" #shift ", %%mm5		\n\t"\
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm0, %%mm3			\n\t" /* B3		b3 */\
	"paddd %%mm3, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm3, %%mm4			\n\t" /* a3-B3		a3-b3 */\
994 995
	"psrad $" #shift ", %%mm6		\n\t"\
	"psrad $" #shift ", %%mm4		\n\t"\
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
	"packssdw %%mm2, %%mm2			\n\t" /* A2+B2	a2+b2 */\
	"packssdw %%mm6, %%mm6			\n\t" /* A3+B3	a3+b3 */\
	"movd %%mm2, 32+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A3-B3	a3-b3 */\
	"packssdw %%mm5, %%mm5			\n\t" /* A2-B2	a2-b2 */\
	"movd %%mm6, 48+" #dst "		\n\t"\
	"movd %%mm4, 64+" #dst "		\n\t"\
	"movd %%mm5, 80+" #dst "		\n\t"

//IDCT(  src0,   src4,   src1,    src5,    dst, rounder, shift)
IDCT(    (%1), 64(%1), 32(%1),  96(%1),  0(%0),/nop, 20)
IDCT(   8(%1), 72(%1), 40(%1), 104(%1),  4(%0),/nop, 20)
IDCT(  16(%1), 80(%1), 48(%1), 112(%1),  8(%0),/nop, 20)
IDCT(  24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
1010 1011 1012 1013
	"jmp 9f					\n\t"

	"#.balign 16				\n\t"\
	"3:					\n\t"
1014 1015 1016
#undef IDCT
#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
1017
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	#rounder ", %%mm4			\n\t"\
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	#rounder ", %%mm0			\n\t"\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
	"movq %%mm0, %%mm5			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 64(%2), %%mm3			\n\t"\
	"pmaddwd %%mm2, %%mm3			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
1031
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
1032 1033
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"psrad $" #shift ", %%mm7		\n\t"\
1034
	"psrad $" #shift ", %%mm4		\n\t"\
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054
	"movq %%mm0, %%mm1			\n\t" /* A1		a1 */\
	"paddd %%mm3, %%mm0			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm3, %%mm1			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm0		\n\t"\
	"psrad $" #shift ", %%mm1		\n\t"\
	"packssdw %%mm7, %%mm7			\n\t" /* A0+B0	a0+b0 */\
	"movd %%mm7, " #dst "			\n\t"\
	"packssdw %%mm0, %%mm0			\n\t" /* A1+B1	a1+b1 */\
	"movd %%mm0, 16+" #dst "		\n\t"\
	"packssdw %%mm1, %%mm1			\n\t" /* A1-B1	a1-b1 */\
	"movd %%mm1, 96+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A0-B0	a0-b0 */\
	"movd %%mm4, 112+" #dst "		\n\t"\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"pmaddwd %%mm2, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"pmaddwd 96(%2), %%mm2			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
	"movq %%mm5, %%mm1			\n\t" /* A2		a2 */\
	"paddd %%mm4, %%mm1			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm5			\n\t" /* a2-B2		a2-b2 */\
	"psrad $" #shift ", %%mm1		\n\t"\
1055
	"psrad $" #shift ", %%mm5		\n\t"\
1056 1057 1058
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm2, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm2, %%mm4			\n\t" /* a3-B3		a3-b3 */\
1059 1060
	"psrad $" #shift ", %%mm6		\n\t"\
	"psrad $" #shift ", %%mm4		\n\t"\
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
	"packssdw %%mm1, %%mm1			\n\t" /* A2+B2	a2+b2 */\
	"packssdw %%mm6, %%mm6			\n\t" /* A3+B3	a3+b3 */\
	"movd %%mm1, 32+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A3-B3	a3-b3 */\
	"packssdw %%mm5, %%mm5			\n\t" /* A2-B2	a2-b2 */\
	"movd %%mm6, 48+" #dst "		\n\t"\
	"movd %%mm4, 64+" #dst "		\n\t"\
	"movd %%mm5, 80+" #dst "		\n\t"


//IDCT(  src0,   src4,   src1,    src5,    dst, rounder, shift)
IDCT(    (%1), 64(%1), 32(%1),  96(%1),  0(%0),/nop, 20)
IDCT(   8(%1), 72(%1), 40(%1), 104(%1),  4(%0),/nop, 20)
IDCT(  16(%1), 80(%1), 48(%1), 112(%1),  8(%0),/nop, 20)
IDCT(  24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
1076 1077 1078 1079
	"jmp 9f					\n\t"

	"#.balign 16				\n\t"\
	"5:					\n\t"
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
#undef IDCT
#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	#rounder ", %%mm4			\n\t"\
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
1094
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116
	#rounder ", %%mm0			\n\t"\
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq %%mm0, %%mm5			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"paddd %%mm1, %%mm0			\n\t" /* A1		a1 */\
	"psubd %%mm1, %%mm5			\n\t" /* A2		a2 */\
	"movq 8+" #src0 ", %%mm2		\n\t" /* R4	R0	r4	r0 */\
	"movq 8+" #src4 ", %%mm3		\n\t" /* R6	R2	r6	r2 */\
	"movq 16(%2), %%mm1			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm2, %%mm1			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm7			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm7, %%mm2			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm7			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm3, %%mm7			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"pmaddwd 40(%2), %%mm3			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	#rounder ", %%mm1			\n\t"\
	"paddd %%mm1, %%mm7			\n\t" /* A0		a0 */\
	"paddd %%mm1, %%mm1			\n\t" /* 2C0		2c0 */\
	#rounder ", %%mm2			\n\t"\
	"psubd %%mm7, %%mm1			\n\t" /* A3		a3 */\
	"paddd %%mm2, %%mm3			\n\t" /* A1		a1 */\
	"paddd %%mm2, %%mm2			\n\t" /* 2C1		2c1 */\
	"psubd %%mm3, %%mm2			\n\t" /* A2		a2 */\
1117 1118
	"psrad $" #shift ", %%mm4		\n\t"\
	"psrad $" #shift ", %%mm7		\n\t"\
1119 1120 1121
	"psrad $" #shift ", %%mm3		\n\t"\
	"packssdw %%mm7, %%mm4			\n\t" /* A0	a0 */\
	"movq %%mm4, " #dst "			\n\t"\
1122
	"psrad $" #shift ", %%mm0		\n\t"\
1123 1124 1125 1126 1127 1128
	"packssdw %%mm3, %%mm0			\n\t" /* A1	a1 */\
	"movq %%mm0, 16+" #dst "		\n\t"\
	"movq %%mm0, 96+" #dst "		\n\t"\
	"movq %%mm4, 112+" #dst "		\n\t"\
	"psrad $" #shift ", %%mm5		\n\t"\
	"psrad $" #shift ", %%mm6		\n\t"\
1129
	"psrad $" #shift ", %%mm2		\n\t"\
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
	"packssdw %%mm2, %%mm5			\n\t" /* A2-B2	a2-b2 */\
	"movq %%mm5, 32+" #dst "		\n\t"\
	"psrad $" #shift ", %%mm1		\n\t"\
	"packssdw %%mm1, %%mm6			\n\t" /* A3+B3	a3+b3 */\
	"movq %%mm6, 48+" #dst "		\n\t"\
	"movq %%mm6, 64+" #dst "		\n\t"\
	"movq %%mm5, 80+" #dst "		\n\t"	
	

//IDCT(  src0,   src4,   src1,    src5,    dst, rounder, shift)
IDCT(    0(%1), 64(%1), 32(%1),  96(%1),  0(%0),/nop, 20)
//IDCT(   8(%1), 72(%1), 40(%1), 104(%1),  4(%0),/nop, 20)
IDCT(  16(%1), 80(%1), 48(%1), 112(%1),  8(%0),/nop, 20)
//IDCT(  24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
1144 1145 1146 1147 1148
	"jmp 9f					\n\t"


	"#.balign 16				\n\t"\
	"1:					\n\t"
1149 1150 1151 1152
#undef IDCT
#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq " #src4 ", %%mm1			\n\t" /* R6	R2	r6	r2 */\
1153
	"movq " #src1 ", %%mm2			\n\t" /* R3	R1	r3	r1 */\
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm5			\n\t" /* C6	C2	C6	C2 */\
	"pmaddwd %%mm1, %%mm5			\n\t" /* C6R6+C2R2	C6r6+C2r2 */\
	"movq 40(%2), %%mm6			\n\t" /* -C2	C6	-C2	C6 */\
	"pmaddwd %%mm6, %%mm1			\n\t" /* -C2R6+C6R2	-C2r6+C6r2 */\
	#rounder ", %%mm4			\n\t"\
	"movq %%mm4, %%mm6			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 48(%2), %%mm7			\n\t" /* C3	C1	C3	C1 */\
	#rounder ", %%mm0			\n\t"\
	"pmaddwd %%mm2, %%mm7			\n\t" /* C3R3+C1R1	C3r3+C1r1 */\
1167
	"paddd %%mm5, %%mm4			\n\t" /* A0		a0 */\
1168 1169 1170 1171 1172 1173 1174
	"psubd %%mm5, %%mm6			\n\t" /* A3		a3 */\
	"movq %%mm0, %%mm5			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"paddd %%mm1, %%mm0			\n\t" /* A1		a1 */\
	"psubd %%mm1, %%mm5			\n\t" /* A2		a2 */\
	"movq 64(%2), %%mm1			\n\t"\
	"pmaddwd %%mm2, %%mm1			\n\t" /* -C7R3+C3R1	-C7r3+C3r1 */\
	"paddd %%mm4, %%mm7			\n\t" /* A0+B0		a0+b0 */\
1175
	"paddd %%mm4, %%mm4			\n\t" /* 2A0		2a0 */\
1176 1177
	"psubd %%mm7, %%mm4			\n\t" /* A0-B0		a0-b0 */\
	"psrad $" #shift ", %%mm7		\n\t"\
1178
	"psrad $" #shift ", %%mm4		\n\t"\
1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
	"movq %%mm0, %%mm3			\n\t" /* A1		a1 */\
	"paddd %%mm1, %%mm0			\n\t" /* A1+B1		a1+b1 */\
	"psubd %%mm1, %%mm3			\n\t" /* A1-B1		a1-b1 */\
	"psrad $" #shift ", %%mm0		\n\t"\
	"psrad $" #shift ", %%mm3		\n\t"\
	"packssdw %%mm7, %%mm7			\n\t" /* A0+B0	a0+b0 */\
	"movd %%mm7, " #dst "			\n\t"\
	"packssdw %%mm0, %%mm0			\n\t" /* A1+B1	a1+b1 */\
	"movd %%mm0, 16+" #dst "		\n\t"\
	"packssdw %%mm3, %%mm3			\n\t" /* A1-B1	a1-b1 */\
	"movd %%mm3, 96+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A0-B0	a0-b0 */\
	"movd %%mm4, 112+" #dst "		\n\t"\
	"movq 80(%2), %%mm4			\n\t" /* -C1	C5	-C1 	C5 */\
	"pmaddwd %%mm2, %%mm4			\n\t" /* -C1R3+C5R1	-C1r3+C5r1 */\
	"pmaddwd 96(%2), %%mm2			\n\t" /* -C5R3+C7R1	-C5r3+C7r1 */\
	"movq %%mm5, %%mm3			\n\t" /* A2		a2 */\
	"paddd %%mm4, %%mm3			\n\t" /* A2+B2		a2+b2 */\
	"psubd %%mm4, %%mm5			\n\t" /* a2-B2		a2-b2 */\
	"psrad $" #shift ", %%mm3		\n\t"\
	"psrad $" #shift ", %%mm5		\n\t"\
	"movq %%mm6, %%mm4			\n\t" /* A3		a3 */\
	"paddd %%mm2, %%mm6			\n\t" /* A3+B3		a3+b3 */\
	"psubd %%mm2, %%mm4			\n\t" /* a3-B3		a3-b3 */\
1203
	"psrad $" #shift ", %%mm6		\n\t"\
1204 1205
	"packssdw %%mm3, %%mm3			\n\t" /* A2+B2	a2+b2 */\
	"movd %%mm3, 32+" #dst "		\n\t"\
1206
	"psrad $" #shift ", %%mm4		\n\t"\
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
	"packssdw %%mm6, %%mm6			\n\t" /* A3+B3	a3+b3 */\
	"movd %%mm6, 48+" #dst "		\n\t"\
	"packssdw %%mm4, %%mm4			\n\t" /* A3-B3	a3-b3 */\
	"packssdw %%mm5, %%mm5			\n\t" /* A2-B2	a2-b2 */\
	"movd %%mm4, 64+" #dst "		\n\t"\
	"movd %%mm5, 80+" #dst "		\n\t"
	

//IDCT(  src0,   src4,   src1,    src5,    dst, rounder, shift)
IDCT(    (%1), 64(%1), 32(%1),  96(%1),  0(%0),/nop, 20)
IDCT(   8(%1), 72(%1), 40(%1), 104(%1),  4(%0),/nop, 20)
IDCT(  16(%1), 80(%1), 48(%1), 112(%1),  8(%0),/nop, 20)
IDCT(  24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
1220 1221 1222 1223 1224
	"jmp 9f					\n\t"


	"#.balign 16				\n\t"
	"7:					\n\t"
1225 1226 1227 1228 1229 1230 1231 1232 1233
#undef IDCT
#define IDCT(src0, src4, src1, src5, dst, rounder, shift) \
	"movq " #src0 ", %%mm0			\n\t" /* R4	R0	r4	r0 */\
	"movq 16(%2), %%mm4			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm0, %%mm4			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm5			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm5, %%mm0			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	#rounder ", %%mm4			\n\t"\
	#rounder ", %%mm0			\n\t"\
1234 1235
	"psrad $" #shift ", %%mm4		\n\t"\
	"psrad $" #shift ", %%mm0		\n\t"\
1236 1237 1238 1239 1240 1241 1242 1243
	"movq 8+" #src0 ", %%mm2		\n\t" /* R4	R0	r4	r0 */\
	"movq 16(%2), %%mm1			\n\t" /* C4	C4	C4	C4 */\
	"pmaddwd %%mm2, %%mm1			\n\t" /* C4R4+C4R0	C4r4+C4r0 */\
	"movq 24(%2), %%mm7			\n\t" /* -C4	C4	-C4	C4 */\
	"pmaddwd %%mm7, %%mm2			\n\t" /* -C4R4+C4R0	-C4r4+C4r0 */\
	"movq 32(%2), %%mm7			\n\t" /* C6	C2	C6	C2 */\
	#rounder ", %%mm1			\n\t"\
	#rounder ", %%mm2			\n\t"\
1244
	"psrad $" #shift ", %%mm1		\n\t"\
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261
	"packssdw %%mm1, %%mm4			\n\t" /* A0	a0 */\
	"movq %%mm4, " #dst "			\n\t"\
	"psrad $" #shift ", %%mm2		\n\t"\
	"packssdw %%mm2, %%mm0			\n\t" /* A1	a1 */\
	"movq %%mm0, 16+" #dst "		\n\t"\
	"movq %%mm0, 96+" #dst "		\n\t"\
	"movq %%mm4, 112+" #dst "		\n\t"\
	"movq %%mm0, 32+" #dst "		\n\t"\
	"movq %%mm4, 48+" #dst "		\n\t"\
	"movq %%mm4, 64+" #dst "		\n\t"\
	"movq %%mm0, 80+" #dst "		\n\t"	

//IDCT(  src0,   src4,   src1,    src5,    dst, rounder, shift)
IDCT(   0(%1), 64(%1), 32(%1),  96(%1),  0(%0),/nop, 20)
//IDCT(   8(%1), 72(%1), 40(%1), 104(%1),  4(%0),/nop, 20)
IDCT(  16(%1), 80(%1), 48(%1), 112(%1),  8(%0),/nop, 20)
//IDCT(  24(%1), 88(%1), 56(%1), 120(%1), 12(%0),/nop, 20)
1262 1263 1264 1265 1266 1267


#endif

/*
Input
1268 1269 1270
 00 40 04 44 20 60 24 64
 10 30 14 34 50 70 54 74
 01 41 03 43 21 61 23 63
1271
 11 31 13 33 51 71 53 73
1272 1273 1274 1275 1276
 02 42 06 46 22 62 26 66
 12 32 16 36 52 72 56 76
 05 45 07 47 25 65 27 67
 15 35 17 37 55 75 57 77
  
1277
Temp
1278 1279
 00 04 10 14 20 24 30 34
 40 44 50 54 60 64 70 74
1280 1281
 01 03 11 13 21 23 31 33
 41 43 51 53 61 63 71 73
1282 1283
 02 06 12 16 22 26 32 36
 42 46 52 56 62 66 72 76
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
 05 07 15 17 25 27 35 37
 45 47 55 57 65 67 75 77
*/

"9: \n\t"
		:: "r" (block), "r" (temp), "r" (coeffs)
		: "%eax"
	);
}

void simple_idct_mmx(int16_t *block)
{
	idct(block);
}