Vc  1.1.0
SIMD Vector Classes for C++
windows_fix_intrin.h
1 /* This file is part of the Vc library. {{{
2 Copyright © 2009-2015 Matthias Kretz <kretz@kde.org>
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the names of contributing organizations nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 }}}*/
28 
29 #ifndef VC_COMMON_WINDOWS_FIX_INTRIN_H_
30 #define VC_COMMON_WINDOWS_FIX_INTRIN_H_
31 
32 #if defined(Vc_MSVC) && !defined(__midl)
33 // MSVC sucks. If you include intrin.h you get all SSE and AVX intrinsics
34 // declared. This is a problem because we need to implement the intrinsics
35 // that are not supported in hardware ourselves.
36 // Something always includes intrin.h even if you don't
37 // do it explicitly. Therefore we try to be the first to include it
38 // but with __midl defined, in which case it is basically empty.
39 #ifdef __INTRIN_H_
40 #error "intrin.h was already included, polluting the namespace. Please fix your code to include the Vc headers before anything that includes intrin.h. (Vc will declare the relevant intrinsics as they are required by some system headers.)"
41 #endif
42 #define __midl
43 #include <intrin.h>
44 #undef __midl
45 #include <crtdefs.h>
46 #include <setjmp.h>
47 #include <stddef.h>
48 extern "C" {
49 
50 #ifdef _WIN64
51 _CRTIMP double ceil(_In_ double);
52 __int64 _InterlockedDecrement64(__int64 volatile *);
53 __int64 _InterlockedExchange64(__int64 volatile *, __int64);
54 void * _InterlockedExchangePointer(void * volatile *, void *);
55 __int64 _InterlockedExchangeAdd64(__int64 volatile *, __int64);
56 void *_InterlockedCompareExchangePointer (void * volatile *, void *, void *);
57 __int64 _InterlockedIncrement64(__int64 volatile *);
58 int __cdecl _setjmpex(jmp_buf);
59 void __faststorefence(void);
60 __int64 __mulh(__int64,__int64);
61 unsigned __int64 __umulh(unsigned __int64,unsigned __int64);
62 unsigned __int64 __readcr0(void);
63 unsigned __int64 __readcr2(void);
64 unsigned __int64 __readcr3(void);
65 unsigned __int64 __readcr4(void);
66 unsigned __int64 __readcr8(void);
67 void __writecr0(unsigned __int64);
68 void __writecr3(unsigned __int64);
69 void __writecr4(unsigned __int64);
70 void __writecr8(unsigned __int64);
71 unsigned __int64 __readdr(unsigned int);
72 void __writedr(unsigned int, unsigned __int64);
73 unsigned __int64 __readeflags(void);
74 void __writeeflags(unsigned __int64);
75 void __movsq(unsigned long long *, unsigned long long const *, size_t);
76 unsigned char __readgsbyte(unsigned long Offset);
77 unsigned short __readgsword(unsigned long Offset);
78 unsigned long __readgsdword(unsigned long Offset);
79 unsigned __int64 __readgsqword(unsigned long Offset);
80 void __writegsbyte(unsigned long Offset, unsigned char Data);
81 void __writegsword(unsigned long Offset, unsigned short Data);
82 void __writegsdword(unsigned long Offset, unsigned long Data);
83 void __writegsqword(unsigned long Offset, unsigned __int64 Data);
84 void __addgsbyte(unsigned long Offset, unsigned char Data);
85 void __addgsword(unsigned long Offset, unsigned short Data);
86 void __addgsdword(unsigned long Offset, unsigned long Data);
87 void __addgsqword(unsigned long Offset, unsigned __int64 Data);
88 void __incgsbyte(unsigned long Offset);
89 void __incgsword(unsigned long Offset);
90 void __incgsdword(unsigned long Offset);
91 void __incgsqword(unsigned long Offset);
92 unsigned char __vmx_vmclear(unsigned __int64*);
93 unsigned char __vmx_vmlaunch(void);
94 unsigned char __vmx_vmptrld(unsigned __int64*);
95 unsigned char __vmx_vmread(size_t, size_t*);
96 unsigned char __vmx_vmresume(void);
97 unsigned char __vmx_vmwrite(size_t, size_t);
98 unsigned char __vmx_on(unsigned __int64*);
99 void __stosq(unsigned __int64 *, unsigned __int64, size_t);
100 unsigned char _interlockedbittestandset64(__int64 volatile *a, __int64 b);
101 unsigned char _interlockedbittestandreset64(__int64 volatile *a, __int64 b);
102 short _InterlockedCompareExchange16_np(short volatile *Destination, short Exchange, short Comparand);
103 long _InterlockedCompareExchange_np (long volatile *, long, long);
104 __int64 _InterlockedCompareExchange64_np(__int64 volatile *, __int64, __int64);
105 void *_InterlockedCompareExchangePointer_np (void * volatile *, void *, void *);
106 unsigned char _InterlockedCompareExchange128(__int64 volatile *, __int64, __int64, __int64 *);
107 unsigned char _InterlockedCompareExchange128_np(__int64 volatile *, __int64, __int64, __int64 *);
108 long _InterlockedAnd_np(long volatile *, long);
109 char _InterlockedAnd8_np(char volatile *, char);
110 short _InterlockedAnd16_np(short volatile *, short);
111 __int64 _InterlockedAnd64_np(__int64 volatile *, __int64);
112 long _InterlockedOr_np(long volatile *, long);
113 char _InterlockedOr8_np(char volatile *, char);
114 short _InterlockedOr16_np(short volatile *, short);
115 __int64 _InterlockedOr64_np(__int64 volatile *, __int64);
116 long _InterlockedXor_np(long volatile *, long);
117 char _InterlockedXor8_np(char volatile *, char);
118 short _InterlockedXor16_np(short volatile *, short);
119 __int64 _InterlockedXor64_np(__int64 volatile *, __int64);
120 unsigned __int64 __lzcnt64(unsigned __int64);
121 unsigned __int64 __popcnt64(unsigned __int64);
122 __int64 _InterlockedOr64(__int64 volatile *, __int64);
123 __int64 _InterlockedXor64(__int64 volatile *, __int64);
124 __int64 _InterlockedAnd64(__int64 volatile *, __int64);
125 unsigned char _bittest64(__int64 const *a, __int64 b);
126 unsigned char _bittestandset64(__int64 *a, __int64 b);
127 unsigned char _bittestandreset64(__int64 *a, __int64 b);
128 unsigned char _bittestandcomplement64(__int64 *a, __int64 b);
129 unsigned char _BitScanForward64(unsigned long* Index, unsigned __int64 Mask);
130 unsigned char _BitScanReverse64(unsigned long* Index, unsigned __int64 Mask);
131 unsigned __int64 __shiftleft128(unsigned __int64 LowPart, unsigned __int64 HighPart, unsigned char Shift);
132 unsigned __int64 __shiftright128(unsigned __int64 LowPart, unsigned __int64 HighPart, unsigned char Shift);
133 unsigned __int64 _umul128(unsigned __int64 multiplier, unsigned __int64 multiplicand, unsigned __int64 *highproduct);
134 __int64 _mul128(__int64 multiplier, __int64 multiplicand, __int64 *highproduct);
135 #endif
136 
137 long _InterlockedOr(long volatile *, long);
138 char _InterlockedOr8(char volatile *, char);
139 short _InterlockedOr16(short volatile *, short);
140 long _InterlockedXor(long volatile *, long);
141 char _InterlockedXor8(char volatile *, char);
142 short _InterlockedXor16(short volatile *, short);
143 long _InterlockedAnd(long volatile *, long);
144 char _InterlockedAnd8(char volatile *, char);
145 short _InterlockedAnd16(short volatile *, short);
146 unsigned char _bittest(long const *a, long b);
147 unsigned char _bittestandset(long *a, long b);
148 unsigned char _bittestandreset(long *a, long b);
149 unsigned char _bittestandcomplement(long *a, long b);
150 unsigned char _BitScanForward(unsigned long* Index, unsigned long Mask);
151 unsigned char _BitScanReverse(unsigned long* Index, unsigned long Mask);
152 _CRTIMP wchar_t * __cdecl wcscat( _Pre_cap_for_(_Source) _Prepost_z_ wchar_t *, _In_z_ const wchar_t * _Source);
153 _Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *,_In_z_ const wchar_t *);
154 _CRTIMP wchar_t * __cdecl wcscpy(_Pre_cap_for_(_Source) _Post_z_ wchar_t *, _In_z_ const wchar_t * _Source);
155 _Check_return_ _CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *);
156 #pragma warning(suppress: 4985)
157 _CRTIMP wchar_t * __cdecl _wcsset(_Inout_z_ wchar_t *, wchar_t);
158 void _ReadBarrier(void);
159 unsigned char _rotr8(unsigned char value, unsigned char shift);
160 unsigned short _rotr16(unsigned short value, unsigned char shift);
161 unsigned char _rotl8(unsigned char value, unsigned char shift);
162 unsigned short _rotl16(unsigned short value, unsigned char shift);
163 short _InterlockedIncrement16(short volatile *Addend);
164 short _InterlockedDecrement16(short volatile *Addend);
165 short _InterlockedCompareExchange16(short volatile *Destination, short Exchange, short Comparand);
166 void __nvreg_save_fence(void);
167 void __nvreg_restore_fence(void);
168 
169 #ifdef _M_IX86
170 unsigned long __readcr0(void);
171 unsigned long __readcr2(void);
172 unsigned long __readcr3(void);
173 unsigned long __readcr4(void);
174 unsigned long __readcr8(void);
175 void __writecr0(unsigned);
176 void __writecr3(unsigned);
177 void __writecr4(unsigned);
178 void __writecr8(unsigned);
179 unsigned __readdr(unsigned int);
180 void __writedr(unsigned int, unsigned);
181 unsigned __readeflags(void);
182 void __writeeflags(unsigned);
183 void __addfsbyte(unsigned long Offset, unsigned char Data);
184 void __addfsword(unsigned long Offset, unsigned short Data);
185 void __addfsdword(unsigned long Offset, unsigned long Data);
186 void __incfsbyte(unsigned long Offset);
187 void __incfsword(unsigned long Offset);
188 void __incfsdword(unsigned long Offset);
189 unsigned char __readfsbyte(unsigned long Offset);
190 unsigned short __readfsword(unsigned long Offset);
191 unsigned long __readfsdword(unsigned long Offset);
192 unsigned __int64 __readfsqword(unsigned long Offset);
193 void __writefsbyte(unsigned long Offset, unsigned char Data);
194 void __writefsword(unsigned long Offset, unsigned short Data);
195 void __writefsdword(unsigned long Offset, unsigned long Data);
196 void __writefsqword(unsigned long Offset, unsigned __int64 Data);
197 long _InterlockedAddLargeStatistic(__int64 volatile *, long);
198 #endif
199 
200 _Ret_bytecap_(_Size) void * __cdecl _alloca(size_t _Size);
201 int __cdecl abs(_In_ int);
202 _Check_return_ unsigned short __cdecl _byteswap_ushort(_In_ unsigned short value);
203 _Check_return_ unsigned long __cdecl _byteswap_ulong(_In_ unsigned long value);
204 _Check_return_ unsigned __int64 __cdecl _byteswap_uint64(_In_ unsigned __int64 value);
205 void __cdecl __debugbreak(void);
206 void __cdecl _disable(void);
207 __int64 __emul(int,int);
208 unsigned __int64 __emulu(unsigned int,unsigned int);
209 void __cdecl _enable(void);
210 long __cdecl _InterlockedDecrement(long volatile *);
211 long _InterlockedExchange(long volatile *, long);
212 short _InterlockedExchange16(short volatile *, short);
213 char _InterlockedExchange8(char volatile *, char);
214 long _InterlockedExchangeAdd(long volatile *, long);
215 short _InterlockedExchangeAdd16(short volatile *, short);
216 char _InterlockedExchangeAdd8(char volatile *, char);
217 long _InterlockedCompareExchange (long volatile *, long, long);
218 __int64 _InterlockedCompareExchange64(__int64 volatile *, __int64, __int64);
219 long __cdecl _InterlockedIncrement(long volatile *);
220 int __cdecl _inp(unsigned short);
221 int __cdecl inp(unsigned short);
222 unsigned long __cdecl _inpd(unsigned short);
223 unsigned long __cdecl inpd(unsigned short);
224 unsigned short __cdecl _inpw(unsigned short);
225 unsigned short __cdecl inpw(unsigned short);
226 long __cdecl labs(_In_ long);
227 _Check_return_ unsigned long __cdecl _lrotl(_In_ unsigned long,_In_ int);
228 _Check_return_ unsigned long __cdecl _lrotr(_In_ unsigned long,_In_ int);
229 unsigned __int64 __ll_lshift(unsigned __int64,int);
230 __int64 __ll_rshift(__int64,int);
231 _Check_return_ int __cdecl memcmp(_In_opt_bytecount_(_Size) const void *,_In_opt_bytecount_(_Size) const void *,_In_ size_t _Size);
232 void * __cdecl memcpy(_Out_opt_bytecapcount_(_Size) void *,_In_opt_bytecount_(_Size) const void *,_In_ size_t _Size);
233 void * __cdecl memset(_Out_opt_bytecapcount_(_Size) void *,_In_ int,_In_ size_t _Size);
234 int __cdecl _outp(unsigned short,int);
235 int __cdecl outp(unsigned short,int);
236 unsigned long __cdecl _outpd(unsigned short,unsigned long);
237 unsigned long __cdecl outpd(unsigned short,unsigned long);
238 unsigned short __cdecl _outpw(unsigned short,unsigned short);
239 unsigned short __cdecl outpw(unsigned short,unsigned short);
240 void * _ReturnAddress(void);
241 _Check_return_ unsigned int __cdecl _rotl(_In_ unsigned int,_In_ int);
242 _Check_return_ unsigned int __cdecl _rotr(_In_ unsigned int,_In_ int);
243 int __cdecl _setjmp(jmp_buf);
244 _Check_return_ int __cdecl strcmp(_In_z_ const char *,_In_z_ const char *);
245 _Check_return_ size_t __cdecl strlen(_In_z_ const char *);
246 char * __cdecl strset(_Inout_z_ char *,_In_ int);
247 unsigned __int64 __ull_rshift(unsigned __int64,int);
248 void * _AddressOfReturnAddress(void);
249 
250 void _WriteBarrier(void);
251 void _ReadWriteBarrier(void);
252 void __wbinvd(void);
253 void __invlpg(void*);
254 unsigned __int64 __readmsr(unsigned long);
255 void __writemsr(unsigned long, unsigned __int64);
256 unsigned __int64 __rdtsc(void);
257 void __movsb(unsigned char *, unsigned char const *, size_t);
258 void __movsw(unsigned short *, unsigned short const *, size_t);
259 void __movsd(unsigned long *, unsigned long const *, size_t);
260 unsigned char __inbyte(unsigned short Port);
261 unsigned short __inword(unsigned short Port);
262 unsigned long __indword(unsigned short Port);
263 void __outbyte(unsigned short Port, unsigned char Data);
264 void __outword(unsigned short Port, unsigned short Data);
265 void __outdword(unsigned short Port, unsigned long Data);
266 void __inbytestring(unsigned short Port, unsigned char *Buffer, unsigned long Count);
267 void __inwordstring(unsigned short Port, unsigned short *Buffer, unsigned long Count);
268 void __indwordstring(unsigned short Port, unsigned long *Buffer, unsigned long Count);
269 void __outbytestring(unsigned short Port, unsigned char *Buffer, unsigned long Count);
270 void __outwordstring(unsigned short Port, unsigned short *Buffer, unsigned long Count);
271 void __outdwordstring(unsigned short Port, unsigned long *Buffer, unsigned long Count);
272 unsigned int __getcallerseflags();
273 void __vmx_vmptrst(unsigned __int64 *);
274 void __vmx_off(void);
275 void __svm_clgi(void);
276 void __svm_invlpga(void*, int);
277 void __svm_skinit(int);
278 void __svm_stgi(void);
279 void __svm_vmload(size_t);
280 void __svm_vmrun(size_t);
281 void __svm_vmsave(size_t);
282 void __halt(void);
283 void __sidt(void*);
284 void __lidt(void*);
285 void __ud2(void);
286 void __nop(void);
287 void __stosb(unsigned char *, unsigned char, size_t);
288 void __stosw(unsigned short *, unsigned short, size_t);
289 void __stosd(unsigned long *, unsigned long, size_t);
290 unsigned char _interlockedbittestandset(long volatile *a, long b);
291 unsigned char _interlockedbittestandreset(long volatile *a, long b);
292 void __cpuid(int a[4], int b);
293 void __cpuidex(int a[4], int b, int c);
294 unsigned __int64 __readpmc(unsigned long a);
295 unsigned long __segmentlimit(unsigned long a);
296 _Check_return_ unsigned __int64 __cdecl _rotl64(_In_ unsigned __int64,_In_ int);
297 _Check_return_ unsigned __int64 __cdecl _rotr64(_In_ unsigned __int64,_In_ int);
298 __int64 __cdecl _abs64(__int64);
299 void __int2c(void);
300 char _InterlockedCompareExchange8(char volatile *Destination, char Exchange, char Comparand);
301 unsigned short __lzcnt16(unsigned short);
302 unsigned int __lzcnt(unsigned int);
303 unsigned short __popcnt16(unsigned short);
304 unsigned int __popcnt(unsigned int);
305 unsigned __int64 __rdtscp(unsigned int*);
306 }
307 #endif
308 
309 #endif // VC_COMMON_WINDOWS_FIX_INTRIN_H_
Vc::Vector< T > abs(const Vc::Vector< T > &v)
Returns the absolute value of v.