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