Commit Graph

1108 Commits

Author SHA1 Message Date
Bill Currie c02fcee58a [util] Make zone functions 64-bit clean
This allows nq and qw clients/servers to use over 2GB of memory if
necessary.
2021-07-26 15:43:57 +09:00
Bill Currie 03921c03c5 [util] Expose set_expand and fix an out-by-one bug
Having set_expand exposed is useful for loading data into a set.

However, it turns out there was a bug in its size calculation in that
when the requested set size was a multiple of SET_BITS (and greater than
the current set size), the new set size one be SET_BITS larger than
requested. There's now some tests for this :)
2021-07-26 09:54:03 +09:00
Bill Currie 41de8c9187 [util] Cast swapped signed shorts in bspfile
This fixes a bug when loading bsp29 files that resulted in leaf nodes
having bogus bounding boxes if any coordinates were negative (and thus
dynamic lights, and probably all sorts of other things) being broken.
And it took me only 9 years to notice :P
2021-07-22 14:25:51 +09:00
Bill Currie 1078bd9efa [util] Implement Sys_Free for windows
And get the tests so they can (sort of) be run.
2021-07-12 18:55:16 +09:00
Bill Currie 0a847f92f1 [util] Use mmap/munmap for cmem internal alloc/free
This reduces the overhead needed to manage the memory blocks as the
blocks are guaranteed to be page-aligned. Also, the superblock is now
alllocated from within one of the memory blocks it manages. While this
does slightly reduce the available cachelines within the first block (by
one or two depending on 32 vs 64 bit pointers), it removes the need for
an extra memory allocation (probably via malloc) for the superblock.
2021-07-12 16:33:47 +09:00
Bill Currie 3c0ad2ca71 [qw] Fix some server status output issues
The uptime display had not been updated for the offset Sys_DoubleTime,
so add Sys_DoubleTimeBase to make it easy to use Sys_DoubleTime as
uptime.

Line up the layout of the client list was not consistent for drop and
qport.
2021-07-11 08:18:02 +09:00
Bill Currie 139a6aee87
Merge pull request #17 from ionenwks/noexecstack
Add GNU-stack notes to assembly files
2021-06-28 10:16:46 +09:00
Bill Currie 789ef6be63
Merge pull request #18 from digitall/avx-fix
[simd] fix build when avx2 is not available, but avx is.
2021-06-28 10:12:32 +09:00
Bill Currie 0be609e0fd [util] Make PI_LoadPlugin always call general init function
As the root cause for #16 was something else, this fixes only the basic
cvar initialization, but does fix #19 (for now, at least).
2021-06-26 16:18:05 +09:00
D G Turner b799d48ccb [simd] fix build when avx2 is not available, but avx is.
This failed with errors such as:
                 from ./include/QF/simd/vec4d.h:32,
                 from libs/util/simd.c:37:
./include/QF/simd/vec4d.h: In function ‘qmuld’:
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/avx2intrin.h:1049:1: error: inlining failed in call to ‘always_inline’ ‘_mm256_permute4x64_pd’: target specific option mismatch
 1049 | _mm256_permute4x64_pd (__m256d __X, const int __M)
2021-06-23 01:10:42 +01:00
Bill Currie c9319966ce [plugin] Clean up the rest of the plugin structs 2021-06-22 19:47:20 +09:00
Bill Currie 097d44e270 [util] Handle double shutdown
If Sys_Shutdown gets called twice, particularly if a shutdown callback
hangs and the program is killed with INT or QUIT, shutdown_list would be
in an invalid state. Thus, get the required data (function pointer and
data pointer) from the list element, then unlink the element before
calling the function. This ensures that a reinvocation of Sys_Shutdown
continues from the next callback or ends cleanly. Fixes a segfault when
killing testsound while using the oss output (it hangs on shutdown).
2021-06-21 16:45:46 +09:00
Ionen Wolkens 881add2c51
Add GNU-stack notes to assembly files
Prevents GCC from assuming an executable stack is needed.

Signed-off-by: Ionen Wolkens <ionen@gentoo.org>
2021-06-13 10:12:03 -04:00
Bill Currie 36df16eefc [util] Fix incorrect type in test-mat3
Fixes make check for gcc-11
2021-06-13 15:00:57 +09:00
Bill Currie 24fd443ef3 [ui] Move txtbuffer and vrect tests to libs/ui
Fixes make check
2021-06-13 14:29:46 +09:00
Bill Currie 813497a1aa [ui] Create library for UI support code
Currently this has text buffer, input line, vrect and view code.
2021-06-12 22:50:51 +09:00
Bill Currie 713862c511 [util] Fix format issue in set test
I guess I hadn't done a "make check" on 64-bit since getting windows
builds to work.
2021-06-01 19:11:51 +09:00
Bill Currie bcc5686606 [util] Add fuzzy and reentrant bsearch
Fuzzy bsearch is useful for finding an entry in a prefix sum array
(value is >= ele[0], < ele[1]), and the reentrant version is good when
data needs to be passed to the compare function. Adapted from the code
used in pr_resolve.
2021-06-01 18:53:53 +09:00
Bill Currie 0293167bd2 [util] Get simd tests working for emulated simd
A bit of a mess for optimized vs unoptimized, but the tests acknowledge
the differences in precision while checking that the code produces the
right results allowing for that precision.
2021-06-01 18:53:53 +09:00
Bill Currie ef9b04ba83 [util] Get tests working with sse2
It seems that i686 code generation is all over the place reguarding sse2
vs fp, with the resulting differences in carried precision. I'm not sure
I'm happy with the situation, but at least it's being tested to a
certain extent. Not sure if this broke basic (no sse) i686 tests.
2021-06-01 18:53:53 +09:00
Bill Currie 778c07e91f [util] Get vectors working for non-SSE archs
GCC does a fairly nice job of producing code for vector types when the
hardware doesn't support SIMD, but it seems to break certain math
optimization rules due to excess precision (?). Still, it works well
enough for the core engine, but may not be well suited to the tools.
However, so far, only qfvis uses vector types (and it's not tested yet),
and tools should probably be used on suitable machines anyway (not
forces, of course).
2021-06-01 18:53:53 +09:00
Bill Currie a461c09586 [util] Make cmem consistent on 32 and 64 bit systems
I don't know that the cache line size is 64 bytes on 32 bit systems, but
it should be ok to assume that 64-byte alignment behaves well on systems
with smaller cache lines so long as they are powers of two. This does
mean there is some waste on 32-bit systems, but it should be fairly
minimal (32 bytes per memblock, which manages page sized regions).
2021-06-01 18:53:52 +09:00
Bill Currie 9dca47c0e1 Make the set tests word size agnostic. 2021-06-01 18:53:52 +09:00
Bill Currie 1e9329ccf6 [nq,qw] Stop wring to config.cfg
QF now uses its own configuration file (quakeforge.cfg for now) rather
than overwriting config.cfg so that people trying out QF in their normal
quake installs don't trash their config.cfg for other quake clients. If
quakeforge.cfg is present, all other config files are ignored except
that quake.rc is scanned for a startdemos command and that is executed.
2021-04-12 22:09:09 +09:00
Bill Currie f596eacf0c [util] Add message short and long poke functions
Both big and little endian.
2021-04-04 15:56:14 +09:00
Bill Currie 972b0f8a70 [util] Make sizebuf and msg sizes unisgned
And clean up the mess.
2021-04-04 15:53:53 +09:00
Bill Currie 9a2f82bbc6 [util] Add big-endian short msg read/write
And improve the generated code for MSG_ReadShort

I suspect gcc didn't like all the excess pointer dereferences and so
couldn't assume that the bytes were being read sequentially.
2021-04-04 15:19:38 +09:00
Bill Currie afd7b38551 [util] Add big-endian long msg read/write
And improve the generated code as well (ie, use a code sequence that gcc
recognizes and optimizes to a single 32-bit read and a byte-swap).

nq uses big-endian for its packet headers (arg, though it is consistent
with IP, it's not with the rest of quake).
2021-04-04 15:11:09 +09:00
Bill Currie 7864bb0ba6 [util] Use a clearer parameter name for SZ_Alloc 2021-04-04 14:09:02 +09:00
Bill Currie 39103cc8a3 [sw] Fix some 32-bit assembly issues
I'm not sure that the mismatch between refdef_t and the assembly defines
was a problem (many fields unused), but the main problem was due to
execute permission on the pages: one chunk of asm was in the data
section, and the patched code was not marked as being executable (due to
such a thing not existing when quake was written).
2021-04-02 22:17:32 +09:00
Bill Currie 9ded490806 [util] Add Sys_PageSize
Eliminate that particular problem once and for all.
2021-04-01 18:20:56 +09:00
Bill Currie 73a610508c [util] Fix cmem for windows
I had quite messed up the page size (oops), and missed the fact that
_aligned_free is to be used with _aligned_malloc rather than just free.
2021-04-01 18:00:59 +09:00
Bill Currie 5f93c115ff [util] Make developer flag names easier to manage
They're now an enum, and the flag part of the name is all lowercase, but
now the flag definitions and names list will never get out of sync.
2021-03-29 22:38:47 +09:00
Bill Currie 6fea5f5e1a [build] Add -Wformat-non-literal option
While this caused some trouble for pr_strings and configurable strftime
(evil hacks abound), it's the result of discovering an ancient (from
maybe as early as 2004, definitely before 2012) bug in qwaq's printing
that somehow got past months of trial-by-fire testing (origin understood
thanks to the warning finding it).
2021-03-29 17:27:06 +09:00
Bill Currie a754dbca37 [util] Make va return const char *
And clean up the resulting mess.

I don't know why it wasn't doing so, but it certainly should have been.
2021-03-29 17:24:30 +09:00
Bill Currie 00aa584506 [util] Add re-entrant set_as_string
Makes it easier to debug set-related code in multi-threaded code.
2021-03-28 20:25:57 +09:00
Bill Currie b6ab832ed4 [simd] Add vabsf and some more tests 2021-03-28 19:49:43 +09:00
Bill Currie 29e029c792 [util] Add float a simd version of the SEB
And its support functions. I can't tell if it's any faster (mtwist_rand
is a significant chunk of the benchmark timings, oops), but it's nice to
have.
2021-03-27 23:38:10 +09:00
Bill Currie 88ff254f42 Get QF cross-compiling using MXE/mingw32
This includes -win clients (no clue if anything actually works yet).
2021-03-27 20:09:37 +09:00
Bill Currie c4a0f3cc73 [util] Fix a string handling bug
Good grief, they still exist :(
2021-03-27 20:06:40 +09:00
Bill Currie 99f0cde080 [util] Add strndup and reentrant quicksort
Needed for portability.
2021-03-27 20:03:39 +09:00
Bill Currie a9bd436837 [build] Autoconfiscate printf format attribute
I don't know if gnu_printf is appropriate for all cases, but it is
needed for mingw32.
2021-03-27 19:52:59 +09:00
Bill Currie 7c788a6e7a [util] Use size_t for dstring length params
While not overly wrong, unsigned is not really appropriate.
2021-03-27 19:08:18 +09:00
Bill Currie 0167456b21 [util] Loosen up SEB relative epsilon a little
1e-8 is a little too tight, the normal was 4.5x the computed epsilon.
Going to 1e-6 still keeps things tight.
2021-03-27 15:04:13 +09:00
Bill Currie 5d9bf32d3c Merge branch 'vulkan' 2021-03-23 12:31:58 +09:00
Bill Currie cc4167668c Fix a pile of leaks and uninit errors
Still "some" more to go: a pile to do with transforms and temporary
entities, and a nasty one with host_cbuf. There's also all the static
block-alloc lists :/
2021-03-21 19:56:17 +09:00
Bill Currie a3c1b2e992 [util] Rename qfplist.[ch]
The name is a hold-over from before the current quakeforge tree and the
QF include directory.
2021-03-21 16:13:03 +09:00
Bill Currie 6e0cc59e8f [util] Make wad lump failure a soft error
Can't recover from an error if the program is swept out from underneath
you.
2021-03-21 11:36:18 +09:00
Bill Currie 0ace799b27 [util] Support commands with a data parameter
Useful for avoiding a pile of wrapper functions that merely pass on
command-specific data to the actual implementation. Used to clean up the
wrappers in nq and qw cl_input.c
2021-03-20 03:56:16 +09:00
Bill Currie 693225a16f [util] Add a fixme for a comment
The code itself is fine, but the comment is rubbish because it's
confusing, though essentially correct.
2021-03-10 18:05:12 +09:00
Bill Currie 4a97bc3ba5 [util] Create simd quaternion to matrix function
This seems to be pretty close to as fast as it gets (might be able to do
better with some shuffles of the negation constants instead of loading
separate constants).
2021-03-04 17:45:10 +09:00
Bill Currie e3762d8f38 [util] Make plist mostly null-safe
The main purpose is to allow fluent-style:
    const char *targetname = PL_String (PL_ObjectForKey (entity, "targetname"));
    if (targetname && !PL_ObjectForKey (targets, targetname)) {
        PL_D_AddObject (targets, targetname, entity);
    }

[note: the above is iffy due to ownership of entity, but the code from
which the above comes works around the issue]
2021-03-03 18:01:35 +09:00
Bill Currie 45c0255643 [util] Add simd 4x4 matrix functions
Currently just add, subtract, multiply (m m and m v).
2021-03-03 16:34:16 +09:00
Bill Currie 407ea15e35 [util] Fix some test bitrot 2021-03-02 15:05:19 +09:00
Bill Currie 4eb07220cd [util] Make plists more const-correct 2021-02-25 11:55:25 +09:00
Bill Currie 0cd2ece38e [util] Correct element order for vector expressions 2021-02-23 14:37:13 +09:00
Bill Currie 4bda49d798 [util] Correct the lex priority for int constants
The actual need to specify unsigned int constant is a bit of a pain, but
not being able to do so due to lex priority errors is even more of a
pain.
2021-02-17 13:29:53 +09:00
Bill Currie 55104ac430 [util] Allow "any type" results for cexpr
Setting the result type cexpr_exprval tells cexpr to simply return whoe
exprval object rather than the referenced value, thus allowing the
caller to check the type when the expression is context sensitive.
2021-02-09 19:30:30 +09:00
Bill Currie 35f12c36ff [util] Catch some more cexpr errors 2021-02-09 19:29:48 +09:00
Bill Currie 5535d1f8e6 [util] Keep track of plist dictionary key order
The order in which keys are added to the dictionary object is
maintained. Adding a key after removing an old key adds the new key to
the end of the list rather than reusing the old key's spot.
2021-02-09 17:03:33 +09:00
Bill Currie 0dcd946063 [util] Add plist parser for dictionary -> array
PL_ParseLabeledArray works the same way as PL_ParseArray, but instead
takes a dictionary object. The keys of the items are ignored, and the
order is not preserved (at this stage), but this is a cleaner solution
to getting an array of objects when the definitions of those objects
need to be accessible by name as well.
2021-02-09 15:24:28 +09:00
Bill Currie 14e4fd9f6a [util] Pass context to the plist array/symtab parser allocator 2021-02-09 15:01:55 +09:00
Bill Currie a408fd40da [util] Make plist more const-correct 2021-02-09 14:56:48 +09:00
Bill Currie 8664a5b969 [util] Enable parser debugging for cexpr
Not actually turned on in the code, but cexpr_yydebug is present.
2021-02-09 10:02:04 +09:00
Bill Currie dfa7af03c6 [util] Plug a thread-safety hole in plists 2021-02-09 09:57:07 +09:00
Bill Currie e929dca300 [util] Auto-cast plist string items
The casting uses a recursive call to the expression parser, so the
expressions are type-checked automatically.
2021-02-04 22:37:20 +09:00
Bill Currie d2536e584f [util] Add plist support to cexpr
This allows plist objects to be accessed directly from cexpr expressions
using struct.field syntax for dictionary objects and array[index] syntax
for array objects.
2021-02-04 16:58:13 +09:00
Bill Currie 5d1d85f72e [util] Resurrect Hunk_Print and fix some errors
It turned out that Hunk_HighAlloc was not creating a hunk header
(ancient bug by me), and I cleaned up a bunch of name-size issues, along
the way.
2021-02-03 13:21:08 +09:00
Bill Currie 0bfb60775e [util] Ensure hunk allocs are cache alligned
This doesn't seem to make much difference in the vulkan renderer, but it
certainly doesn't hurt.
2021-02-03 13:19:19 +09:00
Bill Currie 7970525ef4 [util] Make va thread-safe
It now takes a context pointer (opaque data) that holds the buffers it
uses for the temporary strings. If the context pointer is null, a static
context is used (making those uses of va NOT thread-safe). Most calls to
va use the static context, but all such calls have been formatted
consistently so they are easy to find when it comes time to do a full
audit.
2021-01-31 16:05:48 +09:00
Bill Currie 12ec6c5c29 [util] Add eol to plist parse errors
I suspect it got lost when I made the error message a string item.
2021-01-26 20:45:07 +09:00
Bill Currie 8224169394 [util] Make plist parse errors a little more useful
Particularly the "unexpected character" ones.
2021-01-23 18:56:15 +09:00
Bill Currie 0622a24380 [util] Support size_t constants
Much like 1u and 1l, 1z is for size_t.
2021-01-20 01:24:32 +09:00
Bill Currie fd07169a80 [util] Support casts from int/uint to size_t
I don't want to do implicit down casts (size_t to uint) but I needed to
be able to reference swapchain array size.
2021-01-10 15:27:39 +09:00
Bill Currie a35eec3877 [util] Fail gracefully when no symtab is present 2021-01-10 15:02:24 +09:00
Bill Currie 16334158bd [util] Support struct pointer accesses in cexpr 2021-01-10 01:51:07 +09:00
Bill Currie 0c1699fdbb Fix a pile of double semicolons 2021-01-09 20:42:23 +09:00
Bill Currie 0da99bc59c [util] Add promotion from float to int to cexpr
I won't go the other way nor will I add double to float.
2021-01-05 23:41:13 +09:00
Bill Currie b493e6ac32 [util] Expose plist type check support functions 2021-01-05 23:39:52 +09:00
Bill Currie a45f8f98b6 [util] Make exprctx hashlinks double pointer
The way I wound up using the field meant that exprctx should not "own"
the hashlinks chain, but rather just point to it. This fixes the nasty
access errors I had.
2021-01-05 19:55:17 +09:00
Bill Currie 5b842da394 [util] Fix types for double and float constants 2021-01-04 00:23:48 +09:00
Bill Currie 55445a25f2 [util] Add some tests for the new cexpr work 2021-01-04 00:23:48 +09:00
Bill Currie 619fe15367 [util] Add vector swizzles to cexpr
That turned out to be a lot easier than expected: needed only 4 ifs per
vector "type" (xyzw vs rgba) instead of 340.
2021-01-04 00:23:48 +09:00
Bill Currie 4562e0b876 [util] Implement more of cexpr
This adds unary, vector and function expressions.
2021-01-04 00:23:48 +09:00
Bill Currie 81300f89f8 [util] Allow multiple types for pl fields
I want to be able to use name references, but that requires string
items, so anything that would normally be dictionary or array (or
binary, even) would also need to accept string. This seemed to be the
cleanest solution. Any custom parser would then need to check the type
and act appropriately, but any inappropriate types have already been
pre-filtered by the standard parsers.
2021-01-02 14:02:33 +09:00
Bill Currie eb52d366c8 [util] Add q-v and v-q multiplication to cexpr 2021-01-02 12:10:58 +09:00
Bill Currie 015cee7b6f [util] Add vector-quaternion shortcut functions
Care needs to be taken to ensure the right function is used with the
right arguments, but with these, the need to use qconj(d|f) for a
one-off inverse rotation is removed.
2021-01-02 10:44:45 +09:00
Bill Currie 7bf90e5f4a [util] Sort out implementation issues for simd 2021-01-02 09:55:59 +09:00
Bill Currie 1fd02322f4 [util] Clean up some minor issues in cmem
I forgot to remove the noinline attribute and do a check with
optimization (to catch the "pure" recommendation).
2021-01-01 22:29:31 +09:00
Bill Currie efdbd59909 [util] Fix handling of sline's list 'pointer'
I forgot to right-shift the value so offsets were becoming 0 or 8
instead of 0-15. This fixes the management of small objects. It turns
out that after this fix, qfvis's problems were caused by fragmentation
in the windings. Need to revisit line allocation and use POT-specialized
pools.
2020-12-30 18:20:11 +09:00
Bill Currie 9090c53519 [util] Add failing sub-line allocator tests
I think the sub-line allocator falling over is the final source of
qfvis's leaks. It certainly causes a mess of the sub-lines. But having
some tests to get working sure beats scratching my head over qfvis :)
2020-12-30 18:20:11 +09:00
Bill Currie d12abc5132 [util] Relink grown free line block
This fixes one source of memory leaks, but it seems some are still
lurking as qfvis still leaks like a sieve.
2020-12-30 18:20:11 +09:00
Bill Currie 73544f0790 [util] Split cmem's free cache-line over size bins
They're binned by powers of two (with in between sizes going to the
smaller bin should I make cache-line allocations NPOT (which I think
might be worthwhile). However, there seems to still be a bug somewhere
causing a nasty leak as now my hacked qfvis consumes 40G in less than a
minute.
2020-12-30 18:20:11 +09:00
Bill Currie 4039075f41 [util] Use a linked list of free cache lines
The idea is to not search through blocks for an available allocation.
While the goal was to speed up allocation of cache lines of varying
cluster sizes, it's not enough due to fragmentation.
2020-12-30 18:20:11 +09:00
Bill Currie 3125009a7c [util] Add vector and quaternion types to cexpr
Although there's no distinction between the two at the C level, I think
it's probably best to separate them in a scripting language.
2020-12-30 18:20:11 +09:00
Bill Currie 1ddd57b09e [util] Add qconj, vtrunc, vceil and vfloor functions
I had forgotten these rather critical functions. Both double and float
versions are included.
2020-12-30 18:20:11 +09:00
Bill Currie 03fcb530c7 [util] Make quat test failure prints clearer 2020-12-30 18:20:11 +09:00
Bill Currie 09a10f80e1 [util] Add basic SIMD implemented vector functions
They take advantage of gcc's vector_size attribute and so only cross,
dot, qmul, qvmul and qrot (create rotation quaternion from two vectors)
are needed at this stage as basic (per-component) math is supported
natively by gcc.

The provided functions work on horizontal (array-of-structs) data, ie a
vec4d_t or vec4f_t represents a single vector, or traditional vector
layout. Vertical layout (struct-of-arrays) does not need any special
functions as the regular math can be used to operate on four vectors at
a time.

Functions are provided for loading a vec4 from a vec3 (4th element set
to 0) and storing a vec4 into a vec3 (discarding the 4th element).

With this, QF will require AVX2 support (needed for vec4d_t). Without
support for doubles, SSE is possible, but may not be worthwhile for
horizontal data.

Fused-multiply-add is NOT used because it alters the results between
unoptimized and optimized code, resulting in -mfma really meaning
-mfast-math-anyway. I really do not want to have to debug issues that
occur only in optimized code.
2020-12-30 18:20:11 +09:00
Bill Currie 4f8a06ddd3 [build] Fix a pile of gcc 10 issues
gcc got stricter about array accesses, complicating progs macros, and
much better at detecting buffer overflows.
2020-12-28 18:58:51 +09:00
Bill Currie d824db68a5 [util] Zero plist symtabl object memory 2020-12-25 00:28:26 +09:00