FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
idct_sh4.c
Go to the documentation of this file.
1 /*
2  * idct for sh4
3  *
4  * Copyright (c) 2001-2003 BERO <bero@geocities.co.jp>
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 #include "dsputil_sh4.h"
24 #include "sh4.h"
25 
26 #define c1 1.38703984532214752434 /* sqrt(2)*cos(1*pi/16) */
27 #define c2 1.30656296487637657577 /* sqrt(2)*cos(2*pi/16) */
28 #define c3 1.17587560241935884520 /* sqrt(2)*cos(3*pi/16) */
29 #define c4 1.00000000000000000000 /* sqrt(2)*cos(4*pi/16) */
30 #define c5 0.78569495838710234903 /* sqrt(2)*cos(5*pi/16) */
31 #define c6 0.54119610014619712324 /* sqrt(2)*cos(6*pi/16) */
32 #define c7 0.27589937928294311353 /* sqrt(2)*cos(7*pi/16) */
33 
34 static const float even_table[] __attribute__ ((aligned(8))) = {
35  c4, c4, c4, c4,
36  c2, c6,-c6,-c2,
37  c4,-c4,-c4, c4,
38  c6,-c2, c2,-c6
39 };
40 
41 static const float odd_table[] __attribute__ ((aligned(8))) = {
42  c1, c3, c5, c7,
43  c3,-c7,-c1,-c5,
44  c5,-c1, c7, c3,
45  c7,-c5, c3,-c1
46 };
47 
48 #undef c1
49 #undef c2
50 #undef c3
51 #undef c4
52 #undef c5
53 #undef c6
54 #undef c7
55 
56 #define load_matrix(table) \
57  do { \
58  const float *t = table; \
59  __asm__ volatile( \
60  " fschg\n" \
61  " fmov @%0+,xd0\n" \
62  " fmov @%0+,xd2\n" \
63  " fmov @%0+,xd4\n" \
64  " fmov @%0+,xd6\n" \
65  " fmov @%0+,xd8\n" \
66  " fmov @%0+,xd10\n" \
67  " fmov @%0+,xd12\n" \
68  " fmov @%0+,xd14\n" \
69  " fschg\n" \
70  : "+r"(t) \
71  ); \
72  } while (0)
73 
74 #define ftrv() \
75  __asm__ volatile("ftrv xmtrx,fv0" \
76  : "+f"(fr0),"+f"(fr1),"+f"(fr2),"+f"(fr3));
77 
78 #define DEFREG \
79  register float fr0 __asm__("fr0"); \
80  register float fr1 __asm__("fr1"); \
81  register float fr2 __asm__("fr2"); \
82  register float fr3 __asm__("fr3")
83 
84 #define DESCALE(x,n) (x)*(1.0f/(1<<(n)))
85 
86 /* this code work worse on gcc cvs. 3.2.3 work fine */
87 
88 
89 //optimized
90 
91 void ff_idct_sh4(int16_t *block)
92 {
93  DEFREG;
94 
95  int i;
96  float tblock[8*8],*fblock;
97  int ofs1,ofs2,ofs3;
98  int fpscr;
99 
100  fp_single_enter(fpscr);
101 
102  /* row */
103 
104  /* even part */
106 
107  fblock = tblock+4;
108  i = 8;
109  do {
110  fr0 = block[0];
111  fr1 = block[2];
112  fr2 = block[4];
113  fr3 = block[6];
114  block+=8;
115  ftrv();
116  *--fblock = fr3;
117  *--fblock = fr2;
118  *--fblock = fr1;
119  *--fblock = fr0;
120  fblock+=8+4;
121  } while(--i);
122  block-=8*8;
123  fblock-=8*8+4;
124 
126 
127  i = 8;
128 
129  do {
130  float t0,t1,t2,t3;
131  fr0 = block[1];
132  fr1 = block[3];
133  fr2 = block[5];
134  fr3 = block[7];
135  block+=8;
136  ftrv();
137  t0 = *fblock++;
138  t1 = *fblock++;
139  t2 = *fblock++;
140  t3 = *fblock++;
141  fblock+=4;
142  *--fblock = t0 - fr0;
143  *--fblock = t1 - fr1;
144  *--fblock = t2 - fr2;
145  *--fblock = t3 - fr3;
146  *--fblock = t3 + fr3;
147  *--fblock = t2 + fr2;
148  *--fblock = t1 + fr1;
149  *--fblock = t0 + fr0;
150  fblock+=8;
151  } while(--i);
152  block-=8*8;
153  fblock-=8*8;
154 
155  /* col */
156 
157  /* even part */
159 
160  ofs1 = sizeof(float)*2*8;
161  ofs2 = sizeof(float)*4*8;
162  ofs3 = sizeof(float)*6*8;
163 
164  i = 8;
165 
166 #define OA(fblock,ofs) *(float*)((char*)fblock + ofs)
167 
168  do {
169  fr0 = OA(fblock, 0);
170  fr1 = OA(fblock,ofs1);
171  fr2 = OA(fblock,ofs2);
172  fr3 = OA(fblock,ofs3);
173  ftrv();
174  OA(fblock,0 ) = fr0;
175  OA(fblock,ofs1) = fr1;
176  OA(fblock,ofs2) = fr2;
177  OA(fblock,ofs3) = fr3;
178  fblock++;
179  } while(--i);
180  fblock-=8;
181 
183 
184  i=8;
185  do {
186  float t0,t1,t2,t3;
187  t0 = OA(fblock, 0); /* [8*0] */
188  t1 = OA(fblock,ofs1); /* [8*2] */
189  t2 = OA(fblock,ofs2); /* [8*4] */
190  t3 = OA(fblock,ofs3); /* [8*6] */
191  fblock+=8;
192  fr0 = OA(fblock, 0); /* [8*1] */
193  fr1 = OA(fblock,ofs1); /* [8*3] */
194  fr2 = OA(fblock,ofs2); /* [8*5] */
195  fr3 = OA(fblock,ofs3); /* [8*7] */
196  fblock+=-8+1;
197  ftrv();
198  block[8*0] = DESCALE(t0 + fr0,3);
199  block[8*7] = DESCALE(t0 - fr0,3);
200  block[8*1] = DESCALE(t1 + fr1,3);
201  block[8*6] = DESCALE(t1 - fr1,3);
202  block[8*2] = DESCALE(t2 + fr2,3);
203  block[8*5] = DESCALE(t2 - fr2,3);
204  block[8*3] = DESCALE(t3 + fr3,3);
205  block[8*4] = DESCALE(t3 - fr3,3);
206  block++;
207  } while(--i);
208 
209  fp_single_leave(fpscr);
210 }