-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rcore] sinfl_bsr fix for TCC #4807
Conversation
@RicoP This change could be changing the behaviour for other configurations and result in unexpected issues. Are you completely sure that it can be replaced by an Also, note that this change is on an external library, it shouldn't be implemented on raylib side... |
Well the current implementation leaves a function with no return statement causing undefined behavior static int
sinfl_bsr(unsigned n) {
#if defined(_MSC_VER) && !defined(__clang__)
_BitScanReverse(&n, n);
return n;
#elif defined(__GNUC__) || defined(__clang__)
return 31 - __builtin_clz(n);
#endif
} an alternative fix could be this with an explicit error static int
sinfl_bsr(unsigned n) {
#if defined(_MSC_VER) && !defined(__clang__)
_BitScanReverse(&n, n);
return n;
#elif defined(__GNUC__) || defined(__clang__) || defined(__TINYC__)
return 31 - __builtin_clz(n);
#else
#error "unknown compiler."
#endif
} another alternative is to of course implement __builtin_clz by hand in the else branch. I could also open a PR on the original repo but I figured it's quicker to do here. |
static int
sinfl_bsr(unsigned n) {
#if defined(_MSC_VER) && !defined(__clang__)
_BitScanReverse(&n, n);
return n;
#elif defined(__GNUC__) || defined(__clang__) || defined(__TINYC__)
return 31 - __builtin_clz(n);
#else
static const unsigned char table_2_32[32] = {
31, 22, 30, 21, 18, 10, 29, 2, 20, 17, 15, 13, 9, 6, 28, 1,
23, 19, 11, 3, 16, 14, 7, 24, 12, 4, 8, 25, 5, 26, 27, 0
};
n |= n >> 1;
n |= n >> 2;
n |= n >> 4;
n |= n >> 8;
n |= n >> 16;
n = table_2_32[(n * 0x07c4acddu) >> 27];
return 31 - n;
#endif
} I got this from https://github.com/TinyCC/tinycc/blob/6ec4a106524ab6a6e3a4178774fd1e884d3fcce2/lib/builtin.c#L50 |
I created a PR for the original lib, let's see what the author says. vurtun/lib#54 |
@raysan5 seems like my pr got merged |
@RicoP nice, can you update this PR accordingly? thanks! |
@raysan5 done |
OK seems MSVC didn't liked a C++ cast |
@RicoP thanks for the review! |
under TCC sinfl_bsr returned no value.