mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-13 13:30:05 -05:00
audioconvert: tweak conversion constants
Tweak the conversion constants a bit so that they handle the extreme ranges a bit better. Align the C and vector instructions. Reactivate the unit test asserts when a conversion fails.
This commit is contained in:
parent
e3951cc1f1
commit
22317da685
4 changed files with 237 additions and 227 deletions
|
|
@ -353,7 +353,7 @@ conv_s32_to_f32d_4s_avx2(void *data, void * SPA_RESTRICT dst[], const void * SPA
|
|||
float *d0 = dst[0], *d1 = dst[1], *d2 = dst[2], *d3 = dst[3];
|
||||
uint32_t n, unrolled;
|
||||
__m256i in[4], t[4];
|
||||
__m256 out[4], factor = _mm256_set1_ps(1.0f / S24_SCALE);
|
||||
__m256 out[4], factor = _mm256_set1_ps(1.0f / S32_SCALE);
|
||||
__m256i mask1 = _mm256_setr_epi64x(0*n_channels, 0*n_channels+2, 4*n_channels, 4*n_channels+2);
|
||||
__m256i mask2 = _mm256_setr_epi64x(1*n_channels, 1*n_channels+2, 5*n_channels, 5*n_channels+2);
|
||||
__m256i mask3 = _mm256_setr_epi64x(2*n_channels, 2*n_channels+2, 6*n_channels, 6*n_channels+2);
|
||||
|
|
@ -373,11 +373,6 @@ conv_s32_to_f32d_4s_avx2(void *data, void * SPA_RESTRICT dst[], const void * SPA
|
|||
in[2] = _mm256_i64gather_epi64((long long int *)&s[0*n_channels], mask3, 4);
|
||||
in[3] = _mm256_i64gather_epi64((long long int *)&s[0*n_channels], mask4, 4);
|
||||
|
||||
in[0] = _mm256_srai_epi32(in[0], 8); /* a0 b0 c0 d0 a4 b4 c4 d4 */
|
||||
in[1] = _mm256_srai_epi32(in[1], 8); /* a1 b1 c1 d1 a5 b5 c5 d5 */
|
||||
in[2] = _mm256_srai_epi32(in[2], 8); /* a2 b2 c2 d2 a6 b6 c6 d6 */
|
||||
in[3] = _mm256_srai_epi32(in[3], 8); /* a3 b3 c3 d3 a7 b7 c7 d7 */
|
||||
|
||||
t[0] = _mm256_unpacklo_epi32(in[0], in[1]); /* a0 a1 b0 b1 a4 a5 b4 b5 */
|
||||
t[1] = _mm256_unpackhi_epi32(in[0], in[1]); /* c0 c1 d0 d1 c4 c5 d4 d5 */
|
||||
t[2] = _mm256_unpacklo_epi32(in[2], in[3]); /* a2 a3 b2 b3 a6 a7 b6 b7 */
|
||||
|
|
@ -405,11 +400,11 @@ conv_s32_to_f32d_4s_avx2(void *data, void * SPA_RESTRICT dst[], const void * SPA
|
|||
s += 8*n_channels;
|
||||
}
|
||||
for(; n < n_samples; n++) {
|
||||
__m128 out[4], factor = _mm_set1_ps(1.0f / S24_SCALE);
|
||||
out[0] = _mm_cvtsi32_ss(factor, s[0]>>8);
|
||||
out[1] = _mm_cvtsi32_ss(factor, s[1]>>8);
|
||||
out[2] = _mm_cvtsi32_ss(factor, s[2]>>8);
|
||||
out[3] = _mm_cvtsi32_ss(factor, s[3]>>8);
|
||||
__m128 out[4], factor = _mm_set1_ps(1.0f / S32_SCALE);
|
||||
out[0] = _mm_cvtsi32_ss(factor, s[0]);
|
||||
out[1] = _mm_cvtsi32_ss(factor, s[1]);
|
||||
out[2] = _mm_cvtsi32_ss(factor, s[2]);
|
||||
out[3] = _mm_cvtsi32_ss(factor, s[3]);
|
||||
out[0] = _mm_mul_ss(out[0], factor);
|
||||
out[1] = _mm_mul_ss(out[1], factor);
|
||||
out[2] = _mm_mul_ss(out[2], factor);
|
||||
|
|
@ -430,7 +425,7 @@ conv_s32_to_f32d_2s_avx2(void *data, void * SPA_RESTRICT dst[], const void * SPA
|
|||
float *d0 = dst[0], *d1 = dst[1];
|
||||
uint32_t n, unrolled;
|
||||
__m256i in[4], t[4];
|
||||
__m256 out[4], factor = _mm256_set1_ps(1.0f / S24_SCALE);
|
||||
__m256 out[4], factor = _mm256_set1_ps(1.0f / S32_SCALE);
|
||||
__m256i perm = _mm256_setr_epi32(0, 2, 4, 6, 1, 3, 5, 7);
|
||||
__m256i mask1 = _mm256_setr_epi64x(0*n_channels, 1*n_channels, 2*n_channels, 3*n_channels);
|
||||
__m256i mask2 = _mm256_setr_epi64x(4*n_channels, 5*n_channels, 6*n_channels, 7*n_channels);
|
||||
|
|
@ -445,9 +440,6 @@ conv_s32_to_f32d_2s_avx2(void *data, void * SPA_RESTRICT dst[], const void * SPA
|
|||
in[0] = _mm256_i64gather_epi64((long long int *)s, mask1, 4);
|
||||
in[1] = _mm256_i64gather_epi64((long long int *)s, mask2, 4);
|
||||
|
||||
in[0] = _mm256_srai_epi32(in[0], 8);
|
||||
in[1] = _mm256_srai_epi32(in[1], 8);
|
||||
|
||||
t[0] = _mm256_permutevar8x32_epi32(in[0], perm);
|
||||
t[1] = _mm256_permutevar8x32_epi32(in[1], perm);
|
||||
|
||||
|
|
@ -466,9 +458,9 @@ conv_s32_to_f32d_2s_avx2(void *data, void * SPA_RESTRICT dst[], const void * SPA
|
|||
s += 8*n_channels;
|
||||
}
|
||||
for(; n < n_samples; n++) {
|
||||
__m128 out[2], factor = _mm_set1_ps(1.0f / S24_SCALE);
|
||||
out[0] = _mm_cvtsi32_ss(factor, s[0]>>8);
|
||||
out[1] = _mm_cvtsi32_ss(factor, s[1]>>8);
|
||||
__m128 out[2], factor = _mm_set1_ps(1.0f / S32_SCALE);
|
||||
out[0] = _mm_cvtsi32_ss(factor, s[0]);
|
||||
out[1] = _mm_cvtsi32_ss(factor, s[1]);
|
||||
out[0] = _mm_mul_ss(out[0], factor);
|
||||
out[1] = _mm_mul_ss(out[1], factor);
|
||||
_mm_store_ss(&d0[n], out[0]);
|
||||
|
|
@ -485,7 +477,7 @@ conv_s32_to_f32d_1s_avx2(void *data, void * SPA_RESTRICT dst[], const void * SPA
|
|||
float *d0 = dst[0];
|
||||
uint32_t n, unrolled;
|
||||
__m256i in[2];
|
||||
__m256 out[2], factor = _mm256_set1_ps(1.0f / S24_SCALE);
|
||||
__m256 out[2], factor = _mm256_set1_ps(1.0f / S32_SCALE);
|
||||
__m256i mask1 = _mm256_setr_epi64x(0*n_channels, 1*n_channels, 2*n_channels, 3*n_channels);
|
||||
__m256i mask2 = _mm256_setr_epi64x(4*n_channels, 5*n_channels, 6*n_channels, 7*n_channels);
|
||||
|
||||
|
|
@ -502,9 +494,6 @@ conv_s32_to_f32d_1s_avx2(void *data, void * SPA_RESTRICT dst[], const void * SPA
|
|||
_mm256_i64gather_epi32(&s[ 8*n_channels], mask1, 4),
|
||||
_mm256_i64gather_epi32(&s[ 8*n_channels], mask2, 4));
|
||||
|
||||
in[0] = _mm256_srai_epi32(in[0], 8);
|
||||
in[1] = _mm256_srai_epi32(in[1], 8);
|
||||
|
||||
out[0] = _mm256_cvtepi32_ps(in[0]);
|
||||
out[1] = _mm256_cvtepi32_ps(in[1]);
|
||||
|
||||
|
|
@ -517,8 +506,8 @@ conv_s32_to_f32d_1s_avx2(void *data, void * SPA_RESTRICT dst[], const void * SPA
|
|||
s += 16*n_channels;
|
||||
}
|
||||
for(; n < n_samples; n++) {
|
||||
__m128 out, factor = _mm_set1_ps(1.0f / S24_SCALE);
|
||||
out = _mm_cvtsi32_ss(factor, s[0]>>8);
|
||||
__m128 out, factor = _mm_set1_ps(1.0f / S32_SCALE);
|
||||
out = _mm_cvtsi32_ss(factor, s[0]);
|
||||
out = _mm_mul_ss(out, factor);
|
||||
_mm_store_ss(&d0[n], out);
|
||||
s += n_channels;
|
||||
|
|
@ -560,7 +549,7 @@ conv_f32d_to_s32_1s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
for(n = 0; n < unrolled; n += 4) {
|
||||
in[0] = _mm_mul_ps(_mm_load_ps(&s0[n]), scale);
|
||||
in[0] = _mm_min_ps(in[0], int_max);
|
||||
out[0] = _mm_cvtps_epi32(in[0]);
|
||||
out[0] = _mm_cvttps_epi32(in[0]);
|
||||
out[1] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(0, 3, 2, 1));
|
||||
out[2] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(1, 0, 3, 2));
|
||||
out[3] = _mm_shuffle_epi32(out[0], _MM_SHUFFLE(2, 1, 0, 3));
|
||||
|
|
@ -605,8 +594,8 @@ conv_f32d_to_s32_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
in[0] = _mm256_min_ps(in[0], int_max);
|
||||
in[1] = _mm256_min_ps(in[1], int_max);
|
||||
|
||||
out[0] = _mm256_cvtps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[1] = _mm256_cvtps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
out[0] = _mm256_cvttps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[1] = _mm256_cvttps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
|
||||
t[0] = _mm256_unpacklo_epi32(out[0], out[1]); /* a0 b0 a1 b1 a4 b4 a5 b5 */
|
||||
t[1] = _mm256_unpackhi_epi32(out[0], out[1]); /* a2 b2 a3 b3 a6 b6 a7 b7 */
|
||||
|
|
@ -645,7 +634,7 @@ conv_f32d_to_s32_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
|
||||
in[0] = _mm_mul_ps(in[0], scale);
|
||||
in[0] = _mm_min_ps(in[0], int_max);
|
||||
out[0] = _mm_cvtps_epi32(in[0]);
|
||||
out[0] = _mm_cvttps_epi32(in[0]);
|
||||
_mm_storel_epi64((__m128i*)d, out[0]);
|
||||
d += n_channels;
|
||||
}
|
||||
|
|
@ -682,10 +671,10 @@ conv_f32d_to_s32_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
in[2] = _mm256_min_ps(in[2], int_max);
|
||||
in[3] = _mm256_min_ps(in[3], int_max);
|
||||
|
||||
out[0] = _mm256_cvtps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[1] = _mm256_cvtps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
out[2] = _mm256_cvtps_epi32(in[2]); /* c0 c1 c2 c3 c4 c5 c6 c7 */
|
||||
out[3] = _mm256_cvtps_epi32(in[3]); /* d0 d1 d2 d3 d4 d5 d6 d7 */
|
||||
out[0] = _mm256_cvttps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[1] = _mm256_cvttps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
out[2] = _mm256_cvttps_epi32(in[2]); /* c0 c1 c2 c3 c4 c5 c6 c7 */
|
||||
out[3] = _mm256_cvttps_epi32(in[3]); /* d0 d1 d2 d3 d4 d5 d6 d7 */
|
||||
|
||||
t[0] = _mm256_unpacklo_epi32(out[0], out[1]); /* a0 b0 a1 b1 a4 b4 a5 b5 */
|
||||
t[1] = _mm256_unpackhi_epi32(out[0], out[1]); /* a2 b2 a3 b3 a6 b6 a7 b7 */
|
||||
|
|
@ -724,7 +713,7 @@ conv_f32d_to_s32_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
|
||||
in[0] = _mm_mul_ps(in[0], scale);
|
||||
in[0] = _mm_min_ps(in[0], int_max);
|
||||
out[0] = _mm_cvtps_epi32(in[0]);
|
||||
out[0] = _mm_cvttps_epi32(in[0]);
|
||||
_mm_storeu_si128((__m128i*)d, out[0]);
|
||||
d += n_channels;
|
||||
}
|
||||
|
|
@ -754,8 +743,9 @@ conv_f32d_to_s16_1s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
uint32_t n, unrolled;
|
||||
__m128 in[2];
|
||||
__m128i out[2];
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX_F);
|
||||
__m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
|
||||
__m128 int_scale = _mm_set1_ps(S16_SCALE);
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX);
|
||||
__m128 int_min = _mm_set1_ps(S16_MIN);
|
||||
|
||||
if (SPA_IS_ALIGNED(s0, 16))
|
||||
unrolled = n_samples & ~7;
|
||||
|
|
@ -763,10 +753,10 @@ conv_f32d_to_s16_1s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
unrolled = 0;
|
||||
|
||||
for(n = 0; n < unrolled; n += 8) {
|
||||
in[0] = _mm_mul_ps(_mm_load_ps(&s0[n]), int_max);
|
||||
in[1] = _mm_mul_ps(_mm_load_ps(&s0[n+4]), int_max);
|
||||
out[0] = _mm_cvtps_epi32(in[0]);
|
||||
out[1] = _mm_cvtps_epi32(in[1]);
|
||||
in[0] = _mm_mul_ps(_mm_load_ps(&s0[n]), int_scale);
|
||||
in[1] = _mm_mul_ps(_mm_load_ps(&s0[n+4]), int_scale);
|
||||
out[0] = _mm_cvttps_epi32(in[0]);
|
||||
out[1] = _mm_cvttps_epi32(in[1]);
|
||||
out[0] = _mm_packs_epi32(out[0], out[1]);
|
||||
|
||||
d[0*n_channels] = _mm_extract_epi16(out[0], 0);
|
||||
|
|
@ -780,7 +770,7 @@ conv_f32d_to_s16_1s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
d += 8*n_channels;
|
||||
}
|
||||
for(; n < n_samples; n++) {
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_max);
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_scale);
|
||||
in[0] = _mm_min_ss(int_max, _mm_max_ss(in[0], int_min));
|
||||
*d = _mm_cvtss_si32(in[0]);
|
||||
d += n_channels;
|
||||
|
|
@ -796,7 +786,7 @@ conv_f32d_to_s16_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
uint32_t n, unrolled;
|
||||
__m256 in[2];
|
||||
__m256i out[4], t[2];
|
||||
__m256 int_max = _mm256_set1_ps(S16_MAX_F);
|
||||
__m256 int_scale = _mm256_set1_ps(S16_SCALE);
|
||||
|
||||
if (SPA_IS_ALIGNED(s0, 32) &&
|
||||
SPA_IS_ALIGNED(s1, 32))
|
||||
|
|
@ -805,11 +795,11 @@ conv_f32d_to_s16_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
unrolled = 0;
|
||||
|
||||
for(n = 0; n < unrolled; n += 8) {
|
||||
in[0] = _mm256_mul_ps(_mm256_load_ps(&s0[n+0]), int_max);
|
||||
in[1] = _mm256_mul_ps(_mm256_load_ps(&s1[n+0]), int_max);
|
||||
in[0] = _mm256_mul_ps(_mm256_load_ps(&s0[n+0]), int_scale);
|
||||
in[1] = _mm256_mul_ps(_mm256_load_ps(&s1[n+0]), int_scale);
|
||||
|
||||
out[0] = _mm256_cvtps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[1] = _mm256_cvtps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
out[0] = _mm256_cvttps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[1] = _mm256_cvttps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
|
||||
t[0] = _mm256_unpacklo_epi32(out[0], out[1]); /* a0 b0 a1 b1 a4 b4 a5 b5 */
|
||||
t[1] = _mm256_unpackhi_epi32(out[0], out[1]); /* a2 b2 a3 b3 a6 b6 a7 b7 */
|
||||
|
|
@ -829,11 +819,12 @@ conv_f32d_to_s16_2s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
}
|
||||
for(; n < n_samples; n++) {
|
||||
__m128 in[2];
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX_F);
|
||||
__m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
|
||||
__m128 int_scale = _mm_set1_ps(S16_SCALE);
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX);
|
||||
__m128 int_min = _mm_set1_ps(S16_MIN);
|
||||
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_max);
|
||||
in[1] = _mm_mul_ss(_mm_load_ss(&s1[n]), int_max);
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_scale);
|
||||
in[1] = _mm_mul_ss(_mm_load_ss(&s1[n]), int_scale);
|
||||
in[0] = _mm_min_ss(int_max, _mm_max_ss(in[0], int_min));
|
||||
in[1] = _mm_min_ss(int_max, _mm_max_ss(in[1], int_min));
|
||||
d[0] = _mm_cvtss_si32(in[0]);
|
||||
|
|
@ -851,7 +842,7 @@ conv_f32d_to_s16_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
uint32_t n, unrolled;
|
||||
__m256 in[4];
|
||||
__m256i out[4], t[4];
|
||||
__m256 int_max = _mm256_set1_ps(S16_MAX_F);
|
||||
__m256 int_scale = _mm256_set1_ps(S16_SCALE);
|
||||
|
||||
if (SPA_IS_ALIGNED(s0, 32) &&
|
||||
SPA_IS_ALIGNED(s1, 32) &&
|
||||
|
|
@ -862,15 +853,15 @@ conv_f32d_to_s16_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
unrolled = 0;
|
||||
|
||||
for(n = 0; n < unrolled; n += 8) {
|
||||
in[0] = _mm256_mul_ps(_mm256_load_ps(&s0[n]), int_max);
|
||||
in[1] = _mm256_mul_ps(_mm256_load_ps(&s1[n]), int_max);
|
||||
in[2] = _mm256_mul_ps(_mm256_load_ps(&s2[n]), int_max);
|
||||
in[3] = _mm256_mul_ps(_mm256_load_ps(&s3[n]), int_max);
|
||||
in[0] = _mm256_mul_ps(_mm256_load_ps(&s0[n]), int_scale);
|
||||
in[1] = _mm256_mul_ps(_mm256_load_ps(&s1[n]), int_scale);
|
||||
in[2] = _mm256_mul_ps(_mm256_load_ps(&s2[n]), int_scale);
|
||||
in[3] = _mm256_mul_ps(_mm256_load_ps(&s3[n]), int_scale);
|
||||
|
||||
t[0] = _mm256_cvtps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
t[1] = _mm256_cvtps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
t[2] = _mm256_cvtps_epi32(in[2]); /* c0 c1 c2 c3 c4 c5 c6 c7 */
|
||||
t[3] = _mm256_cvtps_epi32(in[3]); /* d0 d1 d2 d3 d4 d5 d6 d7 */
|
||||
t[0] = _mm256_cvttps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
t[1] = _mm256_cvttps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
t[2] = _mm256_cvttps_epi32(in[2]); /* c0 c1 c2 c3 c4 c5 c6 c7 */
|
||||
t[3] = _mm256_cvttps_epi32(in[3]); /* d0 d1 d2 d3 d4 d5 d6 d7 */
|
||||
|
||||
t[0] = _mm256_packs_epi32(t[0], t[2]); /* a0 a1 a2 a3 c0 c1 c2 c3 a4 a5 a6 a7 c4 c5 c6 c7 */
|
||||
t[1] = _mm256_packs_epi32(t[1], t[3]); /* b0 b1 b2 b3 d0 d1 d2 d3 b4 b5 b6 b7 d4 d5 d6 d7 */
|
||||
|
|
@ -905,13 +896,14 @@ conv_f32d_to_s16_4s_avx2(void *data, void * SPA_RESTRICT dst, const void * SPA_R
|
|||
}
|
||||
for(; n < n_samples; n++) {
|
||||
__m128 in[4];
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX_F);
|
||||
__m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
|
||||
__m128 int_scale = _mm_set1_ps(S16_SCALE);
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX);
|
||||
__m128 int_min = _mm_set1_ps(S16_MIN);
|
||||
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_max);
|
||||
in[1] = _mm_mul_ss(_mm_load_ss(&s1[n]), int_max);
|
||||
in[2] = _mm_mul_ss(_mm_load_ss(&s2[n]), int_max);
|
||||
in[3] = _mm_mul_ss(_mm_load_ss(&s3[n]), int_max);
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_scale);
|
||||
in[1] = _mm_mul_ss(_mm_load_ss(&s1[n]), int_scale);
|
||||
in[2] = _mm_mul_ss(_mm_load_ss(&s2[n]), int_scale);
|
||||
in[3] = _mm_mul_ss(_mm_load_ss(&s3[n]), int_scale);
|
||||
in[0] = _mm_min_ss(int_max, _mm_max_ss(in[0], int_min));
|
||||
in[1] = _mm_min_ss(int_max, _mm_max_ss(in[1], int_min));
|
||||
in[2] = _mm_min_ss(int_max, _mm_max_ss(in[2], int_min));
|
||||
|
|
@ -948,7 +940,7 @@ conv_f32d_to_s16_4_avx2(struct convert *conv, void * SPA_RESTRICT dst[], const v
|
|||
uint32_t n, unrolled;
|
||||
__m256 in[4];
|
||||
__m256i out[4], t[4];
|
||||
__m256 int_max = _mm256_set1_ps(S16_MAX_F);
|
||||
__m256 int_scale = _mm256_set1_ps(S16_SCALE);
|
||||
|
||||
if (SPA_IS_ALIGNED(s0, 32) &&
|
||||
SPA_IS_ALIGNED(s1, 32) &&
|
||||
|
|
@ -959,15 +951,15 @@ conv_f32d_to_s16_4_avx2(struct convert *conv, void * SPA_RESTRICT dst[], const v
|
|||
unrolled = 0;
|
||||
|
||||
for(n = 0; n < unrolled; n += 8) {
|
||||
in[0] = _mm256_mul_ps(_mm256_load_ps(&s0[n]), int_max);
|
||||
in[1] = _mm256_mul_ps(_mm256_load_ps(&s1[n]), int_max);
|
||||
in[2] = _mm256_mul_ps(_mm256_load_ps(&s2[n]), int_max);
|
||||
in[3] = _mm256_mul_ps(_mm256_load_ps(&s3[n]), int_max);
|
||||
in[0] = _mm256_mul_ps(_mm256_load_ps(&s0[n]), int_scale);
|
||||
in[1] = _mm256_mul_ps(_mm256_load_ps(&s1[n]), int_scale);
|
||||
in[2] = _mm256_mul_ps(_mm256_load_ps(&s2[n]), int_scale);
|
||||
in[3] = _mm256_mul_ps(_mm256_load_ps(&s3[n]), int_scale);
|
||||
|
||||
t[0] = _mm256_cvtps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
t[1] = _mm256_cvtps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
t[2] = _mm256_cvtps_epi32(in[2]); /* c0 c1 c2 c3 c4 c5 c6 c7 */
|
||||
t[3] = _mm256_cvtps_epi32(in[3]); /* d0 d1 d2 d3 d4 d5 d6 d7 */
|
||||
t[0] = _mm256_cvttps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
t[1] = _mm256_cvttps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
t[2] = _mm256_cvttps_epi32(in[2]); /* c0 c1 c2 c3 c4 c5 c6 c7 */
|
||||
t[3] = _mm256_cvttps_epi32(in[3]); /* d0 d1 d2 d3 d4 d5 d6 d7 */
|
||||
|
||||
t[0] = _mm256_packs_epi32(t[0], t[2]); /* a0 a1 a2 a3 c0 c1 c2 c3 a4 a5 a6 a7 c4 c5 c6 c7 */
|
||||
t[1] = _mm256_packs_epi32(t[1], t[3]); /* b0 b1 b2 b3 d0 d1 d2 d3 b4 b5 b6 b7 d4 d5 d6 d7 */
|
||||
|
|
@ -987,13 +979,14 @@ conv_f32d_to_s16_4_avx2(struct convert *conv, void * SPA_RESTRICT dst[], const v
|
|||
}
|
||||
for(; n < n_samples; n++) {
|
||||
__m128 in[4];
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX_F);
|
||||
__m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
|
||||
__m128 int_scale = _mm_set1_ps(S16_SCALE);
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX);
|
||||
__m128 int_min = _mm_set1_ps(S16_MIN);
|
||||
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_max);
|
||||
in[1] = _mm_mul_ss(_mm_load_ss(&s1[n]), int_max);
|
||||
in[2] = _mm_mul_ss(_mm_load_ss(&s2[n]), int_max);
|
||||
in[3] = _mm_mul_ss(_mm_load_ss(&s3[n]), int_max);
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_scale);
|
||||
in[1] = _mm_mul_ss(_mm_load_ss(&s1[n]), int_scale);
|
||||
in[2] = _mm_mul_ss(_mm_load_ss(&s2[n]), int_scale);
|
||||
in[3] = _mm_mul_ss(_mm_load_ss(&s3[n]), int_scale);
|
||||
in[0] = _mm_min_ss(int_max, _mm_max_ss(in[0], int_min));
|
||||
in[1] = _mm_min_ss(int_max, _mm_max_ss(in[1], int_min));
|
||||
in[2] = _mm_min_ss(int_max, _mm_max_ss(in[2], int_min));
|
||||
|
|
@ -1014,7 +1007,7 @@ conv_f32d_to_s16_2_avx2(struct convert *conv, void * SPA_RESTRICT dst[], const v
|
|||
uint32_t n, unrolled;
|
||||
__m256 in[4];
|
||||
__m256i out[4], t[4];
|
||||
__m256 int_max = _mm256_set1_ps(S16_MAX_F);
|
||||
__m256 int_scale = _mm256_set1_ps(S16_SCALE);
|
||||
|
||||
if (SPA_IS_ALIGNED(s0, 32) &&
|
||||
SPA_IS_ALIGNED(s1, 32))
|
||||
|
|
@ -1023,15 +1016,15 @@ conv_f32d_to_s16_2_avx2(struct convert *conv, void * SPA_RESTRICT dst[], const v
|
|||
unrolled = 0;
|
||||
|
||||
for(n = 0; n < unrolled; n += 16) {
|
||||
in[0] = _mm256_mul_ps(_mm256_load_ps(&s0[n+0]), int_max);
|
||||
in[1] = _mm256_mul_ps(_mm256_load_ps(&s1[n+0]), int_max);
|
||||
in[2] = _mm256_mul_ps(_mm256_load_ps(&s0[n+8]), int_max);
|
||||
in[3] = _mm256_mul_ps(_mm256_load_ps(&s1[n+8]), int_max);
|
||||
in[0] = _mm256_mul_ps(_mm256_load_ps(&s0[n+0]), int_scale);
|
||||
in[1] = _mm256_mul_ps(_mm256_load_ps(&s1[n+0]), int_scale);
|
||||
in[2] = _mm256_mul_ps(_mm256_load_ps(&s0[n+8]), int_scale);
|
||||
in[3] = _mm256_mul_ps(_mm256_load_ps(&s1[n+8]), int_scale);
|
||||
|
||||
out[0] = _mm256_cvtps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[1] = _mm256_cvtps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
out[2] = _mm256_cvtps_epi32(in[2]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[3] = _mm256_cvtps_epi32(in[3]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
out[0] = _mm256_cvttps_epi32(in[0]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[1] = _mm256_cvttps_epi32(in[1]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
out[2] = _mm256_cvttps_epi32(in[2]); /* a0 a1 a2 a3 a4 a5 a6 a7 */
|
||||
out[3] = _mm256_cvttps_epi32(in[3]); /* b0 b1 b2 b3 b4 b5 b6 b7 */
|
||||
|
||||
t[0] = _mm256_unpacklo_epi32(out[0], out[1]); /* a0 b0 a1 b1 a4 b4 a5 b5 */
|
||||
t[1] = _mm256_unpackhi_epi32(out[0], out[1]); /* a2 b2 a3 b3 a6 b6 a7 b7 */
|
||||
|
|
@ -1048,11 +1041,12 @@ conv_f32d_to_s16_2_avx2(struct convert *conv, void * SPA_RESTRICT dst[], const v
|
|||
}
|
||||
for(; n < n_samples; n++) {
|
||||
__m128 in[4];
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX_F);
|
||||
__m128 int_min = _mm_sub_ps(_mm_setzero_ps(), int_max);
|
||||
__m128 int_scale = _mm_set1_ps(S16_SCALE);
|
||||
__m128 int_max = _mm_set1_ps(S16_MAX);
|
||||
__m128 int_min = _mm_set1_ps(S16_MIN);
|
||||
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_max);
|
||||
in[1] = _mm_mul_ss(_mm_load_ss(&s1[n]), int_max);
|
||||
in[0] = _mm_mul_ss(_mm_load_ss(&s0[n]), int_scale);
|
||||
in[1] = _mm_mul_ss(_mm_load_ss(&s1[n]), int_scale);
|
||||
in[0] = _mm_min_ss(int_max, _mm_max_ss(in[0], int_min));
|
||||
in[1] = _mm_min_ss(int_max, _mm_max_ss(in[1], int_min));
|
||||
d[0] = _mm_cvtss_si32(in[0]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue