ReactOS  0.4.15-dev-494-g1d8c567
intrin.h
Go to the documentation of this file.
1 /*
2  Compatibility <intrin.h> header for GCC -- GCC equivalents of intrinsic
3  Microsoft Visual C++ functions. Originally developed for the ReactOS
4  (<http://www.reactos.org/>) and TinyKrnl (<http://www.tinykrnl.org/>)
5  projects.
6 
7  Copyright (c) 2006 KJK::Hyperion <hackbunny@reactos.com>
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 */
27 
28 #ifndef KJK_INTRIN_H_
29 #define KJK_INTRIN_H_
30 
31 #ifndef RC_INVOKED
32 
33 #ifdef __clang__
34 #define __INTRIN_INLINE __forceinline
35 #define HAS_BUILTIN(x) __has_builtin(x)
36 #else
37 #define HAS_BUILTIN(x) 0
38 #define __ATTRIBUTE_ARTIFICIAL __attribute__((artificial))
39 #define __INTRIN_INLINE extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) __ATTRIBUTE_ARTIFICIAL
40 #endif
41 
42 #ifndef _SIZE_T_DEFINED
43 #define _SIZE_T_DEFINED
44 #ifdef _WIN64
45  typedef unsigned __int64 size_t;
46 #else
47  typedef unsigned int size_t;
48 #endif
49 #endif
50 
51 #ifndef _UINTPTR_T_DEFINED
52 #define _UINTPTR_T_DEFINED
53 #ifdef _WIN64
54  typedef unsigned __int64 uintptr_t;
55 #else
56  typedef unsigned int uintptr_t;
57 #endif
58 #endif
59 
60 /*
61  FIXME: review all "memory" clobbers, add/remove to match Visual C++
62  behavior: some "obvious" memory barriers are not present in the Visual C++
63  implementation - e.g. __stosX; on the other hand, some memory barriers that
64  *are* present could have been missed
65 */
66 
67 /*
68  NOTE: this is a *compatibility* header. Some functions may look wrong at
69  first, but they're only "as wrong" as they would be on Visual C++. Our
70  priority is compatibility
71 
72  NOTE: unlike most people who write inline asm for GCC, I didn't pull the
73  constraints and the uses of __volatile__ out of my... hat. Do not touch
74  them. I hate cargo cult programming
75 
76  NOTE: be very careful with declaring "memory" clobbers. Some "obvious"
77  barriers aren't there in Visual C++ (e.g. __stosX)
78 
79  NOTE: review all intrinsics with a return value, add/remove __volatile__
80  where necessary. If an intrinsic whose value is ignored generates a no-op
81  under Visual C++, __volatile__ must be omitted; if it always generates code
82  (for example, if it has side effects), __volatile__ must be specified. GCC
83  will only optimize out non-volatile asm blocks with outputs, so input-only
84  blocks are safe. Oddities such as the non-volatile 'rdmsr' are intentional
85  and follow Visual C++ behavior
86 
87  NOTE: on GCC 4.1.0, please use the __sync_* built-ins for barriers and
88  atomic operations. Test the version like this:
89 
90  #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100
91  ...
92 
93  Pay attention to the type of barrier. Make it match with what Visual C++
94  would use in the same case
95 */
96 
97 #if defined(__i386__)
98 #include "intrin_x86.h"
99 #elif defined(_PPC_)
100 #include "intrin_ppc.h"
101 #elif defined(_MIPS_)
102 #include "intrin_mips.h"
103 #elif defined(_M_ARM)
104 #include "intrin_arm.h"
105 #elif defined(__x86_64__)
106 /* TODO: the x64 architecture shares most of the i386 intrinsics. It should be easy to support */
107 #include "intrin_x86.h"
108 #else
109 #error Unsupported architecture
110 #endif
111 
112 
113 /*** Miscellaneous ***/
114 /* BUGBUG: only good for use in macros. Cannot be taken the address of */
115 #define __noop(...) ((void)0)
116 
117 #define __assume(x) if (!(x)) __builtin_unreachable()
118 
119 #endif
120 
121 #endif
122 
123 /* EOF */
unsigned int uintptr_t
Definition: intrin.h:56
unsigned int size_t
Definition: intrin.h:47
#define __int64
Definition: basetyps.h:16