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.

305 lines
11KB

  1. /*
  2. * idct BlackFin
  3. *
  4. * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav 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. * Libav 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 Libav; 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_idct(DCTELEM *in)
  25. Registers Used : A0, A1, R0-R7, I0-I3, B0, B2, B3, M0-M2, L0-L3, P0-P5, LC0.
  26. Performance :
  27. Code Size : 498 Bytes.
  28. Cycle Count : 417 Cycles
  29. -----------------------------------------------------------
  30. Libav conformance testing results
  31. -----------------------------------------------------------
  32. dct-test: modified with the following
  33. dct_error("BFINidct", 1, ff_bfin_idct, idct, test);
  34. produces the following output
  35. libavcodec> ./dct-test -i
  36. Libav DCT/IDCT test
  37. 8 15 -2 21 24 17 0 10
  38. 2 -10 -5 -5 -3 7 -14 -3
  39. 2 -13 -10 -19 18 -6 6 -2
  40. 9 4 16 -3 9 12 10 15
  41. 15 -9 -2 10 1 16 0 -15
  42. -15 5 7 3 13 0 13 20
  43. -6 -15 24 9 -18 1 9 -22
  44. -8 25 23 2 -7 0 30 13
  45. IDCT BFINidct: err_inf=1 err2=0.01002344 syserr=0.00150000 maxout=266 blockSumErr=64
  46. IDCT BFINidct: 88.3 kdct/s
  47. */
  48. #include "config.h"
  49. #include "config_bfin.h"
  50. #if defined(__FDPIC__) && CONFIG_SRAM
  51. .section .l1.data.B,"aw",@progbits
  52. #else
  53. .data
  54. #endif
  55. .align 4;
  56. coefs:
  57. .short 0x5a82; // C4
  58. .short 0x5a82; // C4
  59. .short 0x30FC; //cos(3pi/8) C6
  60. .short 0x7642; //cos(pi/8) C2
  61. .short 0x18F9; //cos(7pi/16)
  62. .short 0x7D8A; //cos(pi/16)
  63. .short 0x471D; //cos(5pi/16)
  64. .short 0x6A6E; //cos(3pi/16)
  65. .short 0x18F9; //cos(7pi/16)
  66. .short 0x7D8A; //cos(pi/16)
  67. #if defined(__FDPIC__) && CONFIG_SRAM
  68. .section .l1.data.A,"aw",@progbits
  69. #endif
  70. vtmp: .space 256
  71. #define TMP0 FP-8
  72. #define TMP1 FP-12
  73. #define TMP2 FP-16
  74. .text
  75. DEFUN(idct,mL1,
  76. (DCTELEM *block)):
  77. /********************** Function Prologue *********************************/
  78. link 16;
  79. [--SP] = (R7:4, P5:3); // Push the registers onto the stack.
  80. B0 = R0; // Pointer to Input matrix
  81. RELOC(R1, P3, coefs); // Pointer to Coefficients
  82. RELOC(R2, P3, vtmp); // Pointer to Temporary matrix
  83. B3 = R1;
  84. B2 = R2;
  85. L3 = 20; // L3 is used for making the coefficient array
  86. // circular.
  87. // MUST BE RESTORED TO ZERO at function exit.
  88. M1 = 16 (X); // All these registers are initialized for
  89. M3 = 8(X); // modifying address offsets.
  90. I0 = B0; // I0 points to Input Element (0, 0).
  91. I2 = B0; // I2 points to Input Element (0, 0).
  92. I2 += M3 || R0.H = W[I0];
  93. // Element 0 is read into R0.H
  94. I1 = I2; // I1 points to input Element (0, 6).
  95. I1 += 4 || R0.L = W[I2++];
  96. // I2 points to input Element (0, 4).
  97. // Element 4 is read into R0.L.
  98. P2 = 8 (X);
  99. P3 = 32 (X);
  100. P4 = -32 (X);
  101. P5 = 98 (X);
  102. R7 = 0x8000(Z);
  103. I3 = B3; // I3 points to Coefficients
  104. P0 = B2; // P0 points to array Element (0, 0) of temp
  105. P1 = B2;
  106. R7 = [I3++] || [TMP2]=R7; // Coefficient C4 is read into R7.H and R7.L.
  107. MNOP;
  108. NOP;
  109. /*
  110. * A1 = Y0 * cos(pi/4)
  111. * A0 = Y0 * cos(pi/4)
  112. * A1 = A1 + Y4 * cos(pi/4)
  113. * A0 = A0 - Y4 * cos(pi/4)
  114. * load:
  115. * R1=(Y2,Y6)
  116. * R7=(C2,C6)
  117. * res:
  118. * R3=Y0, R2=Y4
  119. */
  120. A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+= 4 || R1.L=W[I1++];
  121. R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++];
  122. LSETUP (.0, .1) LC0 = P2; // perform 8 1d idcts
  123. P2 = 112 (X);
  124. P1 = P1 + P2; // P1 points to element (7, 0) of temp buffer.
  125. P2 = -94(X);
  126. .0:
  127. /*
  128. * A1 = Y2 * cos(3pi/8)
  129. * A0 = Y2 * cos(pi/8)
  130. * A1 = A1 - Y6 * cos(pi/8)
  131. * A0 = A0 + Y6 * cos(3pi/8)
  132. * R5 = (Y1,Y7)
  133. * R7 = (C1,C7)
  134. * res:
  135. * R1=Y2, R0=Y6
  136. */
  137. A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0];
  138. R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++];
  139. /*
  140. * Y0 = Y0 + Y6.
  141. * Y4 = Y4 + Y2.
  142. * Y2 = Y4 - Y2.
  143. * Y6 = Y0 - Y6.
  144. * R3 is saved
  145. * R6.l=Y3
  146. * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6
  147. */
  148. R3=R3+R0, R0=R3-R0;
  149. R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--];
  150. /*
  151. * Compute the odd portion (1,3,5,7) even is done.
  152. *
  153. * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3.
  154. * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3.
  155. * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3.
  156. * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3.
  157. */
  158. // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7)
  159. A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--];
  160. A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++];
  161. A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5)
  162. R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS);
  163. A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0];
  164. A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7)
  165. A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS);
  166. R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1;
  167. // R3=Y1, R2=Y7, R7=Y5, R6=Y3
  168. /* Transpose write column. */
  169. R5.H=R4+R2 (RND12); // Y0=Y0+Y7
  170. R5.L=R4-R2 (RND12) || R4 = [TMP1]; // Y7=Y7-Y0
  171. R2.H=R1+R7 (RND12) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0
  172. R2.L=R1-R7 (RND12) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7
  173. R5.H=R0-R3 (RND12) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2
  174. R5.L=R0+R3 (RND12) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5
  175. R3.H=R4-R6 (RND12) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1
  176. R3.L=R4+R6 (RND12) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6
  177. /* pipeline loop start, + drain Y3, Y4 */
  178. A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--];
  179. .1: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++];
  180. I0 = B2; // I0 points to Input Element (0, 0)
  181. I2 = B2; // I2 points to Input Element (0, 0)
  182. I2 += M3 || R0.H = W[I0];
  183. // Y0 is read in R0.H
  184. I1 = I2; // I1 points to input Element (0, 6)
  185. I1 += 4 || R0.L = W[I2++];
  186. // I2 points to input Element (0, 4)
  187. // Y4 is read in R0.L
  188. P2 = 8 (X);
  189. I3 = B3; // I3 points to Coefficients
  190. P0 = B0; // P0 points to array Element (0, 0) for writing
  191. // output
  192. P1 = B0;
  193. R7 = [I3++]; // R7.H = C4 and R7.L = C4
  194. NOP;
  195. /*
  196. * A1 = Y0 * cos(pi/4)
  197. * A0 = Y0 * cos(pi/4)
  198. * A1 = A1 + Y4 * cos(pi/4)
  199. * A0 = A0 - Y4 * cos(pi/4)
  200. * load:
  201. * R1=(Y2,Y6)
  202. * R7=(C2,C6)
  203. * res:
  204. * R3=Y0, R2=Y4
  205. */
  206. A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+=4 || R1.L=W[I1++];
  207. R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++];
  208. LSETUP (.2, .3) LC0 = P2; // peform 8 1d idcts
  209. P2 = 112 (X);
  210. P1 = P1 + P2;
  211. P2 = -94(X);
  212. .2:
  213. /*
  214. * A1 = Y2 * cos(3pi/8)
  215. * A0 = Y2 * cos(pi/8)
  216. * A1 = A1 - Y6 * cos(pi/8)
  217. * A0 = A0 + Y6 * cos(3pi/8)
  218. * R5 = (Y1,Y7)
  219. * R7 = (C1,C7)
  220. * res:
  221. * R1=Y2, R0=Y6
  222. */
  223. A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0];
  224. R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++];
  225. /*
  226. * Y0 = Y0 + Y6.
  227. * Y4 = Y4 + Y2.
  228. * Y2 = Y4 - Y2.
  229. * Y6 = Y0 - Y6.
  230. * R3 is saved
  231. * R6.l=Y3
  232. * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6
  233. */
  234. R3=R3+R0, R0=R3-R0;
  235. R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--];
  236. /*
  237. * Compute the odd portion (1,3,5,7) even is done.
  238. *
  239. * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3.
  240. * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3.
  241. * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3.
  242. * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3.
  243. */
  244. // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7)
  245. A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--];
  246. A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++];
  247. A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5)
  248. R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS);
  249. A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0];
  250. A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7)
  251. A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS);
  252. R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1;
  253. // R3=Y1, R2=Y7, R7=Y5, R6=Y3
  254. /* Transpose write column. */
  255. R5.H=R4+R2 (RND20); // Y0=Y0+Y7
  256. R5.L=R4-R2 (RND20) || R4 = [TMP1]; // Y7=Y7-Y0
  257. R2.H=R1+R7 (RND20) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0
  258. R2.L=R1-R7 (RND20) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7
  259. R5.H=R0-R3 (RND20) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2
  260. R5.L=R0+R3 (RND20) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5
  261. R3.H=R4-R6 (RND20) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1
  262. R3.L=R4+R6 (RND20) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6
  263. /* pipeline loop start, + drain Y3, Y4 */
  264. A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--];
  265. .3: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++];
  266. L3 = 0;
  267. (R7:4,P5:3)=[SP++];
  268. unlink;
  269. RTS;
  270. DEFUN_END(idct)