Skip to content

Commit

Permalink
allow simd constexpr vec to work on arches such as riscv
Browse files Browse the repository at this point in the history
glm only utilizes simd intrinsics for aarch64 and x86_64, but other platforms will now benefit from the arch-agnostic simd constructors and arithmetic operators used in the c++20 vec implementation
  • Loading branch information
sharkautarch committed Dec 26, 2024
1 parent c273819 commit 2cfafd5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions glm/detail/qualifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace detail
};
# endif

#if (defined(__clang__) || defined(__GNUC__)) && (GLM_LANG_CXX20_FLAG & GLM_LANG)
#if ((defined(__clang__) || defined(__GNUC__)) && (GLM_LANG_CXX20_FLAG & GLM_LANG)) && GLM_SIMD_CONSTEXPR
template <typename T>
static constexpr size_t requiredAlignment = alignof(T);

Expand All @@ -127,7 +127,7 @@ namespace detail
struct storage<2, T, true>
{
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
typedef VType type __attribute__((aligned(sizeof(VType)),vector_size(2*sizeof(VType))));
typedef VType type __attribute__((aligned(2*sizeof(VType)),vector_size(2*sizeof(VType))));
};

template<typename T>
Expand All @@ -149,6 +149,14 @@ namespace detail
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
typedef VType type __attribute__((aligned( requiredAlignment<T> ), vector_size(4*sizeof(VType))));
};
# if (!(GLM_ARCH & GLM_ARCH_SIMD_BIT))
template<typename T>
struct storage<4, T, true>
{
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
typedef VType type __attribute__((aligned(4*sizeof(VType)),vector_size(sizeof(VType))));
};
# endif
#endif

# if GLM_ARCH & GLM_ARCH_SSE2_BIT
Expand Down
2 changes: 1 addition & 1 deletion glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ namespace detail
# define GLM_FORCE_ALIGNED_GENTYPES
#endif

#if GLM_HAS_ALIGNOF && (GLM_LANG & GLM_LANG_CXXMS_FLAG) && (defined(GLM_FORCE_ALIGNED_GENTYPES) || (GLM_CONFIG_SIMD == GLM_ENABLE))
#if (GLM_HAS_ALIGNOF && (GLM_LANG & GLM_LANG_CXXMS_FLAG) && (defined(GLM_FORCE_ALIGNED_GENTYPES) || (GLM_CONFIG_SIMD == GLM_ENABLE))) || GLM_SIMD_CONSTEXPR
# define GLM_CONFIG_ALIGNED_GENTYPES GLM_ENABLE
#else
# define GLM_CONFIG_ALIGNED_GENTYPES GLM_DISABLE
Expand Down
1 change: 1 addition & 0 deletions glm/detail/simd_constexpr/vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <variant>
#include <cstring>
#include <ranges>
#include <algorithm>
namespace glm
{
#ifdef __clang__
Expand Down

0 comments on commit 2cfafd5

Please sign in to comment.