Commit graph

2675 commits

Author SHA1 Message Date
Bill Currie
1fa202608e [qfcc] Don't free duplicate method when merging
The method is still held by known_methods, so freeing it causes grief.
However, it may cause a leak thus the free is only commented out. More
investigation is needed. I'm surprised the problem didn't show on linux,
but cygwin-native hit it and valgrind on linux found the spot :)
2022-09-19 16:39:25 +01:00
Bill Currie
08328f4076 Fix some cygwin portability issues
Cygwin's headers seem to be rather out of date with respect to linux
with regards to signed types, especially ctype.
2022-09-19 16:31:08 +01:00
Bill Currie
feba790348 [qfcc] Use _algined_free when using _aligned_malloc
Windows requires the two to be paired. I think this is the first time I
really tested windows qfcc on windows.
2022-09-19 13:37:08 +01:00
Bill Currie
6d64195a7b [qfcc] Fix incorrect progs source path handling
The cvar rewrite changed how to deal with cvar setting in code and I
messed it up for qfprogs.
2022-09-14 22:10:11 +09:00
Bill Currie
3c797e15e6 [qfcc] Use PR_Debug_ValueString when dumping globals
While it does get a bit cluttered currently, being able to see the
contents of structures makes a huge difference. Also highlights that
vector immediates do not get the correct type encodings.
2022-09-14 19:26:17 +09:00
Bill Currie
a8a8c567a2 [qfcc] Promote types before expanding scalars
This fixes the internal error generated by the likes of
`(sv_gravity * '0 0 1')` where sv_gravity is a float and `'0 0 1'` is an
ivec3: the vector is promoted to vec3 first so that expanding sv_gravity
is expanded to vec3 instead of ivec3 (which is not permitted for a
float: expansion requires the destination base type to be the same as
the source).
2022-09-14 14:43:31 +09:00
Bill Currie
5747ddb77f [qfcc] Skip recording defs for binary expressions
For now, anyway, as the generated code looks good. There might be
problems with actual pointer expressions, but it allows entity.field to
work as expected rather than generate an ICE.
2022-09-14 14:43:31 +09:00
Bill Currie
5ae782bf89 [qfcc] Add support for \uXXXX and \UXXXXXXXX
The resultant unicode is encoded as utf-8, which does conflict with the
quake character map, but right now unicode is useful only with font
text, and those support only standard unicode (currently only as utf-8),
but something will need to be sorted out.
2022-09-09 14:48:03 +09:00
Bill Currie
53d86e2a53 [qfcc] Don't check parameter size for arrays
Arrays are passed as a pointer to the first element, so are always valid
parameters. Fixes a bogus "formal parameter N is too large to be passed
by value" error.
2022-09-09 14:48:03 +09:00
Bill Currie
95b8424ddf [qfcc] Use new extend instruction instead of swizzle
While swizzle does work, it requires the source to be properly aligned
and thus is not really the best choice. The extend instruction has no
alignment requirements (at all) and thus is much better suited to
converting a scalar to a vector type.

Fixes #30
2022-08-18 18:18:19 +09:00
Bill Currie
59b73353dd [qfcc] Fix integer vector constants for clang
It seems clang loses track of the usage of the referenced unions by the
time the code leaves the switch. Due to the misoptimization, "random"
values would get into the vector constants. This puts the usages in the
same blocks as the unions, causing clang to "get it right" (though I
strongly suspect I was running into UB).
2022-08-18 18:18:19 +09:00
Bill Currie
42287f1e0e [qfcc] Allow binary operations between vector and vec3
While I might need to tighten up the rules later, this allows binary
operations between vector (the type) and explicitly typed vec3 constants
(and non-constants, about which I am undecided). The idea is that
explicit constants such as '1 2 3'f should be compatible with either
type.

This applies to quaternions as well.
2022-08-18 18:18:19 +09:00
Bill Currie
0897952a57 Fix windows compile issues
ulong seems to be defined somewhere on Linux, thus I missed that, and of
course there's the fun with aligned memory allocation :/
2022-07-31 17:34:09 +09:00
Bill Currie
6253d775e6 [qfcc] Adjust ivar offsets to preserve alignment
As a class's ivars are built up by inheritance, but with only that
class's ivars in the symbol table, is is necessary to include an offset
based on the super class's ivars in order to ensure alignments are
respected. This is achieved via the new `base` parameter to
build_struct(), which is used to offset the current size while
calculating the aligned offset of the symbols. The parameter is ignored
for unions, as they always start at 0. The ivars for the current class
still have a base offset of 0 until they are actually added to the
class.

Fixes #29
2022-07-31 17:15:47 +09:00
Bill Currie
f4ae24e0e0 [qfcc] Support alignment in qfo spaces
The alignment is specified as a power of 2 (ie, actual alignment = 1 <<
alignment) allowing old object files to be compatible (as their
alignment is 0). This is necessary for (in part for #30) as it turned
out even global vectors were not aligned correctly.

Currently, only data spaces even vaguely respect alignment. This may
need to be fixed in the future.
2022-07-31 17:15:47 +09:00
Bill Currie
732ea3a5fd Fix a bunch of issues for clang
One *actual* error (wrong enum type), and some memory alignment issues.
The rest just clang being lame.
2022-07-31 17:15:40 +09:00
Bill Currie
2c8bec27c7 Fix a pile of warnings for gcc 12
Most were pretty easy and fairly logical, but gib's regex was a bit of a
pain until I figured out the real problem was the conditional
assignments.

However, libs/gamecode/test/test-conv4 fails when optimizing due to gcc
using vcvttps2dq (which is nice, actually) for vector forms, but not the
single equivalent other times. I haven't decided what to do with the
test (I might abandon it as it does seem to be UD).
2022-07-31 17:13:26 +09:00
Bill Currie
8633ffe9d2 Fix some MXE build issues
Just some unused variables when vulkan debug is disabled and some scanf
formats for qfcc vectors (and the safety net).
2022-05-22 11:59:53 +09:00
Bill Currie
b9bd45ad99 [qfcc] Create vector lists only for constants
Defs and symbols benefit from swizzling as that's one instruction vs 2-3
for loading a scalar into a vector component by component. Constants are
ok because the result gets converted to a vector constant.
2022-05-01 14:35:24 +09:00
Bill Currie
be4021f8f4 [qfcc] Actually shrink the unaligned hole
This fixes the duplicate allocation caused by an exact fit aligned alloc
in an unaligned hole where the padding remains free.
2022-05-01 14:35:24 +09:00
Bill Currie
cdd8739577 [qfcc] Improve debug printing of statements and operands
Makes it easier to check operand base indices and temporary variable
addresses when known.
2022-05-01 14:35:24 +09:00
Bill Currie
ef9960c6f9 [qfcc] Implement support for the swizzle operator
The destination operand must be a full four component vector, but the
source can be smaller and small sources do not need to be aligned: the
offset of the source operand and the swizzle indices are adjusted. The
adjustments are done during final statement emission in order to avoid
confusing the data flow analyser (and that's when def offsets are known).
2022-05-01 14:35:24 +09:00
Bill Currie
3c20dd515e Revert "Don't bother creating an alias for a def of the same type."
This reverts commit 2904c619c1.

In order to support swizzle operations, I need to be able to alias defs
to larger types (eg, float to vec4), but alias_def rightly won't allow
this. However, as the plan is to do this in the final steps before
emitting the instruction, I plan on creating an alias to a float then
adjusting the type in the alias, but to do so without extra shenanigans,
I need alias_def to allow aliases to the same type. As a fringe benefit,
it makes the code agree with the comment in def.h :P
2022-05-01 14:35:24 +09:00
Bill Currie
709a0a338d [qfcc] Return properly from copying a block expression
This came up when investigating an internal error from the line above.
It turned out the error was correct (problem with converting scalars to
vectors), but the break was not.
2022-04-29 20:53:59 +09:00
Bill Currie
8021848b5b [qfcc] Support promotions for struct initializers
This allows the various vector types to be used to initialized
structures and arrays.
2022-04-29 20:52:57 +09:00
Bill Currie
69ce0e952d [qfcc] Don't auto-promote vector types through ...
Currently, only vector/vec3 and quaternion/vec4 can be printed anyway,
but I plan on making explicit format strings for the types, so there
should be no need to promote any vector types (and really, any hidden
promotion is a bit of a pain, but standards...).
2022-04-29 20:52:27 +09:00
Bill Currie
719fe5a935 [qfcc] Support dot product for all (float) vector types
While the code would handle int vector types, there aren't any such
instructions, and the expression code shouldn't generate them, but all
float (32 and 64 bit) vector types do have a dot product instruction, so
check width rather than just vector/quaternion.
2022-04-29 20:46:33 +09:00
Bill Currie
547cae03ae [qfcc] Copy parameter types when registering new function type
This fixes an error that's been lurking for over two years (since I made
parameters unlimited internally). The problem was the array was being
allocated on the stack and a simple struct copy was used to store type
type, resulting in a dangling pointer onto the stack. I'm surprised it
didn't cause more problems.
2022-04-29 19:27:27 +09:00
Bill Currie
9cccb7a4d4 [qfcc] Implement ulong, long and uint constants
Finally :P
2022-04-29 18:12:47 +09:00
Bill Currie
9c8e13aa4c [qfcc] Implement automatic casting between same-width vectors
This allows all the tests to build and pass. I'll need to add tests to
ensure warnings happen when they should and that all vec operations are
correct (ouch, that'll be a lot of work), but vectors and quaternions
are working again.
2022-04-29 18:12:47 +09:00
Bill Currie
f429777918 [qfcc] Extend vector literal processing
With this, all vector widths and types are supported: 2, 3, 4 and int,
uint, long, ulong, float and double, along with support for suffixes to
make the type explicit: '1 2'd specifies a dvec2 constant, while '1 2 3'u
is a uivec3 constant. Default types are double (dvec2, dvec3, dvec4) for
literals with float-type components, and int (ivec2...) for those with
integer-type components.
2022-04-29 18:12:47 +09:00
Bill Currie
d06185336f [qfcc] Implement component names for the new vector types
And simplify vector and quaternion setup as part of the process. Now
appropriate x, y, z and w can be used with the new vector types.
2022-04-29 16:59:55 +09:00
Bill Currie
b480590d90 [qfcc] Treat long, ulong and ushort as math types
Not so sure about the value of treating ushort (and short) as a math
type, but long and ulong are definitely necessary.
2022-04-29 16:59:55 +09:00
Bill Currie
1da9fff3ae [qfcc] Simplify immediate value emission
This gets immediate values working for the new vector types.
2022-04-29 16:59:55 +09:00
Bill Currie
14545c37cf [qfcc] Merge printing of values into the one place
Having three very similar sets of code for outputting values (just for
debug purposes even) got to be a tad annoying. Now there's only one, and
in the right place, too (with the other value code).
2022-04-29 16:59:55 +09:00
Bill Currie
1eb8b61b83 [qfcc] Clean up handling of value expressions
I'd created new_value_expr some time ago, but never used it...
Also, replace convert_* with cast_expr to the appropriate type (removes
a pile of value check and create code).
2022-04-29 16:59:55 +09:00
Bill Currie
04f60e5ff1 [qfcc] Rework vector expression handling
Use with quaternions and vectors is a little broken in that
vec4/quaternion and vec3/vector are not the same types (by design) and
thus a cast is needed (not what I want, though). However, creating
vectors (that happen to be int due to int constants) does seem to be
working nicely otherwise.
2022-04-29 16:59:55 +09:00
Bill Currie
85d851572f [qfcc] Implement constant casts for the new vector types
Nicely, I was able to reuse the generated conversion code used by the
progs engine to do the work in qfcc, just needed appropriate definitions
for the operand macros, and to set up the conversion code. Helped
greatly by the new value load/store functions.
2022-04-29 16:59:55 +09:00
Bill Currie
ae0b3a5870 [qfcc] Add some utility functions for working with vector types
Finding vector types from base type and width, and getting the base type
for a vector type, as well as basic promotion rules for math types.
2022-04-29 16:59:15 +09:00
Bill Currie
c120bf2940 [qfcc] Add functions to store and load values
This makes working with constant expressions much less tedious,
especially when the relevant code needs to work with many types.
2022-04-29 16:59:15 +09:00
Bill Currie
67bdbc6f7a [qfcc] Split out vector expression code
I plan on extending it for the new vector types and expr.c is just too
big to work in nicely.
2022-04-29 16:59:15 +09:00
Bill Currie
8912c65029 [qfcc] Indicate type width in type strings
Makes for much more informative error messages for type mismatches
(confusing when both sides look the same).
2022-04-29 16:59:15 +09:00
Bill Currie
6d62e91ce7 [gamecode] Clean up progs data access
pr_type_t now contains only the one "value" field, and all the access
macros now use their PACKED variant for base access, making access to
larger types more consistent with the smaller types.
2022-04-29 16:59:15 +09:00
Bill Currie
12c84046f3 [cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.

As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.

The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).

While not used yet (partly due to working out the design), cvars can
have a validation function.

Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.

nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-24 19:15:22 +09:00
Bill Currie
12300d9a98 [qfcc] Remove alias offset from initialize_def
I'm not sure which is mysterious: why it's there, or why it did nothing.
Since it does nothing and things are working, it should be safe to
remove.
2022-03-31 01:15:59 +09:00
Bill Currie
3479897224 [qfcc] Fix some not uninitialized warnings
The "not" because I'm pretty sure they're false positives due to when
the function is called, but clang doesn't know that (wonder why gcc was
ok with it).
2022-03-31 00:37:53 +09:00
Bill Currie
63e5655f68 Clean up some enum sanity checks
It seems clang defaults to unsigned for enums. Interestingly, gcc was ok
with the checks being either way. I guess gcc treats enums that *can* be
unsigned as DWIM.
2022-03-31 00:18:53 +09:00
Bill Currie
70af362562 [qfcc] Unify temp def, return value and parameter sizes
In working with vectors and matrices while testing the scene wrappers, I
found that there was a fair bit of confusion about how large something
could be. Return values can be up to 32 words (but qfcc wasn't aware of
that), parameters were limited to 4 words still (and possibly should be
for varargs), and temp defs were limited to 8 words (1 lvec4). Temps are
used for handling return values (at least when not optimizing) and thus
must be capable of holding a return value, and passing large arguments
through *formal* parameters should be allowed. It seems reasonable to
limit parameter sizes to return value sizes.

A temp and a move are still used for large return values (4x4 matrix),
but that's an optimization issue: the code itself is at least correct.
2022-02-15 08:39:20 +09:00
Bill Currie
2f117dd12e [qfcc] Record referenced def in pointer dereferences
When the def can be found. This fixes direct assignments to arrays (and
probably structs) getting lost when the array is later read using a
variable index.
2022-02-11 19:29:33 +09:00
Bill Currie
246518f487 [qfcc] Get reused type names working for local variables
This allows the likes of "id id;" or

    typedef int foo; ... { double foo; }

So long as the redeclaration is in a sub-scope.
2022-02-07 10:40:26 +09:00