windows_intel64.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Copyright 2005-2013 Intel Corporation. All Rights Reserved.
  3. This file is part of Threading Building Blocks.
  4. Threading Building Blocks is free software; you can redistribute it
  5. and/or modify it under the terms of the GNU General Public License
  6. version 2 as published by the Free Software Foundation.
  7. Threading Building Blocks is distributed in the hope that it will be
  8. useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  9. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with Threading Building Blocks; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  14. As a special exception, you may use this file as part of a free software
  15. library without restriction. Specifically, if other files instantiate
  16. templates or use macros or inline functions from this file, or you compile
  17. this file and link it with other files to produce an executable, this
  18. file does not by itself cause the resulting executable to be covered by
  19. the GNU General Public License. This exception does not however
  20. invalidate any other reasons why the executable file might be covered by
  21. the GNU General Public License.
  22. */
  23. #if !defined(__TBB_machine_H) || defined(__TBB_machine_windows_intel64_H)
  24. #error Do not #include this internal file directly; use public TBB headers instead.
  25. #endif
  26. #define __TBB_machine_windows_intel64_H
  27. #define __TBB_WORDSIZE 8
  28. #define __TBB_BIG_ENDIAN 0
  29. #include <intrin.h>
  30. #include "msvc_ia32_common.h"
  31. //TODO: Use _InterlockedXXX16 intrinsics for 2 byte operations
  32. #if !__INTEL_COMPILER
  33. #pragma intrinsic(_InterlockedOr64)
  34. #pragma intrinsic(_InterlockedAnd64)
  35. #pragma intrinsic(_InterlockedCompareExchange)
  36. #pragma intrinsic(_InterlockedCompareExchange64)
  37. #pragma intrinsic(_InterlockedExchangeAdd)
  38. #pragma intrinsic(_InterlockedExchangeAdd64)
  39. #pragma intrinsic(_InterlockedExchange)
  40. #pragma intrinsic(_InterlockedExchange64)
  41. #endif /* !(__INTEL_COMPILER) */
  42. #if __INTEL_COMPILER && (__INTEL_COMPILER < 1100)
  43. #define __TBB_compiler_fence() __asm { __asm nop }
  44. #define __TBB_full_memory_fence() __asm { __asm mfence }
  45. #elif _MSC_VER >= 1300 || __INTEL_COMPILER
  46. #pragma intrinsic(_ReadWriteBarrier)
  47. #pragma intrinsic(_mm_mfence)
  48. #define __TBB_compiler_fence() _ReadWriteBarrier()
  49. #define __TBB_full_memory_fence() _mm_mfence()
  50. #endif
  51. #define __TBB_control_consistency_helper() __TBB_compiler_fence()
  52. #define __TBB_acquire_consistency_helper() __TBB_compiler_fence()
  53. #define __TBB_release_consistency_helper() __TBB_compiler_fence()
  54. // ATTENTION: if you ever change argument types in machine-specific primitives,
  55. // please take care of atomic_word<> specializations in tbb/atomic.h
  56. extern "C" {
  57. __int8 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp1 (volatile void *ptr, __int8 value, __int8 comparand );
  58. __int8 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd1 (volatile void *ptr, __int8 addend );
  59. __int8 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore1 (volatile void *ptr, __int8 value );
  60. __int16 __TBB_EXPORTED_FUNC __TBB_machine_cmpswp2 (volatile void *ptr, __int16 value, __int16 comparand );
  61. __int16 __TBB_EXPORTED_FUNC __TBB_machine_fetchadd2 (volatile void *ptr, __int16 addend );
  62. __int16 __TBB_EXPORTED_FUNC __TBB_machine_fetchstore2 (volatile void *ptr, __int16 value );
  63. }
  64. inline long __TBB_machine_cmpswp4 (volatile void *ptr, __int32 value, __int32 comparand ) {
  65. return _InterlockedCompareExchange( (long*)ptr, value, comparand );
  66. }
  67. inline long __TBB_machine_fetchadd4 (volatile void *ptr, __int32 addend ) {
  68. return _InterlockedExchangeAdd( (long*)ptr, addend );
  69. }
  70. inline long __TBB_machine_fetchstore4 (volatile void *ptr, __int32 value ) {
  71. return _InterlockedExchange( (long*)ptr, value );
  72. }
  73. inline __int64 __TBB_machine_cmpswp8 (volatile void *ptr, __int64 value, __int64 comparand ) {
  74. return _InterlockedCompareExchange64( (__int64*)ptr, value, comparand );
  75. }
  76. inline __int64 __TBB_machine_fetchadd8 (volatile void *ptr, __int64 addend ) {
  77. return _InterlockedExchangeAdd64( (__int64*)ptr, addend );
  78. }
  79. inline __int64 __TBB_machine_fetchstore8 (volatile void *ptr, __int64 value ) {
  80. return _InterlockedExchange64( (__int64*)ptr, value );
  81. }
  82. #define __TBB_USE_FETCHSTORE_AS_FULL_FENCED_STORE 1
  83. #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1
  84. #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1
  85. #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1
  86. inline void __TBB_machine_OR( volatile void *operand, intptr_t addend ) {
  87. _InterlockedOr64((__int64*)operand, addend);
  88. }
  89. inline void __TBB_machine_AND( volatile void *operand, intptr_t addend ) {
  90. _InterlockedAnd64((__int64*)operand, addend);
  91. }
  92. #define __TBB_AtomicOR(P,V) __TBB_machine_OR(P,V)
  93. #define __TBB_AtomicAND(P,V) __TBB_machine_AND(P,V)