Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: constexpr vec (constructors & operators) when using simd #1313

Draft
wants to merge 59 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
9806342
wip: constexpr vec (constructors) when using simd
sharkautarch Sep 11, 2024
0614e7a
simd constexpr vec: support packed vecs
sharkautarch Sep 11, 2024
02a5163
constexpr simd vec: add all the operators
sharkautarch Sep 11, 2024
8e86332
simd constexpr vec: fix all the compile errors
sharkautarch Sep 11, 2024
dfe35ac
simd constexpr vec: add test thingy
sharkautarch Sep 11, 2024
f0b305c
simd constexpr vec: fix some compile-time and run-time issues
sharkautarch Sep 11, 2024
d950f21
constexpr simd vec: fix more runtime issues
sharkautarch Sep 11, 2024
21b51c9
constexpr simd vec: add constructor for vec1->vec[4,3,2]
sharkautarch Sep 11, 2024
2c236f4
simd constexpr vec: allow SIMD bit to be set if GLM_SIMD_CONSTEXPR == 1
sharkautarch Sep 12, 2024
bc5c672
simd constexpr vec: fix errors when building w/ gcc
sharkautarch Sep 12, 2024
2ad1ffa
constexpr simd vec: fix more things
sharkautarch Sep 12, 2024
90b74f1
simd constexpr vec: fix a couple more compile errors
sharkautarch Sep 13, 2024
6b6f0e4
constexpr simd vec: fix a runtime error and a compile warning
sharkautarch Sep 13, 2024
012df5e
constexpr simd vec: various improvements
sharkautarch Sep 14, 2024
da8fe30
simd constexpr vec: fix compiler error on clang
sharkautarch Sep 14, 2024
7f7eb3c
constexpr simd vec: simd helpers: apply always_inline attribute
sharkautarch Sep 14, 2024
3e20cc6
constexpr simd vec: perf tuning for packed vec3
sharkautarch Sep 15, 2024
d5f8676
constexpr simd vec: mixed element type constructor: fix nullptr being…
sharkautarch Sep 15, 2024
7144171
simd constexpr vec: more improvement
sharkautarch Sep 15, 2024
9dcb526
constexpr simd vec: fix other issue w/ std::ranges::copy in ctor
sharkautarch Sep 17, 2024
2e6aa64
simd constexpr vec: allow converting bigger vec to smaller vec, plus …
sharkautarch Sep 24, 2024
8bbb887
simd constexpr vec: various fixes, some perf tuning, some code tidying
sharkautarch Sep 26, 2024
4620fae
simd constexpr vec: fix syntax error
sharkautarch Sep 26, 2024
b21be86
simd constexpr vec: small change and fix
sharkautarch Sep 27, 2024
c5c4b90
simd constexpr vec: refactor to support constexpr for both operator[]s'
sharkautarch Oct 5, 2024
4f5d589
simd constexpr vec: introduce new function compWiseTernary for bvec, …
sharkautarch Oct 5, 2024
55a64cf
simd constexpr vec: compWiseTernary, swizzle functions: construct the…
sharkautarch Oct 6, 2024
35d73f1
simd constexpr vec: fix compiler error
sharkautarch Oct 8, 2024
f7e57a5
simd constexpr vec: fix another compiler error
sharkautarch Oct 8, 2024
4567851
simd constexpr vec: fix yet another compiler error
sharkautarch Oct 8, 2024
465bf42
simd constexpr vec: fix yet another compiler error #2
sharkautarch Oct 8, 2024
aca3969
simd constexpr vec: fix yet another compiler error #3
sharkautarch Oct 8, 2024
99eb85e
simd constexpr vec: slight tweaks
sharkautarch Oct 8, 2024
b1e0879
simd constexpr vec: slight tweaks
sharkautarch Oct 8, 2024
6d5d26a
glm constexpr vec: fix syntax error
sharkautarch Oct 9, 2024
b463cf9
slight tweaks & promote inlining
sharkautarch Dec 13, 2024
05ce19a
adjustment
sharkautarch Dec 14, 2024
d861484
more adjustments
sharkautarch Dec 25, 2024
c227593
fix clang compile error
sharkautarch Dec 25, 2024
8f0048a
More adjustments for better codegen
sharkautarch Dec 25, 2024
c273819
cleanup my stuff in qualifiers
sharkautarch Dec 26, 2024
3a63220
allow simd constexpr vec to work on arches such as riscv
sharkautarch Dec 26, 2024
547cd7c
allow for swizzling w/ undefined components
sharkautarch Dec 27, 2024
babe723
fix issue w/ the wrong vector size for aligned vec4 for archs like riscv
sharkautarch Dec 27, 2024
d0bb19a
fix typo
sharkautarch Dec 27, 2024
1f76077
add simd blend function, & some other cleanups
sharkautarch Dec 28, 2024
0fc32cb
support compile time evaluation for all operators
sharkautarch Dec 28, 2024
aa19fb1
remove __restrict__ qualifier
sharkautarch Dec 28, 2024
38527c3
simd constexpr vec: use our own functor, functor2 implementations
sharkautarch Dec 28, 2024
839ec52
fix various compiler errors and warnings
sharkautarch Dec 28, 2024
376aa06
slight tweak
sharkautarch Dec 28, 2024
9d77485
simd constexpr vec: improve codegen even more.
sharkautarch Dec 31, 2024
ac32f54
simd constexpr vec: cleanup simd_helpers.inl & attempt to improve cod…
sharkautarch Jan 3, 2025
8eea93b
simd constexpr vec: fix compiler errors
sharkautarch Jan 4, 2025
822e191
fix other compiler error
sharkautarch Jan 4, 2025
228d028
more better
sharkautarch Jan 4, 2025
39ef1ab
fix compiler error
sharkautarch Jan 4, 2025
3a1091d
fix compiler error
sharkautarch Jan 4, 2025
fda04e7
fix compiler error
sharkautarch Jan 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,271 changes: 1,271 additions & 0 deletions glm/detail/_swizzle_func_gcc_vec.hpp

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion glm/detail/_vectorize.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#if GLM_SIMD_CONSTEXPR == 1
#include "simd_constexpr/_vectorize.hpp"
#else
namespace glm{
namespace detail
{
Expand Down Expand Up @@ -228,3 +230,4 @@ namespace detail
};
}//namespace detail
}//namespace glm
#endif
73 changes: 72 additions & 1 deletion glm/detail/qualifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,77 @@ namespace detail
T data[L];
} type;
};

#if ((defined(__clang__) || defined(__GNUC__)) && (GLM_LANG_CXX20_FLAG & GLM_LANG)) && GLM_SIMD_CONSTEXPR
# if GLM_HAS_ALIGNOF
template<length_t L, typename T>
struct storage<L, T, true>
{
typedef struct alignas(L * sizeof(T)) type {
T data[L];
} type;
};
# endif
template <typename T>
static constexpr size_t requiredAlignment = alignof(T);

template<typename T>
struct __attribute__((packed,aligned(requiredAlignment<T>))) storage<2, T, false>
{
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
typedef VType type __attribute__((aligned( requiredAlignment<T> ), vector_size(2*sizeof(VType))));
};
template<typename T>
struct __attribute__((packed,aligned(requiredAlignment<T>))) storage<1, T, false>
{
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
typedef VType type __attribute__((aligned( requiredAlignment<T> ),vector_size(sizeof(VType))));
};
template<typename T>
struct storage<2, T, true>
{
using VType = std::conditional_t< std::is_same_v<T, bool>, uint8_t, T>;
typedef VType type __attribute__((aligned(2*sizeof(VType)),vector_size(2*sizeof(VType))));
};

template<typename T>
struct storage<1, 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(sizeof(VType))));
};
template <typename T>
struct __attribute__((packed,aligned(requiredAlignment<T>))) storage<3, T, false>
{
typedef struct __attribute__((packed,aligned(requiredAlignment<T>))) type {
T data[3];
} type;
};
template <typename T>
struct __attribute__((packed,aligned(requiredAlignment<T>))) storage<4, T, false>
{
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(4*sizeof(VType))));
};
template<typename T>
struct storage<3, 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(4*sizeof(VType))));
};
template<>
struct storage<4, bool, true>
{
typedef uint8_t type __attribute__((aligned(4*sizeof(uint8_t)),vector_size(4*sizeof(uint8_t))));
};
# endif
#else
# if GLM_HAS_ALIGNOF
template<length_t L, typename T>
struct storage<L, T, true>
Expand All @@ -106,6 +176,7 @@ namespace detail
} type;
};
# endif
#endif

# if GLM_ARCH & GLM_ARCH_SSE2_BIT
template<>
Expand Down
4 changes: 2 additions & 2 deletions glm/detail/setup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@

// N2235 Generalized Constant Expressions http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf
// N3652 Extended Constant Expressions http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3652.html
#if (GLM_ARCH & GLM_ARCH_SIMD_BIT) // Compiler SIMD intrinsics don't support constexpr...
#if (GLM_ARCH & GLM_ARCH_SIMD_BIT) && GLM_SIMD_CONSTEXPR == 0 // Compiler SIMD intrinsics don't support constexpr...
# define GLM_HAS_CONSTEXPR 0
#elif (GLM_COMPILER & GLM_COMPILER_CLANG)
# define GLM_HAS_CONSTEXPR __has_feature(cxx_relaxed_constexpr)
Expand Down 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
92 changes: 92 additions & 0 deletions glm/detail/simd_constexpr/_vectorize.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#pragma once
namespace glm{
namespace detail
{
template<template<length_t L, typename T, qualifier Q> class vec, length_t L, typename R, typename T, qualifier Q>
struct functor1
{
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, R, Q> call(R (*Func) (T x), vec<L, T, Q> const& v)
{
vec<L, R, Q> ret{v};
#pragma GCC unroll(4)
for (int i = 0; i < L; i++) {
ret[i] = Func(v[i]);
}
return ret;
}
};


template<template<length_t L, typename T, qualifier Q> class vec, length_t L, typename T, qualifier Q>
struct functor2
{
GLM_FUNC_QUALIFIER static vec<L, T, Q> call(T (*Func) (T x, T y), vec<L, T, Q> a, vec<L, T, Q> const& b)
{
vec<L, T, Q> ret{a};
#pragma GCC unroll(4)
for (int i = 0; i < L; i++) {
ret[i] = Func(a[i], b[i]);
}
return ret;
}

template<typename Fct>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(Fct Func, vec<L, T, Q> a, vec<L, T, Q> const& b)
{
vec<L, T, Q> ret{a};
#pragma GCC unroll(4)
for (int i = 0; i < L; i++) {
ret[i] = Func(a[i], b[i]);
}
return ret;
}
};

template<template<length_t L, typename T, qualifier Q> class vec, length_t L, typename T, qualifier Q>
struct functor2_vec_sca{
GLM_FUNC_QUALIFIER static vec<L, T, Q> call(T (*Func) (T x, T y), vec<L, T, Q> a, T b)
{
vec<L, T, Q> ret{a};
#pragma GCC unroll(4)
for (int i = 0; i < L; i++) {
ret[i] = Func(a[i], b);
}
return ret;
}
template<class Fct>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, T, Q> call(Fct Func, vec<L, T, Q> a, T b)
{
vec<L, T, Q> ret{a};
#pragma GCC unroll(4)
for (int i = 0; i < L; i++) {
ret[i] = Func(a[i], b);
}
return ret;
}
};

template<length_t L, typename T, qualifier Q>
struct functor2_vec_int {
GLM_FUNC_QUALIFIER static vec<L, int, Q> call(int (*Func) (T x, int y), vec<L, T, Q> const& a, vec<L, int, Q> b)
{
vec<L, int, Q> ret{b};
#pragma GCC unroll(4)
for (int i = 0; i < L; i++) {
ret[i] = Func(a[i], b[i]);
}
return ret;
}

template<class Fct>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<L, int, Q> call(Fct Func, vec<L, T, Q> const& a, vec<L, int, Q> b)
{
vec<L, int, Q> ret{b};
#pragma GCC unroll(4)
for (int i = 0; i < L; i++) {
ret[i] = Func(a[i], b[i]);
}
return ret;
}
};
}//namespace detail
}//namespace glm
Loading