AkFPUtilities.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*******************************************************************************
  2. The content of this file includes portions of the AUDIOKINETIC Wwise Technology
  3. released in source code form as part of the SDK installer package.
  4. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Apache License Usage
  10. Alternatively, this file may be used under the Apache License, Version 2.0 (the
  11. "Apache License"); you may not use this file except in compliance with the
  12. Apache License. You may obtain a copy of the Apache License at
  13. http://www.apache.org/licenses/LICENSE-2.0.
  14. Unless required by applicable law or agreed to in writing, software distributed
  15. under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  16. OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
  17. the specific language governing permissions and limitations under the License.
  18. Copyright (c) 2023 Audiokinetic Inc.
  19. *******************************************************************************/
  20. /// \file
  21. /// Floating point performance utilities.
  22. #ifndef _AK_FP_UTILS_H_
  23. #define _AK_FP_UTILS_H_
  24. #include <AK/SoundEngine/Common/AkTypes.h>
  25. #define AK_FSEL( __a__, __b__, __c__) (((__a__) >= 0) ? (__b__) : (__c__))
  26. /// Branchless (where available) version returning minimum value between two AkReal32 values
  27. static AkForceInline AkReal32 AK_FPMin( AkReal32 fA, AkReal32 fB )
  28. {
  29. return (fA < fB ? fA : fB);
  30. }
  31. /// Branchless (where available) version returning maximum value between two AkReal32 values
  32. static AkForceInline AkReal32 AK_FPMax( AkReal32 fA, AkReal32 fB )
  33. {
  34. return (fA > fB ? fA : fB);
  35. }
  36. /// Branchless comparison (where available) setting 3rd argument to 4th argument if 1st argument is greater than 2nd argument.
  37. static AkForceInline void AK_FPSetValGT( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
  38. {
  39. if ( in_fComparandA > in_fComparandB )
  40. io_fVariableToSet = in_fValueIfTrue;
  41. }
  42. /// Branchless comparison (where available) setting 3rd argument to 4th argument if 1st argument is greater than equal 2nd argument.
  43. static AkForceInline void AK_FPSetValGTE( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
  44. {
  45. if ( in_fComparandA >= in_fComparandB )
  46. io_fVariableToSet = in_fValueIfTrue;
  47. }
  48. /// Branchless comparison (where available) setting 3rd argument to 4th argument if 1st argument is less than 2nd argument.
  49. static AkForceInline void AK_FPSetValLT( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
  50. {
  51. if ( in_fComparandA < in_fComparandB )
  52. io_fVariableToSet = in_fValueIfTrue;
  53. }
  54. /// Branchless comparison (where available) setting 3rd argument to 4th argument if 1st argument is less than equal 2nd argument.
  55. static AkForceInline void AK_FPSetValLTE( AkReal32 in_fComparandA, AkReal32 in_fComparandB, AkReal32 & io_fVariableToSet, AkReal32 in_fValueIfTrue )
  56. {
  57. if ( in_fComparandA <= in_fComparandB )
  58. io_fVariableToSet = in_fValueIfTrue;
  59. }
  60. #endif //_AK_FP_UTILS_H_