winMath.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "core/strings/stringFunctions.h"
  23. #include "console/console.h"
  24. #include "console/engineAPI.h"
  25. #include "math/mMath.h"
  26. extern void mInstallLibrary_C();
  27. extern void mInstallLibrary_ASM();
  28. //--------------------------------------
  29. DefineEngineStringlyVariadicFunction( mathInit, void, 1, 10, "( ... )"
  30. "@brief Install the math library with specified extensions.\n\n"
  31. "Possible parameters are:\n\n"
  32. " - 'DETECT' Autodetect math lib settings.\n\n"
  33. " - 'C' Enable the C math routines. C routines are always enabled.\n\n"
  34. " - 'FPU' Enable floating point unit routines.\n\n"
  35. " - 'MMX' Enable MMX math routines.\n\n"
  36. " - 'SSE' Enable SSE math routines.\n\n"
  37. "@ingroup Math")
  38. {
  39. U32 properties = CPU_PROP_C; // C entensions are always used
  40. if (argc == 1)
  41. {
  42. Math::init(0);
  43. return;
  44. }
  45. for (argc--, argv++; argc; argc--, argv++)
  46. {
  47. const char* str = (*argv).getString();
  48. if (dStricmp(str, "DETECT") == 0) {
  49. Math::init(0);
  50. return;
  51. }
  52. if (dStricmp(str, "C") == 0) {
  53. properties |= CPU_PROP_C;
  54. continue;
  55. }
  56. if (dStricmp(str, "FPU") == 0) {
  57. properties |= CPU_PROP_FPU;
  58. continue;
  59. }
  60. if (dStricmp(str, "MMX") == 0) {
  61. properties |= CPU_PROP_MMX;
  62. continue;
  63. }
  64. if (dStricmp(str, "SSE") == 0) {
  65. properties |= CPU_PROP_SSE;
  66. continue;
  67. }
  68. if (dStricmp(str, "SSE2") == 0) {
  69. properties |= CPU_PROP_SSE2;
  70. continue;
  71. }
  72. Con::printf("Error: MathInit(): ignoring unknown math extension '%s'", str);
  73. }
  74. Math::init(properties);
  75. }
  76. //------------------------------------------------------------------------------
  77. void Math::init(U32 properties)
  78. {
  79. if (!properties)
  80. // detect what's available
  81. properties = Platform::SystemInfo.processor.properties;
  82. else
  83. // Make sure we're not asking for anything that's not supported
  84. properties &= Platform::SystemInfo.processor.properties;
  85. Con::printf("Math Init:");
  86. Con::printf(" Installing Standard C extensions");
  87. mInstallLibrary_C();
  88. Con::printf(" Installing Assembly extensions");
  89. mInstallLibrary_ASM();
  90. if (properties & CPU_PROP_FPU)
  91. {
  92. Con::printf(" Installing FPU extensions");
  93. }
  94. if (properties & CPU_PROP_MMX)
  95. {
  96. Con::printf(" Installing MMX extensions");
  97. }
  98. if (properties & CPU_PROP_SSE)
  99. {
  100. Con::printf(" Installing SSE extensions");
  101. }
  102. Con::printf(" ");
  103. }