Debian Codegraph @

third-party/simde/x86/avx512/xorsign.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 /* This is a SIMDe extension which is not part of AVX-512. It exists
29 * because a lot of numerical methods in SIMDe have algoriths which do
30 * something like:
31 *
32 * float sgn = input < 0 ? -1 : 1;
33 * ...
34 * return res * sgn;
35 *
36 * Which can be replaced with a much more efficient call to xorsign:
37 *
38 * return simde_x_mm512_xorsign_ps(res, input);
39 *
40 * While this was originally intended for use in SIMDe, please feel
41 * free to use it in your code.
42 */
43
44 #if !defined(SIMDE_X86_AVX512_XORSIGN_H)
45 #define SIMDE_X86_AVX512_XORSIGN_H
46
47 #include "types.h"
48 #include "mov.h"
49 #include "and.h"
50 #include "xor.h"
51 #include "set1.h"
52
53 HEDLEY_DIAGNOSTIC_PUSH
54 SIMDE_DISABLE_UNWANTED_DIAGNOSTICS
55 SIMDE_BEGIN_DECLS_
56
57 SIMDE_FUNCTION_ATTRIBUTES
58 simde__m512
59 simde_x_mm512_xorsign_ps(simde__m512 dest, simde__m512 src) {
60 return simde_mm512_xor_ps(simde_mm512_and_ps(simde_mm512_set1_ps(-0.0f), src), dest);
61 }
62
63 SIMDE_FUNCTION_ATTRIBUTES
64 simde__m512d
65 simde_x_mm512_xorsign_pd(simde__m512d dest, simde__m512d src) {
66 return simde_mm512_xor_pd(simde_mm512_and_pd(simde_mm512_set1_pd(-0.0), src), dest);
67 }
68
69 SIMDE_END_DECLS_
70 HEDLEY_DIAGNOSTIC_POP
71
72 #endif /* !defined(SIMDE_X86_AVX512_XORSIGN_H) */