]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/multiprecision/cpp_int/intel_intrinsics.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / multiprecision / cpp_int / intel_intrinsics.hpp
1 ///////////////////////////////////////////////////////////////
2 // Copyright 2020 Madhur Chauhan.
3 // Copyright 2020 John Maddock.
4 // Distributed under the Boost
5 // Software License, Version 1.0. (See accompanying file
6 // LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
7
8 #ifndef BOOST_MP_INTEL_INTRINSICS_HPP
9 #define BOOST_MP_INTEL_INTRINSICS_HPP
10 //
11 // Select which actual implementation header to use:
12 //
13 #ifdef __has_include
14 #if __has_include(<immintrin.h>)
15 #define BOOST_MP_HAS_IMMINTRIN_H
16 #endif
17 #endif
18 //
19 // If this is GCC/clang, then check that the actual intrinsic exists:
20 //
21 #if defined(__has_builtin) && defined(__GNUC__)
22 #if !__has_builtin(__builtin_ia32_addcarryx_u64) && defined(BOOST_MP_HAS_IMMINTRIN_H) && !(defined(BOOST_GCC) && (__GNUC__ >= 9))
23 #undef BOOST_MP_HAS_IMMINTRIN_H
24 #endif
25 #elif defined(BOOST_MP_HAS_IMMINTRIN_H) && defined(__GNUC__) && !(defined(BOOST_GCC) && (__GNUC__ >= 9))
26 #undef BOOST_MP_HAS_IMMINTRIN_H
27 #endif
28
29 #if defined(__clang__) && (__clang__ < 9)
30 // We appear to crash the compiler if we try to use these intrinsics?
31 #undef BOOST_MP_HAS_IMMINTRIN_H
32 #endif
33 //
34 // If the compiler supports the intrinsics used by GCC internally
35 // inside <immintrin.h> then we'll use them directly.
36 // This is a bit of defensive programming, mostly for a modern clang
37 // sitting on top of an older GCC header install.
38 //
39 #if defined(__has_builtin) && !defined(BOOST_INTEL)
40
41 # if __has_builtin(__builtin_ia32_addcarryx_u64)
42 # define BOOST_MP_ADDC __builtin_ia32_addcarryx_u
43 # endif
44
45 # if __has_builtin(__builtin_ia32_subborrow_u64)
46 # define BOOST_MP_SUBB __builtin_ia32_subborrow_u
47 # elif __has_builtin(__builtin_ia32_sbb_u64)
48 # define BOOST_MP_SUBB __builtin_ia32_sbb_u
49 # endif
50
51 #endif
52
53 #ifndef BOOST_MP_ADDC
54 #define BOOST_MP_ADDC _addcarry_u
55 #endif
56 #ifndef BOOST_MP_SUBB
57 #define BOOST_MP_SUBB _subborrow_u
58 #endif
59
60 #ifdef BOOST_MP_HAS_IMMINTRIN_H
61
62 #ifdef BOOST_MSVC
63 //
64 // This is a subset of the full <immintrin.h> :
65 //
66 #include <intrin.h>
67 #else
68 #include <immintrin.h>
69 #endif
70
71 #if defined(BOOST_HAS_INT128)
72
73 namespace boost { namespace multiprecision { namespace detail {
74
75 BOOST_MP_FORCEINLINE unsigned char addcarry_limb(unsigned char carry, limb_type a, limb_type b, limb_type* p_result)
76 {
77 #ifdef BOOST_INTEL
78 typedef unsigned __int64 cast_type;
79 #else
80 typedef unsigned long long cast_type;
81 #endif
82 return BOOST_JOIN(BOOST_MP_ADDC, 64)(carry, a, b, reinterpret_cast<cast_type*>(p_result));
83 }
84
85 BOOST_MP_FORCEINLINE unsigned char subborrow_limb(unsigned char carry, limb_type a, limb_type b, limb_type* p_result)
86 {
87 #ifdef BOOST_INTEL
88 typedef unsigned __int64 cast_type;
89 #else
90 typedef unsigned long long cast_type;
91 #endif
92 return BOOST_JOIN(BOOST_MP_SUBB, 64)(carry, a, b, reinterpret_cast<cast_type*>(p_result));
93 }
94
95 }}} // namespace boost::multiprecision::detail
96
97 #else
98
99 namespace boost { namespace multiprecision { namespace detail {
100
101 BOOST_MP_FORCEINLINE unsigned char addcarry_limb(unsigned char carry, limb_type a, limb_type b, limb_type* p_result)
102 {
103 return BOOST_JOIN(BOOST_MP_ADDC, 32)(carry, a, b, reinterpret_cast<unsigned int*>(p_result));
104 }
105
106 BOOST_MP_FORCEINLINE unsigned char subborrow_limb(unsigned char carry, limb_type a, limb_type b, limb_type* p_result)
107 {
108 return BOOST_JOIN(BOOST_MP_SUBB, 32)(carry, a, b, reinterpret_cast<unsigned int*>(p_result));
109 }
110
111 }}} // namespace boost::multiprecision::detail
112
113 #endif
114
115 #endif
116
117 #endif