Unstarted attempt at writing a procedural Rust macro for generating geometric algebra implementations given a specified metric and choice of basis blades and their storage pattern.
'Procedural' means it's a program that runs inside the compiler at compile time and can do arbitrary processing (as opposed to 'declarative' macros which are more limited, like C preprocessor ones). They come in three kinds:
-
'derive' proc macros get applied to data structures, so I guess you'd specify the basis blade choices and ordering most directly this way
-
'attribute' proc macros get applied to anything, this could be used to maybe e.g. write executable maths in TeX notation directly in your code
-
'function-like' proc macros seem the simplest approach, they're invoked directly and passed arguments like a function, and return Rust code to be compiled
It would also be nice to be able to program specialized implementation details, like using SIMD intrinsics for efficiency when you know how the geometric elements are going to be used.
Pinned topics in macros
channel at Rust discord.
Reverse Polish Notation implemented in a declarative macro.
Support library, parsing and quasi-quoting crates.
Geometric Algebra for Computer Science [by Dorst, Fontijne, Mann, 2007]'s unoptimized Java reference implementation, included in a folder in this repository.
Daniel Fontijne's 29MB PhD thesis "Efficient Implementation of Geometric Algebra" describing the Gaigen 2
system in more detail than the book.
The vek
crate for graphics maths is targeting the same sort of domain as we'd like to generate code for.
List of all SIMD intrinsics used in Klein, _mm_
prefixes trimmed
grep -hor _mm_[a-z0-9_]* klein/src/* | sort | uniq
# -h = don't show file names, -o = only show matching words not context
add_ps, add_ss, andnot_ps, and_ps, blend_ps, castsi128_ps, cmpeq_ps, cmplt_ps, dp_ps, loadu_ps, movehdup_ps, movehl_ps, moveldup_ps, movelh_ps, movemask_ps, mul_ps, mul_ss, rcp_ps, rsqrt_ps, set1_ps, set_epi32, set_ps, set_ss, setzero_ps, shuffle_ps, store_ps, store_ss, storeu_ps, sub_ps, sub_ss, swizzle_ps, unpackhi_ps, unpacklo_ps, xor_ps,