2 * MP3 quantization, intrinsics functions
4 * Copyright (c) 2005-2006 Gabriel Bouvigne
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
31 #include "lame_intrin.h"
35 #ifdef HAVE_XMMINTRIN_H
37 #include <xmmintrin.h>
40 int32_t _i_32[4]; /* unions are initialized by its first member */
45 #define TRI_SIZE (5-1) /* 1024 = 4**5 */
46 static const FLOAT costab[TRI_SIZE * 2] = {
47 9.238795325112867e-01, 3.826834323650898e-01,
48 9.951847266721969e-01, 9.801714032956060e-02,
49 9.996988186962042e-01, 2.454122852291229e-02,
50 9.999811752826011e-01, 6.135884649154475e-03
56 init_xrpow_core_sse(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum)
61 int upper4 = (upper / 4) * 4;
62 int rest = upper-upper4;
64 const vecfloat_union fabs_mask = {{ 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF, 0x7FFFFFFF }};
65 const __m128 vec_fabs_mask = _mm_loadu_ps(&fabs_mask._float[0]);
66 vecfloat_union vec_xrpow_max;
67 vecfloat_union vec_sum;
68 vecfloat_union vec_tmp;
70 _mm_prefetch((char *) cod_info->xr, _MM_HINT_T0);
71 _mm_prefetch((char *) xrpow, _MM_HINT_T0);
73 vec_xrpow_max._m128 = _mm_set_ps1(0);
74 vec_sum._m128 = _mm_set_ps1(0);
76 for (i = 0; i < upper4; i += 4) {
77 vec_tmp._m128 = _mm_loadu_ps(&(cod_info->xr[i])); /* load */
78 vec_tmp._m128 = _mm_and_ps(vec_tmp._m128, vec_fabs_mask); /* fabs */
79 vec_sum._m128 = _mm_add_ps(vec_sum._m128, vec_tmp._m128);
80 vec_tmp._m128 = _mm_sqrt_ps(_mm_mul_ps(vec_tmp._m128, _mm_sqrt_ps(vec_tmp._m128)));
81 vec_xrpow_max._m128 = _mm_max_ps(vec_xrpow_max._m128, vec_tmp._m128); /* retrieve max */
82 _mm_storeu_ps(&(xrpow[i]), vec_tmp._m128); /* store into xrpow[] */
84 vec_tmp._m128 = _mm_set_ps1(0);
86 case 3: vec_tmp._float[2] = cod_info->xr[upper4+2];
87 case 2: vec_tmp._float[1] = cod_info->xr[upper4+1];
88 case 1: vec_tmp._float[0] = cod_info->xr[upper4+0];
89 vec_tmp._m128 = _mm_and_ps(vec_tmp._m128, vec_fabs_mask); /* fabs */
90 vec_sum._m128 = _mm_add_ps(vec_sum._m128, vec_tmp._m128);
91 vec_tmp._m128 = _mm_sqrt_ps(_mm_mul_ps(vec_tmp._m128, _mm_sqrt_ps(vec_tmp._m128)));
92 vec_xrpow_max._m128 = _mm_max_ps(vec_xrpow_max._m128, vec_tmp._m128); /* retrieve max */
94 case 3: xrpow[upper4+2] = vec_tmp._float[2];
95 case 2: xrpow[upper4+1] = vec_tmp._float[1];
96 case 1: xrpow[upper4+0] = vec_tmp._float[0];
103 tmp_sum = vec_sum._float[0] + vec_sum._float[1] + vec_sum._float[2] + vec_sum._float[3];
105 float ma = vec_xrpow_max._float[0] > vec_xrpow_max._float[1]
106 ? vec_xrpow_max._float[0] : vec_xrpow_max._float[1];
107 float mb = vec_xrpow_max._float[2] > vec_xrpow_max._float[3]
108 ? vec_xrpow_max._float[2] : vec_xrpow_max._float[3];
109 tmp_max = ma > mb ? ma : mb;
111 cod_info->xrpow_max = tmp_max;
116 static void store4(__m128 v, float* f0, float* f1, float* f2, float* f3)
128 fht_SSE2(FLOAT * fz, int n)
130 const FLOAT *tri = costab;
135 n <<= 1; /* to get BLKSIZE, because of 3DNow! ASM routine */
140 int i, k1, k2, k3, kx;
149 FLOAT f0, f1, f2, f3;
152 f3 = fi[k2] - fi[k3];
153 f2 = fi[k2] + fi[k3];
171 for (i = 1; i < kx; i++) {
176 FLOAT c2, s2, s1_2 = s1+s1;
181 v_c1 = _mm_set_ps1(c1);
182 v_s1 = _mm_set_ps1(s1);
183 v_c2 = _mm_set_ps1(c2);
184 v_s2 = _mm_set_ps1(s2);
186 static const vecfloat_union sign_mask = {{0x80000000,0,0,0}};
187 v_c1 = _mm_xor_ps(sign_mask._m128, v_c1); /* v_c1 := {-c1, +c1, +c1, +c1} */
190 static const vecfloat_union sign_mask = {{0,0x80000000,0,0}};
191 v_s1 = _mm_xor_ps(sign_mask._m128, v_s1); /* v_s1 := {+s1, -s1, +s1, +s1} */
194 static const vecfloat_union sign_mask = {{0,0,0x80000000,0x80000000}};
195 v_c2 = _mm_xor_ps(sign_mask._m128, v_c2); /* v_c2 := {+c2, +c2, -c2, -c2} */
200 q = _mm_setr_ps(fi[k1], fi[k3], gi[k1], gi[k3]); /* Q := {fi_k1,fi_k3,gi_k1,gi_k3}*/
201 p = _mm_mul_ps(_mm_set_ps1(s2), q); /* P := s2 * Q */
202 q = _mm_mul_ps(v_c2, q); /* Q := c2 * Q */
203 q = _mm_shuffle_ps(q, q, _MM_SHUFFLE(1,0,3,2)); /* Q := {-c2*gi_k1,-c2*gi_k3,c2*fi_k1,c2*fi_k3} */
204 p = _mm_add_ps(p, q);
206 r = _mm_setr_ps(gi[0], gi[k2], fi[0], fi[k2]); /* R := {gi_0,gi_k2,fi_0,fi_k2} */
207 q = _mm_sub_ps(r, p); /* Q := {gi_0-p0,gi_k2-p1,fi_0-p2,fi_k2-p3} */
208 r = _mm_add_ps(r, p); /* R := {gi_0+p0,gi_k2+p1,fi_0+p2,fi_k2+p3} */
209 p = _mm_shuffle_ps(q, r, _MM_SHUFFLE(2,0,2,0)); /* P := {q0,q2,r0,r2} */
210 p = _mm_shuffle_ps(p, p, _MM_SHUFFLE(3,1,2,0)); /* P := {q0,r0,q2,r2} */
211 q = _mm_shuffle_ps(q, r, _MM_SHUFFLE(3,1,3,1)); /* Q := {q1,q3,r1,r3} */
212 r = _mm_mul_ps(v_c1, q);
213 q = _mm_mul_ps(v_s1, q);
214 q = _mm_shuffle_ps(q, q, _MM_SHUFFLE(0,1,2,3)); /* Q := {q3,q2,q1,q0} */
215 q = _mm_add_ps(q, r);
217 store4(_mm_sub_ps(p, q), &gi[k3], &gi[k2], &fi[k3], &fi[k2]);
218 store4(_mm_add_ps(p, q), &gi[k1], &gi[ 0], &fi[k1], &fi[ 0]);
224 c1 = c2 * tri[0] - s1 * tri[1];
225 s1 = c2 * tri[1] + s1 * tri[0];
231 #endif /* HAVE_XMMINTRIN_H */