Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 1 | /* |
| 2 | * NEON type conversions |
| 3 | * Copyright (C) 2012, 2013 Thomas Tsou <tom@tsou.cc> |
| 4 | * |
Pau Espin Pedrol | 21d03d3 | 2019-07-22 12:05:52 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: LGPL-2.1+ |
| 6 | * |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include <malloc.h> |
| 23 | #include <string.h> |
| 24 | #include "convert.h" |
| 25 | |
| 26 | #ifdef HAVE_CONFIG_H |
| 27 | #include "config.h" |
| 28 | #endif |
| 29 | |
Tom Tsou | 99cf930 | 2015-11-09 20:05:04 +0000 | [diff] [blame] | 30 | void neon_convert_ps_si16_4n(short *, const float *, const float *, int); |
| 31 | void neon_convert_si16_ps_4n(float *, const short *, int); |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 32 | |
Pau Espin Pedrol | 4a25d6b | 2018-01-11 17:55:03 +0100 | [diff] [blame] | 33 | void convert_init(void) { |
| 34 | } |
| 35 | |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 36 | /* 4*N 16-bit signed integer conversion with remainder */ |
Tom Tsou | 99cf930 | 2015-11-09 20:05:04 +0000 | [diff] [blame] | 37 | static void neon_convert_si16_ps(float *out, |
| 38 | const short *in, |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 39 | int len) |
| 40 | { |
| 41 | int start = len / 4 * 4; |
| 42 | |
| 43 | neon_convert_si16_ps_4n(out, in, len >> 2); |
| 44 | |
| 45 | for (int i = 0; i < len % 4; i++) |
| 46 | out[start + i] = (float) in[start + i]; |
| 47 | } |
| 48 | |
| 49 | /* 4*N 16-bit signed integer conversion with remainder */ |
Tom Tsou | 99cf930 | 2015-11-09 20:05:04 +0000 | [diff] [blame] | 50 | static void neon_convert_ps_si16(short *out, |
| 51 | const float *in, |
| 52 | const float *scale, |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 53 | int len) |
| 54 | { |
| 55 | int start = len / 4 * 4; |
| 56 | |
| 57 | neon_convert_ps_si16_4n(out, in, scale, len >> 2); |
| 58 | |
| 59 | for (int i = 0; i < len % 4; i++) |
| 60 | out[start + i] = (short) (in[start + i] * (*scale)); |
| 61 | } |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 62 | |
Tom Tsou | 99cf930 | 2015-11-09 20:05:04 +0000 | [diff] [blame] | 63 | void convert_float_short(short *out, const float *in, float scale, int len) |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 64 | { |
| 65 | #ifdef HAVE_NEON |
| 66 | float q[4] = { scale, scale, scale, scale }; |
| 67 | |
| 68 | if (len % 4) |
| 69 | neon_convert_ps_si16(out, in, q, len); |
| 70 | else |
| 71 | neon_convert_ps_si16_4n(out, in, q, len >> 2); |
| 72 | #else |
Philipp Maier | fe97698 | 2017-03-16 14:50:25 +0100 | [diff] [blame] | 73 | base_convert_float_short(out, in, scale, len); |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 74 | #endif |
| 75 | } |
| 76 | |
Tom Tsou | 99cf930 | 2015-11-09 20:05:04 +0000 | [diff] [blame] | 77 | void convert_short_float(float *out, const short *in, int len) |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 78 | { |
| 79 | #ifdef HAVE_NEON |
| 80 | if (len % 4) |
| 81 | neon_convert_si16_ps(out, in, len); |
| 82 | else |
| 83 | neon_convert_si16_ps_4n(out, in, len >> 2); |
| 84 | #else |
Philipp Maier | fe97698 | 2017-03-16 14:50:25 +0100 | [diff] [blame] | 85 | base_convert_short_float(out, in, len); |
Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 86 | #endif |
| 87 | } |