1 /********************************************************************
2  *                                                                  *
3  * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
5  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
7  *                                                                  *
8  * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009                *
9  * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
10  *                                                                  *
11  ********************************************************************
12 
13   function:
14     last mod: Id
15 
16  ********************************************************************/
17 
18 /*MMX acceleration of Theora's iDCT.
19   Originally written by Rudolf Marek, based on code from On2's VP3.*/
20 #include "x86int.h"
21 #include "../dct.h"
22 
23 #if defined(OC_X86_ASM)
24 
25 /*These are offsets into the table of constants below.*/
26 /*7 rows of cosines, in order: pi/16 * (1 ... 7).*/
27 #define OC_COSINE_OFFSET (0)
28 /*A row of 8's.*/
29 #define OC_EIGHT_OFFSET  (56)
30 
31 
32 
33 /*A table of constants used by the MMX routines.*/
34 static const ogg_uint16_t __attribute__((aligned(8),used))
35  OC_IDCT_CONSTS[(7+1)*4]={
36   (ogg_uint16_t)OC_C1S7,(ogg_uint16_t)OC_C1S7,
37   (ogg_uint16_t)OC_C1S7,(ogg_uint16_t)OC_C1S7,
38   (ogg_uint16_t)OC_C2S6,(ogg_uint16_t)OC_C2S6,
39   (ogg_uint16_t)OC_C2S6,(ogg_uint16_t)OC_C2S6,
40   (ogg_uint16_t)OC_C3S5,(ogg_uint16_t)OC_C3S5,
41   (ogg_uint16_t)OC_C3S5,(ogg_uint16_t)OC_C3S5,
42   (ogg_uint16_t)OC_C4S4,(ogg_uint16_t)OC_C4S4,
43   (ogg_uint16_t)OC_C4S4,(ogg_uint16_t)OC_C4S4,
44   (ogg_uint16_t)OC_C5S3,(ogg_uint16_t)OC_C5S3,
45   (ogg_uint16_t)OC_C5S3,(ogg_uint16_t)OC_C5S3,
46   (ogg_uint16_t)OC_C6S2,(ogg_uint16_t)OC_C6S2,
47   (ogg_uint16_t)OC_C6S2,(ogg_uint16_t)OC_C6S2,
48   (ogg_uint16_t)OC_C7S1,(ogg_uint16_t)OC_C7S1,
49   (ogg_uint16_t)OC_C7S1,(ogg_uint16_t)OC_C7S1,
50       8,    8,    8,    8
51 };
52 
53 /*Converts the expression in the argument to a string.*/
54 #define OC_M2STR(_s) #_s
55 
56 /*38 cycles*/
57 #define OC_IDCT_BEGIN \
58   "#OC_IDCT_BEGIN\n\t" \
59   "movq "OC_I(3)",%%mm2\n\t" \
60   "movq "OC_C(3)",%%mm6\n\t" \
61   "movq %%mm2,%%mm4\n\t" \
62   "movq "OC_J(5)",%%mm7\n\t" \
63   "pmulhw %%mm6,%%mm4\n\t" \
64   "movq "OC_C(5)",%%mm1\n\t" \
65   "pmulhw %%mm7,%%mm6\n\t" \
66   "movq %%mm1,%%mm5\n\t" \
67   "pmulhw %%mm2,%%mm1\n\t" \
68   "movq "OC_I(1)",%%mm3\n\t" \
69   "pmulhw %%mm7,%%mm5\n\t" \
70   "movq "OC_C(1)",%%mm0\n\t" \
71   "paddw %%mm2,%%mm4\n\t" \
72   "paddw %%mm7,%%mm6\n\t" \
73   "paddw %%mm1,%%mm2\n\t" \
74   "movq "OC_J(7)",%%mm1\n\t" \
75   "paddw %%mm5,%%mm7\n\t" \
76   "movq %%mm0,%%mm5\n\t" \
77   "pmulhw %%mm3,%%mm0\n\t" \
78   "paddw %%mm7,%%mm4\n\t" \
79   "pmulhw %%mm1,%%mm5\n\t" \
80   "movq "OC_C(7)",%%mm7\n\t" \
81   "psubw %%mm2,%%mm6\n\t" \
82   "paddw %%mm3,%%mm0\n\t" \
83   "pmulhw %%mm7,%%mm3\n\t" \
84   "movq "OC_I(2)",%%mm2\n\t" \
85   "pmulhw %%mm1,%%mm7\n\t" \
86   "paddw %%mm1,%%mm5\n\t" \
87   "movq %%mm2,%%mm1\n\t" \
88   "pmulhw "OC_C(2)",%%mm2\n\t" \
89   "psubw %%mm5,%%mm3\n\t" \
90   "movq "OC_J(6)",%%mm5\n\t" \
91   "paddw %%mm7,%%mm0\n\t" \
92   "movq %%mm5,%%mm7\n\t" \
93   "psubw %%mm4,%%mm0\n\t" \
94   "pmulhw "OC_C(2)",%%mm5\n\t" \
95   "paddw %%mm1,%%mm2\n\t" \
96   "pmulhw "OC_C(6)",%%mm1\n\t" \
97   "paddw %%mm4,%%mm4\n\t" \
98   "paddw %%mm0,%%mm4\n\t" \
99   "psubw %%mm6,%%mm3\n\t" \
100   "paddw %%mm7,%%mm5\n\t" \
101   "paddw %%mm6,%%mm6\n\t" \
102   "pmulhw "OC_C(6)",%%mm7\n\t" \
103   "paddw %%mm3,%%mm6\n\t" \
104   "movq %%mm4,"OC_I(1)"\n\t" \
105   "psubw %%mm5,%%mm1\n\t" \
106   "movq "OC_C(4)",%%mm4\n\t" \
107   "movq %%mm3,%%mm5\n\t" \
108   "pmulhw %%mm4,%%mm3\n\t" \
109   "paddw %%mm2,%%mm7\n\t" \
110   "movq %%mm6,"OC_I(2)"\n\t" \
111   "movq %%mm0,%%mm2\n\t" \
112   "movq "OC_I(0)",%%mm6\n\t" \
113   "pmulhw %%mm4,%%mm0\n\t" \
114   "paddw %%mm3,%%mm5\n\t" \
115   "movq "OC_J(4)",%%mm3\n\t" \
116   "psubw %%mm1,%%mm5\n\t" \
117   "paddw %%mm0,%%mm2\n\t" \
118   "psubw %%mm3,%%mm6\n\t" \
119   "movq %%mm6,%%mm0\n\t" \
120   "pmulhw %%mm4,%%mm6\n\t" \
121   "paddw %%mm3,%%mm3\n\t" \
122   "paddw %%mm1,%%mm1\n\t" \
123   "paddw %%mm0,%%mm3\n\t" \
124   "paddw %%mm5,%%mm1\n\t" \
125   "pmulhw %%mm3,%%mm4\n\t" \
126   "paddw %%mm0,%%mm6\n\t" \
127   "psubw %%mm2,%%mm6\n\t" \
128   "paddw %%mm2,%%mm2\n\t" \
129   "movq "OC_I(1)",%%mm0\n\t" \
130   "paddw %%mm6,%%mm2\n\t" \
131   "paddw %%mm3,%%mm4\n\t" \
132   "psubw %%mm1,%%mm2\n\t" \
133   "#end OC_IDCT_BEGIN\n\t" \
134 
135 /*38+8=46 cycles.*/
136 #define OC_ROW_IDCT \
137   "#OC_ROW_IDCT\n" \
138   OC_IDCT_BEGIN \
139   /*r3=D'*/ \
140   "movq "OC_I(2)",%%mm3\n\t" \
141   /*r4=E'=E-G*/ \
142   "psubw %%mm7,%%mm4\n\t" \
143   /*r1=H'+H'*/ \
144   "paddw %%mm1,%%mm1\n\t" \
145   /*r7=G+G*/ \
146   "paddw %%mm7,%%mm7\n\t" \
147   /*r1=R1=A''+H'*/ \
148   "paddw %%mm2,%%mm1\n\t" \
149   /*r7=G'=E+G*/ \
150   "paddw %%mm4,%%mm7\n\t" \
151   /*r4=R4=E'-D'*/ \
152   "psubw %%mm3,%%mm4\n\t" \
153   "paddw %%mm3,%%mm3\n\t" \
154   /*r6=R6=F'-B''*/ \
155   "psubw %%mm5,%%mm6\n\t" \
156   "paddw %%mm5,%%mm5\n\t" \
157   /*r3=R3=E'+D'*/ \
158   "paddw %%mm4,%%mm3\n\t" \
159   /*r5=R5=F'+B''*/ \
160   "paddw %%mm6,%%mm5\n\t" \
161   /*r7=R7=G'-C'*/ \
162   "psubw %%mm0,%%mm7\n\t" \
163   "paddw %%mm0,%%mm0\n\t" \
164   /*Save R1.*/ \
165   "movq %%mm1,"OC_I(1)"\n\t" \
166   /*r0=R0=G.+C.*/ \
167   "paddw %%mm7,%%mm0\n\t" \
168   "#end OC_ROW_IDCT\n\t" \
169 
170 /*The following macro does two 4x4 transposes in place.
171   At entry, we assume:
172     r0 = a3 a2 a1 a0
173   I(1) = b3 b2 b1 b0
174     r2 = c3 c2 c1 c0
175     r3 = d3 d2 d1 d0
176 
177     r4 = e3 e2 e1 e0
178     r5 = f3 f2 f1 f0
179     r6 = g3 g2 g1 g0
180     r7 = h3 h2 h1 h0
181 
182   At exit, we have:
183   I(0) = d0 c0 b0 a0
184   I(1) = d1 c1 b1 a1
185   I(2) = d2 c2 b2 a2
186   I(3) = d3 c3 b3 a3
187 
188   J(4) = h0 g0 f0 e0
189   J(5) = h1 g1 f1 e1
190   J(6) = h2 g2 f2 e2
191   J(7) = h3 g3 f3 e3
192 
193   I(0) I(1) I(2) I(3) is the transpose of r0 I(1) r2 r3.
194   J(4) J(5) J(6) J(7) is the transpose of r4  r5  r6 r7.
195 
196   Since r1 is free at entry, we calculate the Js first.*/
197 /*19 cycles.*/
198 #define OC_TRANSPOSE \
199   "#OC_TRANSPOSE\n\t" \
200   "movq %%mm4,%%mm1\n\t" \
201   "punpcklwd %%mm5,%%mm4\n\t" \
202   "movq %%mm0,"OC_I(0)"\n\t" \
203   "punpckhwd %%mm5,%%mm1\n\t" \
204   "movq %%mm6,%%mm0\n\t" \
205   "punpcklwd %%mm7,%%mm6\n\t" \
206   "movq %%mm4,%%mm5\n\t" \
207   "punpckldq %%mm6,%%mm4\n\t" \
208   "punpckhdq %%mm6,%%mm5\n\t" \
209   "movq %%mm1,%%mm6\n\t" \
210   "movq %%mm4,"OC_J(4)"\n\t" \
211   "punpckhwd %%mm7,%%mm0\n\t" \
212   "movq %%mm5,"OC_J(5)"\n\t" \
213   "punpckhdq %%mm0,%%mm6\n\t" \
214   "movq "OC_I(0)",%%mm4\n\t" \
215   "punpckldq %%mm0,%%mm1\n\t" \
216   "movq "OC_I(1)",%%mm5\n\t" \
217   "movq %%mm4,%%mm0\n\t" \
218   "movq %%mm6,"OC_J(7)"\n\t" \
219   "punpcklwd %%mm5,%%mm0\n\t" \
220   "movq %%mm1,"OC_J(6)"\n\t" \
221   "punpckhwd %%mm5,%%mm4\n\t" \
222   "movq %%mm2,%%mm5\n\t" \
223   "punpcklwd %%mm3,%%mm2\n\t" \
224   "movq %%mm0,%%mm1\n\t" \
225   "punpckldq %%mm2,%%mm0\n\t" \
226   "punpckhdq %%mm2,%%mm1\n\t" \
227   "movq %%mm4,%%mm2\n\t" \
228   "movq %%mm0,"OC_I(0)"\n\t" \
229   "punpckhwd %%mm3,%%mm5\n\t" \
230   "movq %%mm1,"OC_I(1)"\n\t" \
231   "punpckhdq %%mm5,%%mm4\n\t" \
232   "punpckldq %%mm5,%%mm2\n\t" \
233   "movq %%mm4,"OC_I(3)"\n\t" \
234   "movq %%mm2,"OC_I(2)"\n\t" \
235   "#end OC_TRANSPOSE\n\t" \
236 
237 /*38+19=57 cycles.*/
238 #define OC_COLUMN_IDCT \
239   "#OC_COLUMN_IDCT\n" \
240   OC_IDCT_BEGIN \
241   "paddw "OC_8",%%mm2\n\t" \
242   /*r1=H'+H'*/ \
243   "paddw %%mm1,%%mm1\n\t" \
244   /*r1=R1=A''+H'*/ \
245   "paddw %%mm2,%%mm1\n\t" \
246   /*r2=NR2*/ \
247   "psraw $4,%%mm2\n\t" \
248   /*r4=E'=E-G*/ \
249   "psubw %%mm7,%%mm4\n\t" \
250   /*r1=NR1*/ \
251   "psraw $4,%%mm1\n\t" \
252   /*r3=D'*/ \
253   "movq "OC_I(2)",%%mm3\n\t" \
254   /*r7=G+G*/ \
255   "paddw %%mm7,%%mm7\n\t" \
256   /*Store NR2 at I(2).*/ \
257   "movq %%mm2,"OC_I(2)"\n\t" \
258   /*r7=G'=E+G*/ \
259   "paddw %%mm4,%%mm7\n\t" \
260   /*Store NR1 at I(1).*/ \
261   "movq %%mm1,"OC_I(1)"\n\t" \
262   /*r4=R4=E'-D'*/ \
263   "psubw %%mm3,%%mm4\n\t" \
264   "paddw "OC_8",%%mm4\n\t" \
265   /*r3=D'+D'*/ \
266   "paddw %%mm3,%%mm3\n\t" \
267   /*r3=R3=E'+D'*/ \
268   "paddw %%mm4,%%mm3\n\t" \
269   /*r4=NR4*/ \
270   "psraw $4,%%mm4\n\t" \
271   /*r6=R6=F'-B''*/ \
272   "psubw %%mm5,%%mm6\n\t" \
273   /*r3=NR3*/ \
274   "psraw $4,%%mm3\n\t" \
275   "paddw "OC_8",%%mm6\n\t" \
276   /*r5=B''+B''*/ \
277   "paddw %%mm5,%%mm5\n\t" \
278   /*r5=R5=F'+B''*/ \
279   "paddw %%mm6,%%mm5\n\t" \
280   /*r6=NR6*/ \
281   "psraw $4,%%mm6\n\t" \
282   /*Store NR4 at J(4).*/ \
283   "movq %%mm4,"OC_J(4)"\n\t" \
284   /*r5=NR5*/ \
285   "psraw $4,%%mm5\n\t" \
286   /*Store NR3 at I(3).*/ \
287   "movq %%mm3,"OC_I(3)"\n\t" \
288   /*r7=R7=G'-C'*/ \
289   "psubw %%mm0,%%mm7\n\t" \
290   "paddw "OC_8",%%mm7\n\t" \
291   /*r0=C'+C'*/ \
292   "paddw %%mm0,%%mm0\n\t" \
293   /*r0=R0=G'+C'*/ \
294   "paddw %%mm7,%%mm0\n\t" \
295   /*r7=NR7*/ \
296   "psraw $4,%%mm7\n\t" \
297   /*Store NR6 at J(6).*/ \
298   "movq %%mm6,"OC_J(6)"\n\t" \
299   /*r0=NR0*/ \
300   "psraw $4,%%mm0\n\t" \
301   /*Store NR5 at J(5).*/ \
302   "movq %%mm5,"OC_J(5)"\n\t" \
303   /*Store NR7 at J(7).*/ \
304   "movq %%mm7,"OC_J(7)"\n\t" \
305   /*Store NR0 at I(0).*/ \
306   "movq %%mm0,"OC_I(0)"\n\t" \
307   "#end OC_COLUMN_IDCT\n\t" \
308 
309 #define OC_MID(_m,_i) OC_M2STR(_m+(_i)*8)"(%[c])"
310 #define OC_C(_i)      OC_MID(OC_COSINE_OFFSET,_i-1)
311 #define OC_8          OC_MID(OC_EIGHT_OFFSET,0)
312 
oc_idct8x8_slow(ogg_int16_t _y[64])313 static void oc_idct8x8_slow(ogg_int16_t _y[64]){
314   /*This routine accepts an 8x8 matrix, but in partially transposed form.
315     Every 4x4 block is transposed.*/
316   __asm__ __volatile__(
317 #define OC_I(_k)      OC_M2STR((_k*16))"(%[y])"
318 #define OC_J(_k)      OC_M2STR(((_k-4)*16)+8)"(%[y])"
319     OC_ROW_IDCT
320     OC_TRANSPOSE
321 #undef  OC_I
322 #undef  OC_J
323 #define OC_I(_k)      OC_M2STR((_k*16)+64)"(%[y])"
324 #define OC_J(_k)      OC_M2STR(((_k-4)*16)+72)"(%[y])"
325     OC_ROW_IDCT
326     OC_TRANSPOSE
327 #undef  OC_I
328 #undef  OC_J
329 #define OC_I(_k)      OC_M2STR((_k*16))"(%[y])"
330 #define OC_J(_k)      OC_I(_k)
331     OC_COLUMN_IDCT
332 #undef  OC_I
333 #undef  OC_J
334 #define OC_I(_k)      OC_M2STR((_k*16)+8)"(%[y])"
335 #define OC_J(_k)      OC_I(_k)
336     OC_COLUMN_IDCT
337 #undef  OC_I
338 #undef  OC_J
339     :
340     :[y]"r"(_y),[c]"r"(OC_IDCT_CONSTS)
341   );
342 }
343 
344 /*25 cycles.*/
345 #define OC_IDCT_BEGIN_10 \
346  "#OC_IDCT_BEGIN_10\n\t" \
347  "movq "OC_I(3)",%%mm2\n\t" \
348  "nop\n\t" \
349  "movq "OC_C(3)",%%mm6\n\t" \
350  "movq %%mm2,%%mm4\n\t" \
351  "movq "OC_C(5)",%%mm1\n\t" \
352  "pmulhw %%mm6,%%mm4\n\t" \
353  "movq "OC_I(1)",%%mm3\n\t" \
354  "pmulhw %%mm2,%%mm1\n\t" \
355  "movq "OC_C(1)",%%mm0\n\t" \
356  "paddw %%mm2,%%mm4\n\t" \
357  "pxor %%mm6,%%mm6\n\t" \
358  "paddw %%mm1,%%mm2\n\t" \
359  "movq "OC_I(2)",%%mm5\n\t" \
360  "pmulhw %%mm3,%%mm0\n\t" \
361  "movq %%mm5,%%mm1\n\t" \
362  "paddw %%mm3,%%mm0\n\t" \
363  "pmulhw "OC_C(7)",%%mm3\n\t" \
364  "psubw %%mm2,%%mm6\n\t" \
365  "pmulhw "OC_C(2)",%%mm5\n\t" \
366  "psubw %%mm4,%%mm0\n\t" \
367  "movq "OC_I(2)",%%mm7\n\t" \
368  "paddw %%mm4,%%mm4\n\t" \
369  "paddw %%mm5,%%mm7\n\t" \
370  "paddw %%mm0,%%mm4\n\t" \
371  "pmulhw "OC_C(6)",%%mm1\n\t" \
372  "psubw %%mm6,%%mm3\n\t" \
373  "movq %%mm4,"OC_I(1)"\n\t" \
374  "paddw %%mm6,%%mm6\n\t" \
375  "movq "OC_C(4)",%%mm4\n\t" \
376  "paddw %%mm3,%%mm6\n\t" \
377  "movq %%mm3,%%mm5\n\t" \
378  "pmulhw %%mm4,%%mm3\n\t" \
379  "movq %%mm6,"OC_I(2)"\n\t" \
380  "movq %%mm0,%%mm2\n\t" \
381  "movq "OC_I(0)",%%mm6\n\t" \
382  "pmulhw %%mm4,%%mm0\n\t" \
383  "paddw %%mm3,%%mm5\n\t" \
384  "paddw %%mm0,%%mm2\n\t" \
385  "psubw %%mm1,%%mm5\n\t" \
386  "pmulhw %%mm4,%%mm6\n\t" \
387  "paddw "OC_I(0)",%%mm6\n\t" \
388  "paddw %%mm1,%%mm1\n\t" \
389  "movq %%mm6,%%mm4\n\t" \
390  "paddw %%mm5,%%mm1\n\t" \
391  "psubw %%mm2,%%mm6\n\t" \
392  "paddw %%mm2,%%mm2\n\t" \
393  "movq "OC_I(1)",%%mm0\n\t" \
394  "paddw %%mm6,%%mm2\n\t" \
395  "psubw %%mm1,%%mm2\n\t" \
396  "nop\n\t" \
397  "#end OC_IDCT_BEGIN_10\n\t" \
398 
399 /*25+8=33 cycles.*/
400 #define OC_ROW_IDCT_10 \
401  "#OC_ROW_IDCT_10\n\t" \
402  OC_IDCT_BEGIN_10 \
403  /*r3=D'*/ \
404  "movq "OC_I(2)",%%mm3\n\t" \
405  /*r4=E'=E-G*/ \
406  "psubw %%mm7,%%mm4\n\t" \
407  /*r1=H'+H'*/ \
408  "paddw %%mm1,%%mm1\n\t" \
409  /*r7=G+G*/ \
410  "paddw %%mm7,%%mm7\n\t" \
411  /*r1=R1=A''+H'*/ \
412  "paddw %%mm2,%%mm1\n\t" \
413  /*r7=G'=E+G*/ \
414  "paddw %%mm4,%%mm7\n\t" \
415  /*r4=R4=E'-D'*/ \
416  "psubw %%mm3,%%mm4\n\t" \
417  "paddw %%mm3,%%mm3\n\t" \
418  /*r6=R6=F'-B''*/ \
419  "psubw %%mm5,%%mm6\n\t" \
420  "paddw %%mm5,%%mm5\n\t" \
421  /*r3=R3=E'+D'*/ \
422  "paddw %%mm4,%%mm3\n\t" \
423  /*r5=R5=F'+B''*/ \
424  "paddw %%mm6,%%mm5\n\t" \
425  /*r7=R7=G'-C'*/ \
426  "psubw %%mm0,%%mm7\n\t" \
427  "paddw %%mm0,%%mm0\n\t" \
428  /*Save R1.*/ \
429  "movq %%mm1,"OC_I(1)"\n\t" \
430  /*r0=R0=G'+C'*/ \
431  "paddw %%mm7,%%mm0\n\t" \
432  "#end OC_ROW_IDCT_10\n\t" \
433 
434 /*25+19=44 cycles'*/
435 #define OC_COLUMN_IDCT_10 \
436  "#OC_COLUMN_IDCT_10\n\t" \
437  OC_IDCT_BEGIN_10 \
438  "paddw "OC_8",%%mm2\n\t" \
439  /*r1=H'+H'*/ \
440  "paddw %%mm1,%%mm1\n\t" \
441  /*r1=R1=A''+H'*/ \
442  "paddw %%mm2,%%mm1\n\t" \
443  /*r2=NR2*/ \
444  "psraw $4,%%mm2\n\t" \
445  /*r4=E'=E-G*/ \
446  "psubw %%mm7,%%mm4\n\t" \
447  /*r1=NR1*/ \
448  "psraw $4,%%mm1\n\t" \
449  /*r3=D'*/ \
450  "movq "OC_I(2)",%%mm3\n\t" \
451  /*r7=G+G*/ \
452  "paddw %%mm7,%%mm7\n\t" \
453  /*Store NR2 at I(2).*/ \
454  "movq %%mm2,"OC_I(2)"\n\t" \
455  /*r7=G'=E+G*/ \
456  "paddw %%mm4,%%mm7\n\t" \
457  /*Store NR1 at I(1).*/ \
458  "movq %%mm1,"OC_I(1)"\n\t" \
459  /*r4=R4=E'-D'*/ \
460  "psubw %%mm3,%%mm4\n\t" \
461  "paddw "OC_8",%%mm4\n\t" \
462  /*r3=D'+D'*/ \
463  "paddw %%mm3,%%mm3\n\t" \
464  /*r3=R3=E'+D'*/ \
465  "paddw %%mm4,%%mm3\n\t" \
466  /*r4=NR4*/ \
467  "psraw $4,%%mm4\n\t" \
468  /*r6=R6=F'-B''*/ \
469  "psubw %%mm5,%%mm6\n\t" \
470  /*r3=NR3*/ \
471  "psraw $4,%%mm3\n\t" \
472  "paddw "OC_8",%%mm6\n\t" \
473  /*r5=B''+B''*/ \
474  "paddw %%mm5,%%mm5\n\t" \
475  /*r5=R5=F'+B''*/ \
476  "paddw %%mm6,%%mm5\n\t" \
477  /*r6=NR6*/ \
478  "psraw $4,%%mm6\n\t" \
479  /*Store NR4 at J(4).*/ \
480  "movq %%mm4,"OC_J(4)"\n\t" \
481  /*r5=NR5*/ \
482  "psraw $4,%%mm5\n\t" \
483  /*Store NR3 at I(3).*/ \
484  "movq %%mm3,"OC_I(3)"\n\t" \
485  /*r7=R7=G'-C'*/ \
486  "psubw %%mm0,%%mm7\n\t" \
487  "paddw "OC_8",%%mm7\n\t" \
488  /*r0=C'+C'*/ \
489  "paddw %%mm0,%%mm0\n\t" \
490  /*r0=R0=G'+C'*/ \
491  "paddw %%mm7,%%mm0\n\t" \
492  /*r7=NR7*/ \
493  "psraw $4,%%mm7\n\t" \
494  /*Store NR6 at J(6).*/ \
495  "movq %%mm6,"OC_J(6)"\n\t" \
496  /*r0=NR0*/ \
497  "psraw $4,%%mm0\n\t" \
498  /*Store NR5 at J(5).*/ \
499  "movq %%mm5,"OC_J(5)"\n\t" \
500  /*Store NR7 at J(7).*/ \
501  "movq %%mm7,"OC_J(7)"\n\t" \
502  /*Store NR0 at I(0).*/ \
503  "movq %%mm0,"OC_I(0)"\n\t" \
504  "#end OC_COLUMN_IDCT_10\n\t" \
505 
oc_idct8x8_10(ogg_int16_t _y[64])506 static void oc_idct8x8_10(ogg_int16_t _y[64]){
507   __asm__ __volatile__(
508 #define OC_I(_k) OC_M2STR((_k*16))"(%[y])"
509 #define OC_J(_k) OC_M2STR(((_k-4)*16)+8)"(%[y])"
510     /*Done with dequant, descramble, and partial transpose.
511       Now do the iDCT itself.*/
512     OC_ROW_IDCT_10
513     OC_TRANSPOSE
514 #undef  OC_I
515 #undef  OC_J
516 #define OC_I(_k) OC_M2STR((_k*16))"(%[y])"
517 #define OC_J(_k) OC_I(_k)
518     OC_COLUMN_IDCT_10
519 #undef  OC_I
520 #undef  OC_J
521 #define OC_I(_k) OC_M2STR((_k*16)+8)"(%[y])"
522 #define OC_J(_k) OC_I(_k)
523     OC_COLUMN_IDCT_10
524 #undef  OC_I
525 #undef  OC_J
526     :
527     :[y]"r"(_y),[c]"r"(OC_IDCT_CONSTS)
528   );
529 }
530 
531 /*Performs an inverse 8x8 Type-II DCT transform.
532   The input is assumed to be scaled by a factor of 4 relative to orthonormal
533    version of the transform.*/
oc_idct8x8_mmx(ogg_int16_t _y[64],int _last_zzi)534 void oc_idct8x8_mmx(ogg_int16_t _y[64],int _last_zzi){
535   /*_last_zzi is subtly different from an actual count of the number of
536      coefficients we decoded for this block.
537     It contains the value of zzi BEFORE the final token in the block was
538      decoded.
539     In most cases this is an EOB token (the continuation of an EOB run from a
540      previous block counts), and so this is the same as the coefficient count.
541     However, in the case that the last token was NOT an EOB token, but filled
542      the block up with exactly 64 coefficients, _last_zzi will be less than 64.
543     Provided the last token was not a pure zero run, the minimum value it can
544      be is 46, and so that doesn't affect any of the cases in this routine.
545     However, if the last token WAS a pure zero run of length 63, then _last_zzi
546      will be 1 while the number of coefficients decoded is 64.
547     Thus, we will trigger the following special case, where the real
548      coefficient count would not.
549     Note also that a zero run of length 64 will give _last_zzi a value of 0,
550      but we still process the DC coefficient, which might have a non-zero value
551      due to DC prediction.
552     Although convoluted, this is arguably the correct behavior: it allows us to
553      use a smaller transform when the block ends with a long zero run instead
554      of a normal EOB token.
555     It could be smarter... multiple separate zero runs at the end of a block
556      will fool it, but an encoder that generates these really deserves what it
557      gets.
558     Needless to say we inherited this approach from VP3.*/
559   /*Then perform the iDCT.*/
560   if(_last_zzi<10)oc_idct8x8_10(_y);
561   else oc_idct8x8_slow(_y);
562 }
563 
564 #endif
565