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 25Prototype : void ff_bfin_vp3_idct(DCTELEM *in) 26 27Registers Used : A0, A1, R0-R7, I0-I3, B0, B2, B3, M0-M2, L0-L3, P0-P5, LC0. 28 29*/ 30 31#include "config_bfin.h" 32 33#ifdef __FDPIC__ 34.section .l1.data.B,"aw",@progbits 35#else 36.data 37#endif 38 39.align 4; 40coefs: 41.short 0x5a82; // C4 42.short 0x5a82; // C4 43.short 0x30FC; //cos(3pi/8) C6 44.short 0x7642; //cos(pi/8) C2 45.short 0x18F9; //cos(7pi/16) 46.short 0x7D8A; //cos(pi/16) 47.short 0x471D; //cos(5pi/16) 48.short 0x6A6E; //cos(3pi/16) 49.short 0x18F9; //cos(7pi/16) 50.short 0x7D8A; //cos(pi/16) 51 52#ifdef __FDPIC__ 53.section .l1.data.A 54#endif 55 56vtmp: .space 256 57 58#define TMP0 FP-8 59#define TMP1 FP-12 60#define TMP2 FP-16 61 62 63.text 64DEFUN(vp3_idct,mL1, 65 (DCTELEM *block)): 66 67/********************** Function Prologue *********************************/ 68 link 16; 69 [--SP] = (R7:4, P5:3); // Push the registers onto the stack. 70 B0 = R0; // Pointer to Input matrix 71 RELOC(R1, P3, coefs); // Pointer to Coefficients 72 RELOC(R2, P3, vtmp); // Pointer to Temporary matrix 73 B3 = R1; 74 B2 = R2; 75 L3 = 20; // L3 is used for making the coefficient array 76 // circular. 77 // MUST BE RESTORED TO ZERO at function exit. 78 M1 = 16 (X); // All these registers are initialized for 79 M3 = 8(X); // modifying address offsets. 80 81 I0 = B0; // I0 points to Input Element (0, 0). 82 I2 = B0; // I2 points to Input Element (0, 0). 83 I2 += M3 || R0.H = W[I0]; 84 // Element 0 is read into R0.H 85 I1 = I2; // I1 points to input Element (0, 6). 86 I1 += 4 || R0.L = W[I2++]; 87 // I2 points to input Element (0, 4). 88 // Element 4 is read into R0.L. 89 P2 = 8 (X); 90 P3 = 32 (X); 91 P4 = -32 (X); 92 P5 = 98 (X); 93 R7 = 0x8000(Z); 94 I3 = B3; // I3 points to Coefficients 95 P0 = B2; // P0 points to array Element (0, 0) of temp 96 P1 = B2; 97 R7 = [I3++] || [TMP2]=R7; // Coefficient C4 is read into R7.H and R7.L. 98 MNOP; 99 NOP; 100 101 /* 102 * A1 = Y0 * cos(pi/4) 103 * A0 = Y0 * cos(pi/4) 104 * A1 = A1 + Y4 * cos(pi/4) 105 * A0 = A0 - Y4 * cos(pi/4) 106 * load: 107 * R1=(Y2,Y6) 108 * R7=(C2,C6) 109 * res: 110 * R3=Y0, R2=Y4 111 */ 112 A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+= 4 || R1.L=W[I1++]; 113 R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++]; 114 115 LSETUP (.0, .1) LC0 = P2; // perform 8 1d idcts 116 117 P2 = 112 (X); 118 P1 = P1 + P2; // P1 points to element (7, 0) of temp buffer. 119 P2 = -94(X); 120 121.0: 122 /* 123 * A1 = Y2 * cos(3pi/8) 124 * A0 = Y2 * cos(pi/8) 125 * A1 = A1 - Y6 * cos(pi/8) 126 * A0 = A0 + Y6 * cos(3pi/8) 127 * R5 = (Y1,Y7) 128 * R7 = (C1,C7) 129 * res: 130 * R1=Y2, R0=Y6 131 */ 132 A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0]; 133 R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++]; 134 /* 135 * Y0 = Y0 + Y6. 136 * Y4 = Y4 + Y2. 137 * Y2 = Y4 - Y2. 138 * Y6 = Y0 - Y6. 139 * R3 is saved 140 * R6.l=Y3 141 * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6 142 */ 143 R3=R3+R0, R0=R3-R0; 144 R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--]; 145 /* 146 * Compute the odd portion (1,3,5,7) even is done. 147 * 148 * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3. 149 * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3. 150 * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3. 151 * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3. 152 */ 153 // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7) 154 A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--]; 155 A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++]; 156 A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5) 157 R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS); 158 A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0]; 159 A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7) 160 A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS); 161 R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1; 162 // R3=Y1, R2=Y7, R7=Y5, R6=Y3 163 164 /* Transpose write column. */ 165 R5.H=R4+R2 (RND12); // Y0=Y0+Y7 166 R5.L=R4-R2 (RND12) || R4 = [TMP1]; // Y7=Y7-Y0 167 R2.H=R1+R7 (RND12) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0 168 R2.L=R1-R7 (RND12) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7 169 R5.H=R0-R3 (RND12) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2 170 R5.L=R0+R3 (RND12) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5 171 R3.H=R4-R6 (RND12) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1 172 R3.L=R4+R6 (RND12) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6 173 174 /* pipeline loop start, + drain Y3, Y4 */ 175 A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--]; 176.1: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++]; 177 178 179 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 /* 197 * A1 = Y0 * cos(pi/4) 198 * A0 = Y0 * cos(pi/4) 199 * A1 = A1 + Y4 * cos(pi/4) 200 * A0 = A0 - Y4 * cos(pi/4) 201 * load: 202 * R1=(Y2,Y6) 203 * R7=(C2,C6) 204 * res: 205 * R3=Y0, R2=Y4 206 */ 207 A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || I0+=4 || R1.L=W[I1++]; 208 R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || R1.H=W[I0--] || R7=[I3++]; 209 210 LSETUP (.2, .3) LC0 = P2; // peform 8 1d idcts 211 P2 = 112 (X); 212 P1 = P1 + P2; 213 P2 = -94(X); 214 215.2: 216 /* 217 * A1 = Y2 * cos(3pi/8) 218 * A0 = Y2 * cos(pi/8) 219 * A1 = A1 - Y6 * cos(pi/8) 220 * A0 = A0 + Y6 * cos(3pi/8) 221 * R5 = (Y1,Y7) 222 * R7 = (C1,C7) 223 * res: 224 * R1=Y2, R0=Y6 225 */ 226 A1=R7.L*R1.H, A0=R7.H*R1.H (IS) || I0+=4 || R5.H=W[I0]; 227 R1=(A1-=R7.H*R1.L), R0=(A0+=R7.L*R1.L) (IS) || R5.L=W[I1--] || R7=[I3++]; 228 /* 229 * Y0 = Y0 + Y6. 230 * Y4 = Y4 + Y2. 231 * Y2 = Y4 - Y2. 232 * Y6 = Y0 - Y6. 233 * R3 is saved 234 * R6.l=Y3 235 * note: R3: Y0, R2: Y4, R1: Y2, R0: Y6 236 */ 237 R3=R3+R0, R0=R3-R0; 238 R2=R2+R1, R1=R2-R1 || [TMP0]=R3 || R6.L=W[I0--]; 239 /* 240 * Compute the odd portion (1,3,5,7) even is done. 241 * 242 * Y1 = C7 * Y1 - C1 * Y7 + C3 * Y5 - C5 * Y3. 243 * Y7 = C1 * Y1 + C7 * Y7 + C5 * Y5 + C3 * Y3. 244 * Y5 = C5 * Y1 + C3 * Y7 + C7 * Y5 - C1 * Y3. 245 * Y3 = C3 * Y1 - C5 * Y7 - C1 * Y5 - C7 * Y3. 246 */ 247 // R5=(Y1,Y7) R6=(Y5,Y3) // R7=(C1,C7) 248 A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || [TMP1]=R2 || R6.H=W[I2--]; 249 A1-=R7.H*R5.L, A0+=R7.L*R5.L (IS) || I0-=4 || R7=[I3++]; 250 A1+=R7.H*R6.H, A0+=R7.L*R6.H (IS) || I0+=M1; // R7=(C3,C5) 251 R3 =(A1-=R7.L*R6.L), R2 =(A0+=R7.H*R6.L) (IS); 252 A1 =R7.L*R5.H, A0 =R7.H*R5.H (IS) || R4=[TMP0]; 253 A1+=R7.H*R5.L, A0-=R7.L*R5.L (IS) || I1+=M1 || R7=[I3++]; // R7=(C1,C7) 254 A1+=R7.L*R6.H, A0-=R7.H*R6.H (IS); 255 R7 =(A1-=R7.H*R6.L), R6 =(A0-=R7.L*R6.L) (IS) || I2+=M1; 256 // R3=Y1, R2=Y7, R7=Y5, R6=Y3 257 258 /* Transpose write column. */ 259 R5.H=R4+R2 (RND20); // Y0=Y0+Y7 260 R5.L=R4-R2 (RND20) || R4 = [TMP1]; // Y7=Y7-Y0 261 R5=R5>>>2(v); 262 R2.H=R1+R7 (RND20) || W[P0++P3]=R5.H; // Y2=Y2+Y5 st Y0 263 R2.L=R1-R7 (RND20) || W[P1++P4]=R5.L || R7=[I3++]; // Y5=Y2-Y5 st Y7 264 R2=R2>>>2(v); 265 R5.H=R0-R3 (RND20) || W[P0++P3]=R2.H || R1.L=W[I1++]; // Y1=Y6-Y1 st Y2 266 R5.L=R0+R3 (RND20) || W[P1++P4]=R2.L || R0.H=W[I0++]; // Y6=Y6+Y1 st Y5 267 R5=R5>>>2(v); 268 R3.H=R4-R6 (RND20) || W[P0++P3]=R5.H || R0.L=W[I2++]; // Y3=Y3-Y4 st Y1 269 R3.L=R4+R6 (RND20) || W[P1++P4]=R5.L || R1.H=W[I0++]; // Y4=Y3+Y4 st Y6 270 R3=R3>>>2(v); 271 /* pipeline loop start, + drain Y3, Y4 */ 272 A1=R7.H*R0.H, A0=R7.H*R0.H (IS) || W[P0++P2]= R3.H || R1.H = W[I0--]; 273.3: R3=(A1+=R7.H*R0.L), R2=(A0-=R7.H*R0.L) (IS) || W[P1++P5]= R3.L || R7 = [I3++]; 274 275 L3 = 0; 276 (R7:4,P5:3)=[SP++]; 277 unlink; 278 RTS; 279DEFUN_END(vp3_idct) 280 281 282