x86UNIXMath_ASM.cpp
Engine/source/platformX86UNIX/x86UNIXMath_ASM.cpp
Public Functions
m_mulDivS32_ASM(S32 a, S32 b, S32 c)
m_mulDivU32_ASM(S32 a, S32 b, U32 c)
Detailed Description
Public Functions
m_mulDivS32_ASM(S32 a, S32 b, S32 c)
m_mulDivU32_ASM(S32 a, S32 b, U32 c)
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 26static S32 m_mulDivS32_ASM(S32 a, S32 b, S32 c) 27{ // a * b / c 28 S32 r; 29 30 __asm__ __volatile__( 31 "imul %2\n" 32 "idiv %3\n" 33 : "=a" (r) : "a" (a) , "b" (b) , "c" (c) 34 ); 35 return r; 36} 37 38 39static U32 m_mulDivU32_ASM(S32 a, S32 b, U32 c) 40{ // a * b / c 41 S32 r; 42 __asm__ __volatile__( 43 "mov $0, %%edx\n" 44 "mul %2\n" 45 "div %3\n" 46 : "=a" (r) : "a" (a) , "b" (b) , "c" (c) 47 ); 48 return r; 49} 50 51//------------------------------------------------------------------------------ 52void mInstallLibrary_ASM() 53{ 54 m_mulDivS32 = m_mulDivS32_ASM; 55 m_mulDivU32 = m_mulDivU32_ASM; 56} 57