Enable libmvec support for AArch64
[platform/upstream/glibc.git] / sysdeps / aarch64 / fpu / sve_utils.h
1 /* Helpers for SVE vector math functions.
2
3    Copyright (C) 2023 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5
6    The GNU C Library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    The GNU C Library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with the GNU C Library; if not, see
18    <https://www.gnu.org/licenses/>.  */
19
20 #include <arm_sve.h>
21
22 #define SV_NAME_F1(fun) _ZGVsMxv_##fun##f
23 #define SV_NAME_D1(fun) _ZGVsMxv_##fun
24 #define SV_NAME_F2(fun) _ZGVsMxvv_##fun##f
25 #define SV_NAME_D2(fun) _ZGVsMxvv_##fun
26
27 static __always_inline svfloat32_t
28 sv_call_f32 (float (*f) (float), svfloat32_t x, svfloat32_t y, svbool_t cmp)
29 {
30   svbool_t p = svpfirst (cmp, svpfalse ());
31   while (svptest_any (cmp, p))
32     {
33       float elem = svclastb_n_f32 (p, 0, x);
34       elem = (*f) (elem);
35       svfloat32_t y2 = svdup_n_f32 (elem);
36       y = svsel_f32 (p, y2, y);
37       p = svpnext_b32 (cmp, p);
38     }
39   return y;
40 }
41
42 static __always_inline svfloat64_t
43 sv_call_f64 (double (*f) (double), svfloat64_t x, svfloat64_t y, svbool_t cmp)
44 {
45   svbool_t p = svpfirst (cmp, svpfalse ());
46   while (svptest_any (cmp, p))
47     {
48       double elem = svclastb_n_f64 (p, 0, x);
49       elem = (*f) (elem);
50       svfloat64_t y2 = svdup_n_f64 (elem);
51       y = svsel_f64 (p, y2, y);
52       p = svpnext_b64 (cmp, p);
53     }
54   return y;
55 }