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 <evan@nemerson.com>
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_float32x2_t
simde_vrndn_f32(simde_float32x2_t a)38 simde_vrndn_f32(simde_float32x2_t a) {
39 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE)
40 return vrndn_f32(a);
41 #else
42 simde_float32x2_private
43 r_,
44 a_ = simde_float32x2_to_private(a);
45
46 SIMDE_VECTORIZE
47 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
48 r_.values[i] = simde_math_roundevenf(a_.values[i]);
49 }
50
51 return simde_float32x2_from_private(r_);
52 #endif
53 }
54 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
55 #undef vrndn_f32
56 #define vrndn_f32(a) simde_vrndn_f32(a)
57 #endif
58
59 SIMDE_FUNCTION_ATTRIBUTES
60 simde_float64x1_t
simde_vrndn_f64(simde_float64x1_t a)61 simde_vrndn_f64(simde_float64x1_t a) {
62 #if defined(SIMDE_ARM_NEON_A64V8_NATIVE)
63 return vrndn_f64(a);
64 #else
65 simde_float64x1_private
66 r_,
67 a_ = simde_float64x1_to_private(a);
68
69 SIMDE_VECTORIZE
70 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
71 r_.values[i] = simde_math_roundeven(a_.values[i]);
72 }
73
74 return simde_float64x1_from_private(r_);
75 #endif
76 }
77 #if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES)
78 #undef vrndn_f64
79 #define vrndn_f64(a) simde_vrndn_f64(a)
80 #endif
81
82 SIMDE_FUNCTION_ATTRIBUTES
83 simde_float32x4_t
simde_vrndnq_f32(simde_float32x4_t a)84 simde_vrndnq_f32(simde_float32x4_t a) {
85 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE)
86 return vrndnq_f32(a);
87 #elif defined(SIMDE_X86_SSE4_1_NATIVE)
88 return _mm_round_ps(a, _MM_FROUND_TO_NEAREST_INT);
89 #else
90 simde_float32x4_private
91 r_,
92 a_ = simde_float32x4_to_private(a);
93
94 SIMDE_VECTORIZE
95 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
96 r_.values[i] = simde_math_roundevenf(a_.values[i]);
97 }
98
99 return simde_float32x4_from_private(r_);
100 #endif
101 }
102 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
103 #undef vrndnq_f32
104 #define vrndnq_f32(a) simde_vrndnq_f32(a)
105 #endif
106
107 SIMDE_FUNCTION_ATTRIBUTES
108 simde_float64x2_t
simde_vrndnq_f64(simde_float64x2_t a)109 simde_vrndnq_f64(simde_float64x2_t a) {
110 #if defined(SIMDE_ARM_NEON_A64V8_NATIVE)
111 return vrndnq_f64(a);
112 #elif defined(SIMDE_X86_SSE4_1_NATIVE)
113 return _mm_round_pd(a, _MM_FROUND_TO_NEAREST_INT);
114 #else
115 simde_float64x2_private
116 r_,
117 a_ = simde_float64x2_to_private(a);
118
119 SIMDE_VECTORIZE
120 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
121 r_.values[i] = simde_math_roundeven(a_.values[i]);
122 }
123
124 return simde_float64x2_from_private(r_);
125 #endif
126 }
127 #if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES)
128 #undef vrndnq_f64
129 #define vrndnq_f64(a) simde_vrndnq_f64(a)
130 #endif
131
132 SIMDE_END_DECLS_
133 HEDLEY_DIAGNOSTIC_POP
134
135 #endif /* !defined(SIMDE_ARM_NEON_RNDN_H) */
136