Skip to content

Commit

Permalink
Tweaked: Component cache inlining
Browse files Browse the repository at this point in the history
Added: GAIA_LAMDAINLINE
  • Loading branch information
richardbiely committed Sep 19, 2023
1 parent fc4b1fe commit cb873f5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
16 changes: 14 additions & 2 deletions include/gaia/config/config_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ namespace gaia {
#define GAIA_CLZ(x) \
([](uint32_t value) noexcept { \
unsigned long index; \
return _BitScanForward(&index, value) ? (uint32_t)index : (uint32_t)32; \
return _BitScanForward(&index, value) ? (uint32_t)index : (uint32_t)32; \
}(x))
#pragma intrinsic(_BitScanForward64)
//! Returns the number of leading zeros of \param x or 64 if \param x is 0.
//! \warning Little-endian format.
#define GAIA_CLZ64(x) \
([](uint64_t value) noexcept { \
unsigned long index; \
return _BitScanForward64(&index, value) ? (uint32_t)index : (uint32_t)64; \
return _BitScanForward64(&index, value) ? (uint32_t)index : (uint32_t)64; \
}(x))

#pragma intrinsic(_BitScanReverse)
Expand Down Expand Up @@ -426,6 +426,18 @@ namespace gaia {
#define GAIA_NOINLINE
#endif

#if GAIA_COMPILER_MSVC
#if _MSC_VER >= 1927 // MSVC 16.7
#define GAIA_LAMBDAINLINE [[msvc::forceinline]]
#else
#define GAIA_LAMBDAINLINE
#endif
#elif GAIA_COMPILER_CLANG || GAIA_COMPILER_GCC
#define GAIA_LAMBDAINLINE __attribute__((always_inline))
#else
#define GAIA_LAMBDAINLINE
#endif

//------------------------------------------------------------------------------

#if GAIA_COMPILER_MSVC
Expand Down
7 changes: 4 additions & 3 deletions include/gaia/ecs/component_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "component.h"
#include "component_desc.h"
#include "component_info.h"
#include "gaia/config/config_core.h"

namespace gaia {
namespace ecs {
Expand Down Expand Up @@ -43,11 +44,11 @@ namespace gaia {
//! Registers the component info for \tparam T. If it already exists it is returned.
//! \return Component info
template <typename T>
GAIA_NODISCARD const component::ComponentInfo& GetOrCreateComponentInfo() {
GAIA_NODISCARD GAIA_FORCEINLINE const component::ComponentInfo& GetOrCreateComponentInfo() {
using U = typename component::DeduceComponent<T>::Type;
const auto componentId = component::GetComponentId<T>();

auto createInfo = [&]() -> const component::ComponentInfo& {
auto createInfo = [&]() GAIA_LAMBDAINLINE -> const component::ComponentInfo& {
const auto* pInfo = component::ComponentInfo::Create<U>();
m_infoByIndex[componentId] = pInfo;
m_descByIndex[componentId] = component::ComponentDesc::Create<U>();
Expand Down Expand Up @@ -84,7 +85,7 @@ namespace gaia {
//! Returns the component info given the \param componentId.
//! \warning It is expected the component info with a given component id exists! Undefined behavior otherwise.
//! \return Component info
GAIA_NODISCARD const component::ComponentInfo&
GAIA_NODISCARD GAIA_FORCEINLINE const component::ComponentInfo&
GetComponentInfo(component::ComponentId componentId) const noexcept {
GAIA_ASSERT(componentId < m_infoByIndex.size());
const auto* pInfo = m_infoByIndex[componentId];
Expand Down
22 changes: 17 additions & 5 deletions single_include/gaia.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ namespace gaia {
#define GAIA_CLZ(x) \
([](uint32_t value) noexcept { \
unsigned long index; \
return _BitScanForward(&index, value) ? (uint32_t)index : (uint32_t)32; \
return _BitScanForward(&index, value) ? (uint32_t)index : (uint32_t)32; \
}(x))
#pragma intrinsic(_BitScanForward64)
//! Returns the number of leading zeros of \param x or 64 if \param x is 0.
//! \warning Little-endian format.
#define GAIA_CLZ64(x) \
([](uint64_t value) noexcept { \
unsigned long index; \
return _BitScanForward64(&index, value) ? (uint32_t)index : (uint32_t)64; \
return _BitScanForward64(&index, value) ? (uint32_t)index : (uint32_t)64; \
}(x))

#pragma intrinsic(_BitScanReverse)
Expand Down Expand Up @@ -426,6 +426,18 @@ namespace gaia {
#define GAIA_NOINLINE
#endif

#if GAIA_COMPILER_MSVC
#if _MSC_VER >= 1927 // MSVC 16.7
#define GAIA_LAMBDAINLINE [[msvc::forceinline]]
#else
#define GAIA_LAMBDAINLINE
#endif
#elif GAIA_COMPILER_CLANG || GAIA_COMPILER_GCC
#define GAIA_LAMBDAINLINE __attribute__((always_inline))
#else
#define GAIA_LAMBDAINLINE
#endif

//------------------------------------------------------------------------------

#if GAIA_COMPILER_MSVC
Expand Down Expand Up @@ -10357,11 +10369,11 @@ namespace gaia {
//! Registers the component info for \tparam T. If it already exists it is returned.
//! \return Component info
template <typename T>
GAIA_NODISCARD const component::ComponentInfo& GetOrCreateComponentInfo() {
GAIA_NODISCARD GAIA_FORCEINLINE const component::ComponentInfo& GetOrCreateComponentInfo() {
using U = typename component::DeduceComponent<T>::Type;
const auto componentId = component::GetComponentId<T>();

auto createInfo = [&]() -> const component::ComponentInfo& {
auto createInfo = [&]() GAIA_LAMBDAINLINE -> const component::ComponentInfo& {
const auto* pInfo = component::ComponentInfo::Create<U>();
m_infoByIndex[componentId] = pInfo;
m_descByIndex[componentId] = component::ComponentDesc::Create<U>();
Expand Down Expand Up @@ -10398,7 +10410,7 @@ namespace gaia {
//! Returns the component info given the \param componentId.
//! \warning It is expected the component info with a given component id exists! Undefined behavior otherwise.
//! \return Component info
GAIA_NODISCARD const component::ComponentInfo&
GAIA_NODISCARD GAIA_FORCEINLINE const component::ComponentInfo&
GetComponentInfo(component::ComponentId componentId) const noexcept {
GAIA_ASSERT(componentId < m_infoByIndex.size());
const auto* pInfo = m_infoByIndex[componentId];
Expand Down

0 comments on commit cb873f5

Please sign in to comment.