Skip to content

Commit 3a63220

Browse files
committed
allow simd constexpr vec to work on arches such as riscv
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
1 parent c273819 commit 3a63220

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

glm/detail/qualifier.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace detail
107107
};
108108
# endif
109109

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

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

133133
template<typename T>
@@ -149,6 +149,14 @@ namespace detail
149149
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
150150
typedef VType type __attribute__((aligned( requiredAlignment<T> ), vector_size(4*sizeof(VType))));
151151
};
152+
# if (!(GLM_ARCH & GLM_ARCH_SIMD_BIT))
153+
template<typename T>
154+
struct storage<4, T, true>
155+
{
156+
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
157+
typedef VType type __attribute__((aligned(4*sizeof(VType)),vector_size(sizeof(VType))));
158+
};
159+
# endif
152160
#endif
153161

154162
# if GLM_ARCH & GLM_ARCH_SSE2_BIT

glm/detail/setup.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ namespace detail
883883
# define GLM_FORCE_ALIGNED_GENTYPES
884884
#endif
885885

886-
#if GLM_HAS_ALIGNOF && (GLM_LANG & GLM_LANG_CXXMS_FLAG) && (defined(GLM_FORCE_ALIGNED_GENTYPES) || (GLM_CONFIG_SIMD == GLM_ENABLE))
886+
#if (GLM_HAS_ALIGNOF && (GLM_LANG & GLM_LANG_CXXMS_FLAG) && (defined(GLM_FORCE_ALIGNED_GENTYPES) || (GLM_CONFIG_SIMD == GLM_ENABLE))) || GLM_SIMD_CONSTEXPR
887887
# define GLM_CONFIG_ALIGNED_GENTYPES GLM_ENABLE
888888
#else
889889
# define GLM_CONFIG_ALIGNED_GENTYPES GLM_DISABLE

glm/detail/simd_constexpr/vec.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <variant>
2424
#include <cstring>
2525
#include <ranges>
26+
#include <algorithm>
2627
namespace glm
2728
{
2829
#ifdef __clang__

test/core/core_c++20_simd_constexpr.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#define GLM_SIMD_CONSTEXPR 1
2+
#include <cmath>
23
#include <glm/glm.hpp>
34
#include <glm/vec4.hpp>
45
#include <cstdio>
@@ -15,10 +16,11 @@
1516

1617
int main()
1718
{
19+
#if defined(__x86_64__) || defined(__aarch64__)
1820
static_assert(GLM_ARCH & GLM_ARCH_SIMD_BIT);
1921
static_assert(GLM_CONFIG_SIMD);
2022
static_assert(GLM_ARCH_SIMD_BIT);
21-
23+
#endif
2224

2325
using avec4 = glm::vec<4, float, glm::aligned_highp>;
2426
static constexpr avec4 v{1.0f};//, 1.1f, 1.2f, 1.0f};

0 commit comments

Comments
 (0)