File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,18 @@ assert can have unique static variables associated with it.
80
80
#define SDL_TriggerBreakpoint ()
81
81
#endif
82
82
83
+ #if defined(_MSC_VER ) && (_MSC_VER > 1400 )
84
+ #define SDL_Assume (cond ) __assume(cond)
85
+ #elif _SDL_HAS_BUILTIN (__builtin_assume )
86
+ #define SDL_Assume (cond ) __builtin_assume(cond)
87
+ #elif defined(__clang__ ) || (defined(__GNUC__ ) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4 )))
88
+ #define SDL_Assume (cond ) do { \
89
+ (__builtin_expect(!(cond), 0) ? __builtin_unreachable() : (void)0); \
90
+ } while (0)
91
+ #else
92
+ #define SDL_Assume (cond )
93
+ #endif
94
+
83
95
#if defined(__STDC_VERSION__ ) && (__STDC_VERSION__ >= 199901L ) /* C99 supports __func__ as a standard. */
84
96
# define SDL_FUNCTION __func__
85
97
#elif ((defined(__GNUC__ ) && (__GNUC__ >= 2 )) || defined(_MSC_VER ) || defined (__WATCOMC__ ))
Original file line number Diff line number Diff line change @@ -438,7 +438,25 @@ static int TestAssertions(SDL_bool verbose)
438
438
return 0 ;
439
439
}
440
440
441
+ <<<<<<< HEAD
441
442
int main (int argc , char * argv [])
443
+ == == == =
444
+ int
445
+ TestAssume (SDL_bool verbose )
446
+ {
447
+ int max , count , i ;
448
+
449
+ max = 16 ;
450
+ srand (time (0 ));
451
+ count = rand () % max ;
452
+ SDL_Assume (count <= max );
453
+ for (i = 0 ; i < count ; i ++ );
454
+ return (0 );
455
+ }
456
+
457
+ int
458
+ main (int argc , char * argv [])
459
+ >>>>>>> bfb4ecda9 (Adding SDL_Assume macro to give hint to the optimiser )
442
460
{
443
461
int i ;
444
462
SDL_bool verbose = SDL_TRUE ;
@@ -483,6 +501,7 @@ int main(int argc, char *argv[])
483
501
status += Test64Bit (verbose );
484
502
status += TestCPUInfo (verbose );
485
503
status += TestAssertions (verbose );
504
+ status += TestAssume (verbose );
486
505
487
506
SDLTest_CommonDestroyState (state );
488
507
You can’t perform that action at this time.
0 commit comments