Commit graph

5085 commits

Author SHA1 Message Date
Bill Currie
54f0af854b [ruamoko] Wrap the transform fuctions
Except for get/set name as I'm still pondering strings.
2022-02-15 00:06:39 +09:00
Bill Currie
ba3879c6e0 [scene] Make transforms owned by the scene
This actually has at least two benefits: the transform id is managed by
the scene and thus does not need separate management by the Ruamoko
wrapper functions, and better memory handling of the transform objects.
Another benefit that isn't realized yet is that this is a step towards
breaking the renderers free of quake and quakeworld: although the
clients don't actually use the scene yet, it will be a good place to
store the rendering information (functions to run, etc).
2022-02-14 20:01:36 +09:00
Bill Currie
f0c35e541a [ruamoko] Pass some more purity tests
Separate because I want to cherry-pick the other commit.
2022-02-14 19:56:56 +09:00
Bill Currie
e58d53d4b6 [gamecode] Pass gcc's purity test again
I guess maybe that change might make a bigger difference than I thought,
gcc wasn't happy with it.
2022-02-14 19:30:50 +09:00
Bill Currie
59044d3827 Fix a bunch of distcheck issues 2022-02-14 19:28:19 +09:00
Bill Currie
afbca54faf [ruamoko] Add wrappers for the existing scene functions
I've run into a bit of an issue with transform management (really, just
need to make them owned by the scene, but that means creating a scene
for quake and quakeworld).
2022-02-14 16:43:10 +09:00
Bill Currie
f6ac614e09 [scene] Add functions for scene and entity create/delete
Scene creation was already there, but now can be deleted, as can
entities.
2022-02-14 16:41:38 +09:00
Bill Currie
4d491a444d [gamecode] Fix handling of undefined builtins
The setup of the function descriptor for undefined builtins was
incomplete and led to the progs running code at address 0. It didn't end
well.
2022-02-14 14: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
944a9253e9 [gamecode] Support %u format in PR_Sprintf
Not sure why it was missed as it would have been useful even before
unsigned was properly supported by qfcc.
2022-02-12 01:58:38 +09:00
Bill Currie
fc8cc0b703 [zone] Be more informative when catching memory errors
The registered error handler is given a chance to report the error, and
the corrupted id is printed.
2022-02-12 01:57:03 +09:00
Bill Currie
1d26c727a3 [ruamoko] Allocate selectors in large blocks
The zone memory block header is 64 bytes, so allocating a single 8 byte
selector is rather wasteful. Instead, allocate selectors in large chunks
(currently 64) and divvy them out as needed. Significantly reduces
memory pressure in large Ruamoko progs.
2022-02-12 01:52:35 +09:00
Bill Currie
eba614336d [gamecode] Add single-component float bitop instructions
These add legacy support for basic float bitops (& | ^ ~). Avoiding the
instructions would require tot only the source to be converted, but also
the servers (as they do access those fields), and this seemed to be too
much.
2022-02-06 21:20:00 +09:00
Bill Currie
7c6ef06dfb [gamecode] Make PF_VarString v6p-only
It's not enforced a this stage, and it would be easy enough to handle,
but it turns out all the standard quake and quakeworld progs never used
... for the print functions: the behavior of PF_VarString was
undocumented and so... tough :P.
2022-02-06 21:20:00 +09:00
Bill Currie
95c4cdd1b0 [vulkan] Set frame buffer before calling draw functions
This lets them set up their subpass inherit info correctly. QF now
renders correctly, albeit painfully slowly, on my VersaPro.
2022-02-06 13:12:16 +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
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
078f36a871 [gamecode] Add "return pointer" mode to with instruction
This loads the current return pointer into the specified register. No
offset is used (should make that an error, but for now any offset is
simply ignored). This is part of the fix for getting obj_msg_sendv to
work with return values.
2022-02-05 18:42:54 +09:00
Bill Currie
208cba85eb [gamecode] Move return buffer to end of progs memory map
With the return buffer in progs_t, it could not be addressed by the
progs on 64-bit machines (this was intentional, actually), but in order
to get obj_msg_sendv working properly, I needed a way to "bounce" the
return address of a calling function to the called function. The
cleanest solution I could think of was to add a mode to the with
instruction allowing the return pointer to be loaded into a register and
then calling the function with a 0 offset for the return value but using
the relevant register (next few commits). Testing promptly segfaulted
due to the 64-bit offset not fitting into a 32-bit value.
2022-02-05 18:37:23 +09:00
Bill Currie
b0810958e7 [ruamoko] Use encoded selector param count when forwarding
This gets message forwarding apparently working, though something isn't
quite right as qwaq-app doesn't update properly when I try to step
through the program, but that could be an error elsewhere.
2022-02-05 14:24:12 +09:00
Bill Currie
9cf2740cb4 [gamecode] Create a globally accessible hash of type encodings
The plan is to use the types to extract the number of parameters for a
selector when it is necessary to know the count. However, it'll probably
become useful for something else alter (these things seem to always do
so).
2022-02-05 14:07:45 +09:00
Bill Currie
2c0969f988 [ruamoko] Rework method call hand-off to preserve the stack
This takes care of the problems with PR_RESET_PARAMS (which has recently
become just a wrapper for PR_SetupParams) changing the stack and causing
PR_CallFunction to save the wrong stack pointer. Message forwarding is
currently broken for Ruamoko ISA progs, but that is due to not having a
valid pr_argc. However, I do have a plan involving extracting the
parameter count from the selector, but that's something for a later
commit. Everything else seems to be ok (my little game is working
nicely).
2022-02-05 13:01:44 +09:00
Bill Currie
01345ba675 [gamecode] Wrap most uses of PR_RESET_PARAMS with push/pop frame
rua_obj was skipped because that looks to be a bit more work and should
be a separate commit.

This is to avoid the stack getting mangled when calling progs functions
with parameters.
2022-02-05 10:26:47 +09:00
Bill Currie
2fc35b39b0 [ruamoko] Use a shared implementation for set functions
I suppose having one builtin call another was a neat idea at the time,
and really could have been fixed by simply wrapping the calls with
push/pop frame, but this is probably faster.
2022-02-04 22:19:05 +09:00
Bill Currie
5f684b2f81 [ruamoko] Rework PF_VarString to work with Ruamoko progs
It's a rather core function used by the game code, though it is rather
horrid.
2022-02-04 22:15:24 +09:00
Bill Currie
cdc3c9822d [ruamoko] Preserve the stack in obj_msg_sendv
obj_msg_sendv needs to push the parameters onto the stack for Ruamoko
progs, but this causes problems because PR_CallFunction winds up
recording the wrong stack pointer for progs functions, and nothing
restores the stack for builtins. The handling is basically the same as
for the return pointer.
2022-02-04 22:09:38 +09:00
Bill Currie
2a8fca80a0 [nq,qw] Give the menu and server progs stacks
They're going to need them :P
2022-02-04 21:53:37 +09:00
Bill Currie
7731c469e2 [gamecode] Count calls to builtins in profile
It's a bit disconcerting seeing a builtin in the top 10 when builtins
are counted by call while progs functions are counted by instruction.

Also, show the total profile after the function top-10 list.
2022-02-04 21:49:59 +09:00
Bill Currie
b425f449b6 [ruamoko] Separate the two str_mid builtins
pr_argc cannot be used in Ruamoko progs because nothing sets it. This
fixes the parse errors and resulting segfault when trying to parse the
Vulkan pipeline config.
2022-02-04 11:38:36 +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
6514e09e7c [gamecode] Use an explicit size for the null page
It's currently only 4 (or even 3 for v6) words, but this fixes false
positives when checking for null pointers in Ruamoko progs due to
pr_return pointing to the return buffer and thus outside the progs
memory map resulting in an impossible to exceed value.
2022-02-01 16:43:29 +09:00
Bill Currie
2fcec6e5cb [zone] Move heap check to Z_TagMalloc
Since Z_Malloc uses Z_TagMalloc to do the work, this ensures the check
is always run.

Also, add the check to Z_Realloc when it needs to adjust an existing
block.
2022-02-01 14:56:47 +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
5d41e90cc7 [gamecode] Remove pushregs and popregs specs
They have been redundant since the operations were moved into with.
2022-01-31 23:47:47 +09:00
Bill Currie
e7ac637687 [ruamoko] Wrap hash table callbacks with push/pop frame
Builtins that call progs with parameters now must always wrap the call
to PR_ExecuteProgram so that the data stack is properly preserved across
the call.

I need to do an audit of all the calls to PR_ExecuteProgram.
2022-01-31 23:47:02 +09:00
Bill Currie
712d800491 [gamecode] Save return ptr for chained calls
It turns out the return pointer still needs to be saved even when a
builtin sets up a chain call to progs, but rather than the pointer being
simply restored, it needs to be saved in the call stack exactly as if
the function was called directly by progs. This fixes the invalid self
issue quite thoroughly: parameter state seems to be correct across all
calls now.

I should set up an automated test now that I know and understand the
situation.
2022-01-31 23:35:56 +09:00
Bill Currie
92711e778c [ruamoko] Set params in obj_msgSend_super only for v6p progs
In Ruamoko ISA progs, the param pointers point to the stack and
generally must most be manipulated by builtins, and there is no need
anyway as Ruamoko doesn't have RCALL. Fixes the mangling of .super.
2022-01-31 19:04:18 +09:00
Bill Currie
cabb53e693 [gamecode] Skip return ptr restore if depth changed
When calling a builtin, normally the return pointer needs to be
restored, but if the builtin changes the call depth (usually by
effecting "return foo()" as in support for objects, but possibly
setjmp/longjmp when they are implemented), then the return pointer must
not be restored. This gets vkgen past object allocation, but it dies
when trying to send messages to super. This appears to be a compiler
bug.
2022-01-31 16:51:46 +09:00
Bill Currie
c5ae1ae13c [ruamoko] Check self is within progs memory
Changes a segfault to a runtime error, which beats the risk of self
pointing somewhere that doesn't segrault.
2022-01-31 14:03:36 +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
7971bcd91c [gamecode] Sort out shr's opname for easier searching
Since the operand types sort out the difference between asr and shr, no
need to give them different opnames. Means qfcc doesn't need to worry
about which one it's searching for.
2022-01-30 22:37:03 +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
4871717fae [gamecode] Rename v6 vector-scalar multiply to scale
Makes it easier to get Ruamoko scaling implemented if they both use the
same opname.
2022-01-30 14:47:26 +09:00
Bill Currie
46ce37160b [gamecode] Correct vecops widths
I had forgotten to update the widths when I moved cross product's
position.
2022-01-30 14:11:41 +09:00
Bill Currie
728c42e921 [gamecode] Use pr_type_names for debug views
I abandoned the reason for doing it (adding a pile of vector types), but
I liked the cleanup. All the implementations are hand-written still, but
at least the boilerplate stuff is automated.
2022-01-30 10:49:33 +09:00
Bill Currie
49395b3ba1 [gamecode] Correct state's types for double time
It takes int for the frame rather than float.
2022-01-29 18:48:05 +09:00
Bill Currie
7e9cf76cfe [qfcc] Change ne to cmp for v6 string inequality check
Since it's really strcmp in disguise (makes the instruction consistent
across all targets).
2022-01-29 18:18:33 +09:00
Bill Currie
10843fe340 [gamecode] Correct memset opname and types 2022-01-29 17:05:10 +09:00
Bill Currie
5c22253095 [gamecode] Use the stack frame to find local defs
Of course, only in Ruamoko progs, but it works quite nicely.
global_string is now passed the absolute address of the referenced
operand. With a little groveling through the progs stack, it should be
possible to resolve pointers to locals in functions further up the
stack.
2022-01-27 14:20:09 +09:00
Bill Currie
de974fdd3f [gamecode] Add format for addressing modes and use in return
This fixes Ruamoko's return format string. It looks like it's producing
the correct address (but doesn't show all the information it should),
but the rest of the debug code needs work locals.
2022-01-27 13:29:38 +09:00
Bill Currie
42db8514ae [gamecode] Use version instead of locals count
It turned out I need locals count and params_start for debugging, so use
the progs version instead to bail early from PR_EnterFunction and
PR_LeaveFunction (which I had forgotten anyway, oops).
2022-01-27 11:24:00 +09:00
Bill Currie
a0d9cf8d8e [gamecode] Improve verbose statement prints for Ruamoko
They now include base register index and effective address of the
operands (though it may be wrong for instructions that don't use a base
register for that operand).
2022-01-27 10:57:31 +09:00
Bill Currie
59ee723201 [gamecode] Rename parm to param
That misspelling bothered me from the very beginning, I'd always have
trouble getting the name right when trying to access one of those fields.
2022-01-27 10:55:06 +09:00
Bill Currie
e9dff4ff9c [gamecode] Correct types and widths for bitnot
bitnot is the only unary operator in the bitops group and thus needs
special handling.
2022-01-27 10:21:48 +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
a2f4522e76 [gamecode] Align Ruamoko progs to 32 bytes.
Intel hardware requires 32-byte alignment for lvec4 and dvec4.
Unfortunately, it turns out that my attempts to align progs data in qfcc
went awry do to the order block sizes are calculated when writing the
progs.
2022-01-26 16:55:14 +09:00
Bill Currie
ee4eecc741 [gamecode] Correct types and opname for memset and move 2022-01-26 12:26:12 +09:00
Bill Currie
6bc6db471d [gamecode] Make return use same addressing as other ops
This makes return consistent with load, store, etc, though its
addressing mode is encoded in bits 5 and 6 of c rather than the opcode.
It turns out I had no tests for any of return's addressing modes other
than basic def references, so no tests needed changing.
2022-01-26 09:51:11 +09:00
Bill Currie
37f08f9d4f [qfcc] Build the Ruamoko function parameters
The parameter defs are allocated from the parameter space using a
minimum alignment of 4, and varargs functions get a va_list struct in
place of the ...

An "args" expression is unconditionally injected into the call arguments
list at the place where ... is in the list, with arguments passed
through ... coming after the ...

Arguments get through to functions now, but there's problems with taking
the address of local variables: currently done using constant pointer
defs, which can't work for the base register addressing used in Ruamoko
progs.

With the update to test-bi's printf (and a hack to qfcc for lea),
triangle.r actually works, printing the expected results (but -1 instead
of 1 for equality, though that too is actually expected). qfcc will take
a bit longer because it seems there are some design issues in address
expressions (ambiguity, and a few other things) that have pretty much
always been there.
2022-01-24 23:44:48 +09:00
Bill Currie
b663fecd4e [gamecode] Use PR_SetupParameters for rua called builtins
It's a bit heavy-handed as it sets all the param pointers, but simple
(no varargs) functions are working nicely in Ruamoko.
2022-01-24 16:46:49 +09:00
Bill Currie
00b7bced7f [gamecode] Rework PR_RESET_PARAMS to use PR_SetupParams
PR_SetupParams is new and sets up the parameter pointers so older code
that expects only up to 8 parameter will work with both v6p and Ruamoko
progs without having to check what progs are running. PR_SetupParams is
useful even when Ruamoko progs are expected as it reserves the required
space (respecting alignment) on the stack and returns a pointer to the
top (bottom? confusing) of the stack. PR_PushFrame and PR_PopFrame
need to be used around PR_SetupParams, regardless of using temp strings,
to avoid a stack leak (need to do an audit).
2022-01-24 12:50:15 +09:00
Bill Currie
9c51c3d2e1 [gamecode] Add a data pointer passed to builtin functions
This is part of the work for #26 (Record resource pointer with builtin
function data). Currently, the data pointer gets as far as the
per-instance VM function table (I don't feel like tackling the job of
converting all the builtin functions tonight). All the builtin modules
that register a resources data block pass that block on to
PR_RegisterBuiltins.
2022-01-24 00:20:05 +09:00
Bill Currie
a818fa4b8e [gamecode] Rearrange bfunction_t in preparation for param offsets
The builtin and progs function data is overlaid so the extra data
doesn't cause too much memory to be used (it's actually 8 bytes smaller
now).  The plan is to pre-compute the offsets based on the parameter
size and alignment data.
2022-01-24 00:19:13 +09:00
Bill Currie
a6b932025c [gamecode] Provide builtins with information about their parameters
This will make it possible for the engine to set up their parameter
pointers when running Ruamoko progs. At this stage, it doesn't matter
*too* much, except for varargs functions, because no builtin yet takes
anything larger than a float quaternion, but it will be critical when
double or long vec3 and vec4 values are passed.
2022-01-23 22:27:27 +09:00
Bill Currie
e746e39738 [gamecode] Create macros for progs sizeof and alignof
I wound up needing the idioms in too many places.
2022-01-23 14:29:33 +09:00
Bill Currie
3c86660d4a [gamecode] Rename MAX_PARMS to PR_MAXPARAMS 2022-01-23 14:17:25 +09:00
Bill Currie
cfaf158ebc [math] Add some bit-op functions
Just 32-bit rounding to next higher power of two, and base 2 logarithm.
Most importantly, they are suitable for use in initializers as they are
constant in, constant out.
2022-01-23 13:47:14 +09:00
Bill Currie
861e98725c [gamecode] Return early if the entered function has no locals
As even the simplest v6p functions that take parameters but have no
local or temporary variables still have locals for the local copy of the
parameters, this is a both a good check for for the Ruamoko ISA as its
functions never have locals (everything's on the progs data stack), and
an optimization for v6p functions that have no params or locals (simple
getters (very rare?), most .ctor, etc).
2022-01-22 21:41:35 +09:00
Bill Currie
06b1ea6837 [gamecode] Tweak some docs and macro names
And fix an incorrect definition for RETURN_QUAT.

Prefixed MAX_STACK_DEPTH and LOCALSTACK_SIZE (and LOCALSTACK_SIZE got an
extra _).

The rest is just edits to documentation comments.
2022-01-22 11:38:14 +09:00
Bill Currie
7a5ee6a55a [gamecode] Initialize .stack if it's available
And implement bounds checks for adjstk.
2022-01-21 20:33:15 +09:00
Bill Currie
9199a0ee54 [gamecode] Don't check v6p progs for Ruamoko progs
It doesn't end well. For now, the Ruamoko check is just a stub, but I do
plan on doing similar checks.
2022-01-21 20:31:49 +09:00
Bill Currie
3df46d197f [gamecode] Add instructions for stack adjust, nop, and ldconst
ldconst isn't implemented yet but the plan is to load various constants
(eg, 0, 1, 2, pi, e, ...).

Stack adjust is useful for adding an offset to the stack pointer without
having to worry about finding it (and it checks for alignment).

nop is just that :)
2022-01-21 20:00:38 +09:00
Bill Currie
c53127707b [qfcc] Set the return of Ruamoko calls
Of course, I had the width of opc wrong :P. But with this, it seems that
unoptimized calls should work once I get the stack frame working.
2022-01-21 13:50:21 +09:00
Bill Currie
16a203c643 [gamecode] Partially implement conversion code debug
The code is simply printed in octal for now, but it's better than
breaking the rest of the format string.
2022-01-21 10:12:50 +09:00
Bill Currie
578314c5a3 [gamecode] Use a buffer for discarded return values
Due to how OP_RETURN works, a destination is required for any function
returning data, but the caller may not have allocated any space for the
value. Thus the VM maintains a buffer into which the data can be put and
ignored. It also makes a good place for return values when the engine
calls Ruamoko code as trusting progs code with return sizes seems like a
recipe for disaster, especially if the return location is on the C
stack.
2022-01-21 10:09:02 +09:00
Bill Currie
4b87d24737 [gamecode] Correct call's operator types 2022-01-21 10:07:35 +09:00
Bill Currie
5f66bfe887 [gamecode] Update printed opcode width
Opcodes now need 3 hex digits (hexits?) to print.
2022-01-20 18:37:28 +09:00
Bill Currie
c39558efaa [gamecode] Audit the widths of rest of the instructions
I can't test them properly until I get qfcc up and running with basic
ruamoko code, but they are at least more correct than they were.
2022-01-20 17:27:56 +09:00
Bill Currie
854e45485a [gamecode] Correct the widths for load, store and lea
The different addressing modes complicate the width calculations, and
lea is particularly fun in that it doesn't care what the width of value
is.
2022-01-20 16:33:04 +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
6ae9daf4b7 [gamecode] Clean out dead any/all/none data
The instructions are gone as hor/hand/hnor take care of them.
2022-01-20 14:52:59 +09:00
Bill Currie
875d4dc7cf [gamecode] Correct some ruamoko instruction meta data
There were some errors in instruction names and operand types resulting
in unsearchable instructions.
2022-01-20 13:08:05 +09:00
Bill Currie
a4ebd6aa58 [gamecode] Fix a few missed opcode renames
if and ifnot became ifnz and ifz, and return_v lost its tail (it was
always redundant, except in dags, and that's fixed with a pointer check).
2022-01-20 13:07:57 +09:00
Bill Currie
143030fec4 [gamecode] Use text for all v6p opcode names
This makes the v6p instruction table consistent with the ruamoko
instruction table, and clears up some of the ugliness with the load,
store, and assign instructions (. .= and = are now spelled out). I think
I'd still prefer an enum code (faster) but at least this is more
readable.
2022-01-20 09:26:01 +09:00
Bill Currie
df890432b7 [qfcc] Add support for unsigned, long, etc
long is ignored for double, and v6p progs are stuck with 32 bits for
longs (don't feel like extending v6p any further), but the basics are
there for Ruamoko.

short is ignored for ints because the minimum size is 32, and signed is
just noise for ints anyway (and no chars, so...).

unsigned, however, is finally implemented properly (or at least seems to
be working correctly: tests pass after getting things compiling again,
and lt.u is used where it should be :)
2022-01-19 18:08:58 +09:00
Bill Currie
8d20997b2b [gamecode] Move pr_void_t to pr_comp.h
I think I had decided to put it there but forgot before committing the
size change, but I wound up needing it for qfcc.
2022-01-18 22:58:26 +09:00
Bill Currie
068c04ece6 [gamecode] Add ev_ushort and partial support
Really, only just enough to get everything compiling (which does include
vkgen running correctly).
2022-01-18 22:08:37 +09:00
Bill Currie
ed501b7734 [gamecode] Specify the alignment for progs types
And provide a table for such for qfcc and the like. With this, using
pr_double_t (for example) in C will cause the double value to always be
8-byte aligned and thus structures shared between gcc and qfcc will be
consistent (with a little fuss to take care of the warts).
2022-01-18 18:41:39 +09:00
Bill Currie
25f8d3a23d [gamecode] Use pr_type_names.h for type sizes
The goal of the previous mess of commits. Ruamoko needs to wait until
qfcc has the new types.
2022-01-18 17:05:12 +09:00
Bill Currie
2c52e26d1a [gamecode] Be more consistent with access types
Eg, pointers via ptr, entities via entity, etc.
2022-01-18 17:05:12 +09:00
Bill Currie
cd30408675 [gamecode] Rename ev_quat to ev_quaternion
I much prefer the full name, though the short version is easier to type.
2022-01-18 17:05:12 +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
afd1eb775b [gamecode] Rename ev_pointer to ev_ptr
Rather short (no worse than ev_int, though) but more consistency is
usually a good thing.
2022-01-18 14:36:06 +09:00
Bill Currie
cfe7c44df0 [gamecode] Rename ev_integer to ev_int
And other related fields so integer is now int (and uinteger is uint). I
really don't know why I went with integer in the first place, but this
will make using macros easier for dealing with types.
2022-01-18 13:27:19 +09:00
Bill Currie
978d6fd3e8 [gamecode] Macro-ize the progs type names
Now they'll never get out of sync again :)
2022-01-18 13:27:19 +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
9348f7b89c [gamecode] Preserve the return pointer across calls
This required delaying the setting of the return pointer by call until
after the current pointer had been saved, and thus passing the desired
pointer into PR_CallFunction (which does have some advantages for C
functions calling progs functions, but some dangers too (should ensure a
128 byte (32 word) buffer when calling untrusted code (which is any,
really)).
2022-01-17 19:12:28 +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
736387bc88 [gamecode] Preserve base registers across calls
With this, functions can call other functions without having to worry
about whether the base registers they set up are still valid.
2022-01-17 15:08:58 +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
213434b705 [gamecode] Save and restore data stack in call stack
This fixes the issue of the data stack not being restored properly
because the returning function needs to return a value from its local
variables (stored on the stack) and accessing stack data below the stack
pointer is a bad idea (sure, no interrupts yet, but who knows...).
2022-01-17 14:45:14 +09:00
Bill Currie
8e5c2c6534 [gamecode] Correct type of return address in stack
This is another one of those "why signed?" things: can't have negative
return addresses.
2022-01-17 14:43:43 +09:00
Bill Currie
cf3106ce28 [gamecode] Correct call's mode selection
Call's operand c is used to specify where the return value of the
function is to be stored. This gets both the correct function being
called, and the value being returned correctly. Test still fails due to
the stack restoration issue.
2022-01-17 14:29:14 +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
56d8bdee82 [gamecode] Add a fixme about using gcc's vec convert
It might produce better code than the way I'm currently doing it.
2022-01-17 10:32:19 +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
0bd05c71ac [gamecode] Use unsigned for entity values
I don't know why they were ever signed (oversight at id and just
propagated?). Anyway, this resulted in "unsigned" spreading a bit, but
all to reasonable places.
2022-01-16 22:15:18 +09:00
Bill Currie
2b82533526 [gamecode] Add double time state instructions
This has been a long-held wishlist item, really, and I thought I might
as well take the opportunity to add the instructions. The double
versions of STATE require both the nextthink field and time global to be
double (but they're not resolved properly yet: marked with
"FIXME double time" comments).

Also, the frame number for double time state is integer rather than
float.
2022-01-16 21:27:49 +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
7ea12b3ff9 [gamecode] Implement the HOPS sub-instructions
In the end, I decided any/all/none should be separate from the other
horizontal ops, if I even do them (can be implemented by first
converting to bool, then using the appropriate horizontal operation (& |
etc).
2022-01-16 16:28:48 +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
38ab0f0243 [gamecode] Move pushregs and popregs into with
This frees up another two instructions.
2022-01-15 16:51:59 +09:00
Bill Currie
a14b9f8252 [gamecode] Move the lea block
It just feels better with it being close the load/store etc
2022-01-15 16:39:52 +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
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