x86UNIXMath.cpp
Engine/source/platformX86UNIX/x86UNIXMath.cpp
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_AMD_Math()
mInstall_Library_SSE()
mInstallLibrary_ASM()
mInstallLibrary_C()
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 "platform/platform.h" 25#include "console/console.h" 26#include "math/mMath.h" 27#include "core/strings/stringFunctions.h" 28#include "console/engineAPI.h" 29 30extern void mInstallLibrary_C(); 31extern void mInstallLibrary_ASM(); 32 33 34extern void mInstall_AMD_Math(); 35extern void mInstall_Library_SSE(); 36 37 38//-------------------------------------- 39DefineEngineStringlyVariadicFunction( mathInit, void, 1, 10, "( ... )" 40 "@brief Install the math library with specified extensions.\n\n" 41 "Possible parameters are:\n\n" 42 " - 'DETECT' Autodetect math lib settings.\n\n" 43 " - 'C' Enable the C math routines. C routines are always enabled.\n\n" 44 " - 'SSE' Enable SSE math routines.\n\n" 45 "@ingroup Math") 46{ 47 U32 properties = CPU_PROP_C; // C entensions are always used 48 49 if (argc == 1) 50 { 51 Math::init(0); 52 return; 53 } 54 for (argc--, argv++; argc; argc--, argv++) 55 { 56 if (dStricmp(*argv, "DETECT") == 0) { 57 Math::init(0); 58 return; 59 } 60 if (dStricmp(*argv, "C") == 0) { 61 properties |= CPU_PROP_C; 62 continue; 63 } 64 if (dStricmp(*argv, "FPU") == 0) { 65 properties |= CPU_PROP_FPU; 66 continue; 67 } 68 if (dStricmp(*argv, "MMX") == 0) { 69 properties |= CPU_PROP_MMX; 70 continue; 71 } 72 if (dStricmp(*argv, "3DNOW") == 0) { 73 properties |= CPU_PROP_3DNOW; 74 continue; 75 } 76 if (dStricmp(*argv, "SSE") == 0) { 77 properties |= CPU_PROP_SSE; 78 continue; 79 } 80 Con::printf("Error: MathInit(): ignoring unknown math extension '%s'", (const char*)argv[0]); 81 } 82 Math::init(properties); 83} 84 85 86 87//------------------------------------------------------------------------------ 88void Math::init(U32 properties) 89{ 90 if (!properties) 91 // detect what's available 92 properties = Platform::SystemInfo.processor.properties; 93 else 94 // Make sure we're not asking for anything that's not supported 95 properties &= Platform::SystemInfo.processor.properties; 96 97 Con::printf("Math Init:"); 98 Con::printf(" Installing Standard C extensions"); 99 mInstallLibrary_C(); 100 101 Con::printf(" Installing Assembly extensions"); 102 mInstallLibrary_ASM(); 103 104 if (properties & CPU_PROP_FPU) 105 { 106 Con::printf(" Installing FPU extensions"); 107 } 108 109 if (properties & CPU_PROP_MMX) 110 { 111 Con::printf(" Installing MMX extensions"); 112 if (properties & CPU_PROP_3DNOW) 113 { 114 Con::printf(" Installing 3DNow extensions"); 115 mInstall_AMD_Math(); 116 } 117 } 118 119#if !defined(__MWERKS__) || (__MWERKS__ >= 0x2400) 120 if (properties & CPU_PROP_SSE) 121 { 122 Con::printf(" Installing SSE extensions"); 123 mInstall_Library_SSE(); 124 } 125#endif //mwerks>2.4 126 127 Con::printf(" "); 128} 129 130 131//------------------------------------------------------------------------------ 132 133static MRandomLCG sgPlatRandom; 134 135F32 Platform::getRandom() 136{ 137 return sgPlatRandom.randF(); 138} 139 140 141#if defined(TORQUE_CPU_X86) || defined(__x86_64__) 142 143U32 Platform::getMathControlState() 144{ 145 U16 cw; 146 asm("fstcw %0" : "=m" (cw) :); 147 return cw; 148} 149 150void Platform::setMathControlState(U32 state) 151{ 152 U16 cw = state; 153 asm("fldcw %0" : : "m" (cw)); 154} 155 156void Platform::setMathControlStateKnown() 157{ 158 U16 cw = 0x27F; 159 asm("fldcw %0" : : "m" (cw)); 160} 161 162#else 163 164U32 Platform::getMathControlState() 165{ 166 return 0; 167} 168 169void Platform::setMathControlState(U32 state) 170{ 171} 172 173void Platform::setMathControlStateKnown() 174{ 175} 176 177#endif 178 179