macMath.mm

Engine/source/platformMac/macMath.mm

More...

Public Variables

Public Functions

DefineEngineStringlyVariadicFunction(mathInit , void , 1 , 10 , "( ... )" "@brief Install the math library with specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">extensions.\n\n</a>" "Possible parameters <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">are:\n\n</a>" " - 'DETECT' Autodetect math lib <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">settings.\n\n</a>" " - 'C' Enable the C math routines. C routines are always <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">enabled.\n\n</a>" " - 'SSE' Enable SSE math <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">routines.\n\n</a>" "@ingroup <a href="/coding/class/structmath/">Math</a>" )

Detailed Description

Public Variables

MRandomLCG sgPlatRandom 

Public Functions

DefineEngineStringlyVariadicFunction(mathInit , void , 1 , 10 , "( ... )" "@brief Install the math library with specified <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">extensions.\n\n</a>" "Possible parameters <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">are:\n\n</a>" " - 'DETECT' Autodetect math lib <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">settings.\n\n</a>" " - 'C' Enable the C math routines. C routines are always <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">enabled.\n\n</a>" " - 'SSE' Enable SSE math <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">routines.\n\n</a>" "@ingroup <a href="/coding/class/structmath/">Math</a>" )

mInstall_Library_SSE()

mInstallLibrary_C()

mInstallLibrary_Vec()

  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#import "platform/platform.h"
 25#import "console/console.h"
 26#import "math/mMath.h"
 27#import "core/strings/stringFunctions.h"
 28#include "console/engineAPI.h"
 29
 30extern void mInstallLibrary_C();
 31extern void mInstallLibrary_Vec();
 32extern void mInstall_Library_SSE();
 33
 34static MRandomLCG sgPlatRandom;
 35
 36U32 Platform::getMathControlState()
 37{
 38   U16 cw;
 39   asm("fstcw %0" : "=m" (cw) :);
 40   return cw;
 41}
 42
 43void Platform::setMathControlState(U32 state)
 44{
 45   U16 cw = state;
 46   asm("fldcw %0" : : "m" (cw));
 47}
 48
 49void Platform::setMathControlStateKnown()
 50{
 51   U16 cw = 0x27F;
 52   asm("fldcw %0" : : "m" (cw));
 53}
 54
 55//--------------------------------------
 56DefineEngineStringlyVariadicFunction( mathInit, void, 1, 10, "( ... )"
 57                                     "@brief Install the math library with specified extensions.\n\n"
 58                                     "Possible parameters are:\n\n"
 59                                     "    - 'DETECT' Autodetect math lib settings.\n\n"
 60                                     "    - 'C' Enable the C math routines. C routines are always enabled.\n\n"
 61                                     "    - 'SSE' Enable SSE math routines.\n\n"
 62                                     "@ingroup Math")
 63{
 64   U32 properties = CPU_PROP_C;  // C entensions are always used
 65   
 66   if (argc == 1)
 67   {
 68         Math::init(0);
 69         return;
 70   }
 71   for (argc--, argv++; argc; argc--, argv++)
 72   {
 73      if (dStricmp(*argv, "DETECT") == 0) { 
 74         Math::init(0);
 75         return;
 76      }
 77      if (dStricmp(*argv, "C") == 0) { 
 78         properties |= CPU_PROP_C; 
 79         continue; 
 80      }
 81      if( dStricmp( *argv, "SSE" ) == 0 )
 82      {
 83         properties |= CPU_PROP_SSE;
 84         continue;
 85      }
 86      //Con::printf("Error: MathInit(): ignoring unknown math extension '%s'", *argv);
 87   }
 88   Math::init(properties);
 89}
 90
 91
 92
 93//------------------------------------------------------------------------------
 94void Math::init(U32 properties)
 95{
 96   if (!properties)
 97      // detect what's available
 98      properties = Platform::SystemInfo.processor.properties;  
 99   else
100      // Make sure we're not asking for anything that's not supported
101      properties &= Platform::SystemInfo.processor.properties;  
102
103   Con::printf("Math Init:");
104   Con::printf("   Installing Standard C extensions");
105   mInstallLibrary_C();   
106
107   #ifdef TORQUE_CPU_X86
108   if( properties & CPU_PROP_SSE )
109   {
110      Con::printf( "   Installing SSE extensions" );
111      mInstall_Library_SSE();
112   }
113   #endif
114   
115   Con::printf(" ");
116}   
117
118//------------------------------------------------------------------------------
119F32 Platform::getRandom()
120{
121   return sgPlatRandom.randF();
122}
123
124