x86UNIXMath.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #include "platform/platform.h"
  23. #include "console/console.h"
  24. #include "math/mMath.h"
  25. #include "core/strings/stringFunctions.h"
  26. extern void mInstallLibrary_C();
  27. extern void mInstallLibrary_ASM();
  28. extern void mInstall_AMD_Math();
  29. extern void mInstall_Library_SSE();
  30. //--------------------------------------
  31. ConsoleFunction( MathInit, void, 1, 10, "(detect|C|FPU|MMX|3DNOW|SSE|...)")
  32. {
  33. U32 properties = CPU_PROP_C; // C entensions are always used
  34. if (argc == 1)
  35. {
  36. Math::init(0);
  37. return;
  38. }
  39. for (argc--, argv++; argc; argc--, argv++)
  40. {
  41. if (dStricmp(*argv, "DETECT") == 0) {
  42. Math::init(0);
  43. return;
  44. }
  45. if (dStricmp(*argv, "C") == 0) {
  46. properties |= CPU_PROP_C;
  47. continue;
  48. }
  49. if (dStricmp(*argv, "FPU") == 0) {
  50. properties |= CPU_PROP_FPU;
  51. continue;
  52. }
  53. if (dStricmp(*argv, "MMX") == 0) {
  54. properties |= CPU_PROP_MMX;
  55. continue;
  56. }
  57. if (dStricmp(*argv, "3DNOW") == 0) {
  58. properties |= CPU_PROP_3DNOW;
  59. continue;
  60. }
  61. if (dStricmp(*argv, "SSE") == 0) {
  62. properties |= CPU_PROP_SSE;
  63. continue;
  64. }
  65. Con::printf("Error: MathInit(): ignoring unknown math extension '%s'", (const char*)argv[0]);
  66. }
  67. Math::init(properties);
  68. }
  69. //------------------------------------------------------------------------------
  70. void Math::init(U32 properties)
  71. {
  72. if (!properties)
  73. // detect what's available
  74. properties = Platform::SystemInfo.processor.properties;
  75. else
  76. // Make sure we're not asking for anything that's not supported
  77. properties &= Platform::SystemInfo.processor.properties;
  78. Con::printf("Math Init:");
  79. Con::printf(" Installing Standard C extensions");
  80. mInstallLibrary_C();
  81. Con::printf(" Installing Assembly extensions");
  82. mInstallLibrary_ASM();
  83. if (properties & CPU_PROP_FPU)
  84. {
  85. Con::printf(" Installing FPU extensions");
  86. }
  87. if (properties & CPU_PROP_MMX)
  88. {
  89. Con::printf(" Installing MMX extensions");
  90. if (properties & CPU_PROP_3DNOW)
  91. {
  92. Con::printf(" Installing 3DNow extensions");
  93. mInstall_AMD_Math();
  94. }
  95. }
  96. #if !defined(__MWERKS__) || (__MWERKS__ >= 0x2400)
  97. if (properties & CPU_PROP_SSE)
  98. {
  99. Con::printf(" Installing SSE extensions");
  100. mInstall_Library_SSE();
  101. }
  102. #endif //mwerks>2.4
  103. Con::printf(" ");
  104. }
  105. //------------------------------------------------------------------------------
  106. static MRandomLCG sgPlatRandom;
  107. F32 Platform::getRandom()
  108. {
  109. return sgPlatRandom.randF();
  110. }
  111. U32 Platform::getMathControlState()
  112. {
  113. return 0;
  114. }
  115. void Platform::setMathControlStateKnown()
  116. {
  117. }
  118. void Platform::setMathControlState(U32 state)
  119. {
  120. }