26 #if defined (_M_ARM) || defined (_M_ARM64)
30 #elif defined (_M_X64)
34 #elif defined (_M_IX86)
39 #error target platform not defined
43 #define HAVE_STRUCT_TIMESPEC
47 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER) || (defined (_MSC_VER ) && defined (_ARM_VER)) )
55 #pragma warning (push, 3)
75 #include <condition_variable>
77 #if (defined (__MINGW32__) || defined (__MINGW64__))
86 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
88 #include <emmintrin.h>
89 #include <pmmintrin.h>
92 #if (defined (_POSIX_VER) || defined (_POSIX_VER_64) || defined (__MINGW32__) || defined (__MINGW64__))
102 #if (!defined(__arm__) && !defined(__aarch64__)) // it was __ARMCC_VERSION before, it should be __ARM__ or aarch64, otherwise cross compiling in gcc fails.
106 #include <pmmintrin.h>
107 #include <emmintrin.h>
108 #include <mmintrin.h>
115 #include <sys/sysctl.h>
117 #if (defined __i386__ || defined __x86_64__)
119 #include <pmmintrin.h>
120 #include <emmintrin.h>
121 #include <mmintrin.h>
147 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
149 #ifndef D_USE_THREAD_EMULATION
150 #define D_USE_THREAD_EMULATION
156 #ifdef D_DISABLE_ASSERT
159 #if defined (_WIN_32_VER) || defined (_WIN_64_VER)
160 #define dAssert(x) _ASSERTE(x)
161 #elif defined (_MSC_VER ) && defined (_ARM_VER)
162 #define dAssert(x) _ASSERTE(x)
165 #define dAssert(x) assert(x)
177 #define D_INLINE inline
179 #if defined(_MSC_VER)
180 #define D_INLINE __forceinline
182 #define D_INLINE inline
187 #if defined (D_USE_VECTOR_AVX)
188 #if defined(_MSC_VER)
189 #define D_MSV_NEWTON_ALIGN_16 __declspec(align(16))
190 #define D_GCC_NEWTON_ALIGN_16
192 #define D_MSV_NEWTON_ALIGN_32 __declspec(align(32))
193 #define D_GCC_NEWTON_ALIGN_32
195 #define D_MSV_NEWTON_ALIGN_16
196 #define D_GCC_NEWTON_ALIGN_16 __attribute__((aligned (16)))
198 #define D_MSV_NEWTON_ALIGN_32
199 #define D_GCC_NEWTON_ALIGN_32 __attribute__((aligned (32)))
202 #if defined(_MSC_VER)
203 #define D_GCC_NEWTON_ALIGN_16
204 #define D_MSV_NEWTON_ALIGN_16 __declspec(align(16))
206 #define D_GCC_NEWTON_ALIGN_32
207 #define D_MSV_NEWTON_ALIGN_32 __declspec(align(32))
209 #define D_GCC_NEWTON_ALIGN_16 __attribute__((aligned (16)))
210 #define D_MSV_NEWTON_ALIGN_16
212 #define D_GCC_NEWTON_ALIGN_32 __attribute__((aligned (32)))
213 #define D_MSV_NEWTON_ALIGN_32
217 #if defined(_MSC_VER)
218 #define D_LIBRARY_EXPORT __declspec(dllexport)
219 #define D_LIBRARY_IMPORT __declspec(dllimport)
221 #define D_LIBRARY_EXPORT __attribute__((visibility("default")))
222 #define D_LIBRARY_IMPORT __attribute__((visibility("default")))
226 #ifdef _D_CORE_EXPORT_DLL
227 #define D_CORE_API D_LIBRARY_EXPORT
229 #define D_CORE_API D_LIBRARY_IMPORT
235 #if ((defined (_WIN_32_VER) || defined (_WIN_64_VER)) && (_MSC_VER >= 1600))
236 typedef int8_t dInt8;
237 typedef uint8_t dUnsigned8;
239 typedef int16_t dInt16;
240 typedef uint16_t dUnsigned16;
242 typedef int32_t dInt32;
243 typedef uint32_t dUnsigned32;
245 typedef int64_t dInt64;
246 typedef uint64_t dUnsigned64;
249 typedef unsigned char dUnsigned8;
251 typedef short dInt16;
252 typedef unsigned short dUnsigned16;
255 typedef unsigned dUnsigned32;
256 typedef unsigned int dUnsigned32;
258 typedef long long dInt64;
259 typedef unsigned long long dUnsigned64;
260 typedef double dFloat64;
263 typedef double dFloat64;
265 #ifdef D_NEWTON_USE_DOUBLE
266 typedef double dFloat32;
268 typedef float dFloat32;
279 #define dPi dFloat32 (3.141592f)
281 #define dEXP dFloat32 (2.71828f)
282 #define dEpsilon dFloat32 (1.0e-5f)
283 #define dDegreeToRad dFloat32 (dPi / 180.0f)
284 #define dRadToDegree dFloat32 (180.0f / dPi)
286 #define dSqrt(x) dFloat32 (sqrt(x))
287 #define dSin(x) dFloat32 (sin(x))
288 #define dCos(x) dFloat32 (cos(x))
289 #define dAsin(x) dFloat32 (asin(x))
290 #define dAcos(x) dFloat32 (acos(x))
291 #define dLog(x) dFloat32 (log(x))
292 #define dCeil(x) dFloat32 (ceil(x))
293 #define dFloor(x) dFloat32 (floor(x))
294 #define dPow(x,y) dFloat32 (pow(x,y))
295 #define dFmod(x,y) dFloat32 (fmod(x,y))
296 #define dTan(x) dFloat32 (tan(x))
297 #define dAtan2(x,y) dFloat32 (atan2(x,y))
298 #define dRsqrt(x) (dFloat32 (1.0f) / dSqrt(x))
299 #define dClearFP() _clearfp()
300 #define dControlFP(x,y) _controlfp(x,y)
304 #ifndef D_NEWTON_USE_DOUBLE
308 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
309 #define dCheckFloat(x) (_finite(x) && !_isnan(x))
312 #define dCheckFloat(x) (isfinite(x) && !isnan(x))
321 #define dAlloca(type, count) (type*) alloca (sizeof (type) * (count))
323 D_INLINE dInt32 dExp2 (dInt32 x)
326 for (exp = -1; x; x >>= 1)
333 D_INLINE dInt32 dBitReversal(dInt32 v, dInt32 base)
336 dInt32 power = dExp2 (base) - 1;
339 x += (v & 1) << power;
350 return T(fmod(T(val), T(mod)));
354 D_INLINE T dMin(T A, T B)
356 return (A < B) ? A : B;
360 D_INLINE T dMax(T A, T B)
362 return (A > B) ? A : B;
366 D_INLINE T dMin(T A, T B, T C)
368 return dMin(dMin (A, B), C);
372 D_INLINE T dMax(T A, T B, T C)
374 return dMax(dMax (A, B), C);
378 D_INLINE T dClamp(T val, T min, T max)
380 return dMax (min, dMin (max, val));
384 D_INLINE
void dSwap(T& A, T& B)
395 return (A >= T(0)) ? A : -A;
399 D_INLINE T dSign(T A)
401 return (A >= T(0)) ? T(1) : T(-1);
405 D_INLINE
bool dAreEqual(T A, T B, T tol)
408 if ((dAbs(A) < tol) && (dAbs(B) < tol))
414 dFloat64 mantissa0 = frexp(dFloat64 (A), &exp0);
417 dFloat64 mantissa1 = frexp(dFloat64(B), &exp1);
418 if (dAbs(exp0 - exp1) > 1)
426 mantissa0 *= dFloat32(2.0f);
430 mantissa1 *= dFloat32(2.0f);
433 return dAbs(mantissa0 - mantissa1) < tol;
437 D_INLINE T AnglesAdd (T angleInRadiand1, T angleInRadiand0)
439 T s1 = T(dSin(angleInRadiand1));
440 T c1 = T(dCos(angleInRadiand1));
441 T s0 = T(dSin(angleInRadiand0));
442 T c0 = T(dCos(angleInRadiand0));
444 T s = s1 * c0 + s0 * c1;
445 T c = c1 * c0 - s0 * s1;
446 return T(dAtan2(s, c));
449 #ifdef D_NEWTON_USE_DOUBLE
482 #define PointerToInt(x) ((size_t)x)
483 #define IntToPointer(x) ((void*)(size_t(x)))
486 #define _stricmp(x,y) strcasecmp(x,y)
490 D_CORE_API dUnsigned64 dGetCpuClock();
493 D_CORE_API dUnsigned64 dGetTimeInMicrosenconds();
498 D_CORE_API dFloat64 dRoundToFloat(dFloat64 val);
500 #ifdef D_USE_THREAD_EMULATION
554 : std::atomic<T>(T(0))
570 #ifndef D_USE_THREAD_EMULATION
578 #ifndef D_USE_THREAD_EMULATION
579 while (m_lock.exchange(1))
581 std::this_thread::yield();
588 #ifndef D_USE_THREAD_EMULATION
593 #ifndef D_USE_THREAD_EMULATION
604 :m_spinLock(spinLock)
617 D_CORE_API dInt32 dVertexListToIndexList (dFloat64*
const vertexList, dInt32 strideInBytes, dInt32 compareCount, dInt32 vertexCount, dInt32*
const indexListOut, dFloat64 tolerance = dEpsilon);
618 D_CORE_API dInt32 dVertexListToIndexList (dFloat32*
const vertexList, dInt32 strideInBytes, dInt32 floatSizeInBytes, dInt32 unsignedSizeInBytes, dInt32 vertexCount, dInt32*
const indexListOut, dFloat32 tolerance = dEpsilon);
625 #define D_FLOAT_EXECTIONS_MASK (EM_INVALID | EM_DENORMAL | EM_ZERODIVIDE)
627 #define D_FLOAT_EXECTIONS_MASK 0
635 #if defined (_MSC_VER)
646 #if (defined (_MSC_VER) && defined (_WIN_32_VER))