1
|
/*
|
2
|
* NEON type conversions
|
3
|
* Copyright (C) 2012, 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>
|
22
|
#include "convert.h"
|
23
|
|
24
|
#ifdef HAVE_CONFIG_H
|
25
|
#include "config.h"
|
26
|
#endif
|
27
|
|
28
|
void neon_convert_ps_si16_4n(short *, const float *, const float *, int);
|
29
|
void neon_convert_si16_ps_4n(float *, const short *, int);
|
30
|
|
31
|
/* 4*N 16-bit signed integer conversion with remainder */
|
32
|
static void neon_convert_si16_ps(float *out,
|
33
|
const short *in,
|
34
|
int len)
|
35
|
{
|
36
|
int start = len / 4 * 4;
|
37
|
|
38
|
neon_convert_si16_ps_4n(out, in, len >> 2);
|
39
|
|
40
|
for (int i = 0; i < len % 4; i++)
|
41
|
out[start + i] = (float) in[start + i];
|
42
|
}
|
43
|
|
44
|
/* 4*N 16-bit signed integer conversion with remainder */
|
45
|
static void neon_convert_ps_si16(short *out,
|
46
|
const float *in,
|
47
|
const float *scale,
|
48
|
int len)
|
49
|
{
|
50
|
int start = len / 4 * 4;
|
51
|
|
52
|
neon_convert_ps_si16_4n(out, in, scale, len >> 2);
|
53
|
|
54
|
for (int i = 0; i < len % 4; i++)
|
55
|
out[start + i] = (short) (in[start + i] * (*scale));
|
56
|
}
|
57
|
//#endif
|
58
|
|
59
|
void convert_float_short(short *out, const float *in, float scale, int len)
|
60
|
{
|
61
|
#ifdef HAVE_NEON
|
62
|
float q[4] = { scale, scale, scale, scale };
|
63
|
|
64
|
if (len % 4)
|
65
|
neon_convert_ps_si16(out, in, q, len);
|
66
|
else
|
67
|
neon_convert_ps_si16_4n(out, in, q, len >> 2);
|
68
|
#else
|
69
|
base_convert_float_short(out, in, scale, len);
|
70
|
#endif
|
71
|
}
|
72
|
|
73
|
void convert_short_float(float *out, const short *in, int len)
|
74
|
{
|
75
|
#ifdef HAVE_NEON
|
76
|
if (len % 4)
|
77
|
neon_convert_si16_ps(out, in, len);
|
78
|
else
|
79
|
neon_convert_si16_ps_4n(out, in, len >> 2);
|
80
|
#else
|
81
|
base_convert_short_float(out, in, len);
|
82
|
#endif
|
83
|
}
|