You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
8.1KB

  1. /*
  2. Originally provided by Intel at AP-922
  3. http://developer.intel.com/vtune/cbts/strmsimd/922down.htm
  4. (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm)
  5. but in a limited edition.
  6. column code adapted from peter gubanov
  7. Copyright (c) 2000-2001 Peter Gubanov <peter@elecard.net.ru>
  8. http://www.elecard.com/peter/idct.shtml
  9. Rounding trick Copyright (c) 2000 Michel Lespinasse <walken@zoy.org>
  10. mmi port by leonvs@iae.nl
  11. */
  12. #include "../common.h"
  13. #include "mmi.h"
  14. #define BITS_INV_ACC 5 // 4 or 5 for IEEE
  15. #define SHIFT_INV_ROW (16 - BITS_INV_ACC)
  16. #define SHIFT_INV_COL (1 + BITS_INV_ACC)
  17. // assume SHIFT_INV_ROW == 11
  18. static int roundertable[8][4] align16 = {
  19. { 0x103ff, 0x103ff, 0x103ff, 0x103ff },
  20. { 1023, 1023, 1023, 1023}
  21. };
  22. #define TAB_i_04 0
  23. #define TAB_i_17 64
  24. #define TAB_i_26 128
  25. #define TAB_i_35 192
  26. static short rowtable[4][32] align16 = {
  27. {
  28. 16384, 16384, 22725, 12873, 21407, 8867, 19266, 4520,
  29. 16384, -16383, 19266, -22724, 8867, -21406, -4519, -12872,
  30. 16384, -16383, 12873, 4520, -8866, 21407, -22724, 19266,
  31. 16384, 16384, 4520, 19266, -21406, -8866, -12872, -22724},
  32. {
  33. 22725, 22725, 31521, 17855, 29692, 12299, 26722, 6270,
  34. 22725, -22724, 26722, -31520, 12299, -29691, -6269, -17854,
  35. 22725, -22724, 17855, 6270, -12298, 29692, -31520, 26722,
  36. 22725, 22725, 6270, 26722, -29691, -12298, -17854, -31520},
  37. {
  38. 21407, 21407, 29692, 16819, 27969, 11585, 25172, 5906,
  39. 21407, -21406, 25172, -29691, 11585, -27968, -5905, -16818,
  40. 21407, -21406, 16819, 5906, -11584, 27969, -29691, 25172,
  41. 21407, 21407, 5906, 25172, -27968, -11584, -16818, -29691},
  42. {
  43. 19266, 19266, 26722, 15137, 25172, 10426, 22654, 5315,
  44. 19266, -19265, 22654, -26721, 10426, -25171, -5314, -15136,
  45. 19266, -19265, 15137, 5315, -10425, 25172, -26721, 22654,
  46. 19266, 19266, 5315, 22654, -25171, -10425, -15136, -26721}
  47. };
  48. #define TG_3_16_minus_one 0
  49. #define ONE_plus_tg_3_16 16
  50. #define ONE_plus_tg_1_16 32
  51. #define TG_1_16_minus_one 48
  52. #define TG_2_16_minus_one 64
  53. #define ONE_plus_tg_2_16 80
  54. #define ZERO_ocos_4_16 96
  55. #define TG1 6518
  56. #define TG2 13573
  57. #define TG3 21895
  58. #define MN1 -32768
  59. #define PL1 32768
  60. #define CS4 23170
  61. static short coltable[7][8] align16 = {
  62. { MN1, TG3, MN1, TG3, MN1, TG3, MN1, TG3},
  63. {-TG3, -PL1, -TG3, -PL1, -TG3, -PL1, -TG3, -PL1},
  64. {-TG1, -PL1, -TG1, -PL1, -TG1, -PL1, -TG1, -PL1},
  65. { MN1, TG1, MN1, TG1, MN1, TG1, MN1, TG1},
  66. { MN1, TG2, MN1, TG2, MN1, TG2, MN1, TG2},
  67. {-TG2, -PL1, -TG2, -PL1, -TG2, -PL1, -TG2, -PL1},
  68. { CS4, 0, CS4, 0, CS4, 0, CS4, 0}
  69. };
  70. #define noprevh(rt, rd)
  71. #define DCT_8_INV_ROW1(rowoff, taboff, rnd, outreg) { \
  72. \
  73. lq($4, rowoff, $16); /* r16 = x7 x6 x5 x4 x3 x2 x1 x0 */ \
  74. lq($24, 0+taboff, $17); /* r17 = w19 w17 w3 w1 w18 w16 w2 w0 */ \
  75. pinth($16, $16, $16); /* r16 = x7 x3 x6 x2 x5 x1 x4 x0 */ \
  76. phmadh($17, $16, $17); /* r17 = (x7*w19+x3*w17)b0'' (x6*w3+x2*w1)a0'' (x5*w18+x1*w16)b0' (x4*w2+x0*w0)a0' */ \
  77. lq($24, 16+taboff, $18);/* r18 = w23 w21 w7 w5 w22 w20 w6 w4 */ \
  78. lq($24, 32+taboff, $19);/* r19 = w27 w25 w11 w9 w26 w24 w10 w8 */ \
  79. lq($24, 48+taboff, $20);/* r20 = w31 w29 w15 w13 w30 w28 w14 w12 */ \
  80. phmadh($18, $16, $18); /* r18 = (b1'')(a1'')(b1')(a1') */ \
  81. pcpyud($17, $17, $21); /* r21 = (b0'')(a0'')(b0'')(a0'') */ \
  82. paddw($17, $21, $17); /* r17 = (--)(--)(b0)(a0) */ \
  83. phmadh($19, $16, $19); /* r19 = (b2'')(a2'')(b2')(a2') */ \
  84. pcpyud($18, $18, $21); /* r21 = (b1'')(a1'')(b1'')(a1'') */ \
  85. paddw($18, $21, $18); /* r18 = (--)(--)(b1)(a1) */ \
  86. pcpyud($19, $19, $21); \
  87. phmadh($20, $16, $20); /* r12 = (b3'')(a3'')(b3')(a3') */ \
  88. paddw($19, $21, $19); /* r19 = (--)(--)(b2)(a2) */ \
  89. pextlw($19, $17, $16); /* r16 = (b2)(b0)(a2)(a0) */ \
  90. pcpyud($20, $20, $21); \
  91. paddw($20, $21, $20); /* r20 = (--)(--)(b3)(a3) */ \
  92. pextlw($20, $18, $17); /* r17 = (b3)(b1)(a3)(a1) */ \
  93. pextlw($17, $16, $20); /* r20 = (a3)(a2)(a1)(a0)" */ \
  94. pextuw($17, $16, $21); /* r21 = (b3)(b2)(b1)(b0) */ \
  95. paddw($20, rnd, $20); /* r20 = (a3)(a2)(a1)(a0) */\
  96. paddw($20, $21, $17); /* r17 = ()()()(a0+b0) */ \
  97. psubw($20, $21, $18); /* r18 = ()()()(a0-b0) */ \
  98. psraw($17, SHIFT_INV_ROW, $17); /* r17 = (y3 y2 y1 y0) */ \
  99. psraw($18, SHIFT_INV_ROW, $18); /* r18 = (y4 y5 y6 y7) */ \
  100. ppach($18, $17, outreg);/* out = y4 y5 y6 y7 y3 y2 y1 y0 Note order */ \
  101. }
  102. #define DCT_8_INV_COL4(pextop, blkoff, revop) { \
  103. lq($24, TG_3_16_minus_one, $2); /* r2 = (tn3)(-1) x 4 */ \
  104. pextop($11, $13, $3); /* r3 = (x3)(x5) x 4 */ \
  105. lq($24, ONE_plus_tg_3_16, $16); /* r16 = -((+1)(tn3)) x 4 */ \
  106. phmadh($3, $2, $17); /* r17 = (tm35) x 4 */ \
  107. lq($24, ONE_plus_tg_1_16, $2); /* r2 = -((+1)(tn1)) x 4 */ \
  108. phmadh($3, $16, $18); /* r18 = -(tp35) x 4 */ \
  109. lq($24, TG_1_16_minus_one, $16);/* r16 = (tn1)(-1) x 4 */ \
  110. pextop($9, $15, $3); /* r3 = (x1)(x7) x 4 */ \
  111. phmadh($3, $2, $19); \
  112. lq($24, ZERO_ocos_4_16, $2); /* r2 = (0)(cos4) x 4 */ \
  113. phmadh($3, $16, $20); /* r20 = (tm17) x 4 */ \
  114. psubw($0, $19, $19); /* r19 = (tp17) x 4 */ \
  115. paddw($19, $18, $3); /* r3 = t1 */ \
  116. paddw($20, $17, $16); /* r16 = t2 */ \
  117. psubw($20, $17, $23); /* r23 = b3 */ \
  118. psubw($19, $18, $20); /* r20 = b0 */ \
  119. paddw($3, $16, $17); /* (t1+t2) */ \
  120. psubw($3, $16, $18); /* (t1-t2) */ \
  121. psraw($17, 15, $17); \
  122. lq($24, TG_2_16_minus_one, $3); /* r3 = (tn2)(-1) x 4 */ \
  123. pmulth($17, $2, $21); /* r21 = b1 */ \
  124. psraw($18, 15, $18); \
  125. lq($24, ONE_plus_tg_2_16, $16); /* r16 = -((+1)(tn2)) x 4 */ \
  126. pmulth($18, $2, $22); /* r22 = b2 */ \
  127. \
  128. pextop($10, $14, $2); /* r2 = (x2)(x6) x 4 */ \
  129. phmadh($2, $3, $18); /* r18 = (tm26) x 4 */ \
  130. phmadh($2, $16, $19); /* r19 = -(tp26) x 4 */ \
  131. pextop($8, $0, $17); /* r17 = (x0)(0) x 4 */ \
  132. psraw($17, 1, $17); \
  133. pextop($12, $0, $16); /* r16 = (x4)(0) x 4 */ \
  134. psraw($16, 1, $16); \
  135. paddw($17, $16, $2); /* r2 = tp04 */ \
  136. psubw($17, $16, $3); /* r3 = tm04 */ \
  137. psubw($2, $19, $16); /* r16 = a0 */ \
  138. paddw($3, $18, $17); /* r17 = a1 */ \
  139. psubw($3, $18, $18); /* r18 = a2 */ \
  140. paddw($2, $19, $19); /* r19 = a3 */ \
  141. \
  142. paddw($16, $20, $2); /* y0 a0+b0 */ \
  143. psubw($16, $20, $16); /* y7 a0-b0 */ \
  144. psraw($2, SHIFT_INV_COL+15, $2); \
  145. psraw($16, SHIFT_INV_COL+15, $16); \
  146. ppach($0, $2, $2); \
  147. ppach($0, $16, $16); \
  148. revop($2, $2); \
  149. revop($16, $16); \
  150. sd3(2, 0+blkoff, 4); \
  151. sd3(16, 112+blkoff, 4); \
  152. \
  153. paddw($17, $21, $3); /* y1 a1+b1 */ \
  154. psubw($17, $21, $17); /* y6 a1-b1 */ \
  155. psraw($3, SHIFT_INV_COL+15, $3); \
  156. psraw($17, SHIFT_INV_COL+15, $17); \
  157. ppach($0, $3, $3); \
  158. ppach($0, $17, $17); \
  159. revop($3, $3); \
  160. revop($17, $17); \
  161. sd3(3, 16+blkoff, 4); \
  162. sd3(17, 96+blkoff, 4); \
  163. \
  164. paddw($18, $22, $2); /* y2 a2+b2 */ \
  165. psubw($18, $22, $18); /* y5 a2-b2 */ \
  166. psraw($2, SHIFT_INV_COL+15, $2); \
  167. psraw($18, SHIFT_INV_COL+15, $18); \
  168. ppach($0, $2, $2); \
  169. ppach($0, $18, $18); \
  170. revop($2, $2); \
  171. revop($18, $18); \
  172. sd3(2, 32+blkoff, 4); \
  173. sd3(18, 80+blkoff, 4); \
  174. \
  175. paddw($19, $23, $3); /* y3 a3+b3 */ \
  176. psubw($19, $23, $19); /* y4 a3-b3 */ \
  177. psraw($3, SHIFT_INV_COL+15, $3); \
  178. psraw($19, SHIFT_INV_COL+15, $19); \
  179. ppach($0, $3, $3); \
  180. ppach($0, $19, $19); \
  181. revop($3, $3); \
  182. revop($19, $19); \
  183. sd3(3, 48+blkoff, 4); \
  184. sd3(19, 64+blkoff, 4); \
  185. }
  186. void ff_mmi_idct(int16_t * block)
  187. {
  188. /* $4 = block */
  189. __asm__ __volatile__("la $7, %0"::"m"(roundertable[0][0]));
  190. __asm__ __volatile__("la $24, %0"::"m"(rowtable[0][0]));
  191. lq($7, 0, $6);
  192. lq($7, 16, $7);
  193. DCT_8_INV_ROW1(0, TAB_i_04, $6, $8);
  194. DCT_8_INV_ROW1(16, TAB_i_17, $7, $9);
  195. DCT_8_INV_ROW1(32, TAB_i_26, $7, $10);
  196. DCT_8_INV_ROW1(48, TAB_i_35, $7, $11);
  197. DCT_8_INV_ROW1(64, TAB_i_04, $7, $12);
  198. DCT_8_INV_ROW1(80, TAB_i_35, $7, $13);
  199. DCT_8_INV_ROW1(96, TAB_i_26, $7, $14);
  200. DCT_8_INV_ROW1(112, TAB_i_17, $7, $15);
  201. __asm__ __volatile__("la $24, %0"::"m"(coltable[0][0]));
  202. DCT_8_INV_COL4(pextlh, 0, noprevh);
  203. DCT_8_INV_COL4(pextuh, 8, prevh);
  204. //let savedtemp regs be saved
  205. __asm__ __volatile__(" ":::"$16", "$17", "$18", "$19", "$20", "$21",
  206. "$22", "$23", "$6", "$7");
  207. }