PxUnixIntrinsics.h
Go to the documentation of this file.
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"
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 
51 namespace physx
52 {
53 namespace intrinsics
54 {
57 {
58  return ::fabsf(a);
59 }
60 
62 PX_CUDA_CALLABLE PX_FORCE_INLINE float fsel(float a, float b, float c)
63 {
64  return (a >= 0.0f) ? b : c;
65 }
66 
69 {
70  return (a >= 0.0f) ? 1.0f : -1.0f;
71 }
72 
75 {
76  return 1.0f / a;
77 }
78 
81 {
82  return 1.0f / a;
83 }
84 
87 {
88  return ::sqrtf(a);
89 }
90 
93 {
94  return 1.0f / ::sqrtf(a);
95 }
96 
98 {
99  return 1.0f / ::sqrtf(a);
100 }
101 
104 {
105  return ::sinf(a);
106 }
107 
110 {
111  return ::cosf(a);
112 }
113 
116 {
117  return a < b ? a : b;
118 }
119 
122 {
123  return a > b ? a : b;
124 }
125 
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 
137 {
138  return !!isfinite(a);
139 }
140 
144 PX_FORCE_INLINE void* memZero(void* dest, uint32_t count)
145 {
146  return memset(dest, 0, count);
147 }
148 
152 PX_FORCE_INLINE void* memSet(void* dest, int32_t c, uint32_t count)
153 {
154  return memset(dest, c, count);
155 }
156 
160 PX_FORCE_INLINE void* memCopy(void* dest, const void* src, uint32_t count)
161 {
162  return memcpy(dest, src, count);
163 }
164 
168 PX_FORCE_INLINE void* memMove(void* dest, const void* src, uint32_t count)
169 {
170  return memmove(dest, src, count);
171 }
172 
176 PX_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
Definition: GuContactBuffer.h:37
PX_CUDA_CALLABLE PX_FORCE_INLINE float recip(float a)
platform-specific reciprocal
Definition: PxUnixIntrinsics.h:74
PX_CUDA_CALLABLE PX_FORCE_INLINE float sqrt(float a)
platform-specific square root
Definition: PxUnixIntrinsics.h:86
PX_CUDA_CALLABLE PX_FORCE_INLINE float recipSqrt(float a)
platform-specific reciprocal square root
Definition: PxUnixIntrinsics.h:92
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:351
uint32_t PxU32
Definition: PxSimpleTypes.h:71
PX_CUDA_CALLABLE PX_FORCE_INLINE float selectMin(float a, float b)
platform-specific minimum
Definition: PxUnixIntrinsics.h:115
PX_CUDA_CALLABLE PX_FORCE_INLINE float selectMax(float a, float b)
platform-specific maximum
Definition: PxUnixIntrinsics.h:121
#define PX_SHARED_ASSERT(exp)
Definition: PxSharedAssert.h:39
PX_FORCE_INLINE void * memCopy(void *dest, const void *src, uint32_t count)
Definition: PxUnixIntrinsics.h:160
PX_CUDA_CALLABLE PX_FORCE_INLINE float sign(float a)
platform-specific sign
Definition: PxUnixIntrinsics.h:68
PX_CUDA_CALLABLE PX_FORCE_INLINE bool isFinite(float a)
platform-specific finiteness check (not INF or NAN)
Definition: PxUnixIntrinsics.h:127
PX_CUDA_CALLABLE PX_FORCE_INLINE float cos(float a)
platform-specific cosine
Definition: PxUnixIntrinsics.h:109
PX_CUDA_CALLABLE PX_FORCE_INLINE float recipSqrtFast(float a)
Definition: PxUnixIntrinsics.h:97
PX_CUDA_CALLABLE PX_FORCE_INLINE float fsel(float a, float b, float c)
platform-specific select float
Definition: PxUnixIntrinsics.h:62
PX_CUDA_CALLABLE PX_FORCE_INLINE float abs(float a)
platform-specific absolute value
Definition: PxUnixIntrinsics.h:56
PX_FORCE_INLINE void * memMove(void *dest, const void *src, uint32_t count)
Definition: PxUnixIntrinsics.h:168
PX_CUDA_CALLABLE PX_FORCE_INLINE float recipFast(float a)
platform-specific reciprocal estimate
Definition: PxUnixIntrinsics.h:80
PX_FORCE_INLINE void * memSet(void *dest, int32_t c, uint32_t count)
Definition: PxUnixIntrinsics.h:152
PX_FORCE_INLINE void memZero128(void *dest, uint32_t offset=0)
Definition: PxUnixIntrinsics.h:176
PX_FORCE_INLINE void * memZero(void *dest, uint32_t count)
Definition: PxUnixIntrinsics.h:144
PX_CUDA_CALLABLE PX_FORCE_INLINE float sin(float a)
platform-specific sine
Definition: PxUnixIntrinsics.h:103
#define PX_CUDA_CALLABLE
Definition: PxPreprocessor.h:460