Commit graph

13768 commits

Author SHA1 Message Date
Bill Currie
73d1044bec [qfcc] Support offset aliases of values
But explicitly not for pointers (even an offset of 0 breaks the pointer
relocation).
2023-09-11 22:56:10 +09:00
Bill Currie
b456f936c6 [qfcc] Fix vector expressions for generic vectors
It seems the code was never really tested due to an incorrect progs
version test.
2023-09-11 12:31:08 +09:00
Bill Currie
91c3049348 [qfcc] Ensure scale expressions have the correct type
fold_constants was replacing the pseudoscalar type with a float. I
really need to rewrite that whole block sometime.
2023-09-11 12:30:38 +09:00
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
c066e638e5 [qfcc] Take memset/move size into account for use/def
This fixed the bogus uninitialized variable working in b648c353f
2023-09-11 00:37:53 +09:00
Bill Currie
b648c353ff [qfcc] Add a failing test for bogus uninitialized
The variable is very definitely initialized... by a memset (which is the
problem, actually).
2023-09-11 00:34:15 +09:00
Bill Currie
4bcbfc3473 [qfcc] Fix an uninitialized test
When the function is empty, not even a stack adjust instruction is
emitted, so checking for one wound up accessing uninitialized memory.
2023-09-11 00:32:01 +09:00
Bill Currie
2d7b5c18af [qfcc] Add named types to algebra subtypes
I'm uncertain about the names, but this makes it much easier to get at
specific subtypes (eg, PGA.tvec as a type) rather than having to know
the group mask.
2023-09-11 00:31:27 +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
bce2b7d767 [ruamoko] Add sincos and sincosh functions
sincos is just a wrapper around the GNU libc sincos. sincosh is the
equivalent for sinh and cosh, but there doesn't seem to be any such
function, so it's just the two wrapped. They both return their results
in a vec2/vec2d as (sih[h], cos[h]).
2023-09-10 14:13:56 +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
7f8cc64720 [qfcc] Clean up algebra type creation
It turned out two structs were being created for the full multi-vector.
Redundant and a potential source of interesting issues in the future.
2023-09-09 22:38:09 +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
a299cda463 [qfcc] Handle algebra types in block initializers
For now, it's an error (but better than a segfault). I'll sort it out
when I'm happier with the type system.
2023-09-08 11:14:04 +09:00
Bill Currie
2e2dedfd78 [gamecode] Print invalid opcodes correctly
Hex is better for opcodes than octal. Probably copied from one of the
sub-instruction opcode error messages.
2023-09-08 11:12:37 +09:00
Bill Currie
51fbdfe87d [qfcc] Merge code blocks more aggressively
The merge_blocks function wasn't reporting whether it had done anything
so the thread/merge/dead blocks loop was bailing early. With this,
simple functions (ie, no control flow) are fully visible to the CSE
optimizer and it can get quite aggressive (removed 3 assignments and a
cross product from my barycenter test code).
2023-09-07 21:42:46 +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
5c32077c2a [iqm] Use type-specified enums
This should make debugging a little easier in the future.
2023-09-04 12:24:40 +09:00
Bill Currie
084ac76f55 [vulkan] Use identity for vertices with no bone weights
Since the identity matrix is mixed in with the other bones, interesting
things will happen if the bone weights don't add up to 1 and are not all
zero.
2023-09-04 11:08:55 +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
2b5b55f416 [iqm] Check frames before freeing its buffer
Fixes a segfault on shutdown when the iqm model has no animation data.
2023-09-04 11:01:46 +09:00
Bill Currie
23b041c2c0 [console] Fix a build failure without ncurses
It seems that I'd gotten some wires crossed when submitting the issue in
that it was the server console, not qwaq-curses, but fixes #54
2023-09-03 22:18:25 +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
2bb1a0a76e [qfcc] Search for alias nodes
This doesn't affect the generated code (aliases are free), but does
simplify the dag significantly, thus optimizing the compiler somewhat,
but also makes reading dags much easier and therefore optimizing the
debugging process.
2023-09-02 10:43:32 +09:00
Bill Currie
0c6586c753 [qfcc] Always initialize Ruamoko opcodes
They're used for compile-time evaluations regardless of the target.
2023-09-01 14:40:05 +09:00
Bill Currie
cea24af5c4 [qfcc] Clean up default option handling
It turns out the switch to c23 (and using bool) broke the way default
options were handled: -1 just doesn't work.
2023-09-01 14:18:54 +09:00
Bill Currie
d8a78fc849 [qfcc] Handle aliased temps better
Because the aliases were treated as live, every alias of a temp resulted
in an assignment, which proved to be quite significant (4-5 assignments
in some simple GA expressions). By using an alias node in the dag, the
unaliased temp can be marked live while the alias is treated as an
operation rather than an operand. Now my GA expressions have no
superfluous assignments (generally no assignments at all).
2023-09-01 11:59:47 +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
e61be2f80f [gamecode] Add 2- and 3-component swizzles
VM side of the work needed for #58. Tests are still only 4-component,
but the geometric algebra tests seem to have 2-component covered at
least a little bit.
2023-08-31 20:08:28 +09:00
Bill Currie
a416e9c060 [gamecode] Add a 2d wedge product
While it could be emulated using a 3d cross-product, it was a hack and
required the use of a swizzle (or alias) to extract the scalar value.
This will make 2d PGA a little nicer when I get to modifying qfcc for it
2023-08-31 17:33:05 +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
c9734aa945 [qfcc] Add some basic 3d PGA tests
And fix a few issues that showed up: I'd forgotten to add @regressive
and objects wider than 4 elements need to use the move instructions.
2023-08-30 17:32:02 +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
9bce0f8e4f [qfcc] Calculate multi-vector size correctly
The struct for multi-group multi-vectors cleans up that code and makes
the "calculation" much easier (since it's handled by the struct building
code).
2023-08-30 14:58:22 +09:00
Bill Currie
4c808fd254 [qfcc] Allow assignment to superset multi-vectors
If the destination multi-vector fully contains the source multi-vector,
then the assignment is ok (any missing values are zeroed).
2023-08-30 14:56:12 +09:00
Bill Currie
52eaa2fee7 [qfcc] Handle more vector type tests
That new_zero_expr is coming in handy. I should clean up expr_bool.c.
2023-08-30 14:52:38 +09:00
Bill Currie
719cf055a5 [qfcc] Check validity of field expressions
Even though I plan on making multi-vector types easier to use with field
accesses, getting segfaults doesn't help with debugging.
2023-08-29 21:37:41 +09:00