Commit graph

1006 commits

Author SHA1 Message Date
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
d824db68a5 [util] Zero plist symtabl object memory 2020-12-25 00:28:26 +09:00
Bill Currie
fefb32bf13 [util] Add a PL dictionary to hash table parser 2020-12-24 16:06:34 +09:00