You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
namespace detail
{
constexpr bool is_constant_evaluated()
{
#if __cpp_lib_is_constant_evaluated >= 201811
return std::is_constant_evaluated();
#else
// The user's compiler doesn't support std::is_constant_evaluated().
// This should be a user-configurable switch to decide if they want
// SIMD or constexpr (since they have to choose one or the other).
return true;
#endif
}
}
constexpr glm::vec4 some_function()
{
if (detail::is_constant_evaluated())
{
// standard c++ implementation
}
else
{
// SIMD implementation, you can do anything here, intrinsics, reinterpret_cast, etc
}
}
In the above example, if the user's compiler supports std::is_constant_evaluated(), this works exactly as expected:
constexpr auto slow_but_compile_time_version = some_function();
const auto fast_runtime_version = some_function();
On older compilers, depending on the value of the user-configurable switch, fast_runtime_version would become "slow" version, or slow_but_compile_time_version would not compile. This is the current behavior, forcing the user to decide between constexpr and SIMD.
The text was updated successfully, but these errors were encountered:
@PazerOP
I’ve made a draft pr that implements support for using simd and constexpr simultaneously: #1313
note that you have to set this define before including glm headers for it to work: #define GLM_SIMD_CONSTEXPR 1
Also three other things to note:
this pr makes use of gcc’s vector extensions for the simd part of the constructors, so it’s only compatible with gcc and clang
Only constexpr constructor support is added, the operator overloads don’t currently work at compile time
Directly using swizzling expressions when calling c-style va_arg functions is broken (ex: printf("%f\n", v.y); always prints 0.0000). C++-style variadic template functions should work fine tho <- fixed
UPDATE: I've now added constexpr support to the operators as well.
I think my draft PR is definitely getting closer to being able to become a real PR, I think I just need to clean up the code a bit more...
With C++20 and
std::is_constant_evaluated()
, it becomes possible to provide both simd and constexpr:In the above example, if the user's compiler supports
std::is_constant_evaluated()
, this works exactly as expected:On older compilers, depending on the value of the user-configurable switch,
fast_runtime_version
would become "slow" version, orslow_but_compile_time_version
would not compile. This is the current behavior, forcing the user to decide between constexpr and SIMD.The text was updated successfully, but these errors were encountered: