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.

282 lines
10KB

  1. /*
  2. * vp3_idct BlackFin
  3. *
  4. * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /*
  23. This blackfin DSP code implements an 8x8 inverse type II DCT.
  24. Prototype : void ff_bfin_vp3_idct(DCTELEM *in)
  25. Registers Used : A0, A1, R0-R7, I0-I3, B0, B2, B3, M0-M2, L0-L3, P0-P5, LC0.
  26. */
  27. #include "config_bfin.h"
  28. #ifdef __FDPIC__
  29. .section .l1.data.B,"aw",@progbits
  30. #else
  31. .data
  32. #endif
  33. .align 4;
  34. coefs:
  35. .short 0x5a82; // C4
  36. .short 0x5a82; // C4
  37. .short 0x30FC; //cos(3pi/8) C6
  38. .short 0x7642; //cos(pi/8) C2
  39. .short 0x18F9; //cos(7pi/16)
  40. .short 0x7D8A; //cos(pi/16)
  41. .short 0x471D; //cos(5pi/16)
  42. .short 0x6A6E; //cos(3pi/16)
  43. .short 0x18F9; //cos(7pi/16)
  44. .short 0x7D8A; //cos(pi/16)
  45. #ifdef __FDPIC__
  46. .section .l1.data.A
  47. #endif
  48. vtmp: .space 256
  49. #define TMP0 FP-8
  50. #define TMP1 FP-12
  51. #define TMP2 FP-16
  52. .text
  53. DEFUN(vp3_idct,mL1,
  54. (DCTELEM *block)):
  55. /********************** Function Prologue *********************************/
  56. link 16;
  57. [--SP] = (R7:4, P5:3); // Push the registers onto the stack.
  58. B0 = R0; // Pointer to Input matrix
  59. RELOC(R1, P3, coefs); // Pointer to Coefficients
  60. RELOC(R2, P3, vtmp); // Pointer to Temporary matrix
  61. B3 = R1;
  62. B2 = R2;
  63. L3 = 20; // L3 is used for making the coefficient array
  64. // circular.
  65. // MUST BE RESTORED TO ZERO at function exit.
  66. M1 = 16 (X); // All these registers are initialized for
  67. M3 = 8(X); // modifying address offsets.
  68. I0 = B0; // I0 points to Input Element (0, 0).
  69. I2 = B0; // I2 points to Input Element (0, 0).
  70. I2 += M3 || R0.H = W[I0];
  71. // Element 0 is read into R0.H
  72. I1 = I2; // I1 points to input Element (0, 6).
  73. I1 += 4 || R0.L = W[I2++];
  74. // I2 points to input Element (0, 4).
  75. // Element 4 is read into R0.L.
  76. P2 = 8 (X);
  77. P3 = 32 (X);
  78. P4 = -32 (X);
  79. P5 = 98 (X);
  80. R7 = 0x8000(Z);
  81. I3 = B3; // I3 points to Coefficients
  82. P0 = B2; // P0 points to array Element (0, 0) of temp
  83. P1 = B2;
  84. R7 = [I3++] || [TMP2]=R7; // Coefficient C4 is read into R7.H and R7.L.
  85. MNOP;
  86. NOP;
  87. /*
  88. * A1 = Y0 * cos(pi/4)
  89. * A0 = Y0 * cos(pi/4)
  90. * A1 = A1 + Y4 * cos(pi/4)
  91. * A0 = A0 - Y4 * cos(pi/4)
  92. * load:
  93. * R1=(Y2,Y6)
  94. * R7=(C2,C6)
  95. * res:
  96. * R3=Y0, R2=Y4
  97. */
  98. A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+= 4 || R1.L=W[I1++];
  99. R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++];
  100. LSETUP (.0, .1) LC0 = P2; // perform 8 1d idcts
  101. P2 = 112 (X);
  102. P1 = P1 + P2; // P1 points to element (7, 0) of temp buffer.
  103. P2 = -94(X);
  104. .0:
  105. /*
  106. * A1 = Y2 * cos(3pi/8)
  107. * A0 = Y2 * cos(pi/8)
  108. * A1 = A1 - Y6 * cos(pi/8)
  109. * A0 = A0 + Y6 * cos(3pi/8)
  110. * R5 = (Y1,Y7)
  111. * R7 = (C1,C7)
  112. * res:
  113. * R1=Y2, R0=Y6
  114. */
  115. A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0];
  116. R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++];
  117. /*
  118. * Y0 = Y0 + Y6.
  119. * Y4 = Y4 + Y2.
  120. * Y2 = Y4 - Y2.
  121. * Y6 = Y0 - Y6.
  122. * R3 is saved
  123. * R6.l=Y3
  124. * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6
  125. */
  126. R3=R3+R0, R0=R3-R0;
  127. R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--];
  128. /*
  129. * Compute the odd portion (1,3,5,7) even is done.
  130. *
  131. * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3.
  132. * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3.
  133. * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3.
  134. * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3.
  135. */
  136. // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7)
  137. A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--];
  138. A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++];
  139. A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5)
  140. R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS);
  141. A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0];
  142. A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7)
  143. A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS);
  144. R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1;
  145. // R3=Y1, R2=Y7, R7=Y5, R6=Y3
  146. /* Transpose write column. */
  147. R5.H=R4+R2 (RND12); // Y0=Y0+Y7
  148. R5.L=R4-R2 (RND12) || R4 = [TMP1]; // Y7=Y7-Y0
  149. R2.H=R1+R7 (RND12) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0
  150. R2.L=R1-R7 (RND12) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7
  151. R5.H=R0-R3 (RND12) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2
  152. R5.L=R0+R3 (RND12) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5
  153. R3.H=R4-R6 (RND12) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1
  154. R3.L=R4+R6 (RND12) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6
  155. /* pipeline loop start, + drain Y3, Y4 */
  156. A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--];
  157. .1: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++];
  158. I0 = B2; // I0 points to Input Element (0, 0)
  159. I2 = B2; // I2 points to Input Element (0, 0)
  160. I2 += M3 || R0.H = W[I0];
  161. // Y0 is read in R0.H
  162. I1 = I2; // I1 points to input Element (0, 6)
  163. I1 += 4 || R0.L = W[I2++];
  164. // I2 points to input Element (0, 4)
  165. // Y4 is read in R0.L
  166. P2 = 8 (X);
  167. I3 = B3; // I3 points to Coefficients
  168. P0 = B0; // P0 points to array Element (0, 0) for writing
  169. // output
  170. P1 = B0;
  171. R7 = [I3++]; // R7.H = C4 and R7.L = C4
  172. NOP;
  173. /*
  174. * A1 = Y0 * cos(pi/4)
  175. * A0 = Y0 * cos(pi/4)
  176. * A1 = A1 + Y4 * cos(pi/4)
  177. * A0 = A0 - Y4 * cos(pi/4)
  178. * load:
  179. * R1=(Y2,Y6)
  180. * R7=(C2,C6)
  181. * res:
  182. * R3=Y0, R2=Y4
  183. */
  184. A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+=4 || R1.L=W[I1++];
  185. R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++];
  186. LSETUP (.2, .3) LC0 = P2; // peform 8 1d idcts
  187. P2 = 112 (X);
  188. P1 = P1 + P2;
  189. P2 = -94(X);
  190. .2:
  191. /*
  192. * A1 = Y2 * cos(3pi/8)
  193. * A0 = Y2 * cos(pi/8)
  194. * A1 = A1 - Y6 * cos(pi/8)
  195. * A0 = A0 + Y6 * cos(3pi/8)
  196. * R5 = (Y1,Y7)
  197. * R7 = (C1,C7)
  198. * res:
  199. * R1=Y2, R0=Y6
  200. */
  201. A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0];
  202. R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++];
  203. /*
  204. * Y0 = Y0 + Y6.
  205. * Y4 = Y4 + Y2.
  206. * Y2 = Y4 - Y2.
  207. * Y6 = Y0 - Y6.
  208. * R3 is saved
  209. * R6.l=Y3
  210. * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6
  211. */
  212. R3=R3+R0, R0=R3-R0;
  213. R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--];
  214. /*
  215. * Compute the odd portion (1,3,5,7) even is done.
  216. *
  217. * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3.
  218. * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3.
  219. * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3.
  220. * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3.
  221. */
  222. // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7)
  223. A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--];
  224. A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++];
  225. A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5)
  226. R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS);
  227. A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0];
  228. A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7)
  229. A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS);
  230. R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1;
  231. // R3=Y1, R2=Y7, R7=Y5, R6=Y3
  232. /* Transpose write column. */
  233. R5.H=R4+R2 (RND20); // Y0=Y0+Y7
  234. R5.L=R4-R2 (RND20) || R4 = [TMP1]; // Y7=Y7-Y0
  235. R5=R5>>>2(v);
  236. R2.H=R1+R7 (RND20) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0
  237. R2.L=R1-R7 (RND20) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7
  238. R2=R2>>>2(v);
  239. R5.H=R0-R3 (RND20) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2
  240. R5.L=R0+R3 (RND20) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5
  241. R5=R5>>>2(v);
  242. R3.H=R4-R6 (RND20) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1
  243. R3.L=R4+R6 (RND20) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6
  244. R3=R3>>>2(v);
  245. /* pipeline loop start, + drain Y3, Y4 */
  246. A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--];
  247. .3: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++];
  248. L3 = 0;
  249. (R7:4,P5:3)=[SP++];
  250. unlink;
  251. RTS;
  252. DEFUN_END(vp3_idct)