Commit graph

25 commits

Author SHA1 Message Date
Bill Currie
a01cbd56fd [qfcc] Write tests for 3d PGA dot products
And fix the bugs that were uncovered.
2023-08-29 21:30:18 +09:00
Bill Currie
c42aaea060 [qfcc] Write tests for 3d PGA wedge products
And fix the discovered bugs.
2023-08-29 19:42:00 +09:00
Bill Currie
33295a8ad9 [qfcc] Use structs for multi-vector type layouts
Simple k-vectors don't use structs for their layout since they're just
an array of scalars, but having the structs for group sets or full
multi-vectors makes the system alignment agnostic.
2023-08-29 17:10:29 +09:00
Bill Currie
8de722bfc7 [qfcc] Mark large products as unimplemented
Before I forget and wonder why they're not working.
2023-08-28 20:35:03 +09:00
Bill Currie
58a1758363 [qfcc] Implement the regressive product
That went surprisingly well (but it is built up from other ops, so
pretty easy, really).
2023-08-28 20:35:03 +09:00
Bill Currie
e2d812ab6a [qfcc] Implement multi-vector dual
It's implemented as the Hodge dual, which is probably reasonable until
people complain. Both ⋆ and ! are supported, though the former is a
little hard to see in Consola.
2023-08-28 20:35:03 +09:00
Bill Currie
1329a1c43a [qfcc] Implement multi-vector negation
That was surprisingly harder than expected due to recursion and a
not-so-good implementation in expr_negate (it went too high-level thus
resulting in multivec expressions getting to the code generator).
2023-08-28 17:00:14 +09:00
Bill Currie
6b1684b711 [qfcc] Implement mutli-vector division
But only for scalar divisors. The simple method of AB†/(BB†) works only
if B is a versor and there's also the problem of left and right
division. Thanks to sudgy for making me stop and think before I actually
implemented anything (though he mentioned only that it doesn't work for
general mutli-vector divisors).
2023-08-28 12:17:59 +09:00
Bill Currie
5b1ce309ef [qfcc] Implement multi-vector reversion
For a change, something that's actually general rather than specific to
PGA.
2023-08-28 11:56:35 +09:00
Bill Currie
55b7547451 [qfcc] Get the rest of the main 2d PGA products working
That was tedious. I can't say I'm looking forward to writing the tests
for 3d. And even though trivector . bivector and bivector . trivector
give the same answer, they're not really commutative when it comes to
the code.
2023-08-27 15:24:35 +09:00
Bill Currie
74b7e0a35b [qfcc] Get some of 2d PGA mostly working
Better yet, some tests :)
2023-08-27 00:24:23 +09:00
Bill Currie
77c1b584ea [qfcc] Clean up the blade scaling
I didn't particularly like that solution due to the implied extra
bandwidth (probably should profile such sometime), but I think the
extend operations could be merged into simple assignments by the
optimizer at some stage (or further cleaned up when this stuff gets
moved to actual code gen where it should be).
2023-08-25 22:34:41 +09:00
Bill Currie
b2301c8bad [qfcc] Implement 3d PGA geometric algebra
No clue whether anything is actually correct. Time to start creating
real tests.
2023-08-25 22:13:54 +09:00
Bill Currie
e888f71f8a [qfcc] Fetch sum operand type early
Because component_sum works in-place, using a[i]'s type after setting
c[i] resulting in a null type and thus a segfault.
2023-08-25 22:13:54 +09:00
Bill Currie
a46f9a63d2 [qfcc] Clean up GA sum and scale expressions
Scale was inconsistent and sum was error prone due to using
new_binary_expression raw.
2023-08-25 17:24:47 +09:00
Bill Currie
55bdcbe4c5 [qfcc] Implement 2d PGA geometric product
This is definitely showing the need for better vector instructions
(mostly a 2d wedge and width dependent swizzles).
2023-08-24 22:07:04 +09:00
Bill Currie
5f22fd07d9 [qfcc] Implement 3d PGA dot products
Also, correct the handling of scalars in dot and wedge products: it
turns out s.v and s^v both scale. However, it seems the CSE code loses
things sometimes.
2023-08-24 15:49:52 +09:00
Bill Currie
6d75d91de2 [qfcc] Implement 2d PGA dot (inner) product
This has shown the need for more instructions, such as a 2d wedge
product and narrower swizzles. Also, making dot product produce a vector
instead of a scalar was a big mistake (works nicely in C, but not so
well in Ruamoko).
2023-08-24 00:19:58 +09:00
Bill Currie
469fdea0a1 [qfcc] Implement 2d PGA outer products
The specialization is really just in the layout.
2023-08-23 21:52:33 +09:00
Bill Currie
da1b797cb7 [qfcc] Get scalar promotion working again
The cleanup of the scalar expressions lost the type promotion so using
ints in expressions didn't always work.
2023-08-23 21:51:01 +09:00
Bill Currie
24c085c1bd [qfcc] Implement 3d-PGA wedge products
Not all possibilities have been tested yet, but the initial code looks
good even if it has a couple of excessive temporary variables.
2023-08-23 15:38:32 +09:00
Bill Currie
0d491ce68c [qfcc] Build multi-vector expressions correctly
Losing the other components and getting the offset wrong doesn't make
for a correct multi-vector expression when pulling apart a multi-vector
def.
2023-08-23 15:38:32 +09:00
Bill Currie
cfcacfbf28 [qfcc] Use scatter-gather for multivec expressions
This makes working with them much easier, and the type system reflects
what's in the multi-vector. Unfortunately, that does mean that large
algebras will wind up having a LOT of types, but it allows for efficient
storage of sparse multi-vectors:

    auto v = 4*(e1 + e032 + e123);

results in:

    0005 0213 1:0008<00000008>4:void     0:0000<00000000>?:invalid
              0:0044<00000044>4:void          assign (<void>), v
    0006 0213 1:000c<0000000c>4:void     0:0000<00000000>?:invalid
              0:0048<00000048>4:void          assign (<void>), {v + 4}

Where the two source vectors are:

    44:1 0 .imm float:18e [4, 0, 0, 0]
    48:1 0 .imm float:1aa [4, 0, 0, 4]

They just happen to be adjacent, but don't need to be.
2023-08-23 15:38:32 +09:00
Bill Currie
dfb719c92b [qfcc] Correct scaling and multivec sums
Scaling now works for multi-vector expressions, and always subtracting
even when addition is wanted doesn't work too well. However, now there's
the problem of multi-vectors very quickly becoming full algebra vectors,
which means certain things need a rethink.
2023-08-21 20:10:13 +09:00
Bill Currie
2e91b29580 [qfcc] Start work on implementing geometric algebra
This gets only some very basics working:
 * Algebra (multi-vector) types: eg @algebra(float(3,0,1)).
 * Algebra scopes (using either the above or @algebra(TYPE_NAME) where
   the above was used in a typedef.
 * Basis blades (eg, e12) done via procedural symbols that evaluate to
   suitable constants based on the basis group for the blade.
 * Addition and subtraction of multi-vectors (only partially tested).
 * Assignment of sub-algebra multi-vectors to full-algebra multi-vectors
   (missing elements zeroed).

There's still much work to be done, but I thought it time to get
something into git.
2023-08-21 17:58:20 +09:00