Debian Codegraph @

third-party/simde/arm/neon/rndn.h

raw
1 /* SPDX-License-Identifier: MIT
2 *
3 * Permission is hereby granted, free of charge, to any person
4 * obtaining a copy of this software and associated documentation
5 * files (the "Software"), to deal in the Software without
6 * restriction, including without limitation the rights to use, copy,
7 * modify, merge, publish, distribute, sublicense, and/or sell copies
8 * of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be
12 * included in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Copyright:
24 * 2020-2021 Evan Nemerson <[email protected]>
25 */
26
27 #if !defined(SIMDE_ARM_NEON_RNDN_H)
28 #define SIMDE_ARM_NEON_RNDN_H
29
30 #include "types.h"
31
32 HEDLEY_DIAGNOSTIC_PUSH
33 SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
34 SIMDE_BEGIN_DECLS_
35
36 SIMDE_FUNCTION_ATTRIBUTES
37 simde_float32_t
38 simde_vrndns_f32(simde_float32_t a) {
39 #if \
40 defined(SIMDE_ARM_NEON_A32V8_NATIVE) && \
41 (!defined(__clang__) || SIMDE_DETECT_CLANG_VERSION_CHECK(7,0,0)) && \
42 (!defined(HEDLEY_GCC_VERSION) || (defined(SIMDE_ARM_NEON_A64V8_NATIVE) && HEDLEY_GCC_VERSION_CHECK(8,0,0)))
43 return vrndns_f32(a);
44 #else
45 return simde_math_roundevenf(a);
46 #endif
47 }
48 #if defined(SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES)
49 #undef vrndns_f32
50 #define vrndns_f32(a) simde_vrndns_f32(a)
51 #endif
52
53 SIMDE_FUNCTION_ATTRIBUTES
54 simde_float32x2_t
55 simde_vrndn_f32(simde_float32x2_t a) {
56 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE)
57 return vrndn_f32(a);
58 #else
59 simde_float32x2_private
60 r_,
61 a_ = simde_float32x2_to_private(a);
62
63 SIMDE_VECTORIZE
64 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
65 r_.values[i] = simde_vrndns_f32(a_.values[i]);
66 }
67
68 return simde_float32x2_from_private(r_);
69 #endif
70 }
71 #if defined(SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES)
72 #undef vrndn_f32
73 #define vrndn_f32(a) simde_vrndn_f32(a)
74 #endif
75
76 SIMDE_FUNCTION_ATTRIBUTES
77 simde_float64x1_t
78 simde_vrndn_f64(simde_float64x1_t a) {
79 #if \
80 defined(SIMDE_ARM_NEON_A64V8_NATIVE)
81 return vrndn_f64(a);
82 #else
83 simde_float64x1_private
84 r_,
85 a_ = simde_float64x1_to_private(a);
86
87 SIMDE_VECTORIZE
88 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
89 r_.values[i] = simde_math_roundeven(a_.values[i]);
90 }
91
92 return simde_float64x1_from_private(r_);
93 #endif
94 }
95 #if defined(SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES)
96 #undef vrndn_f64
97 #define vrndn_f64(a) simde_vrndn_f64(a)
98 #endif
99
100 SIMDE_FUNCTION_ATTRIBUTES
101 simde_float32x4_t
102 simde_vrndnq_f32(simde_float32x4_t a) {
103 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE)
104 return vrndnq_f32(a);
105 #else
106 simde_float32x4_private
107 r_,
108 a_ = simde_float32x4_to_private(a);
109
110 #if defined(SIMDE_X86_SSE4_1_NATIVE)
111 r_.m128 = _mm_round_ps(a_.m128, _MM_FROUND_TO_NEAREST_INT);
112 #else
113 SIMDE_VECTORIZE
114 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
115 r_.values[i] = simde_vrndns_f32(a_.values[i]);
116 }
117 #endif
118
119 return simde_float32x4_from_private(r_);
120 #endif
121 }
122 #if defined(SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES)
123 #undef vrndnq_f32
124 #define vrndnq_f32(a) simde_vrndnq_f32(a)
125 #endif
126
127 SIMDE_FUNCTION_ATTRIBUTES
128 simde_float64x2_t
129 simde_vrndnq_f64(simde_float64x2_t a) {
130 #if \
131 defined(SIMDE_ARM_NEON_A64V8_NATIVE)
132 return vrndnq_f64(a);
133 #else
134 simde_float64x2_private
135 r_,
136 a_ = simde_float64x2_to_private(a);
137
138 #if defined(SIMDE_X86_SSE4_1_NATIVE)
139 r_.m128d = _mm_round_pd(a_.m128d, _MM_FROUND_TO_NEAREST_INT);
140 #else
141 SIMDE_VECTORIZE
142 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
143 r_.values[i] = simde_math_roundeven(a_.values[i]);
144 }
145 #endif
146
147 return simde_float64x2_from_private(r_);
148 #endif
149 }
150 #if defined(SIMDE_ARM_NEON_A32V8_ENABLE_NATIVE_ALIASES)
151 #undef vrndnq_f64
152 #define vrndnq_f64(a) simde_vrndnq_f64(a)
153 #endif
154
155 SIMDE_END_DECLS_
156 HEDLEY_DIAGNOSTIC_POP
157
158 #endif /* !defined(SIMDE_ARM_NEON_RNDN_H) */