From d850c3b7f47e58556c160f9d03ea20aa52452020 Mon Sep 17 00:00:00 2001 From: rodri Date: Fri, 24 Nov 2023 15:39:06 +0000 Subject: add more avx instructions and a bench9 benchmark file. --- bench/main.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 bench/main.c (limited to 'bench') diff --git a/bench/main.c b/bench/main.c new file mode 100644 index 0000000..9d00719 --- /dev/null +++ b/bench/main.c @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include "b.h" + +double dppd(Point2, Point2); +double dppda(Point2, Point2); +double dppd3(Point3, Point3); +double dppd3a(Point3, Point3); +Point3 xvec3(Point3, Point3); + +static void +bdotvec2(int fd) +{ + Bgr g; + B *b0, *b1, *b2; + Point2 a, b; + int i; + + benchinitgr(&g, "2d dot product"); + b0 = benchadd(&g, "dotvec2"); + b1 = benchadd(&g, "dotvec2_simd"); + b2 = benchadd(&g, "dotvec2_avx"); + + while(b0->n > 0 || b1->n > 0){ + a = Vec2(truerand()*frand(), truerand()*frand()); + b = Vec2(truerand()*frand(), truerand()*frand()); + + benchin(b0); + for(i = 0; i < 1e6; i++) + dotvec2(a, b); + benchout(b0); + + benchin(b1); + for(i = 0; i < 1e6; i++) + dppd(a, b); + benchout(b1); + + benchin(b2); + for(i = 0; i < 1e6; i++) + dppda(a, b); + benchout(b2); + } + + benchprintgr(&g, fd); + benchfreegr(&g); +} + +static void +bdotvec3(int fd) +{ + Bgr g; + B *b0, *b1, *b2; + Point3 a, b; + int i; + + benchinitgr(&g, "3d dot product"); + b0 = benchadd(&g, "dotvec3"); + b1 = benchadd(&g, "dotvec3_simd"); + b2 = benchadd(&g, "dotvec3_avx"); + + while(b0->n > 0 || b1->n > 0){ + a = Vec3(truerand()*frand(), truerand()*frand(), truerand()*frand()); + b = Vec3(truerand()*frand(), truerand()*frand(), truerand()*frand()); + + benchin(b0); + for(i = 0; i < 1e6; i++) + dotvec3(a, b); + benchout(b0); + + benchin(b1); + for(i = 0; i < 1e6; i++) + dppd3(a, b); + benchout(b1); + + benchin(b2); + for(i = 0; i < 1e6; i++) + dppd3a(a, b); + benchout(b2); + } + + benchprintgr(&g, fd); + benchfreegr(&g); +} + +static void +bcrossvec3(int fd) +{ + Bgr g; + B *b0, *b1; + Point3 a, b; + int i; + + benchinitgr(&g, "3d cross product"); + b0 = benchadd(&g, "crossvec3"); + b1 = benchadd(&g, "crossvec3_simd"); + + while(b0->n > 0 || b1->n > 0){ + a = Vec3(truerand()*frand(), truerand()*frand(), truerand()*frand()); + b = Vec3(truerand()*frand(), truerand()*frand(), truerand()*frand()); + + benchin(b0); + for(i = 0; i < 1e6; i++) + crossvec3(a, b); + benchout(b0); + + benchin(b1); + for(i = 0; i < 1e6; i++) + xvec3(a, b); + benchout(b1); + } + + benchprintgr(&g, fd); + benchfreegr(&g); +} + +void +threadmain(int argc, char **argv) +{ + ARGBEGIN{ + }ARGEND + + if(benchwire(0) != 0) + fprint(2, "failed to wire: %r\n"); + + bdotvec2(1); + bseparator(1); + bdotvec3(1); + bseparator(1); + bcrossvec3(1); + + threadexitsall(nil); +} -- cgit v1.2.3