Torque3D Documentation / _generateds / winMath_ASM.cpp

winMath_ASM.cpp

Engine/source/platformWin32/winMath_ASM.cpp

More...

Public Functions

Detailed Description

Public Functions

mInstallLibrary_ASM()

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#include "math/mMath.h"
 25
 26#if defined(TORQUE_SUPPORTS_VC_INLINE_X86_ASM)
 27static S32 m_mulDivS32_ASM(S32 a, S32 b, S32 c)
 28{  // a * b / c
 29   S32 r;
 30   _asm
 31   {
 32      mov   eax, a
 33      imul  b
 34      idiv  c
 35      mov   r, eax
 36   }
 37   return r;
 38}
 39
 40
 41static U32 m_mulDivU32_ASM(S32 a, S32 b, U32 c)
 42{  // a * b / c
 43   S32 r;
 44   _asm
 45   {
 46      mov   eax, a
 47      mov   edx, 0
 48      mul   b
 49      div   c
 50      mov   r, eax
 51   }
 52   return r;
 53}
 54
 55static void m_sincos_ASM( F32 angle, F32 *s, F32 *c )
 56{
 57   _asm
 58   {
 59      fld     angle
 60      fsincos
 61      mov     eax, c
 62      fstp    dword ptr [eax]
 63      mov     eax, s
 64      fstp    dword ptr [eax]
 65   }
 66}
 67
 68U32 Platform::getMathControlState()
 69{
 70   U16 cw;
 71   _asm
 72   {
 73      fstcw cw
 74   }
 75   return cw;
 76}
 77
 78void Platform::setMathControlState(U32 state)
 79{
 80   U16 cw = state;
 81   _asm
 82   {
 83      fldcw cw
 84   }
 85}
 86
 87void Platform::setMathControlStateKnown()
 88{
 89   U16 cw = 0x27F;
 90   _asm
 91   {
 92      fldcw cw
 93   }
 94}
 95#else
 96// @source http://msdn.microsoft.com/en-us/library/c9676k6h.aspx
 97U32 Platform::getMathControlState( )
 98{
 99   U32 control_word = 0;
100   S32 error = _controlfp_s( &control_word, _DN_FLUSH, _MCW_DN );
101
102   return error ? 0 : control_word;
103}
104
105void Platform::setMathControlState( U32 state )
106{
107   U32 control_word = 0;
108   _controlfp_s( &control_word, state, _MCW_DN );
109}
110
111void Platform::setMathControlStateKnown( )
112{
113   U32 control_word = 0;
114   _controlfp_s (&control_word, _PC_64, _MCW_DN);
115}
116#endif
117
118//------------------------------------------------------------------------------
119void mInstallLibrary_ASM()
120{
121#if defined(TORQUE_SUPPORTS_VC_INLINE_X86_ASM)
122   m_mulDivS32              = m_mulDivS32_ASM;
123   m_mulDivU32              = m_mulDivU32_ASM;
124   
125   m_sincos = m_sincos_ASM;
126#endif
127}
128
129
130