sdlCPUInfo.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. Platform::SystemInfo_struct Platform::SystemInfo;
  32. void Processor::init()
  33. {
  34. S32 lCpuCount = SDL_GetCPUCount();
  35. Platform::SystemInfo.processor.numLogicalProcessors = lCpuCount;
  36. //sdl dont have logical/physical CPU count so ... time to guess
  37. Platform::SystemInfo.processor.numPhysicalProcessors = 1; // :/ lCpuCount;
  38. Platform::SystemInfo.processor.isMultiCore = lCpuCount > 1;
  39. //modern CPU should have isHyperThreaded
  40. Platform::SystemInfo.processor.isHyperThreaded = true;
  41. //hackfest
  42. Platform::SystemInfo.processor.mhz = 2666;
  43. #if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_X32)
  44. // Set sane default information
  45. Platform::SystemInfo.processor.name = StringTable->insert("Unknown Processor");
  46. Platform::SystemInfo.processor.properties |= CPU_PROP_C | CPU_PROP_FPU | CPU_PROP_LE ;
  47. Platform::SystemInfo.processor.type = CPU_X86Compatible;
  48. #elif defined(TORQUE_CPU_ARM32) || defined(TORQUE_CPU_ARM64)
  49. Platform::SystemInfo.processor.type = CPU_ArmCompatible;
  50. Platform::SystemInfo.processor.name = StringTable->insert("Unknown ARM Processor");
  51. Platform::SystemInfo.processor.properties = CPU_PROP_C;
  52. #else
  53. #warning Unsupported CPU
  54. #endif
  55. // Set 64bit flag
  56. #if defined(TORQUE_CPU_X64) || defined(TORQUE_CPU_ARM64)
  57. Platform::SystemInfo.processor.properties |= CPU_PROP_64bit;
  58. #endif
  59. Con::printf("Processor Init:");
  60. Con::printf(" CPU count: %d", lCpuCount);
  61. Con::printf(" CacheLine size: %d", SDL_GetCPUCacheLineSize());
  62. if (lCpuCount > 1) {
  63. Platform::SystemInfo.processor.properties |= CPU_PROP_MP;
  64. Con::printf(" MultiCore CPU detected" );
  65. }
  66. Con::printf(" RAM: %d MB", SDL_GetSystemRAM());
  67. if (SDL_HasMMX()) {
  68. Platform::SystemInfo.processor.properties |= CPU_PROP_MMX;
  69. Con::printf(" MMX detected" );
  70. }
  71. if (SDL_HasSSE()) {
  72. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE;
  73. Con::printf(" SSE detected" );
  74. }
  75. if (SDL_HasSSE2()) {
  76. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE2;
  77. Con::printf(" SSE2 detected" );
  78. }
  79. if (SDL_HasSSE3()) {
  80. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE3;
  81. Con::printf(" SSE3 detected" );
  82. }
  83. if (SDL_HasSSE41()) {
  84. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_1;
  85. Con::printf(" SSE4.1 detected" );
  86. }
  87. if (SDL_HasSSE42()) {
  88. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_2;
  89. Con::printf(" SSE4.2 detected" );
  90. }
  91. if (SDL_HasSSE42()) {
  92. Platform::SystemInfo.processor.properties |= CPU_PROP_SSE4_2;
  93. Con::printf(" SSE4.2 detected" );
  94. }
  95. if (SDL_HasAVX() || SDL_HasAVX2()) {
  96. Platform::SystemInfo.processor.properties |= CPU_PROP_AVX;
  97. Con::printf(" AVX detected" );
  98. }
  99. if (SDL_HasNEON()) {
  100. Platform::SystemInfo.processor.properties |= CPU_PROP_NEON;
  101. Con::printf(" NEON detected" );
  102. }
  103. Con::printf(" ");
  104. SetProcessorInfo(Platform::SystemInfo.processor, "Unknown", "Unknown");
  105. }
  106. namespace CPUInfo
  107. {
  108. EConfig CPUCount(U32 &logical, U32 &physical)
  109. {
  110. // We don't set logical or physical here because it's already been determined by this point
  111. if (Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
  112. {
  113. return CONFIG_SingleCoreHTEnabled;
  114. }
  115. else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors > 1)
  116. {
  117. return CONFIG_MultiCoreAndHTNotCapable;
  118. }
  119. else if (!Platform::SystemInfo.processor.isHyperThreaded && Platform::SystemInfo.processor.numPhysicalProcessors == 1)
  120. {
  121. return CONFIG_SingleCoreAndHTNotCapable;
  122. }
  123. return CONFIG_MultiCoreAndHTEnabled;
  124. }
  125. }; // namespace CPUInfo
  126. #endif