winMath.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. extern void mInstallLibrary_C();
  26. extern void mInstallLibrary_ASM();
  27. extern void mInstall_AMD_Math();
  28. extern void mInstall_Library_SSE();
  29. //--------------------------------------
  30. ConsoleFunction( mathInit, void, 1, 10, "( extension ) Use the MathInit function to install a specified math extensions, or to detect and enable all extensions.\n"
  31. "Generally speaking, the best extension choice is to used detect. This will automatically detected and enable all extensions supported by the current processor. It will also print out a list of the extension that were enabled to the console\n"
  32. "@param extension Can be any of these:\ndetect – Detect all supported extensions and enable.\nC - Enable standard C extensions.\nFPU - Enable floating-point-unit extensions.\nMMX - Enable Intel MMX extensions.\n3DNOW - Enable AMD 3DNOW extensions.\nSSE - Enable Intel SSE extensions.\n"
  33. "@return No return value.")
  34. {
  35. U32 properties = CPU_PROP_C; // C entensions are always used
  36. if (argc == 1)
  37. {
  38. Math::init(0);
  39. return;
  40. }
  41. for (argc--, argv++; argc; argc--, argv++)
  42. {
  43. if (dStricmp(*argv, "DETECT") == 0) {
  44. Math::init(0);
  45. return;
  46. }
  47. if (dStricmp(*argv, "C") == 0) {
  48. properties |= CPU_PROP_C;
  49. continue;
  50. }
  51. if (dStricmp(*argv, "FPU") == 0) {
  52. properties |= CPU_PROP_FPU;
  53. continue;
  54. }
  55. if (dStricmp(*argv, "MMX") == 0) {
  56. properties |= CPU_PROP_MMX;
  57. continue;
  58. }
  59. if (dStricmp(*argv, "3DNOW") == 0) {
  60. properties |= CPU_PROP_3DNOW;
  61. continue;
  62. }
  63. if (dStricmp(*argv, "SSE") == 0) {
  64. properties |= CPU_PROP_SSE;
  65. continue;
  66. }
  67. Con::printf("Error: MathInit(): ignoring unknown math extension '%s'", *argv);
  68. }
  69. Math::init(properties);
  70. }
  71. //------------------------------------------------------------------------------
  72. void Math::init(U32 properties)
  73. {
  74. Con::printSeparator();
  75. Con::printf("Math Initialization:");
  76. if (!properties)
  77. // detect what's available
  78. properties = PlatformSystemInfo.processor.properties;
  79. else
  80. // Make sure we're not asking for anything that's not supported
  81. properties &= PlatformSystemInfo.processor.properties;
  82. Con::printf(" Installing Standard C extensions");
  83. mInstallLibrary_C();
  84. Con::printf(" Installing Assembly extensions");
  85. mInstallLibrary_ASM();
  86. if (properties & CPU_PROP_FPU)
  87. {
  88. Con::printf(" Installing FPU extensions");
  89. }
  90. if (properties & CPU_PROP_MMX)
  91. {
  92. Con::printf(" Installing MMX extensions");
  93. if (properties & CPU_PROP_3DNOW)
  94. {
  95. Con::printf(" Installing 3DNow extensions");
  96. mInstall_AMD_Math();
  97. }
  98. }
  99. if (properties & CPU_PROP_SSE)
  100. {
  101. Con::printf(" Installing SSE extensions");
  102. mInstall_Library_SSE();
  103. }
  104. Con::printf(" ");
  105. }