sdlCPUInfo.cpp 5.4 KB

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