Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 1 | /* |
| 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 Tsou | 17bbb9b | 2013-10-30 21:24:40 -0400 | [diff] [blame] | 22 | #include "convert.h" |
Philipp Maier | e8ae9fc | 2017-03-20 12:08:42 +0100 | [diff] [blame] | 23 | #include "convert_sse_3.h" |
| 24 | #include "convert_sse_4_1.h" |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 25 | |
| 26 | #ifdef HAVE_CONFIG_H |
| 27 | #include "config.h" |
| 28 | #endif |
| 29 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 30 | /* Architecture dependant function pointers */ |
| 31 | struct 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 | |
| 39 | static struct convert_cpu_context c; |
| 40 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 41 | void convert_init(void) |
| 42 | { |
Philipp Maier | fe97698 | 2017-03-16 14:50:25 +0100 | [diff] [blame] | 43 | 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 Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 48 | |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 49 | #ifdef HAVE___BUILTIN_CPU_SUPPORTS |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 50 | #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 Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 55 | #endif |
| 56 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 57 | #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 Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 64 | #endif |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Tom Tsou | f147b17 | 2015-03-25 12:55:11 -0700 | [diff] [blame] | 67 | void convert_float_short(short *out, const float *in, float scale, int len) |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 68 | { |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 69 | if (!(len % 16)) |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 70 | c.convert_scale_ps_si16_16n(out, in, scale, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 71 | else if (!(len % 8)) |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 72 | c.convert_scale_ps_si16_8n(out, in, scale, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 73 | else |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 74 | c.convert_scale_ps_si16(out, in, scale, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 75 | } |
| 76 | |
Tom Tsou | f147b17 | 2015-03-25 12:55:11 -0700 | [diff] [blame] | 77 | void convert_short_float(float *out, const short *in, int len) |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 78 | { |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 79 | if (!(len % 16)) |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 80 | c.convert_si16_ps_16n(out, in, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 81 | else |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 82 | c.convert_si16_ps(out, in, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 83 | } |