Commit graph

4197 commits

Author SHA1 Message Date
Bill Currie
cb4b073e47 [qfcc] Support some unicode ops and GA ops
Only · (dot product) and × (cross product for vector, commutator product
for geometric algebra) have been tested so far, but that involved
fighting with cpp to get it to not convert the · to \U000000b7, which
was rather annoying.
2023-08-21 17:47:55 +09:00
Bill Currie
a0ddc2b2bd [qfcc] Support explicit dot product in v6p code
The dot product in v6p code returns a float rather than a vector.
2023-08-21 17:47:55 +09:00
Bill Currie
4028590240 [qfbsp] Add an option to extract models to C
Probably not a good idea for large maps, but handy for generating C
structs for small test maps. Does not include vertices or surfaces, just
the bsp tree itself for now.
2023-08-15 17:20:45 +09:00
Th3T3chn0G1t
3098b5d3f7 Implement clang support
Fixing a load of issues related to autoconf and some small source-level issues to re-add clang support.
autoconf feature detection probably needs some addressing - partially as -Werror is applied late.
2023-08-11 14:25:01 +09:00
Bill Currie
9f8a6f5d62 [qfvis] Initialize set pool arrays
The relatively recent changes to ALLOC missed the set pools used in fat
pvs calculations.
2023-07-18 11:27:06 +09:00
Bill Currie
55705dac83 [qfcc] Only compile in the compile-only tests
The source tree is made read-only by `make distcheck`, so writing
temporary files to the source directory is a no-no (really, it's a bit
of a bug in qfcc, as per #51).
2023-07-10 11:04:17 +09:00
Bill Currie
fdeb294c58 [qfcc] Update ptraliasenc test for new format
With the use of the full type for encoding type aliases, ptraliasenc's
simple check became invalid (it's purpose is to ensure the encoding
doesn't have "null" in it, not the exact encoding itself, but this is
good enough).
2023-06-30 02:45:49 +09:00
Bill Currie
7ce475b114 [qfcc] Use full type for encoding alias types
This is needed for distinguishing type aliases when only the name
changes.
2023-06-30 02:42:28 +09:00
Bill Currie
dc61d15340 [qfcc] Add failing test for array-typedef interaction
Two variables declared as arrays (same size) of different typedefs to
the same base type have their type encodings both pointing to the same
short alias.

From vkgen:

    51d3  ty_array  [4={int32_t>i}]      207f  0 4
    51d9  ty_array  [4=i]                1035  0 4
    51df  ty_alias  {>[4=i]}              16  51d9  51e6
    51e6  ty_array  [4={uint32_t>i}]     2063  0 4
    51ec  ty_union  {tag VkClearColorValue-} tag VkClearColorValue
	    4ca0     0 float32
	    51df     0 int32
	    51df     0 uint32

uint32 should use 51e6 and int32 should use 513d,
2023-06-30 02:39:51 +09:00
Bill Currie
56d33d1b98 [qfcc] Remove 8 argument limit from ruamoko function calls
That hasn't been an issue for over a year thanks to the stack.
2023-06-29 21:17:25 +09:00
Bill Currie
9d1c07d2ac Fix a few strict aliasing warnings
gcc 13 got a little stricter on those (at least with gnu2x/c2x).
2023-06-13 18:13:54 +09:00
Bill Currie
dbd3d6502a Nuke qboolean from orbit
I never liked it, but with C2x coming out, it's best to handle bools
properly. I haven't gone through all the uses of int as bool (I'll leave
that for fixing when I encounter them), but this gets QF working with
both c2x (really, gnu2x because of raw strings).
2023-06-13 18:06:11 +09:00
Bill Currie
9871b44d68 [build] Fix a warning in attribute const check
The warning flag check worked too well: it enabled the warning and
autoconf's default main wanted the const attribute. The bug has been
floating around for a while, it seems.
2023-06-13 13:08:38 +09:00
Bill Currie
fe045f75fb [qfcc] Force live vars used by function statements
This uses ud-chains for function statements (call/return) to force their
arguments to be live (in particular, indirect references via pointers)
this fixes the arraylife test.
2023-06-05 17:20:12 +09:00
Bill Currie
fb1b3e0869 [qfcc] Use ud- and du-chains for block live analysis
The ud- and du-chains include known side-effects of the instructions and
thus depict a more accurate view of what operands an instruction uses or
defines. Fixes the arraylife2 test.
2023-06-05 11:03:44 +09:00
Bill Currie
a5ed154cfe [qfcc] Add a second failing array lifetime test
This one covers regular array references across function call.
2023-06-05 10:58:02 +09:00
Bill Currie
38fd09573f [qfcc] Avoid defining whole temp via alias
Like defs, a partial write should not define the whole temp. Thus, copy
the "don't visit main" behavior recently added to def_visit_all. Fixes
missing ud-chains for component-by-component assignments to temporary
vectors.
2023-06-05 09:42:33 +09:00
Bill Currie
8f6e145257 [qfcc] Don't add target def for store statements
Store statements dereference the pointer in target and thus don't modify
target itself.
2023-06-04 11:45:35 +09:00
Bill Currie
e2c1da9b6a [qfcc] Create du-chains from ud-chains
I'm not certain this is correct, but it seems to me that du-chains are
the same information as ud-chains, but from the defining statement's
point of view instead of that of the using statement.
2023-06-04 11:24:52 +09:00
Bill Currie
7149a092f6 [qfcc] Create ud-chains more aggressively
As certain statements (in particular, function calls) can use additional
variables via pointer parameters, it's necessary to iterate ud-chain
building until the count stabilizes. This should make live variable
analysis much easier.
2023-06-04 01:47:30 +09:00
Bill Currie
5d9823af30 [qfcc] Implement designated initializers
Conforms fairly closely to GCC's C implementation.
2023-05-27 12:47:33 +09:00
Bill Currie
09a3e257e8 [qfcc] Fully initialize local structural defs
I think the current build_element_chain implementation does a reasonable
job, but I'm in the process of getting designated initializers working,
thus it will become important to ensure uninitialized members get
initialized.
2023-05-26 21:56:19 +09:00
Bill Currie
d001473536 [qfcc] Make is_struct struct-only
And add is_union to handle unions. Sometimes it's necessary to check
between the two.
2023-05-25 21:23:27 +09:00
Bill Currie
6d5e8922a5 [qfcc] Add a handle type for engine resources
I never liked the various hacks I had come up with for representing
resource handles in Ruamoko. Structs with an int were awkward to test,
pointers and ints could be modified, etc etc. The new @handle keyword (@
used to keep handle free for use) works just like struct, union and
enum in syntax, but creates an opaque type suitable for a 32-bit handle.
The backing type is a function so v6 progs can use it without (all the
necessary opcodes exist) and no modifications were needed for
type-checking in binary expressions, but only assignment and comparisons
are supported, and (of course) nil. Tested using cbuf_t and QFile: seems
to work as desired.

I had considered 64-bit handles, but really, if more than 4G resource
objects are needed, I'm not sure QF can handle the game. However, that
limit is per resource manager, not total.
2023-05-25 10:41:28 +09:00
Bill Currie
7b6b25a751 [qfcc] Find variables referenced by function arguments
This takes advantage of the ud-chains to follow the trail of pointer
assignments looking for an address. This gets array element assignments
surviving across blocks when the array itself is passed to a function.
It doesn't help when the address of the element is taken though. I think
that's a dags problem and probably needs du-chains. Also, the ud-chain
creation should probably be done in two passes so the newly found
information can be recorded.
2023-05-21 22:11:46 +09:00
Bill Currie
a5943c8a3b [qfcc] Use statement use chain for v6 calls
Def and kill are still handled in flow_analyze_statement, but this makes
call meta data more consistent between v6 and ruamoko progs, allowing
the statement use chain to be used for call argument analysis. It even
found a bug in the extraction of param counts from the call instruction.
2023-05-21 10:23:03 +09:00
Bill Currie
208359edc6 [qfcc] Ensure all operands are cleared before flow
I had missed the flowvar clearing for auxiliary use/def/kill operands.
It's possible it wasn't necessary at the time since the operands were
added just for dealloc checking, but there's every reason it could
become necessary.
2023-05-20 13:54:40 +09:00
Bill Currie
b5a57cd15c [qfcc] Use assign_statement for v6p call arguments
I had written assign_statement a while after the call handling code and
didn't think to modify the call code. This makes for more consistent
code.
2023-05-20 13:52:24 +09:00
Bill Currie
9247ab91fd [qfcc] Calculate ud-chains
The first use will be pointer analysis for function arguments where the
argument points to an array to mark the array as live, but I'm sure
there'll be plenty of other uses.
2023-05-20 08:49:51 +09:00
Bill Currie
4b3b6d516a [qfcc] Use available functions for dealloc use/def
I had written those use/def sets before creating the functions, and it
turns out I had goofed slightly with the def chaining.
2023-05-19 19:41:34 +09:00
Bill Currie
0c116b8ff0 [qfcc] Record actual statements in a function
This is to help with building ud-chains as I suspect I won't be all that
interested in defs from the dummy blocks.
2023-05-19 17:50:19 +09:00
Bill Currie
74e15fc582 [qfcc] Show var use in flow vars 2023-05-19 17:48:47 +09:00
Bill Currie
95dd63cd68 [qfcc] Avoid defining whole def via alias
A partial write to a def should not define the whole def, thus
def_visit_all's overlap parameter now has a flag that prevents a visit
to the main def when accessing the def from an alias def. This prevents
a lot of spurious kills and defines in flow analysis.
2023-05-19 16:42:13 +09:00
Bill Currie
8d4602ec61 [qfcc] Fix indexed pointer vector indexing
The array access code was loading the vector, modifying the element,
then forgetting to write the modified vector back to whence it came.
However, that would be rather sub-optimal, so now when the vector is
accessed by a pointer, the array code switches to field access to get at
the vector element thus avoiding the need to copy the whole vector.
2023-05-17 01:09:31 +09:00
Bill Currie
0d78a865c6 [qfcc] Show flow vars and statements for reaching dot
A bunch of nodes with a pile of numbers doesn't mean much without the
context.
2023-05-15 11:08:23 +09:00
Bill Currie
7b7b2ef000 [qfcc] Add flow defs for parameters
Needed for proper analysis (ud-chains etc). Of course, it was then
necessary to remove the parameter defs from the uninitialized defs.

Also, plug a couple of memory leaks (forgot to free some temporary
sets).
2023-05-14 13:40:40 +09:00
Bill Currie
4435db0329 [qfcc] Support pointer arithmetic on arrays
That is, `array + offset`. This actually works around the bug
highlighted by arraylife.r (because the array is explicitly used), but
is not a proper solution, so that test still fails of course. However,
with this, it's no longer necessary to use `&array[index]` instead of
`array + index`.
2023-05-14 12:45:08 +09:00
Bill Currie
8e1883a306 [qfcc] Allow assignment of arrays to void pointers
I guess it just never came up until now.
2023-05-14 12:45:08 +09:00
Bill Currie
61d656881b [qfcc] Improve readability of flow vars in live
I could never remember what any of the numbers meant. While define is
still a little fuzzy (they're (pseudo)statement numbers), at least now
I'll always know that the numbers are the define set. Also, having the
flow address of the variable helps with understanding the reaching defs
output.
2023-05-14 12:45:08 +09:00
Bill Currie
904b211576 [qfcc] Fix some comment typos in the flow analyzer 2023-05-14 12:45:08 +09:00
Bill Currie
ce6b27cfae [qfcc] Add failing test for array life
It seems that the optimizer keeps array assignments live when passing
the array as a pointer, but not when passing the address of an element.
Found when testing the following code:

    BasisBlade *pga_blades[16] = {
        blades[1],  blades[2],  blades[3],  blades[4],
        blades[7],  blades[6],  blades[5],  blades[0],
        blades[8],  blades[9],  blades[10], blades[15],
        blades[14], blades[13], blades[12], blades[11],
    };
    BasisGroup *pga_groups[4] = {
        [BasisGroup new:4 basis:&pga_blades[ 0]],
        [BasisGroup new:4 basis:&pga_blades[ 4]],
        [BasisGroup new:4 basis:&pga_blades[ 8]],
        [BasisGroup new:4 basis:&pga_blades[12]],
    };

Only the first element of pga_blades is being assigned in the optimized
code, but everything is correct when not optimizing.
2023-05-14 12:45:08 +09:00
Bill Currie
a8efde1dd3 Fix some mxe build issues 2023-03-25 21:36:45 +09:00
Bill Currie
ef2793010c [simd] Improve portability for aarch64
No need for compiler flags for 64-bit arm, and the few intrinsics that
are actually needed are in a different header.
2023-03-25 21:21:13 +09:00
Bill Currie
7d4c1d79b1 [plist] Use reference counts for items
This makes it much easier to share items between property lists (eg,
targets and the main entity list in cl_light).
2023-03-13 11:26:13 +09:00
Bill Currie
cee00c8243 [qfcc] Fix declarators for pointers/functions/arrays
I had messed up the handling of declarators for combinations of pointer,
function, and array: the pointer would get lost (and presumably arrays
of functions etc). I think I had gotten confused and thought things were
a tree rather than a simple list, but Holub set me straight once again
(I've never regretted getting that book). Once I understood that, it was
just a matter of finding all the places that needed to be fixed. Nicely,
most of the duplicated code has been refactored and should be easier to
debug in the future.
2023-03-09 02:22:23 +09:00
Bill Currie
549ffcd534 [qfcc] Add failing test for function/array pointers
It turns out I broke the type system when it comes to pointers to
functions and arrays. This test checks basic function and array pointers
and passes with qfcc from before the type system rework.
2023-03-07 13:17:46 +09:00
Bill Currie
45c0341daf [qfcc] Actually skip compile for -E etc
The preprocess-only option wasn't being checked enough.
2023-03-06 13:06:05 +09:00
Bill Currie
e2640d51a7 [gl_stub] Make some gen functions generate indices
This makes gl_stub usable with valgrind (otherwise, the returned indices
are uninitialized).
2023-03-05 18:31:30 +09:00
Bill Currie
795021e229 [util] Record allocated blocs for ALLOC
Recording the blocks makes it possible to free them later. As a
convenience, ALLOC_STATE declares the freelist and blocks vars needed by
ALLOC.
2023-03-05 18:31:30 +09:00
Bill Currie
694c3ad5f5 [qfcc] Ensure params and arguments have unique flow addresses
This fixes the false-negative in the dealloc-warn4.r test (and thus what
I found in vkgen), and should stave off a few other issues.
2023-02-26 20:43:52 +09:00