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. |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <malloc.h> |
| 17 | #include <string.h> |
Thomas Tsou | 17bbb9b | 2013-10-30 21:24:40 -0400 | [diff] [blame] | 18 | #include "convert.h" |
Philipp Maier | e8ae9fc | 2017-03-20 12:08:42 +0100 | [diff] [blame] | 19 | #include "convert_sse_3.h" |
| 20 | #include "convert_sse_4_1.h" |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 21 | |
| 22 | #ifdef HAVE_CONFIG_H |
| 23 | #include "config.h" |
| 24 | #endif |
| 25 | |
Martin Hauke | 066fd04 | 2019-10-13 19:08:00 +0200 | [diff] [blame] | 26 | /* Architecture dependent function pointers */ |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 27 | struct convert_cpu_context { |
| 28 | void (*convert_si16_ps_16n) (float *, const short *, int); |
| 29 | void (*convert_si16_ps) (float *, const short *, int); |
| 30 | void (*convert_scale_ps_si16_16n)(short *, const float *, float, int); |
| 31 | void (*convert_scale_ps_si16_8n)(short *, const float *, float, int); |
| 32 | void (*convert_scale_ps_si16)(short *, const float *, float, int); |
| 33 | }; |
| 34 | |
| 35 | static struct convert_cpu_context c; |
| 36 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 37 | void convert_init(void) |
| 38 | { |
Philipp Maier | fe97698 | 2017-03-16 14:50:25 +0100 | [diff] [blame] | 39 | c.convert_scale_ps_si16_16n = base_convert_float_short; |
| 40 | c.convert_scale_ps_si16_8n = base_convert_float_short; |
| 41 | c.convert_scale_ps_si16 = base_convert_float_short; |
| 42 | c.convert_si16_ps_16n = base_convert_short_float; |
| 43 | c.convert_si16_ps = base_convert_short_float; |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 44 | |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 45 | #ifdef HAVE___BUILTIN_CPU_SUPPORTS |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 46 | #ifdef HAVE_SSE4_1 |
| 47 | if (__builtin_cpu_supports("sse4.1")) { |
| 48 | c.convert_si16_ps_16n = &_sse_convert_si16_ps_16n; |
| 49 | c.convert_si16_ps = &_sse_convert_si16_ps; |
| 50 | } |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 51 | #endif |
| 52 | |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 53 | #ifdef HAVE_SSE3 |
| 54 | if (__builtin_cpu_supports("sse3")) { |
| 55 | c.convert_scale_ps_si16_16n = _sse_convert_scale_ps_si16_16n; |
| 56 | c.convert_scale_ps_si16_8n = _sse_convert_scale_ps_si16_8n; |
| 57 | c.convert_scale_ps_si16 = _sse_convert_scale_ps_si16; |
| 58 | } |
| 59 | #endif |
Vadim Yanitskiy | 3bd763d | 2017-05-20 01:46:51 +0300 | [diff] [blame] | 60 | #endif |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Tom Tsou | f147b17 | 2015-03-25 12:55:11 -0700 | [diff] [blame] | 63 | 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] | 64 | { |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 65 | if (!(len % 16)) |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 66 | c.convert_scale_ps_si16_16n(out, in, scale, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 67 | else if (!(len % 8)) |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 68 | c.convert_scale_ps_si16_8n(out, in, scale, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 69 | else |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 70 | c.convert_scale_ps_si16(out, in, scale, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 71 | } |
| 72 | |
Tom Tsou | f147b17 | 2015-03-25 12:55:11 -0700 | [diff] [blame] | 73 | void convert_short_float(float *out, const short *in, int len) |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 74 | { |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 75 | if (!(len % 16)) |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 76 | c.convert_si16_ps_16n(out, in, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 77 | else |
Philipp Maier | 7e07cf2 | 2017-03-15 18:09:35 +0100 | [diff] [blame] | 78 | c.convert_si16_ps(out, in, len); |
Thomas Tsou | 9471d76 | 2013-08-20 21:24:24 -0400 | [diff] [blame] | 79 | } |