1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14#ifndef PX_FOUNDATION_PX_UNIX_INTRINSICS_H
15#define PX_FOUNDATION_PX_UNIX_INTRINSICS_H
16
17#include "foundation/Px.h"
18#include "foundation/PxAssert.h"
19
20#if !(defined PX_LINUX || defined PX_ANDROID || defined PX_PS4 || defined PX_APPLE)
21 #error "This file should only be included by Unix builds!!"
22#endif
23
24#include <math.h>
25#include <float.h>
26
27namespace physx
28{
29 namespace intrinsics
30{
31 //! \brief platform-specific absolute value
32 PX_CUDA_CALLABLE PX_FORCE_INLINE float abs(float a) { return ::fabs(a); }
33
34 //! \brief platform-specific select float
35 PX_CUDA_CALLABLE PX_FORCE_INLINE float fsel(float a, float b, float c) { return (a >= 0.0f) ? b : c; }
36
37 //! \brief platform-specific sign
38 PX_CUDA_CALLABLE PX_FORCE_INLINE float sign(float a) { return (a >= 0.0f) ? 1.0f : -1.0f; }
39
40 //! \brief platform-specific reciprocal
41 PX_CUDA_CALLABLE PX_FORCE_INLINE float recip(float a) { return 1.0f/a; }
42
43 //! \brief platform-specific reciprocal estimate
44 PX_CUDA_CALLABLE PX_FORCE_INLINE float recipFast(float a) { return 1.0f/a; }
45
46 //! \brief platform-specific square root
47 PX_CUDA_CALLABLE PX_FORCE_INLINE float sqrt(float a) { return ::sqrtf(a); }
48
49 //! \brief platform-specific reciprocal square root
50 PX_CUDA_CALLABLE PX_FORCE_INLINE float recipSqrt(float a) { return 1.0f/::sqrtf(a); }
51
52 PX_CUDA_CALLABLE PX_FORCE_INLINE float recipSqrtFast(float a) { return 1.0f/::sqrtf(a); }
53
54 //! \brief platform-specific sine
55 PX_CUDA_CALLABLE PX_FORCE_INLINE float sin(float a) { return ::sinf(a); }
56
57 //! \brief platform-specific cosine
58 PX_CUDA_CALLABLE PX_FORCE_INLINE float cos(float a) { return ::cosf(a); }
59
60 //! \brief platform-specific minimum
61 PX_CUDA_CALLABLE PX_FORCE_INLINE float selectMin(float a, float b) { return a<b ? a : b; }
62
63 //! \brief platform-specific maximum
64 PX_CUDA_CALLABLE PX_FORCE_INLINE float selectMax(float a, float b) { return a>b ? a : b; }
65
66 //! \brief platform-specific float floor
67 PX_FORCE_INLINE float floor(float a)
68 {
69 return ::floorf(a);
70 }
71
72 //! \brief platform-specific finiteness check (not INF or NAN)
73 PX_FORCE_INLINE bool isFinite(float a)
74 {
75 return isfinite(a);
76 }
77
78 //! \brief platform-specific finiteness check (not INF or NAN)
79 PX_FORCE_INLINE bool isFinite(double a)
80 {
81 return isfinite(a);
82 }
83
84 /*!
85 Sets \c count bytes starting at \c dst to zero.
86 */
87 PX_FORCE_INLINE void* memZero(void* PX_RESTRICT dest, PxU32 count)
88 {
89 return memset(dest, 0, count);
90 }
91
92 /*!
93 Sets \c count bytes starting at \c dst to \c c.
94 */
95 PX_FORCE_INLINE void* memSet(void* PX_RESTRICT dest, PxI32 c, PxU32 count)
96 {
97 return memset(dest, c, count);
98 }
99
100 /*!
101 Copies \c count bytes from \c src to \c dst. User memMove if regions overlap.
102 */
103 PX_FORCE_INLINE void* memCopy(void* PX_RESTRICT dest, const void* PX_RESTRICT src, PxU32 count)
104 {
105 return memcpy(dest, src, count);
106 }
107
108 /*!
109 Copies \c count bytes from \c src to \c dst. Supports overlapping regions.
110 */
111 PX_FORCE_INLINE void* memMove(void* PX_RESTRICT dest, const void* PX_RESTRICT src, PxU32 count)
112 {
113 return memmove(dest, src, count);
114 }
115
116 /*!
117 Set 128B to zero starting at \c dst+offset. Must be aligned.
118 */
119 PX_FORCE_INLINE void memZero128(void* PX_RESTRICT dest, PxU32 offset = 0)
120 {
121 PX_ASSERT(((size_t(dest)+offset) & 0x7f) == 0);
122 memSet((char* PX_RESTRICT)dest+offset, 0, 128);
123 }
124
125} // namespace intrinsics
126} // namespace physx
127
128#endif
129
130