From d18ee8dd86a77fb98f1be2ce12efa8fdb8c81041 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 30 Jan 2022 14:17:52 +0900 Subject: [PATCH] [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. --- tools/qfcc/test/vecaddr.r | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/qfcc/test/vecaddr.r b/tools/qfcc/test/vecaddr.r index 323d9205c..6bd407d9b 100644 --- a/tools/qfcc/test/vecaddr.r +++ b/tools/qfcc/test/vecaddr.r @@ -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; }