Commit Graph

62 Commits

Author SHA1 Message Date
Bill Currie e61be2f80f [gamecode] Add 2- and 3-component swizzles
VM side of the work needed for #58. Tests are still only 4-component,
but the geometric algebra tests seem to have 2-component covered at
least a little bit.
2023-08-31 20:08:28 +09:00
Bill Currie a416e9c060 [gamecode] Add a 2d wedge product
While it could be emulated using a 3d cross-product, it was a hack and
required the use of a swizzle (or alias) to extract the scalar value.
This will make 2d PGA a little nicer when I get to modifying qfcc for it
2023-08-31 17:33:05 +09:00
Bill Currie a66fb80517 [gamecode] Switch dot products to give a scalar
Making them give a vector was a mistake for Ruamoko. I've probably got a
mess to clean up in game-source, but oh well.
2023-08-31 15:32:52 +09:00
Bill Currie 7338f86c77 [gamecode] Extend extend to support reversal
Using swizzle for some of the geometric product operations was a bit
clunky and has problems with alignment. While I will still need it in
the future, it turns out that the extend instruction almost did what I
needed. However, I'm unsure that reversing components within an extended
vector is the way to go.
2023-08-25 10:30:14 +09:00
Th3T3chn0G1t 3098b5d3f7 Implement clang support
Fixing a load of issues related to autoconf and some small source-level issues to re-add clang support.
autoconf feature detection probably needs some addressing - partially as -Werror is applied late.
2023-08-11 14:25:01 +09:00
Bill Currie 717cbaff87 [gamecode] Support offset for lea on globals
Allows using `array + offset` addressing. Both constant and variable
offsets are supported.
2023-05-14 12:45:08 +09:00
Bill Currie f18837f195 [gamecode] Fix a pile of UB in the test cases
I always suspected the overflow conversions were UB, but with gcc doing
different things on arm, I thought it was about time to abandon those
particular tests. What I was not expecting was for the return value of
strcmp to be "UB" (in that there's no guarantee of the exact value, just
< = > 0). Fortunately, nothing actually relies on the value of the op
other than the tests, so modify the test to make the behavior well
defined.
2023-03-25 21:21:13 +09:00
Bill Currie 0c54b0652b Abandon support for clang
The inconsistencies in clang's handling of casts was bad enough, and its
silliness with certain extensions, but discovering that it doesn't
support raw strings was just too much. Yes, it gives a 3s boost to qfvis
on gmsp3v2.bsp, but it's not worth the hassle.
2022-10-16 18:02:25 +09:00
Bill Currie 1e54799f69 [gamecode] Take care of failing uint conversion tests
By not doing the unrepresentable conversions, since they seem to be
undefined behavior and even gcc 12 is inconsistent with them
2022-08-18 18:18:19 +09:00
Bill Currie d9d0a80752 [gamecode] Add an extend instruction
The extend instruction is for loading narrower data types into wider
data types, eg, single element into 2, 3, or 4 element types, with a
small set of extension schemes: 0, 1, -1, copy (for 1->any and 2 -> 4).
Possibly most importantly, it works with unaligned data.

Progress towards #30
2022-08-18 18:18:19 +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 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 14ad364e17 [gamecode] Document the tests that fail under clang
The tests fail due to differences in how clang and gcc treat floating
point to unsigned integral type conversions when the values overflow. It
wouldn't be so bad if clang was consistent with conversions to 32-bit
unsigned integers, like it seems to be with conversion to 64-bit
unsigned integers.

With this, the "get QF building with clang" mini-project is done and I
won't have to panic when someone comes to me and asks if it will work.
At worst, there'll be a little bit-rot.
2022-03-31 14:50:49 +09:00
Bill Currie 2f9df0f05b Work around some clang parsing issues
clang has no problem with labels crossing declarations, but it can't
cope with a declaration (or end of block) just after a label.
2022-03-31 02:44:58 +09:00
Bill Currie 59044d3827 Fix a bunch of distcheck issues 2022-02-14 19:28:19 +09:00
Bill Currie e1ecda9221 [gamecode] Add unsigned divide and remainder instructions
I had forgotten that unsigned division was different from signed
division (rather silly of me). However, with some testing and analysis,
unsigned true modulo is not needed as it's not possible to have
negative inputs and thus it's the same as remainder.
2022-02-06 12:20:17 +09:00
Bill Currie 0211b6ec5b [gamecode] Add 64-bit load/store instructions
Only widths 3 and 4 have been added because widths 1 and 2 can be
implemented by widths 2 and 4 of the 32-bit load/store instructions.
2022-02-02 14:47:36 +09:00
Bill Currie 766bf758ab [gamecode] Redesign jump's B addressing
Yet another redundant addressing mode (since ptr + 0 can be used), so
replace it with a variable-indexed array (same as in v6p). Was forced
into noticing the problem when trying to compile Machine.r.
2022-01-30 22:34:40 +09:00
Bill Currie faa98d8198 [gamecode] Use a struct for offset/count pairs
This cleans up dprograms_t, making it easier to read and see what chunks
are in it (I was surprised to see only 6, the explicit pairs made it
seem to have more).
2022-01-26 19:30:25 +09:00
Bill Currie e20aed5c5a [gamecode] Change address mode B to entity.field
It turned out that address mode B was redundant as C with 0 offset
(immediate) was the same (except for the underlying C code of course,
but adding st->b is very cheap). This allowed B to be used for
entity.field for all transfer operations. Thus instructions 0-3 are now
free as load E became load B, and other than the specifics of format
codes for statement printing, transfers+lea are unified.
2022-01-20 14:55:29 +09:00
Bill Currie e9e54d08c0 [gamecode] Rename func_t to pr_func_t
Even more consistency.
2022-01-18 15:36:58 +09:00
Bill Currie 2df64384c1 [gamecode] Clean up string_t and pointer_t
They are both gone, and pr_pointer_t is now pr_ptr_t (pointer may be a
little clearer than ptr, but ptr is consistent with things like intptr,
and keeps the type name short).
2022-01-18 12:11:14 +09:00
Bill Currie e9af549195 [gamecode] Fix some goofs in the callchain test
They made it difficult to tell when I got things working :P
2022-01-17 18:51:50 +09:00
Bill Currie 306fcbfbd0 [gamecode] Improve callchain test
Add another function call to further mess up the return value address
and verify just where it is pointing.
2022-01-17 16:55:39 +09:00
Bill Currie 89e120ba34 [gamecode] Make return support 32 words
This took interpreting the lower 5 bits of operand c as size - 1, and
0xffff as void (0 words).
2022-01-17 16:54:27 +09:00
Bill Currie 94ef9931a5 [gamecode] Add two more call/return tests
The two tests check that 32 words can be returned (fails) and that
function calls can be nested and their values returned properly (also
fails).
2022-01-17 16:30:13 +09:00
Bill Currie 8da1163a82 [gamecode] Add bases check to callret test
The base registers must be preserved across a function call and they
currently are not, thus the updated test fails again.
2022-01-17 14:59:17 +09:00
Bill Currie b3909dbe4c [gamecode] Add a test for call and return
It currently fails for two reasons:
 - call's mode selection is incorrect (never updated from when there was
   only the one call instruction and the mode was encoded in operand c)
 - return should automatically restore the stack pointer to the value it
   had on entry to the function, thus allowing local values stored on
   the stack to be safely returned.
2022-01-17 14:26:12 +09:00
Bill Currie 1beadbf871 [gamecode] Add tests for the branch instructions 2022-01-17 09:57:54 +09:00
Bill Currie 1baf17b780 [gamecode] Add tests for the jump instructions 2022-01-17 09:34:16 +09:00
Bill Currie 1397c94ef5 [gamecode] Add tests for the state instructions 2022-01-16 22:17:17 +09:00
Bill Currie d57712975e [gamecode] Add tests for the hops instructions
And, of course, fix a bug in the inverted hops (yay for tests).
2022-01-16 18:46:29 +09:00
Bill Currie 8050c7bd77 [gamecode] Rearrange several instructions
ANY/ALL/NONE have been temporarily removed until I implement the HOPS
(horizontal operations) sub-instructions, which will all both 32-bit and
64-bit operands and several other operations (eg, horizontal add).

All the fancy addressing modes for the conditional branch instructions
have been permanently removed: I decided the gain was too little for the
cost (24 instructions vs 6). JUMP and CALL retain their addressing
modes, though.

Other instructions have been shuffled around a little to fill most of
the holes in the upper block of 256 instructions: just a single small
7-instruction hole.

Rearrangements in the actual engine are mostly just to keep the code
organized. The only real changes were the various IF statements and
dealing with the resulting changes in their addressing.
2022-01-16 14:22:04 +09:00
Bill Currie dc4df49fff [gamecode] Add tests for the swizzle instructions
While not always generated (yet?) the tests are at least in. Just not
sure about auto-generated tests that can't be hand-edited.
2022-01-15 22:44:58 +09:00
Bill Currie 49dcd5ef40 [gamecode] Add tests for the with instruction(s)
While mode 4 was tested a lot, none of the rest were. Also added a full
reset instruction.
2022-01-15 18:44:11 +09:00
Bill Currie e133de8c89 [gamecode] Drop B addressing for lea
When creating the tests for lea, I noticed that B was yet another simple
assign, so I decided it was best to drop it and move E into its place
(freeing up another instruction).
2022-01-15 16:27:46 +09:00
Bill Currie 11e89c8c97 [gamecode] Add tests for lea 2022-01-15 16:07:11 +09:00
Bill Currie fae432f46e [gamecode] Make no-op conversions simple copies
Most useful for 64-bit values as only one instruction is needed to move
the data around rather than two, but could be slightly faster for 32-bit
as the addressing is simpler (needs profiling).
2022-01-15 15:44:53 +09:00
Bill Currie bffcbfc9fc [gamecode] Add tests for bitops 2022-01-15 13:59:03 +09:00
Bill Currie 7cd398d4a7 [gamecodee] Add tests for move and memset 2022-01-15 13:20:33 +09:00
Bill Currie 6f1f56aea7 [gamecode] Make commented braces match
They annoyed me
2022-01-14 22:51:18 +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 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 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