RavEngine
Loading...
Searching...
No Matches
PxUnixMathIntrinsics.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PXFOUNDATION_PXUNIXINTRINSICS_H
30#define PXFOUNDATION_PXUNIXINTRINSICS_H
31
32#include "foundation/Px.h"
33#include "foundation/PxAssert.h"
34
35#if !(PX_LINUX || PX_APPLE_FAMILY)
36#error "This file should only be included by Unix builds!!"
37#endif
38
39#if PX_LINUX && !defined(__CUDACC__) && !PX_EMSCRIPTEN
40 // Linux and CUDA compilation does not work with std::isfnite, as it is not marked as CUDA callable
41 #include <cmath>
42 #ifndef isfinite
43 using std::isfinite;
44 #endif
45#endif
46
47#include <math.h>
48#include <float.h>
49
50#if !PX_DOXYGEN
51namespace physx
52{
53#endif
54
55namespace intrinsics
56{
58PX_CUDA_CALLABLE PX_FORCE_INLINE float abs(float a)
59{
60 return ::fabsf(a);
61}
62
64PX_CUDA_CALLABLE PX_FORCE_INLINE float fsel(float a, float b, float c)
65{
66 return (a >= 0.0f) ? b : c;
67}
68
70PX_CUDA_CALLABLE PX_FORCE_INLINE float sign(float a)
71{
72 return (a >= 0.0f) ? 1.0f : -1.0f;
73}
74
76PX_CUDA_CALLABLE PX_FORCE_INLINE float recip(float a)
77{
78 return 1.0f / a;
79}
80
82PX_CUDA_CALLABLE PX_FORCE_INLINE float recipFast(float a)
83{
84 return 1.0f / a;
85}
86
88PX_CUDA_CALLABLE PX_FORCE_INLINE float sqrt(float a)
89{
90 return ::sqrtf(a);
91}
92
94PX_CUDA_CALLABLE PX_FORCE_INLINE float recipSqrt(float a)
95{
96 return 1.0f / ::sqrtf(a);
97}
98
99PX_CUDA_CALLABLE PX_FORCE_INLINE float recipSqrtFast(float a)
100{
101 return 1.0f / ::sqrtf(a);
102}
103
105PX_CUDA_CALLABLE PX_FORCE_INLINE float sin(float a)
106{
107 return ::sinf(a);
108}
109
111PX_CUDA_CALLABLE PX_FORCE_INLINE float cos(float a)
112{
113 return ::cosf(a);
114}
115
117PX_CUDA_CALLABLE PX_FORCE_INLINE float selectMin(float a, float b)
118{
119 return a < b ? a : b;
120}
121
123PX_CUDA_CALLABLE PX_FORCE_INLINE float selectMax(float a, float b)
124{
125 return a > b ? a : b;
126}
127
129PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite(float a)
130{
131 //std::isfinite not recommended as of Feb 2017, since it doesn't work with g++/clang's floating point optimization.
132 union localU { PxU32 i; float f; } floatUnion;
133 floatUnion.f = a;
134 return !((floatUnion.i & 0x7fffffff) >= 0x7f800000);
135}
136
138PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite(double a)
139{
140 return !!isfinite(a);
141}
142
146PX_FORCE_INLINE void* memZero(void* dest, uint32_t count)
147{
148 return memset(dest, 0, count);
149}
150
154PX_FORCE_INLINE void* memSet(void* dest, int32_t c, uint32_t count)
155{
156 return memset(dest, c, count);
157}
158
162PX_FORCE_INLINE void* memCopy(void* dest, const void* src, uint32_t count)
163{
164 return memcpy(dest, src, count);
165}
166
170PX_FORCE_INLINE void* memMove(void* dest, const void* src, uint32_t count)
171{
172 return memmove(dest, src, count);
173}
174
175} // namespace intrinsics
176#if !PX_DOXYGEN
177} // namespace physx
178#endif
179
180#endif // #ifndef PXFOUNDATION_PXUNIXINTRINSICS_H
GLM_FUNC_QUALIFIER vec< L, T, Q > sqrt(vec< L, T, Q > const &x)
Definition func_exponential.inl:128
GLM_FUNC_QUALIFIER vec< L, T, Q > sin(vec< L, T, Q > const &v)
Definition func_trigonometric.inl:41
GLM_FUNC_QUALIFIER vec< L, T, Q > cos(vec< L, T, Q > const &v)
Definition func_trigonometric.inl:50
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39