xbox360_ppc.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. // TODO: revise by comparing with mac_ppc.h
  24. #if !defined(__TBB_machine_H) || defined(__TBB_machine_xbox360_ppc_H)
  25. #error Do not #include this internal file directly; use public TBB headers instead.
  26. #endif
  27. #define __TBB_machine_xbox360_ppc_H
  28. #define NONET
  29. #define NOD3D
  30. #include "xtl.h"
  31. #include "ppcintrinsics.h"
  32. #if _MSC_VER >= 1300
  33. extern "C" void _MemoryBarrier();
  34. #pragma intrinsic(_MemoryBarrier)
  35. #define __TBB_control_consistency_helper() __isync()
  36. #define __TBB_acquire_consistency_helper() _MemoryBarrier()
  37. #define __TBB_release_consistency_helper() _MemoryBarrier()
  38. #endif
  39. #define __TBB_full_memory_fence() __sync()
  40. #define __TBB_WORDSIZE 4
  41. #define __TBB_BIG_ENDIAN 1
  42. //todo: define __TBB_USE_FENCED_ATOMICS and define acquire/release primitives to maximize performance
  43. inline __int32 __TBB_machine_cmpswp4(volatile void *ptr, __int32 value, __int32 comparand ) {
  44. __sync();
  45. __int32 result = InterlockedCompareExchange((volatile LONG*)ptr, value, comparand);
  46. __isync();
  47. return result;
  48. }
  49. inline __int64 __TBB_machine_cmpswp8(volatile void *ptr, __int64 value, __int64 comparand )
  50. {
  51. __sync();
  52. __int64 result = InterlockedCompareExchange64((volatile LONG64*)ptr, value, comparand);
  53. __isync();
  54. return result;
  55. }
  56. #define __TBB_USE_GENERIC_PART_WORD_CAS 1
  57. #define __TBB_USE_GENERIC_FETCH_ADD 1
  58. #define __TBB_USE_GENERIC_FETCH_STORE 1
  59. #define __TBB_USE_GENERIC_HALF_FENCED_LOAD_STORE 1
  60. #define __TBB_USE_GENERIC_RELAXED_LOAD_STORE 1
  61. #define __TBB_USE_GENERIC_DWORD_LOAD_STORE 1
  62. #define __TBB_USE_GENERIC_SEQUENTIAL_CONSISTENCY_LOAD_STORE 1
  63. #pragma optimize( "", off )
  64. inline void __TBB_machine_pause (__int32 delay )
  65. {
  66. for (__int32 i=0; i<delay; i++) {;};
  67. }
  68. #pragma optimize( "", on )
  69. #define __TBB_Yield() Sleep(0)
  70. #define __TBB_Pause(V) __TBB_machine_pause(V)
  71. // This port uses only 2 hardware threads for TBB on XBOX 360.
  72. // Others are left to sound etc.
  73. // Change the following mask to allow TBB use more HW threads.
  74. static const int __TBB_XBOX360_HARDWARE_THREAD_MASK = 0x0C;
  75. static inline int __TBB_XBOX360_DetectNumberOfWorkers()
  76. {
  77. char a[__TBB_XBOX360_HARDWARE_THREAD_MASK]; //compile time assert - at least one bit should be set always
  78. a[0]=0;
  79. return ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 0) & 1) +
  80. ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 1) & 1) +
  81. ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 2) & 1) +
  82. ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 3) & 1) +
  83. ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 4) & 1) +
  84. ((__TBB_XBOX360_HARDWARE_THREAD_MASK >> 5) & 1) + 1; // +1 accomodates for the master thread
  85. }
  86. static inline int __TBB_XBOX360_GetHardwareThreadIndex(int workerThreadIndex)
  87. {
  88. workerThreadIndex %= __TBB_XBOX360_DetectNumberOfWorkers()-1;
  89. int m = __TBB_XBOX360_HARDWARE_THREAD_MASK;
  90. int index = 0;
  91. int skipcount = workerThreadIndex;
  92. while (true)
  93. {
  94. if ((m & 1)!=0)
  95. {
  96. if (skipcount==0) break;
  97. skipcount--;
  98. }
  99. m >>= 1;
  100. index++;
  101. }
  102. return index;
  103. }
  104. #define __TBB_HardwareConcurrency() __TBB_XBOX360_DetectNumberOfWorkers()