sdlcpuinfo.inc 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. {*
  2. * This is a guess for the cacheline size used for padding.
  3. * Most x86 processors have a 64 byte cache line.
  4. * The 64-bit PowerPC processors have a 128 byte cache line.
  5. * We'll use the larger value to be generally safe.
  6. *}
  7. const
  8. SDL_CACHELINE_SIZE = 128;
  9. {**
  10. * This function returns the number of CPU cores available.
  11. *}
  12. function SDL_GetCPUCount(): cint; cdecl;
  13. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetCPUCount' {$ENDIF} {$ENDIF};
  14. {**
  15. * This function returns the L1 cache line size of the CPU.
  16. *
  17. * This is useful for determining multi-threaded structure padding
  18. * or SIMD prefetch sizes.
  19. *}
  20. function SDL_GetCPUCacheLineSize(): cint; cdecl;
  21. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetCPUCacheLineSize' {$ENDIF} {$ENDIF};
  22. {**
  23. * This function returns true if the CPU has the RDTSC instruction.
  24. *
  25. * This always returns false on CPUs that aren't using Intel instruction sets.
  26. *}
  27. function SDL_HasRDTSC(): TSDL_Bool; cdecl;
  28. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasRDTSC' {$ENDIF} {$ENDIF};
  29. {**
  30. * This function returns true if the CPU has AltiVec features.
  31. *
  32. * This always returns false on CPUs that aren't using PowerPC
  33. * instruction sets.
  34. *}
  35. function SDL_HasAltiVec(): TSDL_Bool; cdecl;
  36. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasAltiVec' {$ENDIF} {$ENDIF};
  37. {**
  38. * This function returns true if the CPU has MMX features.
  39. *
  40. * This always returns false on CPUs that aren't using Intel instruction sets.
  41. *}
  42. function SDL_HasMMX(): TSDL_Bool; cdecl;
  43. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasMMX' {$ENDIF} {$ENDIF};
  44. {**
  45. * This function returns true if the CPU has 3DNow! features.
  46. *
  47. * This always returns false on CPUs that aren't using AMD instruction sets.
  48. *}
  49. function SDL_Has3DNow(): TSDL_Bool; cdecl;
  50. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_Has3DNow' {$ENDIF} {$ENDIF};
  51. {**
  52. * This function returns true if the CPU has SSE features.
  53. *
  54. * This always returns false on CPUs that aren't using Intel instruction sets.
  55. *}
  56. function SDL_HasSSE(): TSDL_Bool; cdecl;
  57. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasSSE' {$ENDIF} {$ENDIF};
  58. {**
  59. * This function returns true if the CPU has SSE2 features.
  60. *
  61. * This always returns false on CPUs that aren't using Intel instruction sets.
  62. *}
  63. function SDL_HasSSE2(): TSDL_Bool; cdecl;
  64. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasSSE2' {$ENDIF} {$ENDIF};
  65. {**
  66. * This function returns true if the CPU has SSE3 features.
  67. *
  68. * This always returns false on CPUs that aren't using Intel instruction sets.
  69. *}
  70. function SDL_HasSSE3(): TSDL_Bool; cdecl;
  71. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasSSE3' {$ENDIF} {$ENDIF};
  72. {**
  73. * This function returns true if the CPU has SSE4.1 features.
  74. *
  75. * This always returns false on CPUs that aren't using Intel instruction sets.
  76. *}
  77. function SDL_HasSSE41(): TSDL_Bool; cdecl;
  78. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasSSE41' {$ENDIF} {$ENDIF};
  79. {**
  80. * This function returns true if the CPU has SSE4.2 features.
  81. *
  82. * This always returns false on CPUs that aren't using Intel instruction sets.
  83. *}
  84. function SDL_HasSSE42(): TSDL_Bool; cdecl;
  85. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasSSE42' {$ENDIF} {$ENDIF};
  86. {**
  87. * This function returns true if the CPU has AVX features.
  88. *
  89. * This always returns false on CPUs that aren't using Intel instruction sets.
  90. *}
  91. function SDL_HasAVX(): TSDL_Bool; cdecl;
  92. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasAVX' {$ENDIF} {$ENDIF};
  93. {**
  94. * This function returns true if the CPU has AVX2 features.
  95. *
  96. * This always returns false on CPUs that aren't using Intel instruction sets.
  97. *}
  98. function SDL_HasAVX2(): TSDL_Bool; cdecl;
  99. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasAVX2' {$ENDIF} {$ENDIF};
  100. {**
  101. * Determine whether the CPU has AVX-512F (foundation) features.
  102. *
  103. * This always returns false on CPUs that aren't using Intel instruction sets.
  104. *}
  105. function SDL_HasAVX512F(): TSDL_Bool; cdecl;
  106. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasAVX512F' {$ENDIF} {$ENDIF};
  107. {**
  108. * Determine whether the CPU has ARM SIMD (ARMv6) features.
  109. * This is different from ARM NEON, which is a different instruction set.
  110. *
  111. * This always returns false on CPUs that aren't using ARM instruction sets.
  112. *}
  113. function SDL_HasARMSIMD(): TSDL_Bool; cdecl;
  114. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasARMSIMD' {$ENDIF} {$ENDIF};
  115. {**
  116. * Determine whether the CPU has NEON (ARM SIMD) features.
  117. *
  118. * This always returns false on CPUs that aren't using ARM instruction sets.
  119. *}
  120. function SDL_HasNEON(): TSDL_Bool; cdecl;
  121. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_HasNEON' {$ENDIF} {$ENDIF};
  122. {**
  123. * This function returns the amount of RAM configured in the system, in MB.
  124. *}
  125. function SDL_GetSystemRAM(): cint; cdecl;
  126. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_GetSystemRAM' {$ENDIF} {$ENDIF};
  127. {**
  128. * Report the alignment this system needs for SIMD allocations.
  129. *
  130. * This will return the minimum number of bytes to which a pointer must be
  131. * aligned to be compatible with SIMD instructions on the current machine. For
  132. * example, if the machine supports SSE only, it will return 16, but if it
  133. * supports AVX-512F, it'll return 64 (etc). This only reports values for
  134. * instruction sets SDL knows about, so if your SDL build doesn't have
  135. * SDL_HasAVX512F(), then it might return 16 for the SSE support it sees and
  136. * not 64 for the AVX-512 instructions that exist but SDL doesn't know about.
  137. * Plan accordingly.
  138. *}
  139. function SDL_SIMDGetAlignment(): csize_t; cdecl;
  140. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SIMDGetAlignment' {$ENDIF} {$ENDIF};
  141. {*
  142. * Allocate memory in a SIMD-friendly way.
  143. *
  144. * This will allocate a block of memory that is suitable for use with SIMD
  145. * instructions. Specifically, it will be properly aligned and padded for the
  146. * system's supported vector instructions.
  147. *
  148. * The memory returned will be padded such that it is safe to read or write an
  149. * incomplete vector at the end of the memory block. This can be useful so you
  150. * don't have to drop back to a scalar fallback at the end of your SIMD
  151. * processing loop to deal with the final elements without overflowing the
  152. * allocated buffer.
  153. *
  154. * You must free this memory with SDL_FreeSIMD(), not free() or SDL_free().
  155. *
  156. * Note that SDL will only deal with SIMD instruction sets it is aware of; for
  157. * example, SDL 2.0.8 knows that SSE wants 16-byte vectors (SDL_HasSSE()), and
  158. * AVX2 wants 32 bytes (SDL_HasAVX2()), but doesn't know that AVX-512 wants
  159. * 64. To be clear: if you can't decide to use an instruction set with an
  160. * SDL_Has*() function, don't use that instruction set with memory allocated
  161. * through here.
  162. *
  163. * SDL_AllocSIMD(0) will return a non-NULL pointer, assuming the system isn't
  164. * out of memory, but you are not allowed to dereference it (because you only
  165. * own zero bytes of that buffer).
  166. *}
  167. function SDL_SIMDAlloc(const len: csize_t): Pointer; cdecl;
  168. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SIMDAlloc' {$ENDIF} {$ENDIF};
  169. {**
  170. * Reallocate memory obtained from SDL_SIMDAlloc.
  171. *
  172. * It is not valid to use this function on a pointer from anything but
  173. * SDL_SIMDAlloc(). It can't be used on pointers from SDL_malloc, GetMem, etc.
  174. *}
  175. function SDL_SIMDRealloc(mem: Pointer; const len: csize_t): Pointer; cdecl;
  176. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SIMDRealloc' {$ENDIF} {$ENDIF};
  177. {**
  178. * Deallocate memory obtained from SDL_SIMDAlloc.
  179. *
  180. * It is not valid to use this function on a pointer from anything but
  181. * SDL_SIMDAlloc() or SDL_SIMDRealloc(). It can't be used on pointers from
  182. * SDL_malloc, GetMem, etc.
  183. *
  184. * However, SDL_SIMDFree(NIL) is a legal no-op.
  185. *
  186. * The memory pointed to by `mem` is no longer valid for access upon return,
  187. * and may be returned to the system or reused by a future allocation. The
  188. * pointer passed to this function is no longer safe to dereference once this
  189. * function returns, and should be discarded.
  190. *}
  191. procedure SDL_SIMDFree(mem: Pointer); cdecl;
  192. external {$IFDEF DYNAMIC_LINK}SDL_LibName{$ENDIF} {$IFDEF DELPHI} {$IFDEF MACOS} name '_SDL_SIMDFree' {$ENDIF} {$ENDIF};