Commit graph

12211 commits

Author SHA1 Message Date
Bill Currie
e1a0c31e3f [qfcc] Encode the new vector types
Thanks to the size of the type encoding being explicit in the encoding,
anything that tries to read the encodings without expecting the width
will simply skip over the width, as it is placed after the ev type in
the encoding.

Any code that needs to read both the old encodings and the new can check
the size of the basic encodings to see if the width field is present.
2022-01-30 16:00:49 +09:00
Bill Currie
4b8fdf3696 [qfcc] Implement vector scaling for Ruamoko
With this, qfcc-tests builds (can't run yet due to unsigned not having
any tests and thus the rest the Ruamoko code in QF not building yet).
2022-01-30 14:48:49 +09:00
Bill Currie
4871717fae [gamecode] Rename v6 vector-scalar multiply to scale
Makes it easier to get Ruamoko scaling implemented if they both use the
same opname.
2022-01-30 14:47:26 +09:00
Bill Currie
d18ee8dd86 [qfcc] Make vecaddr work in both v6p and Ruamoko
It's full of evil hacks, but has always been an evil hack relying on
undefined behavior. The weird shenanigans with local variables are
because Ruamoko doesn't copy the parameters like v6p does and thus v and
z are NOT adjacent as parameters. Worse, the padding is uninitialized
and thus should not be relied upon to be any particular value. Still
does a nice job of testing dot products, though.
2022-01-30 14:22:05 +09:00
Bill Currie
09eef8a07b [qfcc] Define __RUAMOKO__ as 2 for Ruamoko ISA
and __RAUMOKO__ as well.
2022-01-30 14:22:05 +09:00
Bill Currie
d8f6a9445e [qfcc] Implement dot and cross product for Ruamoko
With explicit operators, even. While they're a tad verbose, they're at
least unambiguous and most importantly have the right precedence (or at
least adjustable precedence if I got it wrong, but vector ops having
high precedence than scalar or component seems reasonable to me).
2022-01-30 14:14:15 +09:00
Bill Currie
46ce37160b [gamecode] Correct vecops widths
I had forgotten to update the widths when I moved cross product's
position.
2022-01-30 14:11:41 +09:00
Bill Currie
e195dba626 [qfcc] Do not unalias temporary operands
I don't remember why I did this originally, but it causes the dags code
to lose the offset temp alias when accessing fields on structural temps
(known to be the case for vectors (temp-component.r), and I seem to
remember having problems with structs).
2022-01-30 14:02:13 +09:00
Bill Currie
218481764b [qfcc] Add failing test for temp.component
While it specifically checks vectors, I'm pretty sure it applies to
structs, too. Also, it's a little redundant with vecaddr.r, but is much
more specific and far less evil in what it does (no horrible pointer
shenanigans): just something that is fairly common practice.
2022-01-30 13:57:41 +09:00
Bill Currie
3f389b602a [qfcc] Add support for horizontal vector ops
And reimplement vector comparison for Ruamoko.
2022-01-30 10:56:15 +09:00
Bill Currie
feb3be4e6b [qfcc] Add types for ivec3/4 and vec3/4
Needed to get quaternions and vectors going. I'll add more later.
2022-01-30 10:54:07 +09:00
Bill Currie
c467217b4b [simd] Use inttypes.h for long vector formats
Much nicer than cluttering up the headers with word-size checks.
2022-01-30 10:50:14 +09:00
Bill Currie
728c42e921 [gamecode] Use pr_type_names for debug views
I abandoned the reason for doing it (adding a pile of vector types), but
I liked the cleanup. All the implementations are hand-written still, but
at least the boilerplate stuff is automated.
2022-01-30 10:49:33 +09:00
Bill Currie
5ba6bf02e8 [qfcc] Cast functions to ints for comparison
Yet more (non-)wasted instructions.
2022-01-29 18:59:38 +09:00
Bill Currie
61727941fd [qfcc] Prepend state epxression instead of just linking
This fixes an expression loop ICE when building for Ruamoko (not that
there actually was a loop, but the test is rather simplistic).
2022-01-29 18:57:48 +09:00
Bill Currie
49395b3ba1 [gamecode] Correct state's types for double time
It takes int for the frame rather than float.
2022-01-29 18:48:05 +09:00
Bill Currie
fbaf1456fe [qfcc] Use auxiliary operands for move instructions
Since Ruamoko progs must use lea to get the address of a local variable,
add use/def/kill references to the move instruction in order to inform
flow analysis of the variable since it is otherwise lost via the
resulting pointer (not an issue when direct var reference move can be
used).

The test and digging for the def can probably do with being more
aggressive, but this did nicely as a proof of concept.
2022-01-29 18:26:54 +09:00
Bill Currie
f853a449b8 [qfcc] Cast pointers to ints for comparison
Ruamoko doesn't wast instructions on otherwise compatible low-level
types.
2022-01-29 18:23:07 +09:00
Bill Currie
501dd7db76 [qfcc] Use != nil for unary ! for Ruamoko progs
Ruamoko has no explicit ! instruction.
2022-01-29 18:22:41 +09:00
Bill Currie
7e9cf76cfe [qfcc] Change ne to cmp for v6 string inequality check
Since it's really strcmp in disguise (makes the instruction consistent
across all targets).
2022-01-29 18:18:33 +09:00
Bill Currie
baca7cbb4c [qfcc] Do not reverse function args in ruamoko call
It messed up the later check for calls to i[super dealloc].
2022-01-29 17:07:19 +09:00
Bill Currie
d61e906cb9 [qfcc] Don't use v6p store for assinging to entity.field
Ruamoko has a native addressing mode just for entities.
2022-01-29 17:05:50 +09:00
Bill Currie
10843fe340 [gamecode] Correct memset opname and types 2022-01-29 17:05:10 +09:00
Bill Currie
54e079ab75 [qfcc] Fold int constants more aggressively
This code now reaches into one level of the expression tree and
rearranges the nodes to allow the constant folder to do its things, but
only for ints, and only when the folding is trivially correct (* and *,
+/- and +/-). There may be more opportunities, but these cover what I
needed for now and anything more will need code generation or smarter
tree manipulation as things are getting out of hand.
2022-01-29 15:38:39 +09:00
Bill Currie
284fcd312d [qfcc] Rewrite assignment destination addressing
It now addressing_mode cleaning up store instructions to use ptr+offset
instead of lea;store ptr...

Entity.field addressing has been impelmented as well.

Move instructions still generate sub-optimal code in that they use an
add instruction instead of lea.
2022-01-28 15:50:46 +09:00
Bill Currie
d3764c108a [qfcc] Rewrite expr_deref to use addressing_mode
This cleans up the generation of load instructions such that they use
ptr+offset addressing instead of lea;load ptr.
2022-01-28 15:42:06 +09:00
Bill Currie
e298f0d993 [qfcc] Break out pointer addressing
This allows the code handling simple pointer dereferences to recurse
along an alias chain that resulted from casting between different
pointer types (such chains could probably be eliminated by replacing the
type in the original pointer expression, but it wasn't worth it at this
stage).
2022-01-28 15:37:08 +09:00
Bill Currie
d28507eacf [qfcc] Reduce some alias chaining
Aliasing an alias expression to the same type as the original aliased
expression is a no-op, so drop the alias entirely in order to simplify
code generation.
2022-01-28 15:29:40 +09:00
Bill Currie
ec9fa3fee8 [qfcc] Clean up an unnecessary use of array_expr
Simply dereferencing a pointer does not need to go through array_expr
and thus collect a 0 offset that will only be constant-folded out again.
Really just a minor optimization in qfcc, but at one stage in today's
modification, it resulted in some unwanted aliasing chains.
2022-01-28 15:26:47 +09:00
Bill Currie
8d873a891f [qfcc] Make struct ptr access consistent with class ivar access
While this does make the generated code a little worse, load is behaving
nicely), the two are at least consistent with each other and when I fix
one, I'll fix both. I missed this change the other day when I did the
address_expr cleanup. Yay near-duplicate code :P
2022-01-28 09:25:53 +09:00
Bill Currie
7877168e93 [qfcc] Make a field name more clear
Just "type" isn't very informative, but "result_type" is at least a fair
bit better.
2022-01-27 23:29:32 +09:00
Bill Currie
f57aa82c4b [qfcc] Use an alias op for return_operand
This is what using new_ret_expr would result in, but new_ret_expr is no
longer used for referencing .return (except in pascal, but I haven't
gotten around to sorting that out) due to the recent changes for Ruamoko
progs. Fixes an ICE when compiling (with optimization) something like
the following (dir is a vector):

    dir /= sqrt (dir * dir);
    return dir * speed;
2022-01-27 23:24:43 +09:00
Bill Currie
82166406df [qfcc] Remove the def sorting (reverts 9a08a51ebd)
It turns out the sorting wasn't working properly and I've decided that
anything that actually needs the defs to be sorted by address (such as a
debugger searching for defs by address) can do the sorting itself. Fixes
a weird swapping of def names.
2022-01-27 16:43:43 +09:00
Bill Currie
5c22253095 [gamecode] Use the stack frame to find local defs
Of course, only in Ruamoko progs, but it works quite nicely.
global_string is now passed the absolute address of the referenced
operand. With a little groveling through the progs stack, it should be
possible to resolve pointers to locals in functions further up the
stack.
2022-01-27 14:20:09 +09:00
Bill Currie
de974fdd3f [gamecode] Add format for addressing modes and use in return
This fixes Ruamoko's return format string. It looks like it's producing
the correct address (but doesn't show all the information it should),
but the rest of the debug code needs work locals.
2022-01-27 13:29:38 +09:00
Bill Currie
4b4cb60c65 [qfcc] Check qfo target matches compile target
Linking mixed target VMs is unlikely to end well.
2022-01-27 13:24:21 +09:00
Bill Currie
0123e12304 [qfcc] Use locals and params_start to describe stack frame
This is necessary to get statement disassembly working, and likely
debugging in general. locals is the total size of the stack frame and
thus reaches above the function-entry stack pointer, and params_start is
the local space relative start of the parameters. Thus, knowing the
function-entry stack pointer, the bottom of the locals space can be
found by subtracting params_start, and the top of the locals space by
adding (locals - params_start).
2022-01-27 11:37:37 +09:00
Bill Currie
42db8514ae [gamecode] Use version instead of locals count
It turned out I need locals count and params_start for debugging, so use
the progs version instead to bail early from PR_EnterFunction and
PR_LeaveFunction (which I had forgotten anyway, oops).
2022-01-27 11:24:00 +09:00
Bill Currie
a0d9cf8d8e [gamecode] Improve verbose statement prints for Ruamoko
They now include base register index and effective address of the
operands (though it may be wrong for instructions that don't use a base
register for that operand).
2022-01-27 10:57:31 +09:00
Bill Currie
59ee723201 [gamecode] Rename parm to param
That misspelling bothered me from the very beginning, I'd always have
trouble getting the name right when trying to access one of those fields.
2022-01-27 10:55:06 +09:00
Bill Currie
e9dff4ff9c [gamecode] Correct types and widths for bitnot
bitnot is the only unary operator in the bitops group and thus needs
special handling.
2022-01-27 10:21:48 +09:00
Bill Currie
169b8cc398 [qfcc] Rewrite qfo_to_progs offset/size calculation
This gets all the sections of the progs file nicely aligned and the code
easier to read with the offset and size calculations not being spread
through the function. ivar-struct-return now works when compiled for
Ruamoko.
2022-01-26 23:18:15 +09:00
Bill Currie
faa98d8198 [gamecode] Use a struct for offset/count pairs
This cleans up dprograms_t, making it easier to read and see what chunks
are in it (I was surprised to see only 6, the explicit pairs made it
seem to have more).
2022-01-26 19:30:25 +09:00
Bill Currie
a2fd42f174 [qfcc] Align progs memory to 32 bytes in the test harness
This ensures the engine can align everything to 32 bytes.
2022-01-26 16:57:34 +09:00
Bill Currie
a2f4522e76 [gamecode] Align Ruamoko progs to 32 bytes.
Intel hardware requires 32-byte alignment for lvec4 and dvec4.
Unfortunately, it turns out that my attempts to align progs data in qfcc
went awry do to the order block sizes are calculated when writing the
progs.
2022-01-26 16:55:14 +09:00
Bill Currie
90b40e7e52 [qfcc] Ensure adjstk and with always come first
While I think the reason the dags code moved an instruction before
adjstk and with was they shared a constant with that instruction (which
is a different bug), this ensures other instructions cannot get
reordered in front of adjstk and with, as doing so would cause any such
instructions to access incorrect data.
2022-01-26 15:50:04 +09:00
Bill Currie
0b9b6955aa [qfcc] Implement addressing modes for return
There's still entity.field to go, but basic def and ptr + const offset
seem to work.
2022-01-26 15:48:08 +09:00
Bill Currie
982a090143 [qfcc] Mask off base register bits when printing statements
Fixes a segfault when compiling Ruamoko progs with debug output.
2022-01-26 12:26:50 +09:00
Bill Currie
ee4eecc741 [gamecode] Correct types and opname for memset and move 2022-01-26 12:26:12 +09:00
Bill Currie
6bc6db471d [gamecode] Make return use same addressing as other ops
This makes return consistent with load, store, etc, though its
addressing mode is encoded in bits 5 and 6 of c rather than the opcode.
It turns out I had no tests for any of return's addressing modes other
than basic def references, so no tests needed changing.
2022-01-26 09:51:11 +09:00