Commit graph

48 commits

Author SHA1 Message Date
Bill Currie
eb9954700a [qfcc] Simplify algebra_field_expr
This removes all the special cases and thus it should be more robust. It
did show up some out-by-one (or a factor of two!) errors elsewhere in
the group mask calculations.
2023-09-11 10:25:35 +09:00
Bill Currie
d387b56f60 [qfcc] Support block initializers for multi-vectors
They're not supported (yet) for single-group multi-vectors, and
designators are required for all initializer elements.
2023-09-11 00:24:50 +09:00
Bill Currie
b35f4c82a4 [qfcc] Implement field access for multi-vector expressions
Of course as an r-value (I think), but it makes getting only the desired
part of a geometric algebra expression much nicer.
2023-09-10 13:13:49 +09:00
Bill Currie
97624b84aa [qfcc] Implement field access to sub-algebra variables
This makes working with the plethora of types a little easier still. The
check for an algebra expression in field_expr needed to be moved up
because the struct code thought the algebra type was a normal vector.
2023-09-10 10:53:59 +09:00
Bill Currie
55fc343383 [qfcc] Allow casting float algebras to double
And vis-versa.

I'm not sure what I was thinking, but I've decided that not being able
to cast the pseudo-scalar from float to double (for printf etc) was a
bug.
2023-09-10 10:49:50 +09:00
Bill Currie
ed824405fe [qfcc] Support struct access to full algebra vectors
This makes them actually useable. Multi-vector expressions and variables
will be done soon.
2023-09-09 23:08:38 +09:00
Bill Currie
2967b97c18 [qfcc] Flip the 2d PGA layout
The makes 2d PGA and 3d VGA layouts consistent.
2023-09-09 21:19:50 +09:00
Bill Currie
be4405485d [qfcc] Implement the rest of 3d VGA
With tests.
2023-09-08 11:15:36 +09:00
Bill Currie
6096edb1ca [qfcc] Implement wedge products for 3d VGA
That was pretty easy, but necessary for trying out barycentric
coordinates in geometric algebra :)
2023-09-07 21:40:17 +09:00
Bill Currie
8dd0410968 [qfcc] Ensure multi-vector objects have the correct type
Failing to promote ints to the algebra type results in a segfault in
assignment of a multi-vector due to the symbol pointer walking off the
end of the list of symbols.
2023-09-04 11:06:28 +09:00
Bill Currie
25e27bba64 [qfcc] Catch simple summed extend assignments
Simple k-vector assignments weren't being checked for summed extends.
This removes a whole pile of instructions from the 2d PGA test.
2023-09-02 21:41:10 +09:00
Bill Currie
5af1bf54f0 [qfcc] Convert summed extends to simple assignments
This knocked off another 6 instructions total :) The remaining
optimizations require better detection of products that unconditionally
produce 0.
2023-09-02 20:35:10 +09:00
Bill Currie
b514bbdb44 [qfcc] Propagate double-negative through addition
And convert addition to subtraction when extend expressions are not
involved. This has taken my little test down to 56 instructions total
(21 for `l p ~l`), down from 74 (39).
2023-09-02 19:43:51 +09:00
Bill Currie
c2472e99fa [qfcc] Merge extend expressions through sums
This takes care of chained sums of extend expressions. Now `l p ~l` has
only four extend instructions which is expected for the code not
detecting the cross product that always produces 0.
2023-09-02 18:46:14 +09:00
Bill Currie
924c13f925 [qfcc] Extract sub-vectors through summed extends
This goes a ways towards minimizing extend expressions, even finding
zeros and thus eliminating whole branches of expressions, but shows the
need for better handling of chained sums of extends.
2023-09-02 17:41:32 +09:00
Bill Currie
f3a1239095 [qfcc] Propagate negations above aliases
No change to the generated code, but this does get negations up as close
to extends (and final sums) as possible.
2023-09-02 13:43:22 +09:00
Bill Currie
4135849903 [qfcc] Apply algebraic rules to products of negatives
Any geometric algebra product of two negatives cancels out the negative,
and if the result is negative (because only one operand was negative),
the negation is migrated to above the operation. This resulted in
removing 2 instructions from one if my mini-tests (went from 74 to 78
with the addition/subtraction change, but this takes it back to 76
instructions).
2023-09-02 13:18:27 +09:00
Bill Currie
74e9b6b7dd [qfcc] Be consistent with summed extends
Summed extend expressions are used for merging a sub-vector with a
scalar. Putting the vector first in the sum will simplify checks later
on (it really doesn't matter which is first so long as it's consistent).
2023-09-02 11:43:49 +09:00
Bill Currie
3e142534c9 [qfcc] Clean up multi-vector addition and subtraction
Subtraction is implemented as adding a negative (with the plan of
optimizing it later). The idea is to give tree inspection and
manipulation a more consistent view without having to worry about
addition vs subtraction.

Negation is moved as high as possible in the expression, but is always
below an extend expression. The plane here is that the manipulation code
can bypass an alias-add-extend combo and see the negation.
2023-09-02 11:18:50 +09:00
Bill Currie
d11f7be6bf [qfcc] Use the new 2d wedge and 2-component swizzles
This cleans up the generated geometric algebra a little bit and, more
importantly, fixes #58.
2023-08-31 20:22:59 +09:00
Bill Currie
a66fb80517 [gamecode] Switch dot products to give a scalar
Making them give a vector was a mistake for Ruamoko. I've probably got a
mess to clean up in game-source, but oh well.
2023-08-31 15:32:52 +09:00
Bill Currie
d6e30538a8 [qfcc] Fix some more multi-vectors type issues
The full multi-vector group type got the wrong type (struct instead of
the wrapping algebra type), and the wrong group was used for v * v.
2023-08-30 15:45:44 +09:00
Bill Currie
1cad355366 [qfcc] Write tests for 3d PGA geometric products
And fix the flood of errors.
2023-08-30 15:00:27 +09:00
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