Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FTEQCC pointer instructions #215

Merged
merged 9 commits into from
Nov 12, 2024
Merged

Add FTEQCC pointer instructions #215

merged 9 commits into from
Nov 12, 2024

Conversation

divVerent
Copy link
Contributor

@divVerent divVerent commented Nov 1, 2024

This adds the following instructions:

  • GLOBALADDRESS
  • ADD_PIW
  • LOADA_{F,V,S,ENT,FLD,FNC,I}
  • LOAD_P
  • LOADP_{F,V,S,ENT,FLD,FNC,I}
  • Offset feature, and support for global pointers, for STOREP_{F,V,S,ENT,FLD,FNC,I}

It changes QC "address space" as follows:

  • Before:
    • [0x0, num_ents * num_fields[: entities
  • After:
    • [0x0, 0x80000000[: reserved (FTE puts strings and "malloc area" there)
    • [0x80000000, 0x80000000 + num_globals[: globals
    • [0x80000000 + num_globals, 0x80000000 + num_globals + num_ents * num_fields[: entities

This changes nothing visible, as these pointer values are generally invisible to well written QC code, however, writing to a NULL pointer notably now errors in the QC VM (previously, it would overwrite world.modelindex, which, I guess, may make the map go away, doesn't do that for me though).

Tested: this speeds up Xonotic serverbench by 6.8% while keeping correctness:

  • Before/GMQCC: real 44.68 user 43.77 progs.dat size 6892660
  • Before/FTEQCC: real 43.35 user 42.53 progs.dat size 6774526
  • This/FTEQCC: real 41.87 user 40.96 progs.dat size 6436758

@divVerent
Copy link
Contributor Author

divVerent commented Nov 1, 2024

To try with Xonotic, apply the attached patch, and compile like:

QCCFLAGS_WERROR='-O3' make -C data/xonotic-data.pk3dir/qcsrc ../progs.dat QCC=$HOME/Downloads/fteqw/build/fteqcc

use-new-opcodes-diff.txt

Note that there is one difference between fteqcc and gmqcc in constant folding; use this patch to remove this difference and get identical serverbench hashes so you can benchmark:

gmqcc-do-not-fold-into-reciprocal-diff.txt

Filed that as graphitemaster/gmqcc#210.

@divVerent
Copy link
Contributor Author

@graphitemaster Any chance gmqcc could gain support for these opcodes as well (behind a flag), and then no longer emit array accessor functions?

@divVerent divVerent force-pushed the divVerent/pointers branch 3 times, most recently from 6593bf9 to d7c38c3 Compare November 8, 2024 13:02
@divVerent
Copy link
Contributor Author

After having talked to @ladyhavoc, renamed FIELD_F etc. instruction in the disassembly to LOAD_F etc., matching the pr_comp.h names.

0 to 0x7FFFFFFF: reserved.
0x80000000 to 0x80000000 + num_globals - 1: global pointers.
0x80000000 + num_globals to 0x80000000 + num_globals + num_entities * num_entityfields - 1: entity field pointers.

Note that there are no instructions yet to _make_ global pointers, or to
load values from them.

This is the beginning of implementing the pointer instruction set.
@Cloudwalk9 Cloudwalk9 added enhancement New feature or request fteqw compatibility A quirk or feature making the engine (in)compatible with FTEQW and its mods. mod compatibility A quirk making the engine (in)compatible with mods that work on other engines labels Nov 8, 2024
This is used by FTEQCC array and pointer support.
Also, for safety, check the unused arg in 2 arg instructions.
Also fix instruction coloring and naming in disassembler.

- For some reason, all LOAD_ instructions are called FIELD_ now. Weren't
  they called INDIRECT_ once? Well, anyway, not touching that, just
  making it consistent with itself.

- Match new instructions in color to existing ones doing the same.
Changes:

- DIV -> DIV_F
- FIELD_* -> LOAD_*
Adds _F and _I type suffixes to lots of Quake-inherited opcodes that had
no type suffix but used floats (or ints).

Not handling IF/IFNOT yet, but documenting a plan.
@divVerent
Copy link
Contributor Author

From private chat, Spoike seems to be OK with this instruction set being added, and has plans of how to add it to FTEQCC.

So I am gonna merge now.

@divVerent divVerent merged commit 55e5665 into master Nov 12, 2024
1 of 2 checks passed
@Cloudwalk9
Copy link
Contributor

Retroactive approval/LGTM from my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fteqw compatibility A quirk or feature making the engine (in)compatible with FTEQW and its mods. mod compatibility A quirk making the engine (in)compatible with mods that work on other engines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants