intrin.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. /* ===-------- intrin.h ---------------------------------------------------===
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. *
  21. *===-----------------------------------------------------------------------===
  22. */
  23. /* Only include this if we're compiling for the windows platform. */
  24. #ifndef _MSC_VER
  25. #include_next <intrin.h>
  26. #else
  27. #ifndef __INTRIN_H
  28. #define __INTRIN_H
  29. /* First include the standard intrinsics. */
  30. #if defined(__i386__) || defined(__x86_64__)
  31. #include <x86intrin.h>
  32. #endif
  33. #if defined(__arm__)
  34. #include <armintr.h>
  35. #endif
  36. #if defined(__aarch64__)
  37. #include <arm64intr.h>
  38. #endif
  39. /* For the definition of jmp_buf. */
  40. #if __STDC_HOSTED__
  41. #include <setjmp.h>
  42. #endif
  43. /* Define the default attributes for the functions in this file. */
  44. #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__))
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. #if defined(__MMX__)
  49. /* And the random ones that aren't in those files. */
  50. __m64 _m_from_float(float);
  51. float _m_to_float(__m64);
  52. #endif
  53. /* Other assorted instruction intrinsics. */
  54. void __addfsbyte(unsigned long, unsigned char);
  55. void __addfsdword(unsigned long, unsigned long);
  56. void __addfsword(unsigned long, unsigned short);
  57. void __code_seg(const char *);
  58. static __inline__
  59. void __cpuid(int[4], int);
  60. static __inline__
  61. void __cpuidex(int[4], int, int);
  62. static __inline__
  63. __int64 __emul(int, int);
  64. static __inline__
  65. unsigned __int64 __emulu(unsigned int, unsigned int);
  66. unsigned int __getcallerseflags(void);
  67. static __inline__
  68. void __halt(void);
  69. unsigned char __inbyte(unsigned short);
  70. void __inbytestring(unsigned short, unsigned char *, unsigned long);
  71. void __incfsbyte(unsigned long);
  72. void __incfsdword(unsigned long);
  73. void __incfsword(unsigned long);
  74. unsigned long __indword(unsigned short);
  75. void __indwordstring(unsigned short, unsigned long *, unsigned long);
  76. void __int2c(void);
  77. void __invlpg(void *);
  78. unsigned short __inword(unsigned short);
  79. void __inwordstring(unsigned short, unsigned short *, unsigned long);
  80. void __lidt(void *);
  81. unsigned __int64 __ll_lshift(unsigned __int64, int);
  82. __int64 __ll_rshift(__int64, int);
  83. unsigned int __lzcnt(unsigned int);
  84. unsigned short __lzcnt16(unsigned short);
  85. static __inline__
  86. void __movsb(unsigned char *, unsigned char const *, size_t);
  87. static __inline__
  88. void __movsd(unsigned long *, unsigned long const *, size_t);
  89. static __inline__
  90. void __movsw(unsigned short *, unsigned short const *, size_t);
  91. static __inline__
  92. void __nop(void);
  93. void __nvreg_restore_fence(void);
  94. void __nvreg_save_fence(void);
  95. void __outbyte(unsigned short, unsigned char);
  96. void __outbytestring(unsigned short, unsigned char *, unsigned long);
  97. void __outdword(unsigned short, unsigned long);
  98. void __outdwordstring(unsigned short, unsigned long *, unsigned long);
  99. void __outword(unsigned short, unsigned short);
  100. void __outwordstring(unsigned short, unsigned short *, unsigned long);
  101. unsigned long __readcr0(void);
  102. unsigned long __readcr2(void);
  103. static __inline__
  104. unsigned long __readcr3(void);
  105. unsigned long __readcr4(void);
  106. unsigned long __readcr8(void);
  107. unsigned int __readdr(unsigned int);
  108. #ifdef __i386__
  109. static __inline__
  110. unsigned char __readfsbyte(unsigned long);
  111. static __inline__
  112. unsigned __int64 __readfsqword(unsigned long);
  113. static __inline__
  114. unsigned short __readfsword(unsigned long);
  115. #endif
  116. static __inline__
  117. unsigned __int64 __readmsr(unsigned long);
  118. unsigned __int64 __readpmc(unsigned long);
  119. unsigned long __segmentlimit(unsigned long);
  120. void __sidt(void *);
  121. static __inline__
  122. void __stosb(unsigned char *, unsigned char, size_t);
  123. static __inline__
  124. void __stosd(unsigned long *, unsigned long, size_t);
  125. static __inline__
  126. void __stosw(unsigned short *, unsigned short, size_t);
  127. void __svm_clgi(void);
  128. void __svm_invlpga(void *, int);
  129. void __svm_skinit(int);
  130. void __svm_stgi(void);
  131. void __svm_vmload(size_t);
  132. void __svm_vmrun(size_t);
  133. void __svm_vmsave(size_t);
  134. void __ud2(void);
  135. unsigned __int64 __ull_rshift(unsigned __int64, int);
  136. void __vmx_off(void);
  137. void __vmx_vmptrst(unsigned __int64 *);
  138. void __wbinvd(void);
  139. void __writecr0(unsigned int);
  140. static __inline__
  141. void __writecr3(unsigned int);
  142. void __writecr4(unsigned int);
  143. void __writecr8(unsigned int);
  144. void __writedr(unsigned int, unsigned int);
  145. void __writefsbyte(unsigned long, unsigned char);
  146. void __writefsdword(unsigned long, unsigned long);
  147. void __writefsqword(unsigned long, unsigned __int64);
  148. void __writefsword(unsigned long, unsigned short);
  149. void __writemsr(unsigned long, unsigned __int64);
  150. static __inline__
  151. void *_AddressOfReturnAddress(void);
  152. static __inline__
  153. unsigned char _BitScanForward(unsigned long *_Index, unsigned long _Mask);
  154. static __inline__
  155. unsigned char _BitScanReverse(unsigned long *_Index, unsigned long _Mask);
  156. unsigned char _bittest(long const *, long);
  157. unsigned char _bittestandcomplement(long *, long);
  158. unsigned char _bittestandreset(long *, long);
  159. unsigned char _bittestandset(long *, long);
  160. void __cdecl _disable(void);
  161. void __cdecl _enable(void);
  162. long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
  163. unsigned char _interlockedbittestandreset(long volatile *, long);
  164. unsigned char _interlockedbittestandset(long volatile *, long);
  165. void *_InterlockedCompareExchangePointer_HLEAcquire(void *volatile *, void *,
  166. void *);
  167. void *_InterlockedCompareExchangePointer_HLERelease(void *volatile *, void *,
  168. void *);
  169. long _InterlockedExchangeAdd_HLEAcquire(long volatile *, long);
  170. long _InterlockedExchangeAdd_HLERelease(long volatile *, long);
  171. __int64 _InterlockedExchangeAdd64_HLEAcquire(__int64 volatile *, __int64);
  172. __int64 _InterlockedExchangeAdd64_HLERelease(__int64 volatile *, __int64);
  173. void __cdecl _invpcid(unsigned int, void *);
  174. static __inline__ void
  175. __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
  176. _ReadBarrier(void);
  177. static __inline__ void
  178. __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
  179. _ReadWriteBarrier(void);
  180. unsigned int _rorx_u32(unsigned int, const unsigned int);
  181. int _sarx_i32(int, unsigned int);
  182. #if __STDC_HOSTED__
  183. int __cdecl _setjmp(jmp_buf);
  184. #endif
  185. unsigned int _shlx_u32(unsigned int, unsigned int);
  186. unsigned int _shrx_u32(unsigned int, unsigned int);
  187. void _Store_HLERelease(long volatile *, long);
  188. void _Store64_HLERelease(__int64 volatile *, __int64);
  189. void _StorePointer_HLERelease(void *volatile *, void *);
  190. static __inline__ void
  191. __attribute__((__deprecated__("use other intrinsics or C++11 atomics instead")))
  192. _WriteBarrier(void);
  193. unsigned __int32 xbegin(void);
  194. void _xend(void);
  195. static __inline__
  196. #define _XCR_XFEATURE_ENABLED_MASK 0
  197. unsigned __int64 __cdecl _xgetbv(unsigned int);
  198. void __cdecl _xsetbv(unsigned int, unsigned __int64);
  199. /* These additional intrinsics are turned on in x64/amd64/x86_64 mode. */
  200. #if defined (__x86_64__) || (__aarch64__)
  201. void __addgsbyte(unsigned long, unsigned char);
  202. void __addgsdword(unsigned long, unsigned long);
  203. void __addgsqword(unsigned long, unsigned __int64);
  204. void __addgsword(unsigned long, unsigned short);
  205. static __inline__
  206. void __faststorefence(void);
  207. void __incgsbyte(unsigned long);
  208. void __incgsdword(unsigned long);
  209. void __incgsqword(unsigned long);
  210. void __incgsword(unsigned long);
  211. unsigned __int64 __lzcnt64(unsigned __int64);
  212. static __inline__
  213. void __movsq(unsigned long long *, unsigned long long const *, size_t);
  214. static __inline__
  215. unsigned char __readgsbyte(unsigned long);
  216. static __inline__
  217. unsigned long __readgsdword(unsigned long);
  218. static __inline__
  219. unsigned __int64 __readgsqword(unsigned long);
  220. unsigned short __readgsword(unsigned long);
  221. unsigned __int64 __shiftleft128(unsigned __int64 _LowPart,
  222. unsigned __int64 _HighPart,
  223. unsigned char _Shift);
  224. unsigned __int64 __shiftright128(unsigned __int64 _LowPart,
  225. unsigned __int64 _HighPart,
  226. unsigned char _Shift);
  227. static __inline__
  228. void __stosq(unsigned __int64 *, unsigned __int64, size_t);
  229. unsigned char __vmx_on(unsigned __int64 *);
  230. unsigned char __vmx_vmclear(unsigned __int64 *);
  231. unsigned char __vmx_vmlaunch(void);
  232. unsigned char __vmx_vmptrld(unsigned __int64 *);
  233. unsigned char __vmx_vmread(size_t, size_t *);
  234. unsigned char __vmx_vmresume(void);
  235. unsigned char __vmx_vmwrite(size_t, size_t);
  236. void __writegsbyte(unsigned long, unsigned char);
  237. void __writegsdword(unsigned long, unsigned long);
  238. void __writegsqword(unsigned long, unsigned __int64);
  239. void __writegsword(unsigned long, unsigned short);
  240. unsigned char _bittest64(__int64 const *, __int64);
  241. unsigned char _bittestandcomplement64(__int64 *, __int64);
  242. unsigned char _bittestandreset64(__int64 *, __int64);
  243. unsigned char _bittestandset64(__int64 *, __int64);
  244. long _InterlockedAnd_np(long volatile *_Value, long _Mask);
  245. short _InterlockedAnd16_np(short volatile *_Value, short _Mask);
  246. __int64 _InterlockedAnd64_np(__int64 volatile *_Value, __int64 _Mask);
  247. char _InterlockedAnd8_np(char volatile *_Value, char _Mask);
  248. unsigned char _interlockedbittestandreset64(__int64 volatile *, __int64);
  249. unsigned char _interlockedbittestandset64(__int64 volatile *, __int64);
  250. long _InterlockedCompareExchange_np(long volatile *_Destination, long _Exchange,
  251. long _Comparand);
  252. unsigned char _InterlockedCompareExchange128(__int64 volatile *_Destination,
  253. __int64 _ExchangeHigh,
  254. __int64 _ExchangeLow,
  255. __int64 *_CompareandResult);
  256. unsigned char _InterlockedCompareExchange128_np(__int64 volatile *_Destination,
  257. __int64 _ExchangeHigh,
  258. __int64 _ExchangeLow,
  259. __int64 *_ComparandResult);
  260. short _InterlockedCompareExchange16_np(short volatile *_Destination,
  261. short _Exchange, short _Comparand);
  262. __int64 _InterlockedCompareExchange64_np(__int64 volatile *_Destination,
  263. __int64 _Exchange, __int64 _Comparand);
  264. void *_InterlockedCompareExchangePointer_np(void *volatile *_Destination,
  265. void *_Exchange, void *_Comparand);
  266. long _InterlockedOr_np(long volatile *_Value, long _Mask);
  267. short _InterlockedOr16_np(short volatile *_Value, short _Mask);
  268. __int64 _InterlockedOr64_np(__int64 volatile *_Value, __int64 _Mask);
  269. char _InterlockedOr8_np(char volatile *_Value, char _Mask);
  270. long _InterlockedXor_np(long volatile *_Value, long _Mask);
  271. short _InterlockedXor16_np(short volatile *_Value, short _Mask);
  272. __int64 _InterlockedXor64_np(__int64 volatile *_Value, __int64 _Mask);
  273. char _InterlockedXor8_np(char volatile *_Value, char _Mask);
  274. unsigned __int64 _rorx_u64(unsigned __int64, const unsigned int);
  275. __int64 _sarx_i64(__int64, unsigned int);
  276. unsigned __int64 _shlx_u64(unsigned __int64, unsigned int);
  277. unsigned __int64 _shrx_u64(unsigned __int64, unsigned int);
  278. static __inline__
  279. __int64 __mulh(__int64, __int64);
  280. static __inline__
  281. unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
  282. static __inline__
  283. __int64 _mul128(__int64, __int64, __int64*);
  284. static __inline__
  285. unsigned __int64 _umul128(unsigned __int64,
  286. unsigned __int64,
  287. unsigned __int64*);
  288. #endif /* __x86_64__ */
  289. #if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
  290. static __inline__
  291. unsigned char _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask);
  292. static __inline__
  293. unsigned char _BitScanReverse64(unsigned long *_Index, unsigned __int64 _Mask);
  294. static __inline__
  295. __int64 _InterlockedDecrement64(__int64 volatile *_Addend);
  296. static __inline__
  297. __int64 _InterlockedExchange64(__int64 volatile *_Target, __int64 _Value);
  298. static __inline__
  299. __int64 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value);
  300. static __inline__
  301. __int64 _InterlockedExchangeSub64(__int64 volatile *_Subend, __int64 _Value);
  302. static __inline__
  303. __int64 _InterlockedIncrement64(__int64 volatile *_Addend);
  304. static __inline__
  305. __int64 _InterlockedOr64(__int64 volatile *_Value, __int64 _Mask);
  306. static __inline__
  307. __int64 _InterlockedXor64(__int64 volatile *_Value, __int64 _Mask);
  308. static __inline__
  309. __int64 _InterlockedAnd64(__int64 volatile *_Value, __int64 _Mask);
  310. #endif
  311. /*----------------------------------------------------------------------------*\
  312. |* Interlocked Exchange Add
  313. \*----------------------------------------------------------------------------*/
  314. #if defined(__arm__) || defined(__aarch64__)
  315. char _InterlockedExchangeAdd8_acq(char volatile *_Addend, char _Value);
  316. char _InterlockedExchangeAdd8_nf(char volatile *_Addend, char _Value);
  317. char _InterlockedExchangeAdd8_rel(char volatile *_Addend, char _Value);
  318. short _InterlockedExchangeAdd16_acq(short volatile *_Addend, short _Value);
  319. short _InterlockedExchangeAdd16_nf(short volatile *_Addend, short _Value);
  320. short _InterlockedExchangeAdd16_rel(short volatile *_Addend, short _Value);
  321. long _InterlockedExchangeAdd_acq(long volatile *_Addend, long _Value);
  322. long _InterlockedExchangeAdd_nf(long volatile *_Addend, long _Value);
  323. long _InterlockedExchangeAdd_rel(long volatile *_Addend, long _Value);
  324. __int64 _InterlockedExchangeAdd64_acq(__int64 volatile *_Addend, __int64 _Value);
  325. __int64 _InterlockedExchangeAdd64_nf(__int64 volatile *_Addend, __int64 _Value);
  326. __int64 _InterlockedExchangeAdd64_rel(__int64 volatile *_Addend, __int64 _Value);
  327. #endif
  328. /*----------------------------------------------------------------------------*\
  329. |* Interlocked Increment
  330. \*----------------------------------------------------------------------------*/
  331. #if defined(__arm__) || defined(__aarch64__)
  332. short _InterlockedIncrement16_acq(short volatile *_Value);
  333. short _InterlockedIncrement16_nf(short volatile *_Value);
  334. short _InterlockedIncrement16_rel(short volatile *_Value);
  335. long _InterlockedIncrement_acq(long volatile *_Value);
  336. long _InterlockedIncrement_nf(long volatile *_Value);
  337. long _InterlockedIncrement_rel(long volatile *_Value);
  338. __int64 _InterlockedIncrement64_acq(__int64 volatile *_Value);
  339. __int64 _InterlockedIncrement64_nf(__int64 volatile *_Value);
  340. __int64 _InterlockedIncrement64_rel(__int64 volatile *_Value);
  341. #endif
  342. /*----------------------------------------------------------------------------*\
  343. |* Interlocked Decrement
  344. \*----------------------------------------------------------------------------*/
  345. #if defined(__arm__) || defined(__aarch64__)
  346. short _InterlockedDecrement16_acq(short volatile *_Value);
  347. short _InterlockedDecrement16_nf(short volatile *_Value);
  348. short _InterlockedDecrement16_rel(short volatile *_Value);
  349. long _InterlockedDecrement_acq(long volatile *_Value);
  350. long _InterlockedDecrement_nf(long volatile *_Value);
  351. long _InterlockedDecrement_rel(long volatile *_Value);
  352. __int64 _InterlockedDecrement64_acq(__int64 volatile *_Value);
  353. __int64 _InterlockedDecrement64_nf(__int64 volatile *_Value);
  354. __int64 _InterlockedDecrement64_rel(__int64 volatile *_Value);
  355. #endif
  356. /*----------------------------------------------------------------------------*\
  357. |* Interlocked And
  358. \*----------------------------------------------------------------------------*/
  359. #if defined(__arm__) || defined(__aarch64__)
  360. char _InterlockedAnd8_acq(char volatile *_Value, char _Mask);
  361. char _InterlockedAnd8_nf(char volatile *_Value, char _Mask);
  362. char _InterlockedAnd8_rel(char volatile *_Value, char _Mask);
  363. short _InterlockedAnd16_acq(short volatile *_Value, short _Mask);
  364. short _InterlockedAnd16_nf(short volatile *_Value, short _Mask);
  365. short _InterlockedAnd16_rel(short volatile *_Value, short _Mask);
  366. long _InterlockedAnd_acq(long volatile *_Value, long _Mask);
  367. long _InterlockedAnd_nf(long volatile *_Value, long _Mask);
  368. long _InterlockedAnd_rel(long volatile *_Value, long _Mask);
  369. __int64 _InterlockedAnd64_acq(__int64 volatile *_Value, __int64 _Mask);
  370. __int64 _InterlockedAnd64_nf(__int64 volatile *_Value, __int64 _Mask);
  371. __int64 _InterlockedAnd64_rel(__int64 volatile *_Value, __int64 _Mask);
  372. #endif
  373. /*----------------------------------------------------------------------------*\
  374. |* Bit Counting and Testing
  375. \*----------------------------------------------------------------------------*/
  376. #if defined(__arm__) || defined(__aarch64__)
  377. unsigned char _interlockedbittestandset_acq(long volatile *_BitBase,
  378. long _BitPos);
  379. unsigned char _interlockedbittestandset_nf(long volatile *_BitBase,
  380. long _BitPos);
  381. unsigned char _interlockedbittestandset_rel(long volatile *_BitBase,
  382. long _BitPos);
  383. unsigned char _interlockedbittestandreset_acq(long volatile *_BitBase,
  384. long _BitPos);
  385. unsigned char _interlockedbittestandreset_nf(long volatile *_BitBase,
  386. long _BitPos);
  387. unsigned char _interlockedbittestandreset_rel(long volatile *_BitBase,
  388. long _BitPos);
  389. #endif
  390. /*----------------------------------------------------------------------------*\
  391. |* Interlocked Or
  392. \*----------------------------------------------------------------------------*/
  393. #if defined(__arm__) || defined(__aarch64__)
  394. char _InterlockedOr8_acq(char volatile *_Value, char _Mask);
  395. char _InterlockedOr8_nf(char volatile *_Value, char _Mask);
  396. char _InterlockedOr8_rel(char volatile *_Value, char _Mask);
  397. short _InterlockedOr16_acq(short volatile *_Value, short _Mask);
  398. short _InterlockedOr16_nf(short volatile *_Value, short _Mask);
  399. short _InterlockedOr16_rel(short volatile *_Value, short _Mask);
  400. long _InterlockedOr_acq(long volatile *_Value, long _Mask);
  401. long _InterlockedOr_nf(long volatile *_Value, long _Mask);
  402. long _InterlockedOr_rel(long volatile *_Value, long _Mask);
  403. __int64 _InterlockedOr64_acq(__int64 volatile *_Value, __int64 _Mask);
  404. __int64 _InterlockedOr64_nf(__int64 volatile *_Value, __int64 _Mask);
  405. __int64 _InterlockedOr64_rel(__int64 volatile *_Value, __int64 _Mask);
  406. #endif
  407. /*----------------------------------------------------------------------------*\
  408. |* Interlocked Xor
  409. \*----------------------------------------------------------------------------*/
  410. #if defined(__arm__) || defined(__aarch64__)
  411. char _InterlockedXor8_acq(char volatile *_Value, char _Mask);
  412. char _InterlockedXor8_nf(char volatile *_Value, char _Mask);
  413. char _InterlockedXor8_rel(char volatile *_Value, char _Mask);
  414. short _InterlockedXor16_acq(short volatile *_Value, short _Mask);
  415. short _InterlockedXor16_nf(short volatile *_Value, short _Mask);
  416. short _InterlockedXor16_rel(short volatile *_Value, short _Mask);
  417. long _InterlockedXor_acq(long volatile *_Value, long _Mask);
  418. long _InterlockedXor_nf(long volatile *_Value, long _Mask);
  419. long _InterlockedXor_rel(long volatile *_Value, long _Mask);
  420. __int64 _InterlockedXor64_acq(__int64 volatile *_Value, __int64 _Mask);
  421. __int64 _InterlockedXor64_nf(__int64 volatile *_Value, __int64 _Mask);
  422. __int64 _InterlockedXor64_rel(__int64 volatile *_Value, __int64 _Mask);
  423. #endif
  424. /*----------------------------------------------------------------------------*\
  425. |* Interlocked Exchange
  426. \*----------------------------------------------------------------------------*/
  427. #if defined(__arm__) || defined(__aarch64__)
  428. char _InterlockedExchange8_acq(char volatile *_Target, char _Value);
  429. char _InterlockedExchange8_nf(char volatile *_Target, char _Value);
  430. char _InterlockedExchange8_rel(char volatile *_Target, char _Value);
  431. short _InterlockedExchange16_acq(short volatile *_Target, short _Value);
  432. short _InterlockedExchange16_nf(short volatile *_Target, short _Value);
  433. short _InterlockedExchange16_rel(short volatile *_Target, short _Value);
  434. long _InterlockedExchange_acq(long volatile *_Target, long _Value);
  435. long _InterlockedExchange_nf(long volatile *_Target, long _Value);
  436. long _InterlockedExchange_rel(long volatile *_Target, long _Value);
  437. __int64 _InterlockedExchange64_acq(__int64 volatile *_Target, __int64 _Value);
  438. __int64 _InterlockedExchange64_nf(__int64 volatile *_Target, __int64 _Value);
  439. __int64 _InterlockedExchange64_rel(__int64 volatile *_Target, __int64 _Value);
  440. #endif
  441. /*----------------------------------------------------------------------------*\
  442. |* Interlocked Compare Exchange
  443. \*----------------------------------------------------------------------------*/
  444. #if defined(__arm__) || defined(__aarch64__)
  445. char _InterlockedCompareExchange8_acq(char volatile *_Destination,
  446. char _Exchange, char _Comparand);
  447. char _InterlockedCompareExchange8_nf(char volatile *_Destination,
  448. char _Exchange, char _Comparand);
  449. char _InterlockedCompareExchange8_rel(char volatile *_Destination,
  450. char _Exchange, char _Comparand);
  451. short _InterlockedCompareExchange16_acq(short volatile *_Destination,
  452. short _Exchange, short _Comparand);
  453. short _InterlockedCompareExchange16_nf(short volatile *_Destination,
  454. short _Exchange, short _Comparand);
  455. short _InterlockedCompareExchange16_rel(short volatile *_Destination,
  456. short _Exchange, short _Comparand);
  457. long _InterlockedCompareExchange_acq(long volatile *_Destination,
  458. long _Exchange, long _Comparand);
  459. long _InterlockedCompareExchange_nf(long volatile *_Destination,
  460. long _Exchange, long _Comparand);
  461. long _InterlockedCompareExchange_rel(long volatile *_Destination,
  462. long _Exchange, long _Comparand);
  463. __int64 _InterlockedCompareExchange64_acq(__int64 volatile *_Destination,
  464. __int64 _Exchange, __int64 _Comparand);
  465. __int64 _InterlockedCompareExchange64_nf(__int64 volatile *_Destination,
  466. __int64 _Exchange, __int64 _Comparand);
  467. __int64 _InterlockedCompareExchange64_rel(__int64 volatile *_Destination,
  468. __int64 _Exchange, __int64 _Comparand);
  469. #endif
  470. /*----------------------------------------------------------------------------*\
  471. |* movs, stos
  472. \*----------------------------------------------------------------------------*/
  473. #if defined(__i386__) || defined(__x86_64__)
  474. static __inline__ void __DEFAULT_FN_ATTRS
  475. __movsb(unsigned char *__dst, unsigned char const *__src, size_t __n) {
  476. __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
  477. : : "memory");
  478. }
  479. static __inline__ void __DEFAULT_FN_ATTRS
  480. __movsd(unsigned long *__dst, unsigned long const *__src, size_t __n) {
  481. __asm__ __volatile__("rep movsl" : "+D"(__dst), "+S"(__src), "+c"(__n)
  482. : : "memory");
  483. }
  484. static __inline__ void __DEFAULT_FN_ATTRS
  485. __movsw(unsigned short *__dst, unsigned short const *__src, size_t __n) {
  486. __asm__ __volatile__("rep movsw" : "+D"(__dst), "+S"(__src), "+c"(__n)
  487. : : "memory");
  488. }
  489. static __inline__ void __DEFAULT_FN_ATTRS
  490. __stosd(unsigned long *__dst, unsigned long __x, size_t __n) {
  491. __asm__ __volatile__("rep stosl" : "+D"(__dst), "+c"(__n) : "a"(__x)
  492. : "memory");
  493. }
  494. static __inline__ void __DEFAULT_FN_ATTRS
  495. __stosw(unsigned short *__dst, unsigned short __x, size_t __n) {
  496. __asm__ __volatile__("rep stosw" : "+D"(__dst), "+c"(__n) : "a"(__x)
  497. : "memory");
  498. }
  499. #endif
  500. #ifdef __x86_64__
  501. static __inline__ void __DEFAULT_FN_ATTRS
  502. __movsq(unsigned long long *__dst, unsigned long long const *__src, size_t __n) {
  503. __asm__ __volatile__("rep movsq" : "+D"(__dst), "+S"(__src), "+c"(__n)
  504. : : "memory");
  505. }
  506. static __inline__ void __DEFAULT_FN_ATTRS
  507. __stosq(unsigned __int64 *__dst, unsigned __int64 __x, size_t __n) {
  508. __asm__ __volatile__("rep stosq" : "+D"(__dst), "+c"(__n) : "a"(__x)
  509. : "memory");
  510. }
  511. #endif
  512. /*----------------------------------------------------------------------------*\
  513. |* Misc
  514. \*----------------------------------------------------------------------------*/
  515. #if defined(__i386__) || defined(__x86_64__)
  516. static __inline__ void __DEFAULT_FN_ATTRS
  517. __cpuid(int __info[4], int __level) {
  518. __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
  519. : "a"(__level));
  520. }
  521. static __inline__ void __DEFAULT_FN_ATTRS
  522. __cpuidex(int __info[4], int __level, int __ecx) {
  523. __asm__ ("cpuid" : "=a"(__info[0]), "=b" (__info[1]), "=c"(__info[2]), "=d"(__info[3])
  524. : "a"(__level), "c"(__ecx));
  525. }
  526. static __inline__ unsigned __int64 __cdecl __DEFAULT_FN_ATTRS
  527. _xgetbv(unsigned int __xcr_no) {
  528. unsigned int __eax, __edx;
  529. __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no));
  530. return ((unsigned __int64)__edx << 32) | __eax;
  531. }
  532. static __inline__ void __DEFAULT_FN_ATTRS
  533. __halt(void) {
  534. __asm__ volatile ("hlt");
  535. }
  536. #endif
  537. #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
  538. static __inline__ void __DEFAULT_FN_ATTRS
  539. __nop(void) {
  540. __asm__ volatile ("nop");
  541. }
  542. #endif
  543. /*----------------------------------------------------------------------------*\
  544. |* MS AArch64 specific
  545. \*----------------------------------------------------------------------------*/
  546. #if defined(__aarch64__)
  547. unsigned __int64 __getReg(int);
  548. long _InterlockedAdd(long volatile *Addend, long Value);
  549. int _ReadStatusReg(int);
  550. void _WriteStatusReg(int, int);
  551. #endif
  552. /*----------------------------------------------------------------------------*\
  553. |* Privileged intrinsics
  554. \*----------------------------------------------------------------------------*/
  555. #if defined(__i386__) || defined(__x86_64__)
  556. static __inline__ unsigned __int64 __DEFAULT_FN_ATTRS
  557. __readmsr(unsigned long __register) {
  558. // Loads the contents of a 64-bit model specific register (MSR) specified in
  559. // the ECX register into registers EDX:EAX. The EDX register is loaded with
  560. // the high-order 32 bits of the MSR and the EAX register is loaded with the
  561. // low-order 32 bits. If less than 64 bits are implemented in the MSR being
  562. // read, the values returned to EDX:EAX in unimplemented bit locations are
  563. // undefined.
  564. unsigned long __edx;
  565. unsigned long __eax;
  566. __asm__ ("rdmsr" : "=d"(__edx), "=a"(__eax) : "c"(__register));
  567. return (((unsigned __int64)__edx) << 32) | (unsigned __int64)__eax;
  568. }
  569. static __inline__ unsigned long __DEFAULT_FN_ATTRS
  570. __readcr3(void) {
  571. unsigned long __cr3_val;
  572. __asm__ __volatile__ ("mov %%cr3, %0" : "=q"(__cr3_val) : : "memory");
  573. return __cr3_val;
  574. }
  575. static __inline__ void __DEFAULT_FN_ATTRS
  576. __writecr3(unsigned int __cr3_val) {
  577. __asm__ ("mov %0, %%cr3" : : "q"(__cr3_val) : "memory");
  578. }
  579. #endif
  580. #ifdef __cplusplus
  581. }
  582. #endif
  583. #undef __DEFAULT_FN_ATTRS
  584. #endif /* __INTRIN_H */
  585. #endif /* _MSC_VER */