Commit graph

12240 commits

Author SHA1 Message Date
Bill Currie
1aa4844bf6 [gamecode] Make string ops mostly conform with bools
The compare/ne operator returns "random" -ve, 0, +ve values (really,
just the numerical difference between the chars of the strings), but all
the rest return -1 for true and 0 for false, as with the rest of the
comparison operators.
2022-01-14 22:44:08 +09:00
Bill Currie
c8362c28fe [gamecode] Add tests for string ops
Does not include string concatenation because I don't feel like messing
with zone init, but all the other operators are tested (currently
failing due to bool convention)
2022-01-14 22:42:56 +09:00
Bill Currie
f4eeed36b7 [gamecode] Add tests for the scale instructions 2022-01-14 19:46:35 +09:00
Bill Currie
1a2ac24d8d [gamecode] Make num_globals() calculate actual globals
It calculating only the size of the array (which was often 4 or 8
globals per element) proved to be a pain when I forgot to alter the size
for the new scale tests. Fixing the size calculation even found a bug in
the shiftop tests.
2022-01-14 19:45:51 +09:00
Bill Currie
a81067603c [gamecode] Mention possibly undefined behavior
It seems casting from float/double to [unsigned] int/long when the value
doesn't fit is undefined (which would explain the inconsistent results).
Mentioning the possibility seems like a good idea should the results for
such casts change and cause the tests to fail.
2022-01-14 16:52:44 +09:00
Bill Currie
a1c1c9fcf0 [gamecode] Add test for conversions to double
And fix an incorrect base index in the bool64 tests.
2022-01-14 15:51:49 +09:00
Bill Currie
1f73b26d24 [gamecode] Correct incorrect bool32-bool64 conversion
And add tests for long, ulong and bool64 conversions.
2022-01-14 14:54:35 +09:00
Bill Currie
4bf934e6b9 [gamecode] Correct incorrect bool64-bool32 conversion
And add tests for float, uint and bool32 conversions.
2022-01-14 13:54:03 +09:00
Bill Currie
e26fb49df7 [gamecode] Get conversion to int working for all types
Bools turned out to be a problem to due to me wanting any non-zero value
to be treated as true thus had to expand them out as well as the
floating point <-> integral conversions.
2022-01-14 12:11:23 +09:00
Bill Currie
cd68455e46 [gamecode] Add tests for converting to int
They currently fail because for vector values, gcc casts the view, not
the value, so vec4 cast to ivec4 simply views the bits as int rather
than doing the actual conversion.
2022-01-14 12:11:22 +09:00
Bill Currie
e8e0a69628 [gamecode] Add conversions to/from bool
For now, from bool results in 0/1, but conversion to bool guarantees
0/-1 and correct interpretations for floating point types.
2022-01-13 17:37:44 +09:00
Bill Currie
ba1d73200f [gamecode] Clean up a pile of duplicate code
All those duplicated formats were getting unwieldy, especially as I want
to add more conversion modes.
2022-01-13 16:10:06 +09:00
Bill Currie
3eb2194343 [gamecode] Invert the meaning of the skip matrix
Rather than specifying that the conversion should be skipped, it now
specifies the mode of the conversions (with 0 being no conversion). This
is in preparation for boolean conversion.
2022-01-13 15:58:12 +09:00
Bill Currie
6f6f47e27e [gamecode] Drop bool ops in favor of long bit ops
I realized that being able to do bit-wise operations with 64-bit values
(and 256-bit vectors) is far more important than some convenient boolean
logic operators. The logic ops can be handled via the bit-wise ops so
long as the values are all properly boolean, and I plan on adding some
boolean conversion ope, so no real loss.
2022-01-13 14:24:11 +09:00
Bill Currie
424bdcbf96 [gamecode] Implement the scale instructions
Both float 2,3,4 vectors and double 2,3,4 vectors (1 would be just a
copy of the mul instructions).

This completes the currently planned instructions. Now for testing.
2022-01-13 13:53:07 +09:00
Bill Currie
3587b13a40 [gamecode] Implement the conversion instructions
Not all possibilities are supported because converting between int and
uint, and long and ulong is essentially a no-op. However, thanks to
Deek's suggestion, not only are all reasonable conversions available,
conversions for all widths are available, so vector conversions are
supported.

The code for the conversions is generated.
2022-01-13 13:51:24 +09:00
Bill Currie
f7181a09b4 [gamecode] Add tests for shiftops
They're in test-unsigned because 2/3 of them are unsigned.
2022-01-12 10:24:59 +09:00
Bill Currie
6229ae8ecc [gamecode] Add tests for unsigned comparisons
And fix the implementation: I had used the wrong macro.
2022-01-11 13:00:54 +09:00
Bill Currie
e7d7ec1989 [gamecode] Add tests for signed comparison ops
Fortunately, they all pass without issues.
2022-01-11 09:37:38 +09:00
Bill Currie
0fb6619585 [gamecode] Compact the convert instructions into one
Thanks to Deek for the suggestion: the mode (ie, src and dst types) are
encoded in st->b. Actual code not written yet, but this frees up 13
instructions: now have 74 available for really interesting stuff :)
2022-01-10 11:53:57 +09:00
Bill Currie
b9e32ee2f5 [gamecode] Rework call and return instructions
The call1-8 instructions have been removed as they are really not needed
(they were put in when I had plans of simple translation of v6p progs to
ruamoko, but they joined the dinosaurs).

The call instruction lost mode A (that is now return) and its mode B is
just the regular function access. The important thing is op_c (with
support for with-bases) specifies the location of the return def.

The return instruction packs both its addressing mode and return value
size into st->c as a 3.5 value: 3 bits for the mode (it supports all
five addressing modes with entity.field being mode 4) and 5 for the
size, limiting return sizes to 32 words, which is enough for one 4x4
double matrix.

This, especially with the following convert patch, frees up a lot of
instructions.
2022-01-10 11:53:14 +09:00
Bill Currie
ba29be3f82 [gamecode] Rename ifnot and if to be less confusing
I think :) anyway, now they're ifz and ifnz, making them consistent with
the rest of the if instructions.
2022-01-10 11:27:57 +09:00
Bill Currie
db7a67e5b7 [gamecode] Rearrange vector instructions
This allows the dot products to be consistent with their sizes: cdot is
really dot_2, vdot dot_3, and qdot dot_4.
2022-01-10 11:16:55 +09:00
Bill Currie
494a6908bb [gamecode] Improve with's comment 2022-01-10 11:04:43 +09:00
Bill Currie
66528e34fc [qfcc] Give return expressions their own type
Very simple for now (just the return value if not a void return), but
that's the last of the statements masquerading as expressions.
2022-01-09 16:28:08 +09:00
Bill Currie
563de20208 [qfcc] Give branch expressions their own type
This includes calls and unconditional jumps, relative and through a
table. The parameters are all lumped into the one object, with some
being unused by the different types (eg, args and ret_type used only by
call expressions). Just having nice names for the parameters (instead of
e1 and e2) makes it nice, even with all the sub-types lumped together.

No mysterious type aliasing bugs this time ;)
2022-01-09 14:02:16 +09:00
Bill Currie
09002c17e6 [gamecode] Add an enum for the different branch types
While it doesn't cover the addressing modes, it does match the bit
pattern used in the Ruamoko instruction set. It will make selecting
branch instructions easier (especially for Ruamoko).
2022-01-09 13:56:09 +09:00
Bill Currie
86e81ba250 [gamecode] Rearrange the branch instructions
Now they're in a much more consistent arrangement, in particular with
the comparison opcodes if the conditional branch instructions are
considered to be fast comparisons with zero (ifnot -> ifeq, if -> ifne,
etc). Unconditional jump and call fill in the gaps. The goal was to get
them all in an arrangement that would work as a small enum for qfcc: it
can use the enum directly for the ruamoko IS, and a small map array for
v6p (except for call).
2022-01-09 01:07:23 +09:00
Bill Currie
7d5c692313 [gamecode] Generate the new opcodes enum too
It turns out I'll be tweaking it more than I expected.
2022-01-09 01:04:51 +09:00
Bill Currie
4111d44dcc [gamecode] Move progs auxiliary headers into a subdirectory
Just another step along the road of tidying up the QF include directory
(and desirable for generated data).
2022-01-09 00:26:52 +09:00
Bill Currie
63795e790b [qfcc] Clean out some old code
The move operator names are definitely obsolete (due to dropping the
expressions a year or two ago) and the precedence checks seem to be
handled elsewhere. Memset and state expressions went away a while back
too.
2022-01-08 21:21:31 +09:00
Bill Currie
14352ea65a [qfcc] Really fix those type aliasing bugs
Found the cause: revered to wrong case for template code :/
2022-01-08 18:49:35 +09:00
Bill Currie
62d58a2255 Revert "[qfcc] Fix another type aliasing bug"
This reverts commit d14f695c68.

Found the cause: revered to wrong case for template code
2022-01-08 18:48:54 +09:00
Bill Currie
134f5ca6a4 Revert "[qfcc] Fix some type aliasing bugs"
This reverts commit da210db720.

Found the cause: revered to wrong case for template code
2022-01-08 18:48:23 +09:00
Bill Currie
65b6c366c3 [qfcc] Give assignment expressions their own type
This is getting easier (know where to look, I guess). Nicely, I found
the source of those weird type aliasing bugs :)
2022-01-08 18:44:29 +09:00
Bill Currie
d14f695c68 [qfcc] Fix another type aliasing bug
This one exposed by the address expression cleanup.
2022-01-08 16:54:08 +09:00
Bill Currie
fa482e8ee5 [qfcc] Give address expressions their own type
Definitely a pain to get working after the switch, but definitely worth
the effort. Still exposing type aliasing bugs.
2022-01-08 16:52:24 +09:00
Bill Currie
cf8061c4d3 [qfcc] Mark opcode_get as pure
Because gcc told me to :P
2022-01-08 12:14:27 +09:00
Bill Currie
da210db720 [qfcc] Fix some type aliasing bugs
I have no idea why sorting out expression aliasing exposed these type
aliasing bugs, but it did. All tests *build* again (and pass).
2022-01-08 12:10:30 +09:00
Bill Currie
23c9a317f8 [qfcc] Give alias expressions their own type
While this was a pain to get working, that pain only went to prove the
value of using proper "types" (even if only an enum) for different
expression types: just finding all the places to edit was a chore, and
easy to make mistakes (forgetting bits here and there).

Strangely enough, this exposed a pile of *type* aliasing bugs (next
commit).
2022-01-08 12:06:52 +09:00
Bill Currie
420d55406f [qfcc] Add a rule to build the qfcc tests
This makes it easier to build and run (by hand) the tests when things
aren't working.
2022-01-08 03:09:15 +09:00
Bill Currie
ed6b84fbde [gamecode] Add missed long and ulong info
Both pr_type_size and pr_type_name. I want to macroize the enum, but
need to sort out the clutter of headers first, just need to decide on
naming. This at least sorts out the missed values for now.
2022-01-08 03:07:17 +09:00
Bill Currie
f5be54b6d2 [qfcc] Sanitize expr type enum
Got tired of dealing with out of date string tables.
2022-01-07 23:12:20 +09:00
Bill Currie
e186d5064d [gamecode] Correct return's opname
Not meant to have the size in it.
2022-01-07 21:48:19 +09:00
Bill Currie
8559a4fe2d whitespace 2022-01-07 21:48:02 +09:00
Bill Currie
479d82f380 [qfcc] Create separate instruction init and lookup
v6 vs v6p are more or less as before, with ruamoko added in. qfcc will
now try (and fail, due to the opcode table opnames being wrong) to
create ruamoko progs when given the ruamoko target option.
2022-01-07 19:56:15 +09:00
Bill Currie
14d95f81d1 [gamecode] Remove PR_Opcode_Init
It was idempotent, then it became impotent. Now it's just not needed.
2022-01-07 19:25:34 +09:00
Bill Currie
7e303a1151 [qfcc] Hide details about instruction type
At this stage, I doubt emit.c will need to know the details of the
target (v6, v6p, ruamoko) since the instruction formats are identical,
just different meanings for the opcode itself.
2022-01-07 19:05:26 +09:00
Bill Currie
d9ccf3a394 [qfcc] Remove a pile of stale externs
Those opcode pointers haven't been used for years.
2022-01-07 18:54:59 +09:00
Bill Currie
2d245b8cdc [qfcc] Replace [no-]v6only with target=
This allows v6, v6p (older QF VM) or ruamoko (new QF VM) to be targeted.
Currently defaults to v6p to allow QF to continue building without too
much hassle.
2022-01-07 18:34:05 +09:00