mirror of
https://github.com/love2d/megasource.git
synced 2026-08-21 05:02:11 +02:00
Update OpenAL-soft to 1.23.1-bc7cb17.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#ifdef __has_builtin
|
||||
#define HAS_BUILTIN __has_builtin
|
||||
@@ -11,63 +11,72 @@
|
||||
#define HAS_BUILTIN(x) (0)
|
||||
#endif
|
||||
|
||||
#ifdef __has_cpp_attribute
|
||||
#define HAS_ATTRIBUTE __has_cpp_attribute
|
||||
#else
|
||||
#define HAS_ATTRIBUTE(x) (0)
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define force_inline [[gnu::always_inline]]
|
||||
#define force_inline [[gnu::always_inline]] inline
|
||||
#define NOINLINE [[gnu::noinline]]
|
||||
#elif defined(_MSC_VER)
|
||||
#define force_inline __forceinline
|
||||
#define NOINLINE __declspec(noinline)
|
||||
#else
|
||||
#define force_inline inline
|
||||
#define NOINLINE
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || HAS_BUILTIN(__builtin_expect)
|
||||
/* likely() optimizes for the case where the condition is true. The condition
|
||||
* is not required to be true, but it can result in more optimal code for the
|
||||
* true path at the expense of a less optimal false path.
|
||||
/* Unlike the likely attribute, ASSUME requires the condition to be true or
|
||||
* else it invokes undefined behavior. It's essentially an assert without
|
||||
* actually checking the condition at run-time, allowing for stronger
|
||||
* optimizations than the likely attribute.
|
||||
*/
|
||||
template<typename T>
|
||||
force_inline constexpr bool likely(T&& expr) noexcept
|
||||
{ return __builtin_expect(static_cast<bool>(std::forward<T>(expr)), true); }
|
||||
/* The opposite of likely(), optimizing for the case where the condition is
|
||||
* false.
|
||||
*/
|
||||
template<typename T>
|
||||
force_inline constexpr bool unlikely(T&& expr) noexcept
|
||||
{ return __builtin_expect(static_cast<bool>(std::forward<T>(expr)), false); }
|
||||
|
||||
#else
|
||||
|
||||
template<typename T>
|
||||
force_inline constexpr bool likely(T&& expr) noexcept
|
||||
{ return static_cast<bool>(std::forward<T>(expr)); }
|
||||
template<typename T>
|
||||
force_inline constexpr bool unlikely(T&& expr) noexcept
|
||||
{ return static_cast<bool>(std::forward<T>(expr)); }
|
||||
#endif
|
||||
#define LIKELY(x) (likely(x))
|
||||
#define UNLIKELY(x) (unlikely(x))
|
||||
|
||||
#if HAS_BUILTIN(__builtin_assume)
|
||||
/* Unlike LIKELY, ASSUME requires the condition to be true or else it invokes
|
||||
* undefined behavior. It's essentially an assert without actually checking the
|
||||
* condition at run-time, allowing for stronger optimizations than LIKELY.
|
||||
*/
|
||||
#define ASSUME __builtin_assume
|
||||
#elif defined(_MSC_VER)
|
||||
#define ASSUME __assume
|
||||
#elif defined(__GNUC__)
|
||||
#elif __has_attribute(assume)
|
||||
#define ASSUME(x) [[assume(x)]]
|
||||
#elif HAS_BUILTIN(__builtin_unreachable)
|
||||
#define ASSUME(x) do { if(x) break; __builtin_unreachable(); } while(0)
|
||||
#else
|
||||
#define ASSUME(x) ((void)0)
|
||||
#define ASSUME(x) (static_cast<void>(0))
|
||||
#endif
|
||||
|
||||
/* This shouldn't be needed since unknown attributes are ignored, but older
|
||||
* versions of GCC choke on the attribute syntax in certain situations.
|
||||
*/
|
||||
#if HAS_ATTRIBUTE(likely)
|
||||
#define LIKELY [[likely]]
|
||||
#define UNLIKELY [[unlikely]]
|
||||
#else
|
||||
#define LIKELY
|
||||
#define UNLIKELY
|
||||
#endif
|
||||
|
||||
namespace al {
|
||||
|
||||
template<typename T>
|
||||
constexpr std::underlying_type_t<T> to_underlying(T e) noexcept
|
||||
{ return static_cast<std::underlying_type_t<T>>(e); }
|
||||
|
||||
[[noreturn]] inline void unreachable()
|
||||
{
|
||||
#if HAS_BUILTIN(__builtin_unreachable)
|
||||
__builtin_unreachable();
|
||||
#else
|
||||
ASSUME(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
template<std::size_t alignment, typename T>
|
||||
force_inline constexpr auto assume_aligned(T *ptr) noexcept
|
||||
{
|
||||
#ifdef __cpp_lib_assume_aligned
|
||||
return std::assume_aligned<alignment,T>(ptr);
|
||||
#elif defined(__clang__) || (defined(__GNUC__) && !defined(__ICC))
|
||||
#elif HAS_BUILTIN(__builtin_assume_aligned)
|
||||
return static_cast<T*>(__builtin_assume_aligned(ptr, alignment));
|
||||
#elif defined(_MSC_VER)
|
||||
constexpr std::size_t alignment_mask{(1<<alignment) - 1};
|
||||
|
||||
Reference in New Issue
Block a user