버전

menu_open

include/AK/SoundEngine/Common/AkFPUtilities.h

Go to the documentation of this file.
00001 /*******************************************************************************
00002 The content of this file includes portions of the AUDIOKINETIC Wwise Technology
00003 released in source code form as part of the SDK installer package.
00004 
00005 Commercial License Usage
00006 
00007 Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
00008 may use this file in accordance with the end user license agreement provided 
00009 with the software or, alternatively, in accordance with the terms contained in a
00010 written agreement between you and Audiokinetic Inc.
00011 
00012 Apache License Usage
00013 
00014 Alternatively, this file may be used under the Apache License, Version 2.0 (the 
00015 "Apache License"); you may not use this file except in compliance with the 
00016 Apache License. You may obtain a copy of the Apache License at 
00017 http://www.apache.org/licenses/LICENSE-2.0.
00018 
00019 Unless required by applicable law or agreed to in writing, software distributed
00020 under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
00021 OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
00022 the specific language governing permissions and limitations under the License.
00023 
00024   Version: <VERSION>  Build: <BUILDNUMBER>
00025   Copyright (c) <COPYRIGHTYEAR> Audiokinetic Inc.
00026 *******************************************************************************/
00027 
00030 
00031 #ifndef _AK_FP_UTILS_H_
00032 #define _AK_FP_UTILS_H_
00033 
00034 #include <AK/SoundEngine/Common/AkTypes.h>
00035 
00036 // Note: In many case you can use AK_FPSetValXX instead of FSEL. This saves a subtraction on platforms that do not have FSEL instructions.
00037 #if defined(__PPU__)
00038 #include <ppu_intrinsics.h>
00039 #define AK_FSEL( __a__, __b__, __c__ ) ( __fsels((__a__),(__b__),(__c__) ) )
00040 #elif defined(AK_XBOX360)
00041 #include "ppcintrinsics.h"
00042 #define AK_FSEL( __a__, __b__, __c__ ) ( (AkReal32)__fsel((__a__),(__b__),(__c__) ) )
00043 #else
00044 #define AK_FSEL( __a__, __b__, __c__) (((__a__) >= 0) ? (__b__) : (__c__))
00045 #endif
00046 
00047 #if defined(AK_XBOX360) || defined (__PPU__) || defined(AK_WIIU_SOFTWARE)
00048 
00050 static AkForceInline AkReal32 AK_FPMin( AkReal32 fA, AkReal32 fB )
00051 {   
00052     return AK_FSEL(fA-fB,fB,fA);
00053 } 
00054 
00056 static AkForceInline AkReal32 AK_FPMax( AkReal32 fA, AkReal32 fB )
00057 {   
00058     return AK_FSEL(fA-fB,fA,fB);
00059 }
00060 
00062 static AkForceInline void AK_FPSetValGT( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00063 {   
00064     io_fVariableToSet = AK_FSEL( (in_fComparandB-in_fComparandA), io_fVariableToSet, in_fValueIfTrue );
00065 }
00066 
00068 static AkForceInline void AK_FPSetValGTE( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00069 {   
00070     io_fVariableToSet = AK_FSEL( (in_fComparandA-in_fComparandB), in_fValueIfTrue, io_fVariableToSet );
00071 }
00072 
00074 static AkForceInline void AK_FPSetValLT( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00075 {   
00076     io_fVariableToSet = AK_FSEL( (in_fComparandA-in_fComparandB), io_fVariableToSet, in_fValueIfTrue );
00077 }
00078 
00080 static AkForceInline void AK_FPSetValLTE( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00081 {   
00082     io_fVariableToSet = AK_FSEL( (in_fComparandB-in_fComparandA), in_fValueIfTrue, io_fVariableToSet );
00083 }
00084 
00085 #elif defined(__SPU__)
00086 
00087 // Note: spu_insert() and spu_promote should not compile to actual instructions on the SPU where everything is vector types
00088 
00090 static AkForceInline AkReal32 AK_FPMin( AkReal32 fA, AkReal32 fB )
00091 {   
00092     vec_float4 vA = spu_promote( fA, 0 );
00093     vec_float4 vB = spu_promote( fB, 0 );
00094     vec_float4 vSel = spu_sel(vA, vB, spu_cmpgt(vA, vB));
00095     return spu_extract( vSel, 0 );
00096 } 
00097 
00099 static AkForceInline AkReal32 AK_FPMax( AkReal32 fA, AkReal32 fB )
00100 {   
00101     vec_float4 vA = spu_promote( fA, 0 );
00102     vec_float4 vB = spu_promote( fB, 0 );
00103     vec_float4 vSel = spu_sel(vB, vA, spu_cmpgt(vA, vB));
00104     return spu_extract( vSel, 0 );
00105 }
00106 
00108 static AkForceInline void AK_FPSetValGT( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00109 {   
00110     vec_float4 vA = spu_promote( in_fComparandA, 0 );
00111     vec_float4 vB = spu_promote( in_fComparandB, 0 );
00112     vec_float4 vVTS = spu_promote( io_fVariableToSet, 0 );
00113     vec_float4 vVIT = spu_promote( in_fValueIfTrue, 0 );
00114     vVTS = spu_sel(vVTS, vVIT, spu_cmpgt(vA, vB));
00115     io_fVariableToSet = spu_extract( vVTS, 0 );
00116 }
00117 
00120 static AkForceInline void AK_FPSetValGTE( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00121 {   
00122     vec_float4 vA = spu_promote( in_fComparandA, 0 );
00123     vec_float4 vB = spu_promote( in_fComparandB, 0 );
00124     vec_float4 vVTS = spu_promote( io_fVariableToSet, 0 );
00125     vec_float4 vVIT = spu_promote( in_fValueIfTrue, 0 );
00126     vec_uint4 vCmp = spu_cmpgt(vA, vB);
00127     vCmp = spu_or( vCmp, spu_cmpeq( vA, vB ) );
00128     vVTS = spu_sel(vVTS, vVIT, vCmp);
00129     io_fVariableToSet = spu_extract( vVTS, 0 );
00130 }
00131 
00134 static AkForceInline void AK_FPSetValLT( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00135 {   
00136     vec_float4 vA = spu_promote( in_fComparandA, 0 );
00137     vec_float4 vB = spu_promote( in_fComparandB, 0 );
00138     vec_float4 vVTS = spu_promote( io_fVariableToSet, 0 );
00139     vec_float4 vVIT = spu_promote( in_fValueIfTrue, 0 );
00140     vec_uint4 vCmp = spu_cmpgt(vA, vB);
00141     vCmp = spu_nor( vCmp, spu_cmpeq( vA, vB ) );
00142     vVTS = spu_sel(vVTS, vVIT, vCmp);
00143     io_fVariableToSet = spu_extract( vVTS, 0 );
00144 }
00145 
00147 static AkForceInline void AK_FPSetValLTE( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00148 {   
00149     vec_float4 vA = spu_promote( in_fComparandA, 0 );
00150     vec_float4 vB = spu_promote( in_fComparandB, 0 );
00151     vec_float4 vVTS = spu_promote( io_fVariableToSet, 0 );
00152     vec_float4 vVIT = spu_promote( in_fValueIfTrue, 0 );
00153     vec_uint4 vCtl = spu_cmpgt(vA, vB);
00154     vCtl = spu_nand(vCtl,vCtl);
00155     vVTS = spu_sel(vVTS, vVIT, vCtl);
00156     io_fVariableToSet = spu_extract( vVTS, 0 );
00157 }
00158 
00159 #else
00160 
00162 static AkForceInline AkReal32 AK_FPMin( AkReal32 fA, AkReal32 fB )
00163 {   
00164     return (fA < fB ? fA : fB);
00165 } 
00166 
00168 static AkForceInline AkReal32 AK_FPMax( AkReal32 fA, AkReal32 fB )
00169 {   
00170     return (fA > fB ? fA : fB);
00171 }
00172 
00174 static AkForceInline void AK_FPSetValGT( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00175 {   
00176     if ( in_fComparandA > in_fComparandB )
00177         io_fVariableToSet = in_fValueIfTrue;
00178 }
00179 
00181 static AkForceInline void AK_FPSetValGTE( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00182 {   
00183     if ( in_fComparandA >= in_fComparandB )
00184         io_fVariableToSet = in_fValueIfTrue;
00185 }
00186 
00188 static AkForceInline void AK_FPSetValLT( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00189 {   
00190     if ( in_fComparandA < in_fComparandB )
00191         io_fVariableToSet = in_fValueIfTrue;
00192 }
00193 
00195 static AkForceInline void AK_FPSetValLTE( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
00196 {   
00197     if ( in_fComparandA <= in_fComparandB )
00198         io_fVariableToSet = in_fValueIfTrue;
00199 }
00200 
00201 #endif
00202 
00203 #endif //_AK_FP_UTILS_H_
00204 

이 페이지가 도움이 되었나요?

지원이 필요하신가요?

질문이 있으신가요? 문제를 겪고 계신가요? 더 많은 정보가 필요하신가요? 저희에게 문의해주시면 도와드리겠습니다!

지원 페이지를 방문해 주세요

작업하는 프로젝트에 대해 알려주세요. 언제든지 도와드릴 준비가 되어 있습니다.

프로젝트를 등록하세요. 아무런 조건이나 의무 사항 없이 빠른 시작을 도와드리겠습니다.

Wwise를 시작해 보세요