sdlCPUInfo.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // XXTH used for FreeBSD
  23. // Note: SDL_cpuinfo have not all information, but better than using
  24. // "sysctl hw"
  25. //
  26. //-----------------------------------------------------------------------------
  27. #if defined( __FreeBSD__ )
  28. #include "SDL.h"
  29. #include "platform/platformCPUCount.h"
  30. #include "console/console.h"
  31. #include <math/mMathFn.h>
  32. Platform::SystemInfo_struct Platform::SystemInfo;
  33. void Processor::init()
  34. {
  35. S32 lCpuCount = SDL_GetCPUCount();
  36. Platform::SystemInfo.processor.numLogicalProcessors = lCpuCount;
  37. //sdl dont have logical/physical CPU count so ... time to guess
  38. if (lCpuCount > 1)
  39. {
  40. Platform::SystemInfo.processor.numPhysicalProcessors = mFloor(lCpuCount / 2); // guessing ;
  41. Platform::SystemInfo.processor.isMultiCore = true;
  42. //modern CPU should have isHyperThreaded
  43. Platform::SystemInfo.processor.isHyperThreaded = true;
  44. }
  45. else {
  46. Platform::SystemInfo.processor.numPhysicalProcessors = lCpuCount; // guessing ;
  47. Platform::SystemInfo.processor.isMultiCore = false;
  48. Platform::SystemInfo.processor.isHyperThreaded = false;
  49. }
  50. //hackfest
  51. Platform::SystemInfo.processor.mhz = 2666;
  52. #if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_X32)
  53. // Set sane default information
  54. Platform::SystemInfo.processor.name = StringTable->insert("Unknown Processor");
  55. Platform::SystemInfo.processor.properties |= CPU_PROP_C | CPU_PROP_FPU | CPU_PROP_LE ;
  56. Platform::SystemInfo.processor.type = CPU_X86Compatible;
  57. #elif defined(TORQUE_CPU_ARM32) || defined(TORQUE_CPU_ARM64)
  58. Platform::SystemInfo.processor.type = CPU_ArmCompatible;
  59. Platform::SystemInfo.processor.name = StringTable->insert("Unknown ARM Processor");
  60. Platform::SystemInfo.processor.properties = CPU_PROP_C;
  61. #else
  62. #warning Unsupported CPU
  63. #endif
  64. // Set 64bit flag
  65. #if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64)
  66. Platform::SystemInfo.processor.properties |= CPU_PROP_64bit;
  67. #endif
  68. Con::printf("Processor Init:");
  69. Con::printf(" CPU count: %d", lCpuCount);
  70. Con::printf(" CacheLine size: %d", SDL_GetCPUCacheLineSize());
  71. if (lCpuCount > 1) {
  72. Platform::SystemInfo.processor.properties |= CPU_PROP_MP;
  73. Con::printf(" MultiCore CPU detected" );
  74. }
  75. Con::printf(" RAM: %d MB", SDL_GetSystemRAM());
  76. if (SDL_HasMMX()) {
  77. Platform::SystemInfo.processor.properties |= CPU_PROP_MMX;
  78. Con::printf(" MMX detected" );
  79. }
  80. if (SDL_HasSSE()) {
  81. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE;
  82. Con::printf(" SSE detected" );
  83. }
  84. if (SDL_HasSSE2()) {
  85. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE2;
  86. Con::printf(" SSE2 detected" );
  87. }
  88. if (SDL_HasSSE3()) {
  89. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE3;
  90. Con::printf(" SSE3 detected" );
  91. }
  92. if (SDL_HasSSE41()) {
  93. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_1;
  94. Con::printf(" SSE4.1 detected" );
  95. }
  96. if (SDL_HasSSE42()) {
  97. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_2;
  98. Con::printf(" SSE4.2 detected" );
  99. }
  100. if (SDL_HasSSE42()) {
  101. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_2;
  102. Con::printf(" SSE4.2 detected" );
  103. }
  104. if (SDL_HasAVX() || SDL_HasAVX2()) {
  105. Platform::SystemInfo.processor.properties |= CPU_PROP_AVX;
  106. Con::printf(" AVX detected" );
  107. }
  108. if (SDL_HasNEON()) {
  109. Platform::SystemInfo.processor.properties |= CPU_PROP_NEON;
  110. Con::printf(" NEON detected" );
  111. }
  112. Con::printf(" ");
  113. SetProcessorInfo(Platform::SystemInfo.processor, "Unknown", "Unknown");
  114. }
  115. namespace CPUInfo
  116. {
  117. EConfig CPUCount(U32 &logical, U32 &physical)
  118. {
  119. // We don't set logical or physical here because it's already been determined by this point
  120. if (Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
  121. {
  122. return CONFIG_SingleCoreHTEnabled;
  123. }
  124. else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors > 1)
  125. {
  126. return CONFIG_MultiCoreAndHTNotCapable;
  127. }
  128. else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
  129. {
  130. return CONFIG_SingleCoreAndHTNotCapable;
  131. }
  132. return CONFIG_MultiCoreAndHTEnabled;
  133. }
  134. }; // namespace CPUInfo
  135. #endif // defined( __FreeBSD__ )