[qfcc] Make vecaddr work in both v6p and Ruamoko

It's full of evil hacks, but has always been an evil hack relying on
undefined behavior. The weird shenanigans with local variables are
because Ruamoko doesn't copy the parameters like v6p does and thus v and
z are NOT adjacent as parameters. Worse, the padding is uninitialized
and thus should not be relied upon to be any particular value. Still
does a nice job of testing dot products, though.
This commit is contained in:
Bill Currie 2022-01-30 14:17:52 +09:00
parent 09eef8a07b
commit d18ee8dd86

View file

@ -1,8 +1,25 @@
void printf (string fmt, ...) = #0;
float foo (vector v, float z)
#if __RUAMOKO__ > 1
#define dot @dot
#define X .y
#else
#define dot *
#define X
#endif
void forcelive (float z)
{
return v * *(vector*)(&v.y);
}
float foo (vector _v, float _z)
{
vector v = _v;
float z = _z;
_v = nil;
_z = _z - _z;
forcelive (z);
return (v dot *(vector*)(&v.y))X;
}
int
@ -11,6 +28,6 @@ main (int argc, string *argv)
vector v = [1, 2, 3];
vector w = [2, 3, 4];
float f;
printf ("%v %g %g %g\n", v, v*v, v*w, f=foo (v, 4));
return f != v*w;
printf ("%v %g %g %g\n", v, v dot v, v dot w, f=foo (v, 4));
return f != (v dot w)X;
}