winMath_ASM.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "math/mMath.h"
  23. #if defined(TORQUE_SUPPORTS_VC_INLINE_X86_ASM)
  24. static S32 m_mulDivS32_ASM(S32 a, S32 b, S32 c)
  25. { // a * b / c
  26. S32 r;
  27. _asm
  28. {
  29. mov eax, a
  30. imul b
  31. idiv c
  32. mov r, eax
  33. }
  34. return r;
  35. }
  36. static U32 m_mulDivU32_ASM(S32 a, S32 b, U32 c)
  37. { // a * b / c
  38. S32 r;
  39. _asm
  40. {
  41. mov eax, a
  42. mov edx, 0
  43. mul b
  44. div c
  45. mov r, eax
  46. }
  47. return r;
  48. }
  49. static void m_sincos_ASM( F32 angle, F32 *s, F32 *c )
  50. {
  51. _asm
  52. {
  53. fld angle
  54. fsincos
  55. mov eax, c
  56. fstp dword ptr [eax]
  57. mov eax, s
  58. fstp dword ptr [eax]
  59. }
  60. }
  61. U32 Platform::getMathControlState()
  62. {
  63. U16 cw;
  64. _asm
  65. {
  66. fstcw cw
  67. }
  68. return cw;
  69. }
  70. void Platform::setMathControlState(U32 state)
  71. {
  72. U16 cw = state;
  73. _asm
  74. {
  75. fldcw cw
  76. }
  77. }
  78. void Platform::setMathControlStateKnown()
  79. {
  80. U16 cw = 0x27F;
  81. _asm
  82. {
  83. fldcw cw
  84. }
  85. }
  86. #endif
  87. //------------------------------------------------------------------------------
  88. void mInstallLibrary_ASM()
  89. {
  90. #if defined(TORQUE_SUPPORTS_VC_INLINE_X86_ASM)
  91. m_mulDivS32 = m_mulDivS32_ASM;
  92. m_mulDivU32 = m_mulDivU32_ASM;
  93. m_sincos = m_sincos_ASM;
  94. #endif
  95. }