My Project: dynamics.mod/NewtonDynamics/source/core/dgTypes.h Source File

My Project

dgTypes.h
Go to the documentation of this file.
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21
22 #ifndef __DGTYPES_H__
23 #define __DGTYPES_H__
24
25
26 #ifdef DG_SSE4_INSTRUCTIONS_SET
27 #undef DG_SCALAR_VECTOR_CLASS
28 #endif
29
30
31 #if defined (_NEWTON_USE_DOUBLE) || defined (__ppc__) || defined (ANDROID) || defined (IOS)
32 #undef DG_SSE4_INSTRUCTIONS_SET
33 #ifndef DG_SCALAR_VECTOR_CLASS
34 #define DG_SCALAR_VECTOR_CLASS
35 #endif
36 #endif
37
38
39
40 #ifdef _MSC_VER
41 #ifdef _M_X64
42 #ifndef _WIN_64_VER
43 #define _WIN_64_VER
44 #endif
45 #else
46 #ifndef _WIN_32_VER
47 #define _WIN_32_VER
48 #endif
49 #endif
50 #endif
51
52
53 #ifdef _MSC_VER
54 #if !(defined (_WIN_32_VER) || defined (_WIN_64_VER))
55 #error "most define _WIN_32_VER or _WIN_64_VER for a correct CPU target"
56 #endif
57 #endif
58
59 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
60
61 #pragma warning (disable: 4100) //unreferenced formal parameter
62 #pragma warning (disable: 4201) //nonstandard extension used : nameless struct/union
63 #pragma warning (disable: 4324) //structure was padded due to __declspec(align())
64 #pragma warning (disable: 4530) //: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
65
66 #include <io.h>
67 #include <direct.h>
68 #include <malloc.h>
69 #include <float.h>
70 #include <stdarg.h>
71 #include <process.h>
72
73
74 #ifdef _DEBUG
75 #pragma warning (disable: 4127) //conditional expression is constant
76 #endif
77
78 #pragma warning (push, 3)
79 #include <windows.h>
80 #include <crtdbg.h>
81 #ifndef _DURANGO
82 #include <tlhelp32.h>
83 #endif
84 #pragma warning (pop)
85 #endif
86
87 #include <new>
88 #include <stdio.h>
89 #include <stdlib.h>
90 #include <string.h>
91 #include <stdarg.h>
92 #include <time.h>
93 #include <math.h>
94 #include <float.h>
95 #include <ctype.h>
96 #include <pthread.h>
97 #include <sched.h>
98 #include <semaphore.h>
99
100
101
102 #if (defined (_MINGW_32_VER) || defined (_MINGW_64_VER))
103 #include <io.h>
104 #include <direct.h>
105 #include <malloc.h>
106 #include <float.h>
107 #include <windows.h>
108 #include <process.h>
109 #endif
110
111
112
113
114 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
115 #include <intrin.h>
116 #endif
117
118
119
120 #ifdef __ppc__
121 #include <vecLib/veclib.h>
122 #endif
123
124
125 #if (defined (_POSIX_VER) || defined (_POSIX_VER_64) || defined (_MINGW_32_VER) || defined (_MINGW_64_VER))
126 #include <unistd.h>
127 #include <assert.h>
128 extern "C"
129 {
130 // for SSE3 and up
131 #include <pmmintrin.h>
132 #include <emmintrin.h>
133 #include <mmintrin.h>
134 }
135 #endif
136
137 #ifdef _MACOSX_VER
138 #include <unistd.h>
139 #include <sys/sysctl.h>
140 #include <assert.h>
141 #if (defined __i386__ || defined __x86_64__)
142 #include <pmmintrin.h>
143 #include <emmintrin.h> //sse3
144 #include <mmintrin.h>
145 #endif
146 #endif
147
148 //************************************************************
149 #ifdef DG_DISABLE_ASSERT
150 #define dgAssert(x)
151 #else
152 #if defined (_WIN_32_VER) || defined (_WIN_64_VER)
153 #define dgAssert(x) _ASSERTE(x)
154 #else
155 #ifdef _DEBUG
156 #define dgAssert(x) assert(x)
157 #else
158 #define dgAssert(x)
159 #endif
160 #endif
161 #endif
162
163
164 #define DG_MAX_THREADS_HIVE_COUNT 16
165
166 #ifdef _DEBUG
167 //#define __ENABLE_DG_CONTAINERS_SANITY_CHECK
168 #endif
169
170
171 #ifdef DLL_DECLSPEC
172 #undef DLL_DECLSPEC
173 #endif
174
175 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
176 #define DG_INLINE __forceinline
177 #else
178 #define DG_INLINE inline
179 //#define DG_INLINE __attribute__((always_inline))
180 #endif
181
182
183 #define DG_VECTOR_SIMD_SIZE 16
184
185 #if ((defined (_WIN_32_VER) || defined (_WIN_64_VER)) && (_MSC_VER >= 1700)) && !defined(_DURANGO)
186 // starting Visual studio 2012 an up we can use high performance computing using AMP
187 #define _NEWTON_AMP
188 #endif
189
190 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
191 #define DG_GCC_VECTOR_ALIGMENT
192 #define DG_MSC_VECTOR_ALIGMENT __declspec(align(DG_VECTOR_SIMD_SIZE))
193 #else
194 #define DG_MSC_VECTOR_ALIGMENT
195 #define DG_GCC_VECTOR_ALIGMENT __attribute__ ((aligned (DG_VECTOR_SIMD_SIZE)))
196 #endif
197
198 #if ((defined (_WIN_32_VER) || defined (_WIN_64_VER)) && (_MSC_VER >= 1600))
199 #include <stdint.h>
200 typedef int8_t dgInt8;
201 typedef uint8_t dgUnsigned8;
202
203 typedef int16_t dgInt16;
204 typedef uint16_t dgUnsigned16;
205
206 typedef int32_t dgInt32;
207 typedef uint32_t dgUnsigned32;
208
209 typedef int64_t dgInt64;
210 typedef uint64_t dgUnsigned64;
211 #else
212 typedef char dgInt8;
213 typedef unsigned char dgUnsigned8;
214
215 typedef short dgInt16;
216 typedef unsigned short dgUnsigned16;
217
218 typedef int dgInt32;
219 typedef unsigned dgUnsigned32;
220 typedef unsigned int dgUnsigned32;
221
222 typedef long long dgInt64;
223 typedef unsigned long long dgUnsigned64;
224 typedef double dgFloat64;
225 #endif
226
227
228 typedef double dgFloat64;
229
230 #ifdef _NEWTON_USE_DOUBLE
231 typedef double dgFloat32;
232 #else
233 typedef float dgFloat32;
234 #endif
235
236
237 class dgTriplex
238 {
239 public:
240 dgFloat32 m_x;
241 dgFloat32 m_y;
242 dgFloat32 m_z;
243 };
244
245
246 #define dgPI dgFloat32 (3.14159f)
247 #define dgPI2 dgFloat32 (dgPI * 2.0f)
248 #define dgEXP dgFloat32 (2.71828f)
249 #define dgEPSILON dgFloat32 (1.0e-5f)
250 #define dgGRAVITY dgFloat32 (9.8f)
251 #define dgDEG2RAD dgFloat32 (dgPI / 180.0f)
252 #define dgRAD2DEG dgFloat32 (180.0f / dgPI)
253 #define dgKMH2MPSEC dgFloat32 (0.278f)
254
255
256 class dgVector;
257 class dgBigVector;
258
259 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
260 #define dgApi __cdecl
261 #define dgStdApi __stdcall
262 #else
263 #define dgApi
264 #define dgStdApi
265 #endif
266
267
268
269 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
270 #define dgCheckFloat(x) (_finite(x) && !_isnan(x))
271 // #define dgCheckFloat(x) 1
272 #else
273 #define dgCheckFloat(x) (isfinite(x) && !isnan(x))
274 // #define dgCheckFloat(x) 1
275 #endif
276
277
278
279 typedef void (dgApi *dgDeserialize) (void* const userData, void* buffer, size_t size);
280 typedef void (dgApi *dgSerialize) (void* const userData, const void* const buffer, size_t size);
281 typedef bool (dgApi *dgReportProgress) (dgFloat32 progressNormalzedPercent, void* const userData);
282
283 DG_INLINE dgInt32 dgExp2 (dgInt32 x)
284 {
285 dgInt32 exp;
286 for (exp = -1; x; x >>= 1) {
287 exp ++;
288 }
289 return exp;
290 }
291
292 template <class T>
293 DG_INLINE T dgMin(T A, T B)
294 {
295 return (A < B) ? A : B;
296 }
297
298 template <class T>
299 DG_INLINE T dgMax(T A, T B)
300 {
301 return (A > B) ? A : B;
302 }
303
304 template <class T>
305 DG_INLINE T dgMin(T A, T B, T C)
306 {
307 return dgMin(dgMin (A, B), C);
308 }
309
310 template <class T>
311 DG_INLINE T dgMax(T A, T B, T C)
312 {
313 return dgMax(dgMax (A, B), C);
314 }
315
316 template <class T>
317 DG_INLINE T dgClamp(T val, T min, T max)
318 {
319 return dgMax (min, dgMin (max, val));
320 }
321
322 template <class T>
323 DG_INLINE void dgSwap(T& A, T& B)
324 {
325 T tmp (A);
326 A = B;
327 B = tmp;
328 }
329
330 template <class T>
331 DG_INLINE T dgSign(T A)
332 {
333 // T sign (1.0f);
334 // if (A < T (0.0f)) {
335 // sign = T (-1.0f);
336 // }
337 // return sign;
338 return (A >= T(0)) ? T(1) : T(-1);
339 }
340
341 template <class T>
342 dgInt32 dgBinarySearch (T const* array, dgInt32 elements, dgInt32 entry)
343 {
344 dgInt32 index0 = 0;
345 dgInt32 index2 = elements - 1;
346 dgInt32 entry0 = array[index0].m_Key;
347 dgInt32 entry2 = array[index2].m_Key;
348
349 while ((index2 - index0) > 1) {
350 dgInt32 index1 = (index0 + index2) >> 1;
351 dgInt32 entry1 = array[index1].m_Key;
352 if (entry1 == entry) {
353 dgAssert (array[index1].m_Key <= entry);
354 dgAssert (array[index1 + 1].m_Key >= entry);
355 return index1;
356 } else if (entry < entry1) {
357 index2 = index1;
358 entry2 = entry1;
359 } else {
360 index0 = index1;
361 entry0 = entry1;
362 }
363 }
364
365 if (array[index0].m_Key > index0) {
366 index0 --;
367 }
368
369 dgAssert (array[index0].m_Key <= entry);
370 dgAssert (array[index0 + 1].m_Key >= entry);
371 return index0;
372 }
373
374
375
376
377 template <class T>
378 void dgRadixSort (T* const array, T* const tmpArray, dgInt32 elements, dgInt32 radixPass,
379 dgInt32 (*getRadixKey) (const T* const A, void* const context), void* const context = NULL)
380 {
381 dgInt32 scanCount[256];
382 dgInt32 histogram[256][4];
383
384 dgAssert (radixPass >= 1);
385 dgAssert (radixPass <= 4);
386
387 memset (histogram, 0, sizeof (histogram));
388 for (dgInt32 i = 0; i < elements; i ++) {
389 dgInt32 key = getRadixKey (&array[i], context);
390 for (dgInt32 j = 0; j < radixPass; j ++) {
391 dgInt32 radix = (key >> (j << 3)) & 0xff;
392 histogram[radix][j] = histogram[radix][j] + 1;
393 }
394 }
395
396 for (dgInt32 radix = 0; radix < radixPass; radix += 2) {
397 scanCount[0] = 0;
398 for (dgInt32 i = 1; i < 256; i ++) {
399 scanCount[i] = scanCount[i - 1] + histogram[i - 1][radix];
400 }
401 dgInt32 radixShift = radix << 3;
402 for (dgInt32 i = 0; i < elements; i ++) {
403 dgInt32 key = (getRadixKey (&array[i], context) >> radixShift) & 0xff;
404 dgInt32 index = scanCount[key];
405 tmpArray[index] = array[i];
406 scanCount[key] = index + 1;
407 }
408
409 if ((radix + 1) < radixPass) {
410 scanCount[0] = 0;
411 for (dgInt32 i = 1; i < 256; i ++) {
412 scanCount[i] = scanCount[i - 1] + histogram[i - 1][radix + 1];
413 }
414
415 dgInt32 radixShift = (radix + 1) << 3;
416 for (dgInt32 i = 0; i < elements; i ++) {
417 dgInt32 key = (getRadixKey (&array[i], context) >> radixShift) & 0xff;
418 dgInt32 index = scanCount[key];
419 array[index] = tmpArray[i];
420 scanCount[key] = index + 1;
421 }
422 } else {
423 memcpy (array, tmpArray, elements * sizeof (T));
424 }
425 }
426
427
428 #ifdef _DEBUG
429 for (dgInt32 i = 0; i < (elements - 1); i ++) {
430 dgAssert (getRadixKey (&array[i], context) <= getRadixKey (&array[i + 1], context));
431 }
432 #endif
433
434 }
435
436
437 template <class T>
438 void dgSort (T* const array, dgInt32 elements, dgInt32 (*compare) (const T* const A, const T* const B, void* const context), void* const context = NULL)
439 {
440 dgInt32 stride = 8;
441 dgInt32 stack[1024][2];
442
443 stack[0][0] = 0;
444 stack[0][1] = elements - 1;
445 dgInt32 stackIndex = 1;
446 while (stackIndex) {
447 stackIndex --;
448 dgInt32 lo = stack[stackIndex][0];
449 dgInt32 hi = stack[stackIndex][1];
450 if ((hi - lo) > stride) {
451 dgInt32 i = lo;
452 dgInt32 j = hi;
453 T val (array[(lo + hi) >> 1]);
454 do {
455 while (compare (&array[i], &val, context) < 0) i ++;
456 while (compare (&array[j], &val, context) > 0) j --;
457
458 if (i <= j) {
459 dgSwap(array[i], array[j]);
460 i++;
461 j--;
462 }
463 } while (i <= j);
464
465 if (i < hi) {
466 stack[stackIndex][0] = i;
467 stack[stackIndex][1] = hi;
468 stackIndex ++;
469 }
470 if (lo < j) {
471 stack[stackIndex][0] = lo;
472 stack[stackIndex][1] = j;
473 stackIndex ++;
474 }
475 dgAssert (stackIndex < dgInt32 (sizeof (stack) / (2 * sizeof (stack[0][0]))));
476 }
477 }
478
479 stride = stride * 2;
480 if (elements < stride) {
481 stride = elements;
482 }
483 for (dgInt32 i = 1; i < stride; i ++) {
484 if (compare (&array[0], &array[i], context) > 0) {
485 dgSwap(array[0], array[i]);
486 }
487 }
488
489 for (dgInt32 i = 1; i < elements; i ++) {
490 dgInt32 j = i;
491 T tmp (array[i]);
492 for (; compare (&array[j - 1], &tmp, context) > 0; j --) {
493 dgAssert (j > 0);
494 array[j] = array[j - 1];
495 }
496 array[j] = tmp;
497 }
498
499 #ifdef _DEBUG
500 for (dgInt32 i = 0; i < (elements - 1); i ++) {
501 dgAssert (compare (&array[i], &array[i + 1], context) <= 0);
502 }
503 #endif
504 }
505
506
507 template <class T>
508 void dgSortIndirect (T** const array, dgInt32 elements, dgInt32 (*compare) (const T* const A, const T* const B, void* const context), void* const context = NULL)
509 {
510 dgInt32 stride = 8;
511 dgInt32 stack[1024][2];
512
513 stack[0][0] = 0;
514 stack[0][1] = elements - 1;
515 dgInt32 stackIndex = 1;
516 while (stackIndex) {
517 stackIndex --;
518 dgInt32 lo = stack[stackIndex][0];
519 dgInt32 hi = stack[stackIndex][1];
520 if ((hi - lo) > stride) {
521 dgInt32 i = lo;
522 dgInt32 j = hi;
523 T* val (array[(lo + hi) >> 1]);
524 do {
525 while (compare (array[i], val, context) < 0) i ++;
526 while (compare (array[j], val, context) > 0) j --;
527
528 if (i <= j) {
529 dgSwap(array[i], array[j]);
530 i++;
531 j--;
532 }
533 } while (i <= j);
534
535 if (i < hi) {
536 stack[stackIndex][0] = i;
537 stack[stackIndex][1] = hi;
538 stackIndex ++;
539 }
540 if (lo < j) {
541 stack[stackIndex][0] = lo;
542 stack[stackIndex][1] = j;
543 stackIndex ++;
544 }
545 dgAssert (stackIndex < dgInt32 (sizeof (stack) / (2 * sizeof (stack[0][0]))));
546 }
547 }
548
549 stride = stride * 2;
550 if (elements < stride) {
551 stride = elements;
552 }
553 for (dgInt32 i = 1; i < stride; i ++) {
554 if (compare (&array[0], &array[i], context) > 0) {
555 dgSwap(array[0], array[i]);
556 }
557 }
558
559 for (dgInt32 i = 1; i < elements; i ++) {
560 dgInt32 j = i;
561 T* tmp (array[i]);
562 for (; compare (&array[j - 1], &tmp, context) > 0; j --) {
563 dgAssert (j > 0);
564 array[j] = array[j - 1];
565 }
566 array[j] = tmp;
567 }
568
569 #ifdef _DEBUG
570 for (dgInt32 i = 0; i < (elements - 1); i ++) {
571 dgAssert (compare (array[i], array[i + 1], context) <= 0);
572 }
573 #endif
574 }
575
576
577
578 #ifdef _NEWTON_USE_DOUBLE
579 union dgFloatSign
580 {
581 struct {
582 dgInt32 m_dommy;
583 dgInt32 m_iVal;
584 } m_integer;
585 dgFloat64 m_fVal;
586 };
587 #else
588 union dgFloatSign
589 {
590 struct {
591 dgInt32 m_iVal;
592 } m_integer;
593 dgFloat32 m_fVal;
594 };
595 #endif
596
597 union dgDoubleInt
598 {
599 struct {
600 dgInt32 m_intL;
601 dgInt32 m_intH;
602 };
603 void* m_ptr;
604 dgInt64 m_int;
605 dgFloat64 m_float;
606 };
607
608
609
610 void GetMinMax (dgVector &Min, dgVector &Max, const dgFloat32* const vArray, dgInt32 vCount, dgInt32 StrideInBytes);
611 void GetMinMax (dgBigVector &Min, dgBigVector &Max, const dgFloat64* const vArray, dgInt32 vCount, dgInt32 strideInBytes);
612
613 dgInt32 dgVertexListToIndexList (dgFloat32* const vertexList, dgInt32 strideInBytes, dgInt32 floatSizeInBytes, dgInt32 unsignedSizeInBytes, dgInt32 vertexCount, dgInt32* const indexListOut, dgFloat32 tolerance = dgEPSILON);
614
615 dgInt32 dgVertexListToIndexList (dgFloat64* const vertexList, dgInt32 strideInBytes, dgInt32 compareCount, dgInt32 vertexCount, dgInt32* const indexListOut, dgFloat64 tolerance = dgEPSILON);
616
617
618 #define PointerToInt(x) ((size_t)x)
619 #define IntToPointer(x) ((void*)(size_t(x)))
620
621
622 #ifndef _MSC_VER
623 #define _stricmp(x,y) strcasecmp(x,y)
624 #endif
625
626
627 DG_INLINE dgFloat32 dgAbsf(dgFloat32 x)
628 {
629 #if 0
630 dgDoubleInt val;
631 val.m_float = x;
632 val.m_intH &= ~(dgUnsigned64 (1)<<31);
633 dgAssert (val.m_float == fabs (x));
634 return dgFloat32 (val.m_float);
635 #else
636 // according to Intel this is better because is doe not read after write
637 return (x >= dgFloat32 (0.0f)) ? x : -x;
638 #endif
639 }
640
641 #ifndef _NEWTON_USE_DOUBLE
642 DG_INLINE dgInt32 dgFastInt (dgFloat64 x)
643 {
644 dgInt32 i = dgInt32 (x);
645 if (dgFloat64 (i) > x) {
646 i --;
647 }
648 return i;
649 }
650 #endif
651
652 DG_INLINE dgInt32 dgFastInt (dgFloat32 x)
653 {
654 dgInt32 i = dgInt32 (x);
655 if (dgFloat32 (i) > x) {
656 i --;
657 }
658 return i;
659 }
660
661 DG_INLINE dgFloat32 dgFloor(dgFloat32 x)
662 {
663 #ifdef _MSC_VER
664 dgFloat32 ret = dgFloat32 (dgFastInt (x));
665 dgAssert (ret == floor (x));
666 return ret;
667 #else
668 return floor (x);
669 #endif
670 }
671
672 DG_INLINE dgFloat32 dgCeil(dgFloat32 x)
673 {
674 #ifdef _MSC_VER
675 dgFloat32 ret = dgFloor(x);
676 if (ret < x) {
677 ret += dgFloat32 (1.0f);
678 }
679 dgAssert (ret == ceil (x));
680 return ret;
681 #else
682 return ceil (x);
683 #endif
684 }
685
686 DG_INLINE dgFloat32 dgRsqrt(dgFloat32 x)
687 {
688 return dgFloat32 (1.0f) / dgFloat32 (sqrt(x));
689 }
690
691 #define dgSqrt(x) dgFloat32 (sqrt(x))
692 #define dgSin(x) dgFloat32 (sin(x))
693 #define dgCos(x) dgFloat32 (cos(x))
694 #define dgAsin(x) dgFloat32 (asin(x))
695 #define dgAcos(x) dgFloat32 (acos(x))
696 #define dgAtan2(x,y) dgFloat32 (atan2(x,y))
697 #define dgLog(x) dgFloat32 (log(x))
698 #define dgPow(x,y) dgFloat32 (pow(x,y))
699 #define dgFmod(x,y) dgFloat32 (fmod(x,y))
700 #define dgClearFP() _clearfp()
701 #define dgControlFP(x,y) _controlfp(x,y)
702
703
704 void dgSerializeMarker(dgSerialize serializeCallback, void* const userData);
705 void dgDeserializeMarker(dgDeserialize serializeCallback, void* const userData);
706
707
708 typedef dgUnsigned32 (dgApi *OnGetPerformanceCountCallback) ();
709
710
711 dgUnsigned64 dgGetTimeInMicrosenconds();
712
713
714 class dgFloatExceptions
715 {
716 public:
717 //#define DG_FLOAT_EXECTIONS_MASK (_EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_UNDERFLOW| _EM_INEXACT)
718 //#define DG_FLOAT_EXECTIONS_MASK (_EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE)
719 //#define DG_FLOAT_EXECTIONS_MASK (_EM_DENORMAL | _EM_ZERODIVIDE)
720
721 enum dgFloatExceptionMask
722 {
723 #if (defined (_MSC_VER) && defined (_DEBUG))
724 m_InvalidDenormalAndivideByZero = _EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE,
725 m_allExepctions = _EM_INVALID | _EM_DENORMAL | _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_UNDERFLOW,
726 #else
727 m_InvalidDenormalAndivideByZero,
728 m_allExepctions,
729 #endif
730 };
731
732 dgFloatExceptions(dgFloatExceptionMask mask = m_InvalidDenormalAndivideByZero)
733 :m_mask (0)
734 {
735 #if (defined (_MSC_VER) && defined (_DEBUG))
736 dgClearFP();
737 m_mask = dgControlFP(0, 0);
738 dgControlFP (m_mask & dgUnsigned32 (~mask), _MCW_EM);
739 #endif
740 }
741
742 ~dgFloatExceptions()
743 {
744 #if (defined (_MSC_VER) && defined (_DEBUG))
745 dgClearFP();
746 dgControlFP(m_mask, _MCW_EM);
747 #endif
748 }
749
750 dgInt32 m_mask;
751 };
752
753
754 class dgSetPrecisionDouble
755 {
756 public:
757 dgSetPrecisionDouble()
758 {
759 #if (defined (_MSC_VER) && defined (_WIN_32_VER))
760 dgClearFP();
761 m_mask = dgControlFP(0, 0);
762 dgControlFP (_PC_53, _MCW_PC);
763 #endif
764 }
765
766 ~dgSetPrecisionDouble()
767 {
768 #if (defined (_MSC_VER) && defined (_WIN_32_VER))
769 dgClearFP();
770 dgControlFP (m_mask, _MCW_PC);
771 #endif
772 }
773 dgInt32 m_mask;
774 };
775
776
777
778
779 DG_INLINE dgInt32 dgAtomicExchangeAndAdd (dgInt32* const addend, dgInt32 amount)
780 {
781 // it is a pity that pthread does not supports cross platform atomics, it would be nice if it did
782 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
783 return _InterlockedExchangeAdd((long*) addend, long (amount));
784 #endif
785
786 #if (defined (_MINGW_32_VER) || defined (_MINGW_64_VER))
787 return InterlockedExchangeAdd((long*) addend, long (amount));
788 #endif
789
790
791 #if (defined (_POSIX_VER) || defined (_POSIX_VER_64) ||defined (_MACOSX_VER))
792 return __sync_fetch_and_add ((int32_t*)addend, amount );
793 #endif
794 }
795
796 DG_INLINE dgInt32 dgInterlockedExchange(dgInt32* const ptr, dgInt32 value)
797 {
798 // it is a pity that pthread does not supports cross platform atomics, it would be nice if it did
799 #if (defined (_WIN_32_VER) || defined (_WIN_64_VER))
800 return _InterlockedExchange((long*) ptr, value);
801 #endif
802
803 #if (defined (_MINGW_32_VER) || defined (_MINGW_64_VER))
804 return InterlockedExchange((long*) ptr, value);
805 #endif
806
807
808 #if (defined (_POSIX_VER) || defined (_POSIX_VER_64) ||defined (_MACOSX_VER))
809 //__sync_synchronize();
810 return __sync_lock_test_and_set((int32_t*)ptr, value);
811 #endif
812 }
813
814 DG_INLINE void dgThreadYield()
815 {
816 #if defined (DG_USE_THREAD_EMULATION)
817 return;
818 #else
819 sched_yield();
820 #endif
821 }
822
823 DG_INLINE void dgPrefetchMem(const void* const mem)
824 {
825 #if !(defined (__ppc__) || defined (ANDROID) || defined (IOS))
826 _mm_prefetch ((const char*)mem, _MM_HINT_T0);
827 #endif
828 }
829
830 #endif
831
OnGetPerformanceCountCallback
dgUnsigned32(dgApi * OnGetPerformanceCountCallback)()
Definition: dgTypes.h:708
dgDoubleInt::m_intH
dgInt32 m_intH
Definition: dgTypes.h:601
dgApi
#define dgApi
Definition: dgTypes.h:263
dgGetTimeInMicrosenconds
dgUnsigned64 dgGetTimeInMicrosenconds()
Definition: dgTypes.cpp:32
dgInt64
long long dgInt64
Definition: dgTypes.h:222
dgUnsigned64
unsigned long long dgUnsigned64
Definition: dgTypes.h:223
dgUnsigned8
unsigned char dgUnsigned8
Definition: dgTypes.h:213
dgBinarySearch
dgInt32 dgBinarySearch(T const *array, dgInt32 elements, dgInt32 entry)
Definition: dgTypes.h:342
dgSetPrecisionDouble::dgSetPrecisionDouble
dgSetPrecisionDouble()
Definition: dgTypes.h:757
dgFloor
DG_INLINE dgFloat32 dgFloor(dgFloat32 x)
Definition: dgTypes.h:661
dgInt16
short dgInt16
Definition: dgTypes.h:215
dgMin
DG_INLINE T dgMin(T A, T B)
Definition: dgTypes.h:293
dgAbsf
DG_INLINE dgFloat32 dgAbsf(dgFloat32 x)
Definition: dgTypes.h:627
dgDoubleInt
Definition: dgTypes.h:597
dgExp2
DG_INLINE dgInt32 dgExp2(dgInt32 x)
Definition: dgTypes.h:283
dgFloatExceptions::dgFloatExceptions
dgFloatExceptions(dgFloatExceptionMask mask=m_InvalidDenormalAndivideByZero)
Definition: dgTypes.h:732
dgDoubleInt::m_intL
dgInt32 m_intL
Definition: dgTypes.h:600
dgFloatExceptions
Definition: dgTypes.h:714
userData
void *const userData
Definition: dgBroadPhase.h:35
DG_INLINE
#define DG_INLINE
Definition: dgTypes.h:178
dgAssert
#define dgAssert(x)
Definition: dgTypes.h:158
dgTriplex::m_y
dgFloat32 m_y
Definition: dgTypes.h:241
dgFloat32
float dgFloat32
Definition: dgTypes.h:233
dgInt32
int dgInt32
Definition: dgTypes.h:218
GetMinMax
void GetMinMax(dgVector &Min, dgVector &Max, const dgFloat32 *const vArray, dgInt32 vCount, dgInt32 StrideInBytes)
Definition: dgTypes.cpp:79
void
typedef void(dgApi *ConstraintsForceFeeback)(const dgConstraint &me
dgMax
DG_INLINE T dgMax(T A, T B)
Definition: dgTypes.h:299
dgVector
Definition: dgVector.h:639
pthread.h
dgSwap
DG_INLINE void dgSwap(T &A, T &B)
Definition: dgTypes.h:323
dgInterlockedExchange
DG_INLINE dgInt32 dgInterlockedExchange(dgInt32 *const ptr, dgInt32 value)
Definition: dgTypes.h:796
dgFloatSign
Definition: dgTypes.h:588
dgFloatExceptions::m_mask
dgInt32 m_mask
Definition: dgTypes.h:750
dgControlFP
#define dgControlFP(x, y)
Definition: dgTypes.h:701
dgFloat64
double dgFloat64
Definition: dgTypes.h:224
dgFloatSign::m_iVal
dgInt32 m_iVal
Definition: dgTypes.h:591
dgDoubleInt::m_float
dgFloat64 m_float
Definition: dgTypes.h:605
dgClamp
DG_INLINE T dgClamp(T val, T min, T max)
Definition: dgTypes.h:317
dgClearFP
#define dgClearFP()
Definition: dgTypes.h:700
dgFloatExceptions::dgFloatExceptionMask
dgFloatExceptionMask
Definition: dgTypes.h:721
dgSetPrecisionDouble::m_mask
dgInt32 m_mask
Definition: dgTypes.h:773
dgSerialize
void(dgApi * dgSerialize)(void *const userData, const void *const buffer, size_t size)
Definition: dgTypes.h:280
dgDoubleInt::m_int
dgInt64 m_int
Definition: dgTypes.h:604
entry
void * entry(void *arg)
Definition: self2.c:53
dgRadixSort
void dgRadixSort(T *const array, T *const tmpArray, dgInt32 elements, dgInt32 radixPass, dgInt32(*getRadixKey)(const T *const A, void *const context), void *const context=NULL)
Definition: dgTypes.h:378
int64_t
#define int64_t
Definition: implement.h:108
dgRsqrt
DG_INLINE dgFloat32 dgRsqrt(dgFloat32 x)
Definition: dgTypes.h:686
sched.h
dgThreadYield
DG_INLINE void dgThreadYield()
Definition: dgTypes.h:814
dgDeserialize
void(dgApi * dgDeserialize)(void *const userData, void *buffer, size_t size)
Definition: dgTypes.h:279
dgInt8
char dgInt8
Definition: dgTypes.h:212
dgFloatExceptions::m_allExepctions
Definition: dgTypes.h:728
dgAtomicExchangeAndAdd
DG_INLINE dgInt32 dgAtomicExchangeAndAdd(dgInt32 *const addend, dgInt32 amount)
Definition: dgTypes.h:779
dgUnsigned32
unsigned dgUnsigned32
Definition: dgTypes.h:219
dgFloatExceptions::~dgFloatExceptions
~dgFloatExceptions()
Definition: dgTypes.h:742
dgPrefetchMem
DG_INLINE void dgPrefetchMem(const void *const mem)
Definition: dgTypes.h:823
dgTriplex::m_z
dgFloat32 m_z
Definition: dgTypes.h:242
semaphore.h
dgReportProgress
bool(dgApi * dgReportProgress)(dgFloat32 progressNormalzedPercent, void *const userData)
Definition: dgTypes.h:281
dgSign
DG_INLINE T dgSign(T A)
Definition: dgTypes.h:331
dgEPSILON
#define dgEPSILON
Definition: dgTypes.h:249
dgFloatSign::m_fVal
dgFloat32 m_fVal
Definition: dgTypes.h:593
dgUnsigned16
unsigned short dgUnsigned16
Definition: dgTypes.h:216
dgFloatExceptions::m_InvalidDenormalAndivideByZero
Definition: dgTypes.h:727
dgDeserializeMarker
void dgDeserializeMarker(dgDeserialize serializeCallback, void *const userData)
Definition: dgTypes.cpp:488
dgFastInt
DG_INLINE dgInt32 dgFastInt(dgFloat64 x)
Definition: dgTypes.h:642
dgSerializeMarker
void dgSerializeMarker(dgSerialize serializeCallback, void *const userData)
Definition: dgTypes.cpp:481
dgCeil
DG_INLINE dgFloat32 dgCeil(dgFloat32 x)
Definition: dgTypes.h:672
dgSort
void dgSort(T *const array, dgInt32 elements, dgInt32(*compare)(const T *const A, const T *const B, void *const context), void *const context=NULL)
Definition: dgTypes.h:438
sched_yield
PTW32_DLLPORT int __cdecl sched_yield(void)
Definition: sched_yield.c:42
dgSetPrecisionDouble::~dgSetPrecisionDouble
~dgSetPrecisionDouble()
Definition: dgTypes.h:766
dgSetPrecisionDouble
Definition: dgTypes.h:754
dgTriplex::m_x
dgFloat32 m_x
Definition: dgTypes.h:240
dgDoubleInt::m_ptr
void * m_ptr
Definition: dgTypes.h:603
dgBigVector
Definition: dgVector.h:207
dgTriplex
Definition: dgTypes.h:237
dgVertexListToIndexList
dgInt32 dgVertexListToIndexList(dgFloat32 *const vertexList, dgInt32 strideInBytes, dgInt32 floatSizeInBytes, dgInt32 unsignedSizeInBytes, dgInt32 vertexCount, dgInt32 *const indexListOut, dgFloat32 tolerance=dgEPSILON)
Definition: dgTypes.cpp:446
dgSortIndirect
void dgSortIndirect(T **const array, dgInt32 elements, dgInt32(*compare)(const T *const A, const T *const B, void *const context), void *const context=NULL)
Definition: dgTypes.h:508