Commit graph

2644 commits

Author SHA1 Message Date
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
Bill Currie
76a35c0352 [qfcc] Always test float against 0 for Ruamoko
Float is not int, and Ruamoko has only int ifz/ifnz, which will fail for
-0.0 (0x80000000 when viewed as an int). And then there's nan, but I
haven't seen too many of those in quake.
2022-02-06 21:20:00 +09:00
Bill Currie
548b7fe753 [qfcc] Set function file and line when building code
I suspect this is an ancient bug that wasn't noticed due to not looking
at progs.src compiled code enough, but it makes the first statements of
the function point to the correct line instead of a forward declaration.
2022-02-06 21:20:00 +09:00
Bill Currie
abe43584ff [qfcc] Create vector component symbols for parameters
This got lost when the stack frame setup was converted for Ruamoko.
2022-02-06 21:20:00 +09:00
Bill Currie
211cd657e0 [qfcc] Alias entity to int for comparison
The ruamoko ISA has no entity comparison operators because an entity is
just an int in disguise.
2022-02-06 21:20:00 +09:00
Bill Currie
afe8c8fca5 [qfcc] Auto-demote double for vector scaling
This was missed in the switch to an explicit scale instruction.
2022-02-06 21:20:00 +09:00
Bill Currie
5f6e0767d7 [qfcc] Make the meaning of vec * vec selectable
Currently only via pragma (not command line options), but I needed to
test the concept. Converting legacy code is just too error prone.
Telling the compiler how to treat the operator makes more sense. When *
acts as @dot with Ruamoko progs, the result is automatically aliased as
a float as this is the legacy meaning (ie, float result for dot
product).
2022-02-06 21:20:00 +09:00
Bill Currie
5f2fd3cac0 [qfcc] Skip over zero stack adjustment
This is a very tiny optimization, but there's no point in adjust the
stack if there's no actual adjustment. I didn't bother with it initially
because I thought it wouldn't happen (and I was more interested in
getting things working first), but it turns out that simple getters that
result in a zero adjustment are quite common (70/535 in qwaq-app.dat).
2022-02-05 20:36:38 +09:00
Bill Currie
1ce026d168 [qfcc] Implement bounced return pointer calls
This is achieved by marking a void function with the void_return
attribute and then calling that function in an @return expression.
@return can be used only inside a void function and only with void
functions marked with the void_return attribute. As this is intended for
Objective-QC message forwarding, it is deliberately "difficult" to use
as returning a larger than expected value is unlikely to end well for
the calling function.

However, as a convenience, "@return nil" is allowed (in a void
function). It always returns an integer (which, of course,can be
interpreted as a pointer). This is safe because if the return value is
ignored, it will go into the progs return buffer, and if it is not
ignored, it is the smallest value that can be returned.
2022-02-05 19:30:08 +09:00
Bill Currie
084c2ccb1f [qfcc] Make is_function_call a little more useful
It can (and must) be used one level higher as it checks that the
expression is a block and that its result expression is call branch
expression.
2022-02-05 19:30:08 +09:00
Bill Currie
eee6744656 [qfcc] Use a function to apply function attributes
There are too may places where they need to be applied, so making them
all use a function will keep things manageable in the future.
2022-02-05 19:30:08 +09:00
Bill Currie
8cc6cbc157 [qfcc] Use a union to manage function attributes
Same idea as the specifiers, but makes checking function types are the
same much easier.
2022-02-05 19:30:08 +09:00
Bill Currie
f153e87daa [qfcc] Use a union to manage specifier bits
Having to remember to copy yet another specifier bit was getting
tedious, so use a union of a struct with the bitfields and an unsigned
int to access them in parallel. Makes for a tidier spec_merge, and one
less headache.
2022-02-05 18:45:54 +09:00
Bill Currie
b6a8a93cc3 [qfcc] Treat vectors and quaternions as non-scalars
Fixes a segfault when initializing vectors thai was caused by the
earlier block init fix.
2022-02-04 22:03:26 +09:00
Bill Currie
6988752dea [qfcc] Clean up line numbers in varargs setup
It's never nice getting the end-of-function line in the middle of some
code.
2022-02-04 22:02:05 +09:00
Bill Currie
24a42dc064 [qfcc] Emit args for ... functions with no other parameters
I missed that the block was < -1, ie at least one real parameters.
2022-02-04 22:00:18 +09:00
Bill Currie
1b40cdbab6 [qfcc] Handle vector scaling by ints
I missed a change when implementing support for the scale instructions.
2022-02-04 21:57:41 +09:00
Bill Currie
26fca581fc [qfcc] Make ruamoko the default and update the docs
It's time to do the dog-food.
2022-02-04 10:46:31 +09:00
Bill Currie
f3770cc647 [qfcc] Add --ruamoko command line option and pragma
The command line option works the same way as
--advanced/traditional/extended, as does the pragma. As well, raumoko
(alternative spelling) can be used because both are legitimate and some
people may prefer one spelling over the other.

As always, use of the pragma is at one's own risk: its intended use is
forcing the target in the unit tests.
2022-02-04 09:27:07 +09:00
Bill Currie
52a399daeb [qfcc] Update sizes and alignments for dvec4 and friends
dvec4, lvec4 and ulvec4 need to be aligned to 8 words (32 bytes) in
order to avoid hardware exceptions. Rather than dealing with possibly
mixed alignment when a function has 8-word aligned locals but only
4-word aligned parameters, simply keep the stack frame 8-word aligned at
all times.

As for sizes, the temp def recycler was written before the Ruamoko ISA
was even a pipe dream and thus never expected temp def sizes over 4. At
least now any future adjustments can be done in one place.

My quick and dirty test program works :)

    dvec4 xy = {1d, 2d, 0d, 0.5};
    void printf(string fmt, ...) = #0;
    int main()
    {
	dvec4 u = {3, 4, 3.14};
	dvec4 v = {3, 4, 0, 1};
	dvec4 w = v * xy + u;
	printf ("[%g, %g, %g, %g]\n", w[0], w[1], w[2], w[3]);
	return 0;
    }
2022-02-04 08:46:58 +09:00
Bill Currie
1487fa6b50 [qfcc] Implement some basics for the vector types
They're now properly part of the type system and can be used for
declaring variables, initialized (using {} block initializers), operated
on (=, *, + tested) though much work needs to be done on binary
expressions, and indexed. So far, only ivec2 has been tested.
2022-02-04 00:25:31 +09:00
Bill Currie
3d8ee5df43 [qfcc] Ensure ops on globals occur before return
This fixes the return-postop test, and covers calls, too.
2022-02-03 16:33:42 +09:00
Bill Currie
a3c37201b2 [qfcc] Emit constant pointers as direct def references
When possible, of course. However, this tightens up struct and constant
index array accesses, and avoids issues with flow analysis losing track
of the def (such trucking is something I want to do, but haven't decided
out to get the information out to the right statements).
2022-02-03 14:41:46 +09:00
Bill Currie
008359862b [qfcc] Avoid pointer alias of address expressions
Since address expressions always product a pointer type, aliasing one to
another pointer type is redundant. Instead, simply return an address
expression with the desired type.
2022-02-03 14:38:26 +09:00
Bill Currie
80c6431544 [qfcc] Clear up a FIXME
The FIXME was there because I couldn't remember why the test was
type_compatible but the internal error complains about the types being
the same size. The compatibility check is to see if the op can be used
directly or whether a temp is required. The offset check is because
types that are the same size (which they must be if they are
compatible) is because it is not possible to create an offset alias def
that escapes the bounds of the real def, which any non-zero offset will
do if the types are the same size.
2022-02-03 14:15:20 +09:00
Bill Currie
6f49b919ec [qfcc] Move constant pointer offset into address expr
This is the intended purpose of the offset field in address expressions,
and will make struct and array accesses more efficient when I sort out
the code generation side.
2022-02-03 10:55:37 +09:00
Bill Currie
b668759b7d [qfcc] Add a very basic attribute system
Ruamoko passes va_list (@args) through the ... parameter (as such), but
IMP uses ... to defeat parameter type and count checking and doesn't
want va_list. While possibly not the best solution, adding a no_va_list
flag to function types and skipping ex_args entirely does take care of
the problem without hard-coding anything specific to IMP.

The system currently just sets some bits in the type specifier (the
attribute list should probably be carried around with the specifier),
but it gets the job done for now, and at least gets things started.
2022-02-02 23:51:37 +09:00
Bill Currie
6fe72b0420 [qfcc] Check load/store operand type before mangling
This fixes the incorrect use of assign64 for quaternions. All tests
except return-postop pass \o/.
2022-02-02 19:14:22 +09:00
Bill Currie
a64f91129f [qfcc] Give lea its own statement type
This makes it much easier to check (and more robust to name changes),
allowing for effectively killing the node to which the variable being
addressed is attached. This fixes the incorrect address being used for
va_list, which is what caused double-alias to fail.
2022-02-02 18:55:01 +09:00
Bill Currie
38550922cc [qfcc] Map 64-bit load/store/assign instructions
In order to not waste instructions, the Ruamoko ISA does not provide 1
and 2 component 64-bit load/store instructions since they can be
implemented using 2 and 4 component 32-bit instructions (load and store
are independent of the interpretation of the data). This fixes the
double test, and technically the double-alias test, but it fails due to
a problem with the optimizer causing lea to use the wrong reference for
the address. It also breaks the quaternion test due to what seems to be
a type error that may have been lurking for a while, further
investigation is needed there.
2022-02-02 16:06:15 +09:00
Bill Currie
93840d9892 [qfcc] Handle Ruamoko's call return destination
Since the call instruction in the Ruamoko ISA specifies the destination
of the return value of the called function, it is much like any
expression type instruction in that the def referenced by its c operand
is both defined and killed by the instruction. However, unlike other
instructions, it really has many pseudo-operands: the arguments placed
on the stack. The problem is that when one of the arguments is also the
destination of the return value, the dags code wants to use the stack
argument as it was the last use of the real argument. Thus, instead of
using the value of the child node for the result, use the value label
attached to the call node (there should be only one such label).

This fixes iterfunc, typedef, zerolinker and vkgen when optimizing. Now
all but the double tests and return postop tests pass (and the retun
postop test is not related to the Ruamoko ISA, so fails either way).
2022-02-01 21:46:28 +09:00
Bill Currie
4ec3486a4b [qfcc] Make lea generate a pointer operand
I really need to come up with a better way to get the result type into
the flow analyser. However, this fixes the aliasing ICE when optimizing
Ruamoko code that uses struct assignment.
2022-02-01 20:01:13 +09:00