111 lines
3.5 KiB
C
111 lines
3.5 KiB
C
// =====================================================================================================================
|
|
// fennec, a free and open source game engine
|
|
// Copyright (C) 2025 Medusa Slockbower
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
// =====================================================================================================================
|
|
|
|
|
|
#ifndef FENNEC_LANG_INTRINSICS_H
|
|
#define FENNEC_LANG_INTRINSICS_H
|
|
|
|
// Most major compilers support __has_builtin, notably GCC, MINGW, CLANG, and MSVC
|
|
#if defined(__has_builtin)
|
|
|
|
|
|
// bitcast is slightly more efficient for build times than using memcpy
|
|
#if __has_builtin(__builtin_bit_cast)
|
|
# define FENNEC_HAS_BUILTIN_BIT_CAST 1
|
|
# define FENNEC_BUILTIN_BIT_CAST(type, arg) __builtin_bit_cast(type, arg)
|
|
#else
|
|
# define FENNEC_HAS_BUILTIN_BIT_CAST 0
|
|
#endif
|
|
|
|
// addressof is very difficult to implement without intrinsics.
|
|
#if __has_builtin(__builtin_addressof)
|
|
# define FENNEC_HAS_BUILTIN_ADDRESSOF 1
|
|
# define FENNEC_BUILTIN_ADDRESSOF(arg) __builtin_addressof(arg)
|
|
#else
|
|
# define FENNEC_HAS_BUILTIN_ADDRESSOF 0
|
|
#endif
|
|
|
|
|
|
// Type Traits
|
|
|
|
// can_convert is also very difficult to implement without intrinsics
|
|
#if __has_builtin(__is_convertible)
|
|
# define FENNEC_HAS_BUILTIN_CAN_CONVERT 1
|
|
# define FENNEC_BUILTIN_CAN_CONVERT(arg0, arg1) __is_convertible(arg0, arg1)
|
|
#else
|
|
# define FENNEC_HAS_BUILTIN_CAN_CONVERT 0
|
|
#endif
|
|
|
|
// Inconsistent without intrinsics.
|
|
#if __has_builtin(__is_empty)
|
|
# define FENNEC_HAS_BUILTIN_IS_EMPTY 1
|
|
# define FENNEC_BUILTIN_IS_EMPTY(arg) __is_empty(arg)
|
|
#else
|
|
# define FENNEC_HAS_BUILTIN_IS_EMPTY 0
|
|
#endif
|
|
|
|
// Inconsistent without intrinsics
|
|
#if __has_builtin(__is_polymorphic)
|
|
# define FENNEC_HAS_BUILTIN_IS_POLYMORPHIC 1
|
|
# define FENNEC_BUILTIN_IS_POLYMORPHIC(arg) __is_polymorphic(arg)
|
|
#else
|
|
# define FENNEC_HAS_BUILTIN_IS_POLYMORPHIC 0
|
|
#endif
|
|
|
|
// Inconsistent without intrinsics
|
|
#if __has_builtin(__is_final)
|
|
# define FENNEC_HAS_BUILTIN_IS_FINAL 1
|
|
# define FENNEC_BUILTIN_IS_FINAL(arg) __is_final(arg)
|
|
#else
|
|
# define FENNEC_HAS_BUILTIN_IS_FINAL 0
|
|
#endif
|
|
|
|
// Inconsistent without intrinsics
|
|
#if __has_builtin(__is_abstract)
|
|
# define FENNEC_HAS_BUILTIN_IS_ABSTRACT 1
|
|
# define FENNEC_BUILTIN_IS_ABSTRACT(arg) __is_abstract(arg)
|
|
#else
|
|
# define FENNEC_HAS_BUILTIN_IS_ABSTRACT 0
|
|
#endif
|
|
|
|
// Impossible without instrinsics
|
|
#if __has_builtin(__is_standard_layout)
|
|
# define FENNEC_HAS_BUILTIN_IS_STANDARD_LAYOUT 1
|
|
# define FENNEC_BUILTIN_IS_STANDARD_LAYOUT(arg) __is_standard_layout(arg)
|
|
#else
|
|
# define FENNEC_HAS_BUILTIN_IS_STANDARD_LAYOUT 0
|
|
#endif
|
|
|
|
// Difficult and Inconsistent without intrinsics
|
|
#if __has_builtin(__is_constructible)
|
|
# define FENNEC_BUILTIN_CAN_CONSTRUCT 1
|
|
# define FENNEC_BUILTIN_CAN_CONSTRUCT(type, args...) __is_constructible(type, args)
|
|
#else
|
|
# define FENNEC_HAS_BUILTIN_CAN_CONSTRUCT 0
|
|
#endif
|
|
|
|
|
|
// For compilers without or differently named builtins
|
|
#else
|
|
|
|
// TODO: More compiler support
|
|
|
|
#endif
|
|
|
|
#endif // FENNEC_LANG_INTRINSICS_H
|