Debian Codegraph @

third-party/simde/arm/neon/rnd.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 Evan Nemerson <[email protected]>
25 */
26
27 #if !defined(SIMDE_ARM_NEON_RND_H)
28 #define SIMDE_ARM_NEON_RND_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
38 simde_vrnd_f32(simde_float32x2_t a) {
39 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE)
40 return vrnd_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_truncf(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 vrnd_f32
56 #define vrnd_f32(a) simde_vrnd_f32(a)
57 #endif
58
59 SIMDE_FUNCTION_ATTRIBUTES
60 simde_float64x1_t
61 simde_vrnd_f64(simde_float64x1_t a) {
62 #if defined(SIMDE_ARM_NEON_A64V8_NATIVE)
63 return vrnd_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_trunc(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 vrnd_f64
79 #define vrnd_f64(a) simde_vrnd_f64(a)
80 #endif
81
82 SIMDE_FUNCTION_ATTRIBUTES
83 simde_float32x4_t
84 simde_vrndq_f32(simde_float32x4_t a) {
85 #if defined(SIMDE_ARM_NEON_A32V8_NATIVE)
86 return vrndq_f32(a);
87 #elif defined(SIMDE_POWER_ALTIVEC_P6_NATIVE)
88 return vec_trunc(a);
89 #else
90 simde_float32x4_private
91 r_,
92 a_ = simde_float32x4_to_private(a);
93
94 #if defined(SIMDE_X86_SSE4_1_NATIVE)
95 r_.m128 = _mm_round_ps(a_.m128, _MM_FROUND_TO_ZERO);
96 #elif defined(SIMDE_X86_SVML_NATIVE) && defined(SIMDE_X86_SSE_NATIVE)
97 r_.m128 = _mm_trunc_ps(a_.m128);
98 #else
99 SIMDE_VECTORIZE
100 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
101 r_.values[i] = simde_math_truncf(a_.values[i]);
102 }
103 #endif
104
105 return simde_float32x4_from_private(r_);
106 #endif
107 }
108 #if defined(SIMDE_ARM_NEON_A32V7_ENABLE_NATIVE_ALIASES)
109 #undef vrndq_f32
110 #define vrndq_f32(a) simde_vrndq_f32(a)
111 #endif
112
113 SIMDE_FUNCTION_ATTRIBUTES
114 simde_float64x2_t
115 simde_vrndq_f64(simde_float64x2_t a) {
116 #if defined(SIMDE_ARM_NEON_A64V8_NATIVE)
117 return vrndq_f64(a);
118 #elif defined(SIMDE_POWER_ALTIVEC_P7_NATIVE)
119 return vec_trunc(a);
120 #else
121 simde_float64x2_private
122 r_,
123 a_ = simde_float64x2_to_private(a);
124
125 #if defined(SIMDE_X86_SSE4_1_NATIVE)
126 r_.m128d = _mm_round_pd(a_.m128d, _MM_FROUND_TO_ZERO);
127 #elif defined(SIMDE_X86_SVML_NATIVE) && defined(SIMDE_X86_SSE_NATIVE)
128 r_.m128d = _mm_trunc_ps(a_.m128d);
129 #else
130 SIMDE_VECTORIZE
131 for (size_t i = 0 ; i < (sizeof(r_.values) / sizeof(r_.values[0])) ; i++) {
132 r_.values[i] = simde_math_trunc(a_.values[i]);
133 }
134 #endif
135
136 return simde_float64x2_from_private(r_);
137 #endif
138 }
139 #if defined(SIMDE_ARM_NEON_A64V8_ENABLE_NATIVE_ALIASES)
140 #undef vrndq_f64
141 #define vrndq_f64(a) simde_vrndq_f64(a)
142 #endif
143
144 SIMDE_END_DECLS_
145 HEDLEY_DIAGNOSTIC_POP
146
147 #endif /* !defined(SIMDE_ARM_NEON_RND_H) */