2023-02-08 18:12:00 +01:00
|
|
|
/* Spa */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2019-03-20 13:04:44 +01:00
|
|
|
|
2019-03-27 17:58:48 +01:00
|
|
|
#include "fmt-ops.h"
|
2019-03-20 13:04:44 +01:00
|
|
|
|
|
|
|
|
#include <smmintrin.h>
|
|
|
|
|
|
2023-10-15 22:20:54 +02:00
|
|
|
#define spa_read_unaligned(ptr, type) \
|
|
|
|
|
__extension__ ({ \
|
|
|
|
|
__typeof__(type) _val; \
|
|
|
|
|
memcpy(&_val, (ptr), sizeof(_val)); \
|
|
|
|
|
_val; \
|
|
|
|
|
})
|
|
|
|
|
|
2019-03-20 13:04:44 +01:00
|
|
|
static void
|
2019-03-29 17:39:59 +01:00
|
|
|
conv_s24_to_f32d_1s_sse41(void *data, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src,
|
|
|
|
|
uint32_t n_channels, uint32_t n_samples)
|
2019-03-20 13:04:44 +01:00
|
|
|
{
|
2022-07-01 12:24:35 +02:00
|
|
|
const int24_t *s = src;
|
2020-03-16 16:11:29 +01:00
|
|
|
float *d0 = dst[0];
|
2019-03-20 13:04:44 +01:00
|
|
|
uint32_t n, unrolled;
|
2022-06-29 14:08:30 +02:00
|
|
|
__m128i in = _mm_setzero_si128();
|
2019-03-20 13:04:44 +01:00
|
|
|
__m128 out, factor = _mm_set1_ps(1.0f / S24_SCALE);
|
|
|
|
|
|
|
|
|
|
if (SPA_IS_ALIGNED(d0, 16))
|
2019-03-28 16:45:57 +01:00
|
|
|
unrolled = n_samples & ~3;
|
2019-03-20 13:04:44 +01:00
|
|
|
else
|
|
|
|
|
unrolled = 0;
|
|
|
|
|
|
2019-03-28 16:45:57 +01:00
|
|
|
for(n = 0; n < unrolled; n += 4) {
|
2023-10-15 22:20:54 +02:00
|
|
|
in = _mm_insert_epi32(in, spa_read_unaligned(&s[0 * n_channels], uint32_t), 0);
|
|
|
|
|
in = _mm_insert_epi32(in, spa_read_unaligned(&s[1 * n_channels], uint32_t), 1);
|
|
|
|
|
in = _mm_insert_epi32(in, spa_read_unaligned(&s[2 * n_channels], uint32_t), 2);
|
|
|
|
|
in = _mm_insert_epi32(in, spa_read_unaligned(&s[3 * n_channels], uint32_t), 3);
|
2019-03-20 13:04:44 +01:00
|
|
|
in = _mm_slli_epi32(in, 8);
|
|
|
|
|
in = _mm_srai_epi32(in, 8);
|
|
|
|
|
out = _mm_cvtepi32_ps(in);
|
|
|
|
|
out = _mm_mul_ps(out, factor);
|
2019-03-27 17:58:48 +01:00
|
|
|
_mm_store_ps(&d0[n], out);
|
2022-07-01 12:24:35 +02:00
|
|
|
s += 4 * n_channels;
|
2019-03-20 13:04:44 +01:00
|
|
|
}
|
|
|
|
|
for(; n < n_samples; n++) {
|
2022-07-01 12:24:35 +02:00
|
|
|
out = _mm_cvtsi32_ss(factor, s24_to_s32(*s));
|
2019-03-20 13:04:44 +01:00
|
|
|
out = _mm_mul_ss(out, factor);
|
|
|
|
|
_mm_store_ss(&d0[n], out);
|
2022-07-01 12:24:35 +02:00
|
|
|
s += n_channels;
|
2019-03-20 13:04:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 17:39:59 +01:00
|
|
|
extern void conv_s24_to_f32d_2s_sse2(void *data, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src,
|
|
|
|
|
uint32_t n_channels, uint32_t n_samples);
|
|
|
|
|
extern void conv_s24_to_f32d_4s_ssse3(void *data, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src,
|
|
|
|
|
uint32_t n_channels, uint32_t n_samples);
|
2019-03-27 17:58:48 +01:00
|
|
|
|
|
|
|
|
void
|
2019-03-29 17:39:59 +01:00
|
|
|
conv_s24_to_f32d_sse41(struct convert *conv, void * SPA_RESTRICT dst[], const void * SPA_RESTRICT src[],
|
|
|
|
|
uint32_t n_samples)
|
2019-03-20 13:04:44 +01:00
|
|
|
{
|
|
|
|
|
const int8_t *s = src[0];
|
2019-03-29 17:39:59 +01:00
|
|
|
uint32_t i = 0, n_channels = conv->n_channels;
|
2019-03-20 13:04:44 +01:00
|
|
|
|
2019-03-27 17:58:48 +01:00
|
|
|
#if defined (HAVE_SSSE3)
|
2019-03-20 13:04:44 +01:00
|
|
|
for(; i + 3 < n_channels; i += 4)
|
2019-03-29 17:39:59 +01:00
|
|
|
conv_s24_to_f32d_4s_ssse3(conv, &dst[i], &s[3*i], n_channels, n_samples);
|
2019-03-27 17:58:48 +01:00
|
|
|
#endif
|
|
|
|
|
#if defined (HAVE_SSE2)
|
2019-03-20 13:04:44 +01:00
|
|
|
for(; i + 1 < n_channels; i += 2)
|
2019-03-29 17:39:59 +01:00
|
|
|
conv_s24_to_f32d_2s_sse2(conv, &dst[i], &s[3*i], n_channels, n_samples);
|
2019-03-27 17:58:48 +01:00
|
|
|
#endif
|
2019-03-20 13:04:44 +01:00
|
|
|
for(; i < n_channels; i++)
|
2019-03-29 17:39:59 +01:00
|
|
|
conv_s24_to_f32d_1s_sse41(conv, &dst[i], &s[3*i], n_channels, n_samples);
|
2019-03-20 13:04:44 +01:00
|
|
|
}
|