SDL
SDL copied to clipboard
Adding SDL_Assume macro to give hint to the optimiser
with a given condition generating less instructions.
Gcc case: __builtin_unreachable requires gcc >= 4.5, and since you add
the new macro to a public header then please stricten the condition like:
#elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)))
I don't know since when clang supports __builtin_unreachable - the only
version I have is clang-3.4.2 and it just does...
Msvc case: As I remember, __assume() became useful only since VS 2005:
https://stackoverflow.com/questions/3096939/ (and no, I can not remember
since which version it has been supported.) So, I'd avdise strictening
its condition, like: #if defined(_MSC_VER) && (_MSC_VER >= 1400)
oh I did not know you supported sdk so far back...
oh I did not know you supported sdk so far back...
Well, my every-day machine runs on an old CentOS-6.10 and it comes with gcc 4.4.7. I'm one of those said-to-be-extinct dinosaurs :)
A silly question from me: can we not just add the assume keywords to SDL_assert itself? Clang's static analyzer already uses SDL_assert as an assumption that the asserted case must be true (that the analyzer_noreturn part in SDL_assert.h).
(Err...and add some preprocessor magic to keep the assumptions when assertions are disabled, to be clear.)
A silly question from me: can we not just add the assume keywords to SDL_assert itself? Clang's static analyzer already uses SDL_assert as an assumption that the asserted case must be true (that the analyzer_noreturn part in SDL_assert.h).
This seems like a good idea.
Ah ignore my last commit I did not see @icculus wanted to take over.
You can keep going, I haven't looked at this in a year, and just want to make sure I pay attention to it soon. :)
The thing is , looking at it now, I m not sure we can just use SDL_assume like SDL_assert ... on clang.
Do we have any benchmarks showing that this provides any benefit? I'd hate to add something to the API that people will start using to improve their code if it doesn't actually help.