Commit graph

4156 commits

Author SHA1 Message Date
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
34da36e1cf [gl_stub] Add a bunch of new stubs
Gets gl_stub working with recent changes to QF.
2022-05-20 16:27:01 +09:00
Bill Currie
688f17fda3 Correct some typos in comments/docs 2022-05-19 13:26:45 +09:00
Bill Currie
8b425a2740 [tools] Show major file offsets in mdl dumper
Handy for debugging the alias model loader.
2022-05-19 13:26:45 +09:00
Bill Currie
9429539f2f [qfbsp] Print node and leaf info
Maximum tree depth, number of nodes in a model, and max faces per node
and leaf.
2022-05-19 13:26:45 +09:00
Bill Currie
2a0bbfb4e9 [io_mesh_qfmdl] Use an int for NLA start frame
At at some stage blender enforced frames being integers (In the past,
there was support for fractional, I think, but I also seem to remember
it not working) (yes, for anybody looking, this commit message is more
or less copied from io_object_mu).
2022-05-08 02:15:50 +09:00
Bill Currie
9c7c081772 [io_mesh_qfmdl] Skip space after parsing a value
Fixes a bogus error on the likes of offset = { x = 0; y = 0 }; (ie,
between the 0 and } )
2022-05-06 15:08:56 +09:00
Bill Currie
c26c3b2739 [mdl] Show bytes remaining if not enough for unpack
It turns out Abyss of Pandemonium has a truncated mdl file causing
buffer overruns.
2022-05-05 23:49:30 +09:00
Bill Currie
1891c1c302 [qflight] Replace a sprintf with va
While 16 chars is plenty for a 32-bit int, just seeing sprintf is enough
reason to make the change.
2022-05-04 21:01:39 +09:00
Bill Currie
3b926ec154 [io_mesh_qfmdl] Update plist parsing for `
This gets it pretty much in line with the C implementation. Certainly
good enough for validating a render pass spec :)
2022-05-04 14:44:54 +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
7518ba0a27 [qfcc] Add failing test case for defspace_alloc_aligned_loc
qfcc is putting two temps in the same location due to
defspace_alloc_aligned_loc returning the same address when there was a
hole caused by an earlier aligned alloc: specifically, a size-3 hole and
a size-2 allocation with alignment-2.
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
bf53edf5e3 [qfcc] Use correct vector expression size in test
Vector expressions no longer auto-widen due to the new vector types (I
might add such later, but for now this lets the tests try to build
(minus actual fixes in qfcc)).
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
790f62a209 [image] Make WritePNG take settings from tex_t
This means that a tex_t object is passed in instead of just raw bytes
and width and height, but it means the texture can specify whether it's
flipped or uses BGR instead of RGB. This fixes the upside down
screenshots for vulkan.
2022-04-01 01:01:53 +09:00
Bill Currie
a29836cc2c [quakefs] Return QFile pointer from QFS_NextFile(name)
QFS_NextFilename was renamed to QFS_NextFile to reflect the fact it now
returns a QFile pointer for the newly created file (as well as the
name). This necessitated updating WritePNG to take a file pointer
instead of a file name, with the advantage that WritePNGqfs is no longer
necessary and callers have much more control over the creation of the
file.

This makes QFS_NextFile much more secure against file system race
conditions and attacks (at least in theory). If nothing else, it will
make it more robust in a multi-threaded environment.
2022-03-31 17:27:04 +09:00
Bill Currie
73c65749fc [qfvis] Fix a vector type error
I suspect I wasn't getting nan like I wanted.
2022-03-31 01:17:47 +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
0bb562f93f Fix a bunch of float vs int bugs
Just those made me glad I tried compiling with clang: running into those
bugs would have lead to some serious headaches, I imagine.
2022-03-31 00:28:26 +09:00
Bill Currie
38319d01b2 Fix some null pointer shenanigans
clang doesn't like anything but a bare 0 as null (and in some of the
cases, it was quite right: '\0' should not be treated as a null
pointer). And the crashers were just for paranoia and probably aren't
needed any more (kept for now, though).
2022-03-31 00:25:22 +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
ef850d97ea [qfmdl] Speed up vertex import slightly
Well, not measured, but I expect that python allocates the destination
list before executing the loop (I've forgotten the name of that coding
form).
2022-03-14 11:11:18 +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
59044d3827 Fix a bunch of distcheck issues 2022-02-14 19:28:19 +09:00
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