blob: 07cdf594872eecc05dd8a7334f99364fe593b77a [file] [log] [blame]
Thomas Tsou9471d762013-08-20 21:24:24 -04001/*
2 * SSE type conversions
3 * Copyright (C) 2013 Thomas Tsou <tom@tsou.cc>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <malloc.h>
21#include <string.h>
Thomas Tsou17bbb9b2013-10-30 21:24:40 -040022#include "convert.h"
Philipp Maiere8ae9fc2017-03-20 12:08:42 +010023#include "convert_sse_3.h"
24#include "convert_sse_4_1.h"
Thomas Tsou9471d762013-08-20 21:24:24 -040025
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
Philipp Maier7e07cf22017-03-15 18:09:35 +010030/* Architecture dependant function pointers */
31struct convert_cpu_context {
32 void (*convert_si16_ps_16n) (float *, const short *, int);
33 void (*convert_si16_ps) (float *, const short *, int);
34 void (*convert_scale_ps_si16_16n)(short *, const float *, float, int);
35 void (*convert_scale_ps_si16_8n)(short *, const float *, float, int);
36 void (*convert_scale_ps_si16)(short *, const float *, float, int);
37};
38
39static struct convert_cpu_context c;
40
Philipp Maier7e07cf22017-03-15 18:09:35 +010041void convert_init(void)
42{
Philipp Maierfe976982017-03-16 14:50:25 +010043 c.convert_scale_ps_si16_16n = base_convert_float_short;
44 c.convert_scale_ps_si16_8n = base_convert_float_short;
45 c.convert_scale_ps_si16 = base_convert_float_short;
46 c.convert_si16_ps_16n = base_convert_short_float;
47 c.convert_si16_ps = base_convert_short_float;
Philipp Maier7e07cf22017-03-15 18:09:35 +010048
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +030049#ifdef HAVE___BUILTIN_CPU_SUPPORTS
Philipp Maier7e07cf22017-03-15 18:09:35 +010050#ifdef HAVE_SSE4_1
51 if (__builtin_cpu_supports("sse4.1")) {
52 c.convert_si16_ps_16n = &_sse_convert_si16_ps_16n;
53 c.convert_si16_ps = &_sse_convert_si16_ps;
54 }
Thomas Tsou9471d762013-08-20 21:24:24 -040055#endif
56
Philipp Maier7e07cf22017-03-15 18:09:35 +010057#ifdef HAVE_SSE3
58 if (__builtin_cpu_supports("sse3")) {
59 c.convert_scale_ps_si16_16n = _sse_convert_scale_ps_si16_16n;
60 c.convert_scale_ps_si16_8n = _sse_convert_scale_ps_si16_8n;
61 c.convert_scale_ps_si16 = _sse_convert_scale_ps_si16;
62 }
63#endif
Vadim Yanitskiy3bd763d2017-05-20 01:46:51 +030064#endif
Philipp Maier7e07cf22017-03-15 18:09:35 +010065}
66
Tom Tsouf147b172015-03-25 12:55:11 -070067void convert_float_short(short *out, const float *in, float scale, int len)
Thomas Tsou9471d762013-08-20 21:24:24 -040068{
Thomas Tsou9471d762013-08-20 21:24:24 -040069 if (!(len % 16))
Philipp Maier7e07cf22017-03-15 18:09:35 +010070 c.convert_scale_ps_si16_16n(out, in, scale, len);
Thomas Tsou9471d762013-08-20 21:24:24 -040071 else if (!(len % 8))
Philipp Maier7e07cf22017-03-15 18:09:35 +010072 c.convert_scale_ps_si16_8n(out, in, scale, len);
Thomas Tsou9471d762013-08-20 21:24:24 -040073 else
Philipp Maier7e07cf22017-03-15 18:09:35 +010074 c.convert_scale_ps_si16(out, in, scale, len);
Thomas Tsou9471d762013-08-20 21:24:24 -040075}
76
Tom Tsouf147b172015-03-25 12:55:11 -070077void convert_short_float(float *out, const short *in, int len)
Thomas Tsou9471d762013-08-20 21:24:24 -040078{
Thomas Tsou9471d762013-08-20 21:24:24 -040079 if (!(len % 16))
Philipp Maier7e07cf22017-03-15 18:09:35 +010080 c.convert_si16_ps_16n(out, in, len);
Thomas Tsou9471d762013-08-20 21:24:24 -040081 else
Philipp Maier7e07cf22017-03-15 18:09:35 +010082 c.convert_si16_ps(out, in, len);
Thomas Tsou9471d762013-08-20 21:24:24 -040083}