Commit graph

49 commits

Author SHA1 Message Date
Bill Currie
942ea22266 [qfcc] Promote types before expanding scalars
This fixes the internal error generated by the likes of
`(sv_gravity * '0 0 1')` where sv_gravity is a float and `'0 0 1'` is an
ivec3: the vector is promoted to vec3 first so that expanding sv_gravity
is expanded to vec3 instead of ivec3 (which is not permitted for a
float: expansion requires the destination base type to be the same as
the source).
2022-09-14 14:39:09 +09:00
Bill Currie
95b8424ddf [qfcc] Use new extend instruction instead of swizzle
While swizzle does work, it requires the source to be properly aligned
and thus is not really the best choice. The extend instruction has no
alignment requirements (at all) and thus is much better suited to
converting a scalar to a vector type.

Fixes #30
2022-08-18 18:18:19 +09:00
Bill Currie
42287f1e0e [qfcc] Allow binary operations between vector and vec3
While I might need to tighten up the rules later, this allows binary
operations between vector (the type) and explicitly typed vec3 constants
(and non-constants, about which I am undecided). The idea is that
explicit constants such as '1 2 3'f should be compatible with either
type.

This applies to quaternions as well.
2022-08-18 18:18:19 +09:00
Bill Currie
b9bd45ad99 [qfcc] Create vector lists only for constants
Defs and symbols benefit from swizzling as that's one instruction vs 2-3
for loading a scalar into a vector component by component. Constants are
ok because the result gets converted to a vector constant.
2022-05-01 14:35:24 +09:00
Bill Currie
ef9960c6f9 [qfcc] Implement support for the swizzle operator
The destination operand must be a full four component vector, but the
source can be smaller and small sources do not need to be aligned: the
offset of the source operand and the swizzle indices are adjusted. The
adjustments are done during final statement emission in order to avoid
confusing the data flow analyser (and that's when def offsets are known).
2022-05-01 14:35:24 +09:00
Bill Currie
9c8e13aa4c [qfcc] Implement automatic casting between same-width vectors
This allows all the tests to build and pass. I'll need to add tests to
ensure warnings happen when they should and that all vec operations are
correct (ouch, that'll be a lot of work), but vectors and quaternions
are working again.
2022-04-29 18:12:47 +09:00
Bill Currie
1eb8b61b83 [qfcc] Clean up handling of value expressions
I'd created new_value_expr some time ago, but never used it...
Also, replace convert_* with cast_expr to the appropriate type (removes
a pile of value check and create code).
2022-04-29 16:59:55 +09:00
Bill Currie
04f60e5ff1 [qfcc] Rework vector expression handling
Use with quaternions and vectors is a little broken in that
vec4/quaternion and vec3/vector are not the same types (by design) and
thus a cast is needed (not what I want, though). However, creating
vectors (that happen to be int due to int constants) does seem to be
working nicely otherwise.
2022-04-29 16:59:55 +09:00
Bill Currie
8912c65029 [qfcc] Indicate type width in type strings
Makes for much more informative error messages for type mismatches
(confusing when both sides look the same).
2022-04-29 16:59:15 +09:00
Bill Currie
3479897224 [qfcc] Fix some not uninitialized warnings
The "not" because I'm pretty sure they're false positives due to when
the function is called, but clang doesn't know that (wonder why gcc was
ok with it).
2022-03-31 00:37:53 +09:00
Bill Currie
211cd657e0 [qfcc] Alias entity to int for comparison
The ruamoko ISA has no entity comparison operators because an entity is
just an int in disguise.
2022-02-06 21:20:00 +09:00
Bill Currie
afe8c8fca5 [qfcc] Auto-demote double for vector scaling
This was missed in the switch to an explicit scale instruction.
2022-02-06 21:20:00 +09:00
Bill Currie
5f6e0767d7 [qfcc] Make the meaning of vec * vec selectable
Currently only via pragma (not command line options), but I needed to
test the concept. Converting legacy code is just too error prone.
Telling the compiler how to treat the operator makes more sense. When *
acts as @dot with Ruamoko progs, the result is automatically aliased as
a float as this is the legacy meaning (ie, float result for dot
product).
2022-02-06 21:20:00 +09:00
Bill Currie
1b40cdbab6 [qfcc] Handle vector scaling by ints
I missed a change when implementing support for the scale instructions.
2022-02-04 21:57:41 +09:00
Bill Currie
1487fa6b50 [qfcc] Implement some basics for the vector types
They're now properly part of the type system and can be used for
declaring variables, initialized (using {} block initializers), operated
on (=, *, + tested) though much work needs to be done on binary
expressions, and indexed. So far, only ivec2 has been tested.
2022-02-04 00:25:31 +09:00
Bill Currie
4b8fdf3696 [qfcc] Implement vector scaling for Ruamoko
With this, qfcc-tests builds (can't run yet due to unsigned not having
any tests and thus the rest the Ruamoko code in QF not building yet).
2022-01-30 14:48:49 +09:00
Bill Currie
d8f6a9445e [qfcc] Implement dot and cross product for Ruamoko
With explicit operators, even. While they're a tad verbose, they're at
least unambiguous and most importantly have the right precedence (or at
least adjustable precedence if I got it wrong, but vector ops having
high precedence than scalar or component seems reasonable to me).
2022-01-30 14:14:15 +09:00
Bill Currie
3f389b602a [qfcc] Add support for horizontal vector ops
And reimplement vector comparison for Ruamoko.
2022-01-30 10:56:15 +09:00
Bill Currie
5ba6bf02e8 [qfcc] Cast functions to ints for comparison
Yet more (non-)wasted instructions.
2022-01-29 18:59:38 +09:00
Bill Currie
f853a449b8 [qfcc] Cast pointers to ints for comparison
Ruamoko doesn't wast instructions on otherwise compatible low-level
types.
2022-01-29 18:23:07 +09:00
Bill Currie
7877168e93 [qfcc] Make a field name more clear
Just "type" isn't very informative, but "result_type" is at least a fair
bit better.
2022-01-27 23:29:32 +09:00
Bill Currie
06d70a32db [qfcc] Rework the functionality of address expressions
The goal was to get lea being used for locals in ruamoko progs because
lea takes the base registers into account while the constant pointer
defs used by v6p cannot. Pointer defs are still used for gobals as they
may be out of reach of 16-bit addressing.

address_expr() has been simplified in that it no longer takes an offset:
the vast majority of the callers never passed one, and the few that did
have been reworked to use other mechanisms. In particular,
offset_pointer_expr does the manipulations needed to add an offset
(unscaled by type size) to a pointer. High-level pointer offsets still
apply a scale, though.

Alias expressions now do a better job of hanling aliasing of aliases by
simply replacing the target type when possible.
2022-01-25 23:39:17 +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
e11fa77a34 [qfcc] Use pr_type_names to generate is_TYPE
This means basic types will always have a check function automatically.
2022-01-19 18:07:54 +09:00
Bill Currie
380cb3ba7f [qfcc] Clean up the type tables for binary expressions
More index labels and remove the null entries since they're not needed
with the labels.
2022-01-19 10:52:07 +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
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
63795e790b [qfcc] Clean out some old code
The move operator names are definitely obsolete (due to dropping the
expressions a year or two ago) and the precedence checks seem to be
handled elsewhere. Memset and state expressions went away a while back
too.
2022-01-08 21:21:31 +09:00
Bill Currie
23c9a317f8 [qfcc] Give alias expressions their own type
While this was a pain to get working, that pain only went to prove the
value of using proper "types" (even if only an enum) for different
expression types: just finding all the places to edit was a chore, and
easy to make mistakes (forgetting bits here and there).

Strangely enough, this exposed a pile of *type* aliasing bugs (next
commit).
2022-01-08 12:06:52 +09:00
Bill Currie
6d5ffa9f8e [build] Move to non-recursive make
There's still some cleanup to do, but everything seems to be working
nicely: `make -j` works, `make distcheck` passes. There is probably
plenty of bitrot in the package directories (RPM, debian), though.

The vc project files have been removed since those versions are way out
of date and quakeforge is pretty much dependent on gcc now anyway.

Most of the old Makefile.am files  are now Makemodule.am.  This should
allow for new Makefile.am files that allow local building (to be added
on an as-needed bases).  The current remaining Makefile.am files are for
standalone sub-projects.a

The installable bins are currently built in the top-level build
directory. This may change if the clutter gets to be too much.

While this does make a noticeable difference in build times, the main
reason for the switch was to take care of the growing dependency issues:
now it's possible to build tools for code generation (eg, using qfcc and
ruamoko programs for code-gen).
2020-06-25 11:35:37 +09:00
Bill Currie
4de2c6b30e [qfcc] Move alias expr inside call block expression
This fixes the trampled return value when the first expression aliases
the return result.
2020-03-26 20:16:52 +09:00
Bill Currie
441e7b99bc [qfcc] Correctly implement pointer arithmetic 2020-03-17 13:39:22 +09:00
Bill Currie
b1459ac816 [qfcc] Move return save temp into call block
This fixes func-expr after the assignment rewrite. Now all tests pass
when not optimizing (something not quite right in assignchain when
optimizing).
2020-03-14 01:24:13 +09:00
Bill Currie
2adcad7c84 Allow non-short-circuited logic to work 2020-02-24 02:25:28 +09:00
Bill Currie
d6752c254c Move short-circuit boolean code to its own file 2020-02-24 01:20:24 +09:00
Bill Currie
5374798ef9 Fix order of operations for implicit casts 2020-02-23 23:18:31 +09:00
Bill Currie
526c27cf03 Handle implicit casts for double/float comparisons 2020-02-23 23:10:10 +09:00
Bill Currie
e23aa40994 Implicitly cast unadorned floating point constants
Floating point constants without f or d adornments will automatically
cast, without warnings, to the type appropriate to the rest of the
expression.
2020-02-23 22:28:54 +09:00
Bill Currie
9d2d33fa50 Implement %% (true modulo) support in qfcc
However, it's not quite working yet
2020-02-16 11:57:58 +09:00
Bill Currie
0542daacdf Create more double related tests
Including catching warnings :) (yay -Werror)
2020-02-15 23:49:12 +09:00
Bill Currie
13b608f40c Don't truncat float % float
This allows full usage, eg, x % pi, but otherwise maintains
compatibility with integer %
2020-02-15 23:49:12 +09:00
Bill Currie
197f856a30 Fix incorrect scalar/quaternion division
It's just not possible.
2020-02-15 23:49:12 +09:00
Bill Currie
83fb588727 Support vector/quaternion division by float
Implemented via v*(1/f) or q*(1/f) to give CSE a chance to optimize the
division if necessary as otherwise the engine would have to divide every
time.
2019-06-10 08:44:36 +09:00
Bill Currie
ef4ad52239 Make binary_expr fold constants
This is where constant folding should have happened all along. While
unary_expr should fold constants too, it seems to already try to do so
and it's a bit much of a mess to clean up right now.
2019-06-10 00:36:13 +09:00
Bill Currie
439cd15620 Do type promotion for short
fold_constants used to do this when it was overly aggressive. Fixes the
ICE when accessing an array in a struct via a pointer.
2019-06-09 22:27:53 +09:00
Bill Currie
d00a2ef82d Convert constant vector expressions in binary expressions
Fixes not being able to compare with eg [1, 2, 3]
2019-06-06 06:44:19 +09:00
Bill Currie
db460155e9 Fix multiple function calls in expressions. 2013-09-27 23:15:57 +09:00
Bill Currie
4bc40b3917 Rewrite binary_expr().
It is now in its own file and uses table lookups to check for valid type
and operator combinations, and also the resulting type of the expression.

This probably breaks multiple function calls in the one expression.
2013-09-27 23:15:57 +09:00