Debian Codegraph @

third-party/simde/x86/avx512/copysign.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 * 2020 Himanshi Mathur <[email protected]>
26 */
27
28 #if !defined(SIMDE_X86_AVX512_COPYSIGN_H)
29 #define SIMDE_X86_AVX512_COPYSIGN_H
30
31 #include "types.h"
32 #include "mov.h"
33 #include "and.h"
34 #include "andnot.h"
35 #include "xor.h"
36
37 HEDLEY_DIAGNOSTIC_PUSH
38 SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
39 SIMDE_BEGIN_DECLS_
40
41 SIMDE_FUNCTION_ATTRIBUTES
42 simde__m512
43 simde_x_mm512_copysign_ps(simde__m512 dest, simde__m512 src) {
44 simde__m512_private
45 r_,
46 dest_ = simde__m512_to_private(dest),
47 src_ = simde__m512_to_private(src);
48
49 #if defined(simde_math_copysignf)
50 SIMDE_VECTORIZE
51 for (size_t i = 0 ; i < (sizeof(r_.f32) / sizeof(r_.f32[0])) ; i++) {
52 r_.f32[i] = simde_math_copysignf(dest_.f32[i], src_.f32[i]);
53 }
54 #else
55 simde__m512 sgnbit = simde_mm512_xor_ps(simde_mm512_set1_ps(SIMDE_FLOAT32_C(0.0)), simde_mm512_set1_ps(-SIMDE_FLOAT32_C(0.0)));
56 return simde_mm512_xor_ps(simde_mm512_and_ps(sgnbit, src), simde_mm512_andnot_ps(sgnbit, dest));
57 #endif
58
59 return simde__m512_from_private(r_);
60 }
61
62 SIMDE_FUNCTION_ATTRIBUTES
63 simde__m512d
64 simde_x_mm512_copysign_pd(simde__m512d dest, simde__m512d src) {
65 simde__m512d_private
66 r_,
67 dest_ = simde__m512d_to_private(dest),
68 src_ = simde__m512d_to_private(src);
69
70 #if defined(simde_math_copysign)
71 SIMDE_VECTORIZE
72 for (size_t i = 0 ; i < (sizeof(r_.f64) / sizeof(r_.f64[0])) ; i++) {
73 r_.f64[i] = simde_math_copysign(dest_.f64[i], src_.f64[i]);
74 }
75 #else
76 simde__m512d sgnbit = simde_mm512_xor_pd(simde_mm512_set1_pd(SIMDE_FLOAT64_C(0.0)), simde_mm512_set1_pd(-SIMDE_FLOAT64_C(0.0)));
77 return simde_mm512_xor_pd(simde_mm512_and_pd(sgnbit, src), simde_mm512_andnot_pd(sgnbit, dest));
78 #endif
79
80 return simde__m512d_from_private(r_);
81 }
82
83 SIMDE_END_DECLS_
84 HEDLEY_DIAGNOSTIC_POP
85
86 #endif /* !defined(SIMDE_X86_AVX512_COPYSIGN_H) */