git subrepo clone https://github.com/libretro/libretro-common.git deps/libretro-common
[pcsx_rearmed.git] / deps / libretro-common / audio / conversion / s16_to_float_neon.c
1 /* Copyright  (C) 2010-2020 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this file (s16_to_float_neon.S).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #if defined(__ARM_NEON__) && defined(HAVE_ARM_NEON_ASM_OPTIMIZATIONS)
23
24 #if defined(__thumb__)
25 #define DECL_ARMMODE(x) "  .align 2\n" "  .global " x "\n" "  .thumb\n" "  .thumb_func\n" "  .type " x ", %function\n" x ":\n"
26 #else
27 #define DECL_ARMMODE(x) "  .align 4\n" "  .global " x "\n" "  .arm\n" x ":\n"
28 #endif
29
30 asm(
31     DECL_ARMMODE("convert_s16_float_asm")
32     DECL_ARMMODE("_convert_s16_float_asm")
33     "# convert_s16_float_asm(float *out, const int16_t *in, size_t samples, const float *gain)\n"
34     "   # Hacky way to get a constant of 2^-15.\n"
35     "   # Might be faster to just load a constant from memory.\n"
36     "   # It's just done once however ...\n"
37     "   vmov.f32 q8, #0.25\n"
38     "   vmul.f32 q8, q8, q8\n"
39     "   vmul.f32 q8, q8, q8\n"
40     "   vmul.f32 q8, q8, q8\n"
41     "   vadd.f32 q8, q8, q8\n"
42     "\n"
43     "   # Apply gain\n"
44     "   vld1.f32 {d6[0]}, [r3]\n"
45     "   vmul.f32 q8, q8, d6[0]\n"
46     "\n"
47     "1:\n"
48     "   # Preload here?\n"
49     "   vld1.s16 {q0}, [r1]!\n"
50     "\n"
51     "   # Widen to 32-bit\n"
52     "   vmovl.s16 q1, d0\n"
53     "   vmovl.s16 q2, d1\n"
54     "\n"
55     "   # Convert to float\n"
56     "   vcvt.f32.s32 q1, q1\n"
57     "   vcvt.f32.s32 q2, q2\n"
58     "\n"
59     "   vmul.f32 q1, q1, q8\n"
60     "   vmul.f32 q2, q2, q8\n"
61     "\n"
62     "   vst1.f32 {q1-q2}, [r0]!\n"
63     "\n"
64     "   # Guaranteed to get samples in multiples of 8.\n"
65     "   subs r2, r2, #8\n"
66     "   bne 1b\n"
67     "\n"
68     "   bx lr\n"
69     "\n"
70     );
71 #endif