1 /* Utilities for SVE libmvec routines.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C 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.
10 The GNU C 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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
25 #include "vecmath_config.h"
27 #define SV_NAME_F1(fun) _ZGVsMxv_##fun##f
28 #define SV_NAME_D1(fun) _ZGVsMxv_##fun
29 #define SV_NAME_F2(fun) _ZGVsMxvv_##fun##f
30 #define SV_NAME_D2(fun) _ZGVsMxvv_##fun
32 /* Double precision. */
33 static inline svint64_t
36 return svdup_n_s64 (x
);
39 static inline svuint64_t
42 return svdup_n_u64 (x
);
45 static inline svfloat64_t
48 return svdup_n_f64 (x
);
51 static inline svfloat64_t
52 sv_call_f64 (double (*f
) (double), svfloat64_t x
, svfloat64_t y
, svbool_t cmp
)
54 svbool_t p
= svpfirst (cmp
, svpfalse ());
55 while (svptest_any (cmp
, p
))
57 double elem
= svclastb_n_f64 (p
, 0, x
);
59 svfloat64_t y2
= svdup_n_f64 (elem
);
60 y
= svsel_f64 (p
, y2
, y
);
61 p
= svpnext_b64 (cmp
, p
);
66 static inline svfloat64_t
67 sv_call2_f64 (double (*f
) (double, double), svfloat64_t x1
, svfloat64_t x2
,
68 svfloat64_t y
, svbool_t cmp
)
70 svbool_t p
= svpfirst (cmp
, svpfalse ());
71 while (svptest_any (cmp
, p
))
73 double elem1
= svclastb_n_f64 (p
, 0, x1
);
74 double elem2
= svclastb_n_f64 (p
, 0, x2
);
75 double ret
= (*f
) (elem1
, elem2
);
76 svfloat64_t y2
= svdup_n_f64 (ret
);
77 y
= svsel_f64 (p
, y2
, y
);
78 p
= svpnext_b64 (cmp
, p
);
83 static inline svuint64_t
84 sv_mod_n_u64_x (svbool_t pg
, svuint64_t x
, uint64_t y
)
86 svuint64_t q
= svdiv_n_u64_x (pg
, x
, y
);
87 return svmls_n_u64_x (pg
, x
, q
, y
);
90 /* Single precision. */
91 static inline svint32_t
94 return svdup_n_s32 (x
);
97 static inline svuint32_t
100 return svdup_n_u32 (x
);
103 static inline svfloat32_t
106 return svdup_n_f32 (x
);
109 static inline svfloat32_t
110 sv_call_f32 (float (*f
) (float), svfloat32_t x
, svfloat32_t y
, svbool_t cmp
)
112 svbool_t p
= svpfirst (cmp
, svpfalse ());
113 while (svptest_any (cmp
, p
))
115 float elem
= svclastb_n_f32 (p
, 0, x
);
117 svfloat32_t y2
= svdup_n_f32 (elem
);
118 y
= svsel_f32 (p
, y2
, y
);
119 p
= svpnext_b32 (cmp
, p
);
124 static inline svfloat32_t
125 sv_call2_f32 (float (*f
) (float, float), svfloat32_t x1
, svfloat32_t x2
,
126 svfloat32_t y
, svbool_t cmp
)
128 svbool_t p
= svpfirst (cmp
, svpfalse ());
129 while (svptest_any (cmp
, p
))
131 float elem1
= svclastb_n_f32 (p
, 0, x1
);
132 float elem2
= svclastb_n_f32 (p
, 0, x2
);
133 float ret
= f (elem1
, elem2
);
134 svfloat32_t y2
= svdup_n_f32 (ret
);
135 y
= svsel_f32 (p
, y2
, y
);
136 p
= svpnext_b32 (cmp
, p
);