Thomas Tsou | 7e4e536 | 2013-10-30 21:18:55 -0400 | [diff] [blame] | 1 | /* |
| 2 | * NEON scaling |
| 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 <scale.h> |
| 23 | |
| 24 | #ifdef HAVE_CONFIG_H |
| 25 | #include "config.h" |
| 26 | #endif |
| 27 | |
| 28 | void neon_scale_4n(float *, float *, float *, int); |
| 29 | |
| 30 | static void scale_ps(float *out, float *in, float *scale, int len) |
| 31 | { |
| 32 | float ai, aq, bi, bq; |
| 33 | |
| 34 | bi = scale[0]; |
| 35 | bq = scale[1]; |
| 36 | |
| 37 | for (int i = 0; i < len; i++) { |
| 38 | ai = in[2 * i + 0]; |
| 39 | aq = in[2 * i + 1]; |
| 40 | |
| 41 | out[2 * i + 0] = ai * bi - aq * bq; |
| 42 | out[2 * i + 1] = ai * bq + aq * bi; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void scale_complex(float *out, float *in, float* scale, int len) |
| 47 | { |
| 48 | #ifdef HAVE_NEON |
| 49 | if (len % 4) |
| 50 | scale_ps(out, in, scale, len); |
| 51 | else |
| 52 | neon_scale_4n(in, scale, out, len >> 2); |
| 53 | #else |
| 54 | scale_ps(out, in, scale, len); |
| 55 | #endif |
| 56 | } |