Commit Graph

4049 Commits

Author SHA1 Message Date
Bill Currie db8cf68ef3 [gamecode] Pass registered data pointer to builtins
This is the bulk of the work for recording the resource pointer with
with builtin data. I don't know how much of a difference it makes for
most things, but it's probably pretty big for qwaq-curses due to the
very high number of calls to the curses builtins.

Closes #26
2022-02-14 12:28:38 +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 c10b09d41b [ruamoko] Make RUA_Sprintf more generally useful
It now takes the function name to print in error message (passed on to
PR_Sprintf) and the argument number of the format string. The variable
arguments (in ...) are assumed to be immediately after the format
argument.
2022-02-05 20:24:17 +09:00
Bill Currie 6f4bb0df2c [qfcc] Update sendv test to use @return
The return value can't be checked in the test, but it was useful for
getting everything actually working.
2022-02-05 19:30:08 +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 0fa9d0d256 [qfcc] Tweak the printf to make more sense
Though I'm sure I had a good reason at the time, seeing 6.98487e-315
when expecting pi is a bit disconcerting.
2022-02-02 19:04:43 +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 9b81d27f1a [qfcc] Add test for var = func(var)
That is, updating a variable using a function that takes the same
variable, probably very common in iterators, thus the name. It happens
to be the first qfcc test specific to Ruamoko. It's really just the
typedef, zerolinker, and vkgen type encoding loop stripped down for ease
of debugging.

Of course, it fails :)
2022-02-01 21:40:59 +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
Bill Currie c84fb3e6d3 [qfcc] Use a hidden local variable for pascal functions
This gets gcd.pas working nicely with the Ruamoko ISA, and keeps things
reasonably nice vor v6p (it will likely do better with global CSE).
2022-02-01 16:08:58 +09:00
Bill Currie fc56d1c6e2 [qfcc] Use dynamic addressing for Ruamoko move source
This fixes the incorrect pointer being used in movep instructions in
Ruamoko progs, as well as 3 of the test cases.
2022-02-01 14:57:16 +09:00
Bill Currie e0c5c475ea [qfcc] Modify the modulo tests to be compatible with Ruamoko ISA
Surprisingly, it passes (I didn't expect it to due to the doubles). I'll
look into to it further later on.
2022-02-01 14:57:16 +09:00
Bill Currie 64c8c02eac [qfcc] Add pragma to control optimization
And force a couple of tests to be built with optimization. I'll probably
add it to most, if not all, but for now I'm clearing up tests as I go.
2022-02-01 14:57:16 +09:00
Bill Currie b8c2b7f856 [ruamoko] Make a common sprintf wrapper function
This takes care of converting from progs varargs to what PR_Sprintf
expects. I got tired of modifying the wrappers when I found a third one.
2022-02-01 09:27:03 +09:00
Bill Currie edf7a781fd [qfcc] Map uint to int for some intructions
Many math instructions don't care about the difference between signed
and unsigned operands and are thus specified using int, but need to be
usable with uint. div is NOT mapped because there is a difference:
0x8000 / 2 (16-bit) is 0x4000 unsigned but 0xc000 signed, and 0x8000 /
0xfffe is 0 unsigned and 0x4000 signed. This means I'll need to add some
more instructions. Not sure what to do about % and %% though as that's a
lot of instructions (12).
2022-01-30 22:47:57 +09:00
Bill Currie 8dc4a0ea80 [qfcc] Change v6p's jumpb opname to jump
More ease of searching, since the operand types help greatly.
2022-01-30 22:39:21 +09:00
Bill Currie b8df11b2cb [qfcc] Really get vecaddr.r working on both ISAs
Deliberately defeating an optimiser is not so easy (but I really needed
that variable to be set).
2022-01-30 20:01:32 +09:00
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 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