annotate liba52/imdct.c @ 3874:8b76388de734

more mad fix
author alex
date Sat, 29 Dec 2001 01:32:46 +0000
parents 120ac80f13c2
children 0410677eda4a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
1 /*
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
2 * imdct.c
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
3 * Copyright (C) 2000-2001 Michel Lespinasse <walken@zoy.org>
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
5 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
6 * This file is part of a52dec, a free ATSC A-52 stream decoder.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
7 * See http://liba52.sourceforge.net/ for updates.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
8 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
9 * a52dec is free software; you can redistribute it and/or modify
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
12 * (at your option) any later version.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
13 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
14 * a52dec is distributed in the hope that it will be useful,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
17 * GNU General Public License for more details.
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
18 *
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
22 *
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
23 * SSE optimizations from Michael Niedermayer (michaelni@gmx.at)
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
24 */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
25
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
26 #include "config.h"
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
27 #include "../cpudetect.h"
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
28
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
29 #include <math.h>
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
30 #include <stdio.h>
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
31 #ifndef M_PI
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
32 #define M_PI 3.1415926535897932384626433832795029
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
33 #endif
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
34 #include <inttypes.h>
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
35
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
36 #include "a52.h"
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
37 #include "a52_internal.h"
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
38 #include "mm_accel.h"
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
39
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
40 void (* imdct_256) (sample_t data[], sample_t delay[], sample_t bias);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
41 void (* imdct_512) (sample_t data[], sample_t delay[], sample_t bias);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
42
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
43 typedef struct complex_s {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
44 sample_t real;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
45 sample_t imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
46 } complex_t;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
47
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
48
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
49 /* 128 point bit-reverse LUT */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
50 static uint8_t bit_reverse_512[] = {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
51 0x00, 0x40, 0x20, 0x60, 0x10, 0x50, 0x30, 0x70,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
52 0x08, 0x48, 0x28, 0x68, 0x18, 0x58, 0x38, 0x78,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
53 0x04, 0x44, 0x24, 0x64, 0x14, 0x54, 0x34, 0x74,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
54 0x0c, 0x4c, 0x2c, 0x6c, 0x1c, 0x5c, 0x3c, 0x7c,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
55 0x02, 0x42, 0x22, 0x62, 0x12, 0x52, 0x32, 0x72,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
56 0x0a, 0x4a, 0x2a, 0x6a, 0x1a, 0x5a, 0x3a, 0x7a,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
57 0x06, 0x46, 0x26, 0x66, 0x16, 0x56, 0x36, 0x76,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
58 0x0e, 0x4e, 0x2e, 0x6e, 0x1e, 0x5e, 0x3e, 0x7e,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
59 0x01, 0x41, 0x21, 0x61, 0x11, 0x51, 0x31, 0x71,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
60 0x09, 0x49, 0x29, 0x69, 0x19, 0x59, 0x39, 0x79,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
61 0x05, 0x45, 0x25, 0x65, 0x15, 0x55, 0x35, 0x75,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
62 0x0d, 0x4d, 0x2d, 0x6d, 0x1d, 0x5d, 0x3d, 0x7d,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
63 0x03, 0x43, 0x23, 0x63, 0x13, 0x53, 0x33, 0x73,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
64 0x0b, 0x4b, 0x2b, 0x6b, 0x1b, 0x5b, 0x3b, 0x7b,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
65 0x07, 0x47, 0x27, 0x67, 0x17, 0x57, 0x37, 0x77,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
66 0x0f, 0x4f, 0x2f, 0x6f, 0x1f, 0x5f, 0x3f, 0x7f};
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
67
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
68 static uint8_t bit_reverse_256[] = {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
69 0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
70 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
71 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
72 0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
73 0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
74 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
75 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
76 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f};
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
77
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
78 #ifdef ARCH_X86
3508
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
79 // NOTE: SSE needs 16byte alignment or it will segfault
3581
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
80 //
3508
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
81 static complex_t __attribute__((aligned(16))) buf[128];
3581
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
82 static float __attribute__((aligned(16))) sseSinCos1c[256];
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
83 static float __attribute__((aligned(16))) sseSinCos1d[256];
3512
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
84 static float __attribute__((aligned(16))) ps111_1[4]={1,1,1,-1};
3534
3483390a902b sse opt
michael
parents: 3529
diff changeset
85 //static float __attribute__((aligned(16))) sseW0[4];
3483390a902b sse opt
michael
parents: 3529
diff changeset
86 static float __attribute__((aligned(16))) sseW1[8];
3483390a902b sse opt
michael
parents: 3529
diff changeset
87 static float __attribute__((aligned(16))) sseW2[16];
3483390a902b sse opt
michael
parents: 3529
diff changeset
88 static float __attribute__((aligned(16))) sseW3[32];
3483390a902b sse opt
michael
parents: 3529
diff changeset
89 static float __attribute__((aligned(16))) sseW4[64];
3483390a902b sse opt
michael
parents: 3529
diff changeset
90 static float __attribute__((aligned(16))) sseW5[128];
3483390a902b sse opt
michael
parents: 3529
diff changeset
91 static float __attribute__((aligned(16))) sseW6[256];
3483390a902b sse opt
michael
parents: 3529
diff changeset
92 static float __attribute__((aligned(16))) *sseW[7]=
3483390a902b sse opt
michael
parents: 3529
diff changeset
93 {NULL /*sseW0*/,sseW1,sseW2,sseW3,sseW4,sseW5,sseW6};
3553
a501627fc6db sse opt
michael
parents: 3552
diff changeset
94 static float __attribute__((aligned(16))) sseWindow[512];
3508
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
95 #else
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
96 static complex_t buf[128];
3508
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
97 #endif
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
98
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
99 /* Twiddle factor LUT */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
100 static complex_t w_1[1];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
101 static complex_t w_2[2];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
102 static complex_t w_4[4];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
103 static complex_t w_8[8];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
104 static complex_t w_16[16];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
105 static complex_t w_32[32];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
106 static complex_t w_64[64];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
107 static complex_t * w[7] = {w_1, w_2, w_4, w_8, w_16, w_32, w_64};
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
108
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
109 /* Twiddle factors for IMDCT */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
110 static sample_t xcos1[128];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
111 static sample_t xsin1[128];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
112 static sample_t xcos2[64];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
113 static sample_t xsin2[64];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
114
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
115 /* Windowing function for Modified DCT - Thank you acroread */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
116 sample_t imdct_window[] = {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
117 0.00014, 0.00024, 0.00037, 0.00051, 0.00067, 0.00086, 0.00107, 0.00130,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
118 0.00157, 0.00187, 0.00220, 0.00256, 0.00297, 0.00341, 0.00390, 0.00443,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
119 0.00501, 0.00564, 0.00632, 0.00706, 0.00785, 0.00871, 0.00962, 0.01061,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
120 0.01166, 0.01279, 0.01399, 0.01526, 0.01662, 0.01806, 0.01959, 0.02121,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
121 0.02292, 0.02472, 0.02662, 0.02863, 0.03073, 0.03294, 0.03527, 0.03770,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
122 0.04025, 0.04292, 0.04571, 0.04862, 0.05165, 0.05481, 0.05810, 0.06153,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
123 0.06508, 0.06878, 0.07261, 0.07658, 0.08069, 0.08495, 0.08935, 0.09389,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
124 0.09859, 0.10343, 0.10842, 0.11356, 0.11885, 0.12429, 0.12988, 0.13563,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
125 0.14152, 0.14757, 0.15376, 0.16011, 0.16661, 0.17325, 0.18005, 0.18699,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
126 0.19407, 0.20130, 0.20867, 0.21618, 0.22382, 0.23161, 0.23952, 0.24757,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
127 0.25574, 0.26404, 0.27246, 0.28100, 0.28965, 0.29841, 0.30729, 0.31626,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
128 0.32533, 0.33450, 0.34376, 0.35311, 0.36253, 0.37204, 0.38161, 0.39126,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
129 0.40096, 0.41072, 0.42054, 0.43040, 0.44030, 0.45023, 0.46020, 0.47019,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
130 0.48020, 0.49022, 0.50025, 0.51028, 0.52031, 0.53033, 0.54033, 0.55031,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
131 0.56026, 0.57019, 0.58007, 0.58991, 0.59970, 0.60944, 0.61912, 0.62873,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
132 0.63827, 0.64774, 0.65713, 0.66643, 0.67564, 0.68476, 0.69377, 0.70269,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
133 0.71150, 0.72019, 0.72877, 0.73723, 0.74557, 0.75378, 0.76186, 0.76981,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
134 0.77762, 0.78530, 0.79283, 0.80022, 0.80747, 0.81457, 0.82151, 0.82831,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
135 0.83496, 0.84145, 0.84779, 0.85398, 0.86001, 0.86588, 0.87160, 0.87716,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
136 0.88257, 0.88782, 0.89291, 0.89785, 0.90264, 0.90728, 0.91176, 0.91610,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
137 0.92028, 0.92432, 0.92822, 0.93197, 0.93558, 0.93906, 0.94240, 0.94560,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
138 0.94867, 0.95162, 0.95444, 0.95713, 0.95971, 0.96217, 0.96451, 0.96674,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
139 0.96887, 0.97089, 0.97281, 0.97463, 0.97635, 0.97799, 0.97953, 0.98099,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
140 0.98236, 0.98366, 0.98488, 0.98602, 0.98710, 0.98811, 0.98905, 0.98994,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
141 0.99076, 0.99153, 0.99225, 0.99291, 0.99353, 0.99411, 0.99464, 0.99513,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
142 0.99558, 0.99600, 0.99639, 0.99674, 0.99706, 0.99736, 0.99763, 0.99788,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
143 0.99811, 0.99831, 0.99850, 0.99867, 0.99882, 0.99895, 0.99908, 0.99919,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
144 0.99929, 0.99938, 0.99946, 0.99953, 0.99959, 0.99965, 0.99969, 0.99974,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
145 0.99978, 0.99981, 0.99984, 0.99986, 0.99988, 0.99990, 0.99992, 0.99993,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
146 0.99994, 0.99995, 0.99996, 0.99997, 0.99998, 0.99998, 0.99998, 0.99999,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
147 0.99999, 0.99999, 0.99999, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000,
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
148 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000 };
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
149
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
150
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
151 static inline void swap_cmplx(complex_t *a, complex_t *b)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
152 {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
153 complex_t tmp;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
154
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
155 tmp = *a;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
156 *a = *b;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
157 *b = tmp;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
158 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
159
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
160
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
161
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
162 static inline complex_t cmplx_mult(complex_t a, complex_t b)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
163 {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
164 complex_t ret;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
165
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
166 ret.real = a.real * b.real - a.imag * b.imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
167 ret.imag = a.real * b.imag + a.imag * b.real;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
168
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
169 return ret;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
170 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
171
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
172 void
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
173 imdct_do_512(sample_t data[],sample_t delay[], sample_t bias)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
174 {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
175 int i,k;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
176 int p,q;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
177 int m;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
178 int two_m;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
179 int two_m_plus_one;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
180
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
181 sample_t tmp_a_i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
182 sample_t tmp_a_r;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
183 sample_t tmp_b_i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
184 sample_t tmp_b_r;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
185
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
186 sample_t *data_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
187 sample_t *delay_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
188 sample_t *window_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
189
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
190 /* 512 IMDCT with source and dest data in 'data' */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
191
3529
a86166b495a6 sse opt
michael
parents: 3527
diff changeset
192 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
193 for( i=0; i < 128; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
194 /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
195 buf[i].real = (data[256-2*i-1] * xcos1[i]) - (data[2*i] * xsin1[i]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
196 buf[i].imag = -1.0 * ((data[2*i] * xcos1[i]) + (data[256-2*i-1] * xsin1[i]));
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
197 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
198
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
199 /* Bit reversed shuffling */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
200 for(i=0; i<128; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
201 k = bit_reverse_512[i];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
202 if (k < i)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
203 swap_cmplx(&buf[i],&buf[k]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
204 }
3529
a86166b495a6 sse opt
michael
parents: 3527
diff changeset
205
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
206
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
207 /* FFT Merge */
3549
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
208 /* unoptimized variant
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
209 for (m=1; m < 7; m++) {
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
210 if(m)
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
211 two_m = (1 << m);
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
212 else
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
213 two_m = 1;
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
214
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
215 two_m_plus_one = (1 << (m+1));
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
216
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
217 for(i = 0; i < 128; i += two_m_plus_one) {
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
218 for(k = 0; k < two_m; k++) {
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
219 p = k + i;
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
220 q = p + two_m;
3508
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
221 tmp_a_r = buf[p].real;
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
222 tmp_a_i = buf[p].imag;
3549
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
223 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag;
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
224 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag;
3508
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
225 buf[p].real = tmp_a_r + tmp_b_r;
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
226 buf[p].imag = tmp_a_i + tmp_b_i;
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
227 buf[q].real = tmp_a_r - tmp_b_r;
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
228 buf[q].imag = tmp_a_i - tmp_b_i;
3549
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
229 }
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
230 }
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
231 }
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
232 */
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
233 /* 1. iteration */
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
234 for(i = 0; i < 128; i += 2) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
235 tmp_a_r = buf[i].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
236 tmp_a_i = buf[i].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
237 tmp_b_r = buf[i+1].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
238 tmp_b_i = buf[i+1].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
239 buf[i].real = tmp_a_r + tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
240 buf[i].imag = tmp_a_i + tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
241 buf[i+1].real = tmp_a_r - tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
242 buf[i+1].imag = tmp_a_i - tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
243 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
244
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
245 /* 2. iteration */
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
246 // Note w[1]={{1,0}, {0,-1}}
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
247 for(i = 0; i < 128; i += 4) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
248 tmp_a_r = buf[i].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
249 tmp_a_i = buf[i].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
250 tmp_b_r = buf[i+2].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
251 tmp_b_i = buf[i+2].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
252 buf[i].real = tmp_a_r + tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
253 buf[i].imag = tmp_a_i + tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
254 buf[i+2].real = tmp_a_r - tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
255 buf[i+2].imag = tmp_a_i - tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
256 tmp_a_r = buf[i+1].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
257 tmp_a_i = buf[i+1].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
258 tmp_b_r = buf[i+3].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
259 tmp_b_i = buf[i+3].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
260 buf[i+1].real = tmp_a_r + tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
261 buf[i+1].imag = tmp_a_i - tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
262 buf[i+3].real = tmp_a_r - tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
263 buf[i+3].imag = tmp_a_i + tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
264 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
265
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
266 /* 3. iteration */
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
267 for(i = 0; i < 128; i += 8) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
268 tmp_a_r = buf[i].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
269 tmp_a_i = buf[i].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
270 tmp_b_r = buf[i+4].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
271 tmp_b_i = buf[i+4].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
272 buf[i].real = tmp_a_r + tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
273 buf[i].imag = tmp_a_i + tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
274 buf[i+4].real = tmp_a_r - tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
275 buf[i+4].imag = tmp_a_i - tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
276 tmp_a_r = buf[1+i].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
277 tmp_a_i = buf[1+i].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
278 tmp_b_r = (buf[i+5].real + buf[i+5].imag) * w[2][1].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
279 tmp_b_i = (buf[i+5].imag - buf[i+5].real) * w[2][1].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
280 buf[1+i].real = tmp_a_r + tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
281 buf[1+i].imag = tmp_a_i + tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
282 buf[i+5].real = tmp_a_r - tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
283 buf[i+5].imag = tmp_a_i - tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
284 tmp_a_r = buf[i+2].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
285 tmp_a_i = buf[i+2].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
286 tmp_b_r = buf[i+6].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
287 tmp_b_i = - buf[i+6].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
288 buf[i+2].real = tmp_a_r + tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
289 buf[i+2].imag = tmp_a_i + tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
290 buf[i+6].real = tmp_a_r - tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
291 buf[i+6].imag = tmp_a_i - tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
292 tmp_a_r = buf[i+3].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
293 tmp_a_i = buf[i+3].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
294 tmp_b_r = (buf[i+7].real - buf[i+7].imag) * w[2][3].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
295 tmp_b_i = (buf[i+7].imag + buf[i+7].real) * w[2][3].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
296 buf[i+3].real = tmp_a_r + tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
297 buf[i+3].imag = tmp_a_i + tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
298 buf[i+7].real = tmp_a_r - tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
299 buf[i+7].imag = tmp_a_i - tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
300 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
301
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
302 /* 4-7. iterations */
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
303 for (m=3; m < 7; m++) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
304 two_m = (1 << m);
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
305
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
306 two_m_plus_one = two_m<<1;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
307
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
308 for(i = 0; i < 128; i += two_m_plus_one) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
309 for(k = 0; k < two_m; k++) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
310 int p = k + i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
311 int q = p + two_m;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
312 tmp_a_r = buf[p].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
313 tmp_a_i = buf[p].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
314 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
315 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
316 buf[p].real = tmp_a_r + tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
317 buf[p].imag = tmp_a_i + tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
318 buf[q].real = tmp_a_r - tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
319 buf[q].imag = tmp_a_i - tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
320 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
321 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
322 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
323
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
324 /* Post IFFT complex multiply plus IFFT complex conjugate*/
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
325 for( i=0; i < 128; i++) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
326 /* y[n] = z[n] * (xcos1[n] + j * xsin1[n]) ; */
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
327 tmp_a_r = buf[i].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
328 tmp_a_i = -1.0 * buf[i].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
329 buf[i].real =(tmp_a_r * xcos1[i]) - (tmp_a_i * xsin1[i]);
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
330 buf[i].imag =(tmp_a_r * xsin1[i]) + (tmp_a_i * xcos1[i]);
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
331 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
332
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
333 data_ptr = data;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
334 delay_ptr = delay;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
335 window_ptr = imdct_window;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
336
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
337 /* Window and convert to real valued signal */
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
338 for(i=0; i< 64; i++) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
339 *data_ptr++ = -buf[64+i].imag * *window_ptr++ + *delay_ptr++ + bias;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
340 *data_ptr++ = buf[64-i-1].real * *window_ptr++ + *delay_ptr++ + bias;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
341 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
342
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
343 for(i=0; i< 64; i++) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
344 *data_ptr++ = -buf[i].real * *window_ptr++ + *delay_ptr++ + bias;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
345 *data_ptr++ = buf[128-i-1].imag * *window_ptr++ + *delay_ptr++ + bias;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
346 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
347
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
348 /* The trailing edge of the window goes into the delay line */
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
349 delay_ptr = delay;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
350
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
351 for(i=0; i< 64; i++) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
352 *delay_ptr++ = -buf[64+i].real * *--window_ptr;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
353 *delay_ptr++ = buf[64-i-1].imag * *--window_ptr;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
354 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
355
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
356 for(i=0; i<64; i++) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
357 *delay_ptr++ = buf[i].imag * *--window_ptr;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
358 *delay_ptr++ = -buf[128-i-1].real * *--window_ptr;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
359 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
360 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
361
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
362 #ifdef ARCH_X86
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
363 void
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
364 imdct_do_512_sse(sample_t data[],sample_t delay[], sample_t bias)
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
365 {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
366 int i,k;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
367 int p,q;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
368 int m;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
369 int two_m;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
370 int two_m_plus_one;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
371
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
372 sample_t tmp_a_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
373 sample_t tmp_a_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
374 sample_t tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
375 sample_t tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
376
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
377 sample_t *data_ptr;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
378 sample_t *delay_ptr;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
379 sample_t *window_ptr;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
380
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
381 /* 512 IMDCT with source and dest data in 'data' */
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
382 /* see the c version (dct_do_512()), its allmost identical, just in C */
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
383
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
384 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
385 /* Bit reversed shuffling */
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
386 asm volatile(
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
387 "xorl %%esi, %%esi \n\t"
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
388 "leal bit_reverse_512, %%eax \n\t"
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
389 "movl $1008, %%edi \n\t"
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
390 "pushl %%ebp \n\t" //use ebp without telling gcc
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
391 ".balign 16 \n\t"
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
392 "1: \n\t"
3584
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
393 "movlps (%0, %%esi), %%xmm0 \n\t" // XXXI
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
394 "movhps 8(%0, %%edi), %%xmm0 \n\t" // RXXI
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
395 "movlps 8(%0, %%esi), %%xmm1 \n\t" // XXXi
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
396 "movhps (%0, %%edi), %%xmm1 \n\t" // rXXi
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
397 "shufps $0x33, %%xmm1, %%xmm0 \n\t" // irIR
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
398 "movaps sseSinCos1c(%%esi), %%xmm2 \n\t"
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
399 "mulps %%xmm0, %%xmm2 \n\t"
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
400 "shufps $0xB1, %%xmm0, %%xmm0 \n\t" // riRI
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
401 "mulps sseSinCos1d(%%esi), %%xmm0 \n\t"
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
402 "subps %%xmm0, %%xmm2 \n\t"
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
403 "movzbl (%%eax), %%edx \n\t"
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
404 "movzbl 1(%%eax), %%ebp \n\t"
3584
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
405 "movlps %%xmm2, (%1, %%edx,8) \n\t"
7c4046c04be3 removing unnecessary sse sin/cos LUT
michael
parents: 3581
diff changeset
406 "movhps %%xmm2, (%1, %%ebp,8) \n\t"
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
407 "addl $16, %%esi \n\t"
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
408 "addl $2, %%eax \n\t" // avoid complex addressing for P4 crap
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
409 "subl $16, %%edi \n\t"
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
410 " jnc 1b \n\t"
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
411 "popl %%ebp \n\t"//no we didnt touch ebp *g*
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
412 :: "b" (data), "c" (buf)
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
413 : "%esi", "%edi", "%eax", "%edx"
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
414 );
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
415
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
416
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
417 /* FFT Merge */
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
418 /* unoptimized variant
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
419 for (m=1; m < 7; m++) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
420 if(m)
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
421 two_m = (1 << m);
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
422 else
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
423 two_m = 1;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
424
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
425 two_m_plus_one = (1 << (m+1));
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
426
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
427 for(i = 0; i < 128; i += two_m_plus_one) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
428 for(k = 0; k < two_m; k++) {
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
429 p = k + i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
430 q = p + two_m;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
431 tmp_a_r = buf[p].real;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
432 tmp_a_i = buf[p].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
433 tmp_b_r = buf[q].real * w[m][k].real - buf[q].imag * w[m][k].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
434 tmp_b_i = buf[q].imag * w[m][k].real + buf[q].real * w[m][k].imag;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
435 buf[p].real = tmp_a_r + tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
436 buf[p].imag = tmp_a_i + tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
437 buf[q].real = tmp_a_r - tmp_b_r;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
438 buf[q].imag = tmp_a_i - tmp_b_i;
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
439 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
440 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
441 }
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
442 */
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
443
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
444 /* 1. iteration */
3549
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
445 // Note w[0][0]={1,0}
3508
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
446 asm volatile(
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
447 "xorps %%xmm1, %%xmm1 \n\t"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
448 "xorps %%xmm2, %%xmm2 \n\t"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
449 "movl %0, %%esi \n\t"
3529
a86166b495a6 sse opt
michael
parents: 3527
diff changeset
450 ".balign 16 \n\t"
3508
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
451 "1: \n\t"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
452 "movlps (%%esi), %%xmm0 \n\t" //buf[p]
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
453 "movlps 8(%%esi), %%xmm1\n\t" //buf[q]
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
454 "movhps (%%esi), %%xmm0 \n\t" //buf[p]
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
455 "movhps 8(%%esi), %%xmm2\n\t" //buf[q]
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
456 "addps %%xmm1, %%xmm0 \n\t"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
457 "subps %%xmm2, %%xmm0 \n\t"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
458 "movaps %%xmm0, (%%esi) \n\t"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
459 "addl $16, %%esi \n\t"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
460 "cmpl %1, %%esi \n\t"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
461 " jb 1b \n\t"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
462 :: "g" (buf), "r" (buf + 128)
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
463 : "%esi"
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
464 );
3549
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
465
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
466 /* 2. iteration */
3512
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
467 // Note w[1]={{1,0}, {0,-1}}
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
468 asm volatile(
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
469 "movaps ps111_1, %%xmm7 \n\t" // 1,1,1,-1
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
470 "movl %0, %%esi \n\t"
3529
a86166b495a6 sse opt
michael
parents: 3527
diff changeset
471 ".balign 16 \n\t"
3512
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
472 "1: \n\t"
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
473 "movaps 16(%%esi), %%xmm2 \n\t" //r2,i2,r3,i3
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
474 "shufps $0xB4, %%xmm2, %%xmm2 \n\t" //r2,i2,i3,r3
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
475 "mulps %%xmm7, %%xmm2 \n\t" //r2,i2,i3,-r3
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
476 "movaps (%%esi), %%xmm0 \n\t" //r0,i0,r1,i1
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
477 "movaps (%%esi), %%xmm1 \n\t" //r0,i0,r1,i1
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
478 "addps %%xmm2, %%xmm0 \n\t"
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
479 "subps %%xmm2, %%xmm1 \n\t"
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
480 "movaps %%xmm0, (%%esi) \n\t"
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
481 "movaps %%xmm1, 16(%%esi) \n\t"
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
482 "addl $32, %%esi \n\t"
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
483 "cmpl %1, %%esi \n\t"
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
484 " jb 1b \n\t"
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
485 :: "g" (buf), "r" (buf + 128)
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
486 : "%esi"
1f166e420b15 a bit more SSE optimizations
michael
parents: 3508
diff changeset
487 );
3549
2e21accd86a8 cleanup
michael
parents: 3546
diff changeset
488
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
489 /* 3. iteration */
3534
3483390a902b sse opt
michael
parents: 3529
diff changeset
490 /*
3483390a902b sse opt
michael
parents: 3529
diff changeset
491 Note sseW2+0={1,1,sqrt(2),sqrt(2))
3483390a902b sse opt
michael
parents: 3529
diff changeset
492 Note sseW2+16={0,0,sqrt(2),-sqrt(2))
3483390a902b sse opt
michael
parents: 3529
diff changeset
493 Note sseW2+32={0,0,-sqrt(2),-sqrt(2))
3483390a902b sse opt
michael
parents: 3529
diff changeset
494 Note sseW2+48={1,-1,sqrt(2),-sqrt(2))
3483390a902b sse opt
michael
parents: 3529
diff changeset
495 */
3483390a902b sse opt
michael
parents: 3529
diff changeset
496 asm volatile(
3537
d7e5a32643c9 C optimizations
michael
parents: 3534
diff changeset
497 "movaps 48+sseW2, %%xmm6 \n\t"
3534
3483390a902b sse opt
michael
parents: 3529
diff changeset
498 "movaps 16+sseW2, %%xmm7 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
499 "xorps %%xmm5, %%xmm5 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
500 "xorps %%xmm2, %%xmm2 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
501 "movl %0, %%esi \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
502 ".balign 16 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
503 "1: \n\t"
3537
d7e5a32643c9 C optimizations
michael
parents: 3534
diff changeset
504 "movaps 32(%%esi), %%xmm2 \n\t" //r4,i4,r5,i5
3534
3483390a902b sse opt
michael
parents: 3529
diff changeset
505 "movaps 48(%%esi), %%xmm3 \n\t" //r6,i6,r7,i7
3537
d7e5a32643c9 C optimizations
michael
parents: 3534
diff changeset
506 "movaps sseW2, %%xmm4 \n\t" //r4,i4,r5,i5
d7e5a32643c9 C optimizations
michael
parents: 3534
diff changeset
507 "movaps 32+sseW2, %%xmm5 \n\t" //r6,i6,r7,i7
d7e5a32643c9 C optimizations
michael
parents: 3534
diff changeset
508 "mulps %%xmm2, %%xmm4 \n\t"
d7e5a32643c9 C optimizations
michael
parents: 3534
diff changeset
509 "mulps %%xmm3, %%xmm5 \n\t"
3534
3483390a902b sse opt
michael
parents: 3529
diff changeset
510 "shufps $0xB1, %%xmm2, %%xmm2 \n\t" //i4,r4,i5,r5
3483390a902b sse opt
michael
parents: 3529
diff changeset
511 "shufps $0xB1, %%xmm3, %%xmm3 \n\t" //i6,r6,i7,r7
3537
d7e5a32643c9 C optimizations
michael
parents: 3534
diff changeset
512 "mulps %%xmm6, %%xmm3 \n\t"
3534
3483390a902b sse opt
michael
parents: 3529
diff changeset
513 "mulps %%xmm7, %%xmm2 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
514 "movaps (%%esi), %%xmm0 \n\t" //r0,i0,r1,i1
3483390a902b sse opt
michael
parents: 3529
diff changeset
515 "movaps 16(%%esi), %%xmm1 \n\t" //r2,i2,r3,i3
3483390a902b sse opt
michael
parents: 3529
diff changeset
516 "addps %%xmm4, %%xmm2 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
517 "addps %%xmm5, %%xmm3 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
518 "movaps %%xmm2, %%xmm4 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
519 "movaps %%xmm3, %%xmm5 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
520 "addps %%xmm0, %%xmm2 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
521 "addps %%xmm1, %%xmm3 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
522 "subps %%xmm4, %%xmm0 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
523 "subps %%xmm5, %%xmm1 \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
524 "movaps %%xmm2, (%%esi) \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
525 "movaps %%xmm3, 16(%%esi) \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
526 "movaps %%xmm0, 32(%%esi) \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
527 "movaps %%xmm1, 48(%%esi) \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
528 "addl $64, %%esi \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
529 "cmpl %1, %%esi \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
530 " jb 1b \n\t"
3483390a902b sse opt
michael
parents: 3529
diff changeset
531 :: "g" (buf), "r" (buf + 128)
3483390a902b sse opt
michael
parents: 3529
diff changeset
532 : "%esi"
3483390a902b sse opt
michael
parents: 3529
diff changeset
533 );
3508
b5220cf63fc3 some SSE optimizations
michael
parents: 3394
diff changeset
534
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
535 /* 4-7. iterations */
3546
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
536 for (m=3; m < 7; m++) {
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
537 two_m = (1 << m);
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
538 two_m_plus_one = two_m<<1;
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
539 asm volatile(
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
540 "movl %0, %%esi \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
541 ".balign 16 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
542 "1: \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
543 "xorl %%edi, %%edi \n\t" // k
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
544 "leal (%%esi, %3), %%edx \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
545 "2: \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
546 "movaps (%%edx, %%edi), %%xmm1 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
547 "movaps (%4, %%edi, 2), %%xmm2 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
548 "mulps %%xmm1, %%xmm2 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
549 "shufps $0xB1, %%xmm1, %%xmm1 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
550 "mulps 16(%4, %%edi, 2), %%xmm1 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
551 "movaps (%%esi, %%edi), %%xmm0 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
552 "addps %%xmm2, %%xmm1 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
553 "movaps %%xmm1, %%xmm2 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
554 "addps %%xmm0, %%xmm1 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
555 "subps %%xmm2, %%xmm0 \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
556 "movaps %%xmm1, (%%esi, %%edi) \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
557 "movaps %%xmm0, (%%edx, %%edi) \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
558 "addl $16, %%edi \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
559 "cmpl %3, %%edi \n\t" //FIXME (opt) count against 0
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
560 " jb 2b \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
561 "addl %2, %%esi \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
562 "cmpl %1, %%esi \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
563 " jb 1b \n\t"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
564 :: "g" (buf), "m" (buf+128), "m" (two_m_plus_one<<3), "r" (two_m<<3),
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
565 "r" (sseW[m])
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
566 : "%esi", "%edi", "%edx"
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
567 );
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
568 }
4e772a3c6b62 sse opt
michael
parents: 3537
diff changeset
569
3623
3f1c2c06d0d8 adding some comments
michael
parents: 3584
diff changeset
570 /* Post IFFT complex multiply plus IFFT complex conjugate*/
3581
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
571 asm volatile(
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
572 "movl $-1024, %%esi \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
573 ".balign 16 \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
574 "1: \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
575 "movaps (%0, %%esi), %%xmm0 \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
576 "movaps (%0, %%esi), %%xmm1 \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
577 "shufps $0xB1, %%xmm0, %%xmm0 \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
578 "mulps 1024+sseSinCos1c(%%esi), %%xmm1 \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
579 "mulps 1024+sseSinCos1d(%%esi), %%xmm0 \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
580 "addps %%xmm1, %%xmm0 \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
581 "movaps %%xmm0, (%0, %%esi) \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
582 "addl $16, %%esi \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
583 " jnz 1b \n\t"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
584 :: "r" (buf+128)
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
585 : "%esi"
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
586 );
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
587
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
588
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
589 data_ptr = data;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
590 delay_ptr = delay;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
591 window_ptr = imdct_window;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
592
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
593 /* Window and convert to real valued signal */
3552
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
594 asm volatile(
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
595 "xorl %%edi, %%edi \n\t" // 0
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
596 "xorl %%esi, %%esi \n\t" // 0
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
597 "movss %3, %%xmm2 \n\t" // bias
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
598 "shufps $0x00, %%xmm2, %%xmm2 \n\t" // bias, bias, ...
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
599 ".balign 16 \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
600 "1: \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
601 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? A ?
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
602 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? C ?
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
603 "movhps -16(%0, %%edi), %%xmm1 \n\t" // ? D C ?
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
604 "movhps -8(%0, %%edi), %%xmm0 \n\t" // ? B A ?
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
605 "shufps $0x99, %%xmm1, %%xmm0 \n\t" // D C B A
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
606 "mulps sseWindow(%%esi), %%xmm0 \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
607 "addps (%2, %%esi), %%xmm0 \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
608 "addps %%xmm2, %%xmm0 \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
609 "movaps %%xmm0, (%1, %%esi) \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
610 "addl $16, %%esi \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
611 "subl $16, %%edi \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
612 "cmpl $512, %%esi \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
613 " jb 1b \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
614 :: "r" (buf+64), "r" (data_ptr), "r" (delay_ptr), "m" (bias)
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
615 : "%esi", "%edi"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
616 );
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
617 data_ptr+=128;
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
618 delay_ptr+=128;
3553
a501627fc6db sse opt
michael
parents: 3552
diff changeset
619 // window_ptr+=128;
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
620
3552
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
621 asm volatile(
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
622 "movl $1024, %%edi \n\t" // 512
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
623 "xorl %%esi, %%esi \n\t" // 0
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
624 "movss %3, %%xmm2 \n\t" // bias
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
625 "shufps $0x00, %%xmm2, %%xmm2 \n\t" // bias, bias, ...
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
626 ".balign 16 \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
627 "1: \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
628 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? ? A
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
629 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? ? C
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
630 "movhps -16(%0, %%edi), %%xmm1 \n\t" // D ? ? C
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
631 "movhps -8(%0, %%edi), %%xmm0 \n\t" // B ? ? A
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
632 "shufps $0xCC, %%xmm1, %%xmm0 \n\t" // D C B A
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
633 "mulps 512+sseWindow(%%esi), %%xmm0 \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
634 "addps (%2, %%esi), %%xmm0 \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
635 "addps %%xmm2, %%xmm0 \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
636 "movaps %%xmm0, (%1, %%esi) \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
637 "addl $16, %%esi \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
638 "subl $16, %%edi \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
639 "cmpl $512, %%esi \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
640 " jb 1b \n\t"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
641 :: "r" (buf), "r" (data_ptr), "r" (delay_ptr), "m" (bias)
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
642 : "%esi", "%edi"
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
643 );
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
644 data_ptr+=128;
3553
a501627fc6db sse opt
michael
parents: 3552
diff changeset
645 // window_ptr+=128;
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
646
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
647 /* The trailing edge of the window goes into the delay line */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
648 delay_ptr = delay;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
649
3553
a501627fc6db sse opt
michael
parents: 3552
diff changeset
650 asm volatile(
a501627fc6db sse opt
michael
parents: 3552
diff changeset
651 "xorl %%edi, %%edi \n\t" // 0
a501627fc6db sse opt
michael
parents: 3552
diff changeset
652 "xorl %%esi, %%esi \n\t" // 0
a501627fc6db sse opt
michael
parents: 3552
diff changeset
653 ".balign 16 \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
654 "1: \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
655 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? ? A
a501627fc6db sse opt
michael
parents: 3552
diff changeset
656 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? ? C
a501627fc6db sse opt
michael
parents: 3552
diff changeset
657 "movhps -16(%0, %%edi), %%xmm1 \n\t" // D ? ? C
a501627fc6db sse opt
michael
parents: 3552
diff changeset
658 "movhps -8(%0, %%edi), %%xmm0 \n\t" // B ? ? A
a501627fc6db sse opt
michael
parents: 3552
diff changeset
659 "shufps $0xCC, %%xmm1, %%xmm0 \n\t" // D C B A
a501627fc6db sse opt
michael
parents: 3552
diff changeset
660 "mulps 1024+sseWindow(%%esi), %%xmm0 \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
661 "movaps %%xmm0, (%1, %%esi) \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
662 "addl $16, %%esi \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
663 "subl $16, %%edi \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
664 "cmpl $512, %%esi \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
665 " jb 1b \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
666 :: "r" (buf+64), "r" (delay_ptr)
a501627fc6db sse opt
michael
parents: 3552
diff changeset
667 : "%esi", "%edi"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
668 );
a501627fc6db sse opt
michael
parents: 3552
diff changeset
669 delay_ptr+=128;
a501627fc6db sse opt
michael
parents: 3552
diff changeset
670 // window_ptr-=128;
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
671
3553
a501627fc6db sse opt
michael
parents: 3552
diff changeset
672 asm volatile(
a501627fc6db sse opt
michael
parents: 3552
diff changeset
673 "movl $1024, %%edi \n\t" // 1024
a501627fc6db sse opt
michael
parents: 3552
diff changeset
674 "xorl %%esi, %%esi \n\t" // 0
a501627fc6db sse opt
michael
parents: 3552
diff changeset
675 ".balign 16 \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
676 "1: \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
677 "movlps (%0, %%esi), %%xmm0 \n\t" // ? ? A ?
a501627fc6db sse opt
michael
parents: 3552
diff changeset
678 "movlps 8(%0, %%esi), %%xmm1 \n\t" // ? ? C ?
a501627fc6db sse opt
michael
parents: 3552
diff changeset
679 "movhps -16(%0, %%edi), %%xmm1 \n\t" // ? D C ?
a501627fc6db sse opt
michael
parents: 3552
diff changeset
680 "movhps -8(%0, %%edi), %%xmm0 \n\t" // ? B A ?
a501627fc6db sse opt
michael
parents: 3552
diff changeset
681 "shufps $0x99, %%xmm1, %%xmm0 \n\t" // D C B A
a501627fc6db sse opt
michael
parents: 3552
diff changeset
682 "mulps 1536+sseWindow(%%esi), %%xmm0 \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
683 "movaps %%xmm0, (%1, %%esi) \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
684 "addl $16, %%esi \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
685 "subl $16, %%edi \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
686 "cmpl $512, %%esi \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
687 " jb 1b \n\t"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
688 :: "r" (buf), "r" (delay_ptr)
a501627fc6db sse opt
michael
parents: 3552
diff changeset
689 : "%esi", "%edi"
a501627fc6db sse opt
michael
parents: 3552
diff changeset
690 );
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
691 }
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
692 #endif //arch_x86
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
693
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
694 void
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
695 imdct_do_256(sample_t data[],sample_t delay[],sample_t bias)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
696 {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
697 int i,k;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
698 int p,q;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
699 int m;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
700 int two_m;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
701 int two_m_plus_one;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
702
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
703 sample_t tmp_a_i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
704 sample_t tmp_a_r;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
705 sample_t tmp_b_i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
706 sample_t tmp_b_r;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
707
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
708 sample_t *data_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
709 sample_t *delay_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
710 sample_t *window_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
711
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
712 complex_t *buf_1, *buf_2;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
713
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
714 buf_1 = &buf[0];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
715 buf_2 = &buf[64];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
716
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
717 /* Pre IFFT complex multiply plus IFFT cmplx conjugate */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
718 for(k=0; k<64; k++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
719 /* X1[k] = X[2*k] */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
720 /* X2[k] = X[2*k+1] */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
721
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
722 p = 2 * (128-2*k-1);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
723 q = 2 * (2 * k);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
724
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
725 /* Z1[k] = (X1[128-2*k-1] + j * X1[2*k]) * (xcos2[k] + j * xsin2[k]); */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
726 buf_1[k].real = data[p] * xcos2[k] - data[q] * xsin2[k];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
727 buf_1[k].imag = -1.0f * (data[q] * xcos2[k] + data[p] * xsin2[k]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
728 /* Z2[k] = (X2[128-2*k-1] + j * X2[2*k]) * (xcos2[k] + j * xsin2[k]); */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
729 buf_2[k].real = data[p + 1] * xcos2[k] - data[q + 1] * xsin2[k];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
730 buf_2[k].imag = -1.0f * ( data[q + 1] * xcos2[k] + data[p + 1] * xsin2[k]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
731 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
732
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
733 /* IFFT Bit reversed shuffling */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
734 for(i=0; i<64; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
735 k = bit_reverse_256[i];
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
736 if (k < i) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
737 swap_cmplx(&buf_1[i],&buf_1[k]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
738 swap_cmplx(&buf_2[i],&buf_2[k]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
739 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
740 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
741
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
742 /* FFT Merge */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
743 for (m=0; m < 6; m++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
744 two_m = (1 << m);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
745 two_m_plus_one = (1 << (m+1));
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
746
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
747 /* FIXME */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
748 if(m)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
749 two_m = (1 << m);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
750 else
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
751 two_m = 1;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
752
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
753 for(k = 0; k < two_m; k++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
754 for(i = 0; i < 64; i += two_m_plus_one) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
755 p = k + i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
756 q = p + two_m;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
757 /* Do block 1 */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
758 tmp_a_r = buf_1[p].real;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
759 tmp_a_i = buf_1[p].imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
760 tmp_b_r = buf_1[q].real * w[m][k].real - buf_1[q].imag * w[m][k].imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
761 tmp_b_i = buf_1[q].imag * w[m][k].real + buf_1[q].real * w[m][k].imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
762 buf_1[p].real = tmp_a_r + tmp_b_r;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
763 buf_1[p].imag = tmp_a_i + tmp_b_i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
764 buf_1[q].real = tmp_a_r - tmp_b_r;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
765 buf_1[q].imag = tmp_a_i - tmp_b_i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
766
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
767 /* Do block 2 */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
768 tmp_a_r = buf_2[p].real;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
769 tmp_a_i = buf_2[p].imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
770 tmp_b_r = buf_2[q].real * w[m][k].real - buf_2[q].imag * w[m][k].imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
771 tmp_b_i = buf_2[q].imag * w[m][k].real + buf_2[q].real * w[m][k].imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
772 buf_2[p].real = tmp_a_r + tmp_b_r;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
773 buf_2[p].imag = tmp_a_i + tmp_b_i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
774 buf_2[q].real = tmp_a_r - tmp_b_r;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
775 buf_2[q].imag = tmp_a_i - tmp_b_i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
776 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
777 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
778 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
779
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
780 /* Post IFFT complex multiply */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
781 for( i=0; i < 64; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
782 /* y1[n] = z1[n] * (xcos2[n] + j * xs in2[n]) ; */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
783 tmp_a_r = buf_1[i].real;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
784 tmp_a_i = -buf_1[i].imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
785 buf_1[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
786 buf_1[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
787 /* y2[n] = z2[n] * (xcos2[n] + j * xsin2[n]) ; */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
788 tmp_a_r = buf_2[i].real;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
789 tmp_a_i = -buf_2[i].imag;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
790 buf_2[i].real =(tmp_a_r * xcos2[i]) - (tmp_a_i * xsin2[i]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
791 buf_2[i].imag =(tmp_a_r * xsin2[i]) + (tmp_a_i * xcos2[i]);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
792 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
793
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
794 data_ptr = data;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
795 delay_ptr = delay;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
796 window_ptr = imdct_window;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
797
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
798 /* Window and convert to real valued signal */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
799 for(i=0; i< 64; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
800 *data_ptr++ = -buf_1[i].imag * *window_ptr++ + *delay_ptr++ + bias;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
801 *data_ptr++ = buf_1[64-i-1].real * *window_ptr++ + *delay_ptr++ + bias;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
802 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
803
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
804 for(i=0; i< 64; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
805 *data_ptr++ = -buf_1[i].real * *window_ptr++ + *delay_ptr++ + bias;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
806 *data_ptr++ = buf_1[64-i-1].imag * *window_ptr++ + *delay_ptr++ + bias;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
807 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
808
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
809 delay_ptr = delay;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
810
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
811 for(i=0; i< 64; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
812 *delay_ptr++ = -buf_2[i].real * *--window_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
813 *delay_ptr++ = buf_2[64-i-1].imag * *--window_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
814 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
815
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
816 for(i=0; i< 64; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
817 *delay_ptr++ = buf_2[i].imag * *--window_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
818 *delay_ptr++ = -buf_2[64-i-1].real * *--window_ptr;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
819 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
820 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
821
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
822 void imdct_init (uint32_t mm_accel)
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
823 {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
824 #ifdef LIBA52_MLIB
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
825 if (mm_accel & MM_ACCEL_MLIB) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
826 fprintf (stderr, "Using mlib for IMDCT transform\n");
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
827 imdct_512 = imdct_do_512_mlib;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
828 imdct_256 = imdct_do_256_mlib;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
829 } else
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
830 #endif
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
831 {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
832 int i, j, k;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
833
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
834 if(gCpuCaps.hasSSE) fprintf (stderr, "Using SSE optimized IMDCT transform\n");
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
835 else fprintf (stderr, "No accelerated IMDCT transform found\n");
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
836
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
837 /* Twiddle factors to turn IFFT into IMDCT */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
838 for (i = 0; i < 128; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
839 xcos1[i] = -cos ((M_PI / 2048) * (8 * i + 1));
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
840 xsin1[i] = -sin ((M_PI / 2048) * (8 * i + 1));
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
841 }
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
842 #ifdef ARCH_X86
3527
5a88b21cfe8a sse opt
michael
parents: 3512
diff changeset
843 for (i = 0; i < 128; i++) {
3581
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
844 sseSinCos1c[2*i+0]= xcos1[i];
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
845 sseSinCos1c[2*i+1]= -xcos1[i];
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
846 sseSinCos1d[2*i+0]= xsin1[i];
8ddf654c4871 sse opt
michael
parents: 3579
diff changeset
847 sseSinCos1d[2*i+1]= xsin1[i];
3527
5a88b21cfe8a sse opt
michael
parents: 3512
diff changeset
848 }
5a88b21cfe8a sse opt
michael
parents: 3512
diff changeset
849 #endif
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
850
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
851 /* More twiddle factors to turn IFFT into IMDCT */
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
852 for (i = 0; i < 64; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
853 xcos2[i] = -cos ((M_PI / 1024) * (8 * i + 1));
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
854 xsin2[i] = -sin ((M_PI / 1024) * (8 * i + 1));
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
855 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
856
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
857 for (i = 0; i < 7; i++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
858 j = 1 << i;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
859 for (k = 0; k < j; k++) {
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
860 w[i][k].real = cos (-M_PI * k / j);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
861 w[i][k].imag = sin (-M_PI * k / j);
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
862 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
863 }
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
864 #ifdef ARCH_X86
3534
3483390a902b sse opt
michael
parents: 3529
diff changeset
865 for (i = 1; i < 7; i++) {
3483390a902b sse opt
michael
parents: 3529
diff changeset
866 j = 1 << i;
3483390a902b sse opt
michael
parents: 3529
diff changeset
867 for (k = 0; k < j; k+=2) {
3483390a902b sse opt
michael
parents: 3529
diff changeset
868
3483390a902b sse opt
michael
parents: 3529
diff changeset
869 sseW[i][4*k + 0] = w[i][k+0].real;
3483390a902b sse opt
michael
parents: 3529
diff changeset
870 sseW[i][4*k + 1] = w[i][k+0].real;
3483390a902b sse opt
michael
parents: 3529
diff changeset
871 sseW[i][4*k + 2] = w[i][k+1].real;
3483390a902b sse opt
michael
parents: 3529
diff changeset
872 sseW[i][4*k + 3] = w[i][k+1].real;
3483390a902b sse opt
michael
parents: 3529
diff changeset
873
3483390a902b sse opt
michael
parents: 3529
diff changeset
874 sseW[i][4*k + 4] = -w[i][k+0].imag;
3483390a902b sse opt
michael
parents: 3529
diff changeset
875 sseW[i][4*k + 5] = w[i][k+0].imag;
3483390a902b sse opt
michael
parents: 3529
diff changeset
876 sseW[i][4*k + 6] = -w[i][k+1].imag;
3483390a902b sse opt
michael
parents: 3529
diff changeset
877 sseW[i][4*k + 7] = w[i][k+1].imag;
3483390a902b sse opt
michael
parents: 3529
diff changeset
878
3483390a902b sse opt
michael
parents: 3529
diff changeset
879 //we multiply more or less uninitalized numbers so we need to use exactly 0.0
3483390a902b sse opt
michael
parents: 3529
diff changeset
880 if(k==0)
3483390a902b sse opt
michael
parents: 3529
diff changeset
881 {
3483390a902b sse opt
michael
parents: 3529
diff changeset
882 // sseW[i][4*k + 0]= sseW[i][4*k + 1]= 1.0;
3483390a902b sse opt
michael
parents: 3529
diff changeset
883 sseW[i][4*k + 4]= sseW[i][4*k + 5]= 0.0;
3483390a902b sse opt
michael
parents: 3529
diff changeset
884 }
3483390a902b sse opt
michael
parents: 3529
diff changeset
885
3483390a902b sse opt
michael
parents: 3529
diff changeset
886 if(2*k == j)
3483390a902b sse opt
michael
parents: 3529
diff changeset
887 {
3483390a902b sse opt
michael
parents: 3529
diff changeset
888 sseW[i][4*k + 0]= sseW[i][4*k + 1]= 0.0;
3483390a902b sse opt
michael
parents: 3529
diff changeset
889 // sseW[i][4*k + 4]= -(sseW[i][4*k + 5]= -1.0);
3483390a902b sse opt
michael
parents: 3529
diff changeset
890 }
3483390a902b sse opt
michael
parents: 3529
diff changeset
891 }
3483390a902b sse opt
michael
parents: 3529
diff changeset
892 }
3552
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
893
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
894 for(i=0; i<128; i++)
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
895 {
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
896 sseWindow[2*i+0]= -imdct_window[2*i+0];
3553
a501627fc6db sse opt
michael
parents: 3552
diff changeset
897 sseWindow[2*i+1]= imdct_window[2*i+1];
3552
9ff2e3801027 sse opt
michael
parents: 3549
diff changeset
898 }
3553
a501627fc6db sse opt
michael
parents: 3552
diff changeset
899
a501627fc6db sse opt
michael
parents: 3552
diff changeset
900 for(i=0; i<64; i++)
a501627fc6db sse opt
michael
parents: 3552
diff changeset
901 {
a501627fc6db sse opt
michael
parents: 3552
diff changeset
902 sseWindow[256 + 2*i+0]= -imdct_window[254 - 2*i+1];
a501627fc6db sse opt
michael
parents: 3552
diff changeset
903 sseWindow[256 + 2*i+1]= imdct_window[254 - 2*i+0];
a501627fc6db sse opt
michael
parents: 3552
diff changeset
904 sseWindow[384 + 2*i+0]= imdct_window[126 - 2*i+1];
a501627fc6db sse opt
michael
parents: 3552
diff changeset
905 sseWindow[384 + 2*i+1]= -imdct_window[126 - 2*i+0];
a501627fc6db sse opt
michael
parents: 3552
diff changeset
906 }
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
907 #endif // arch_x86
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
908
3720
120ac80f13c2 Fixed #ifdef discrepancy that was breaking compilation on PPC platform
melanson
parents: 3623
diff changeset
909 imdct_512 = imdct_do_512;
120ac80f13c2 Fixed #ifdef discrepancy that was breaking compilation on PPC platform
melanson
parents: 3623
diff changeset
910 #ifdef ARCH_X86
3579
831860fada69 runtime cpu detection for the idct
michael
parents: 3553
diff changeset
911 if(gCpuCaps.hasSSE) imdct_512 = imdct_do_512_sse;
3720
120ac80f13c2 Fixed #ifdef discrepancy that was breaking compilation on PPC platform
melanson
parents: 3623
diff changeset
912 #endif // arch_x86
3394
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
913 imdct_256 = imdct_do_256;
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
914 }
35b18ed357c2 imported from liba52 CVS
arpi
parents:
diff changeset
915 }