aboutsummaryrefslogtreecommitdiff
path: root/bench
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-11-24 15:39:06 +0000
committerrodri <rgl@antares-labs.eu>2023-11-24 15:39:06 +0000
commitd850c3b7f47e58556c160f9d03ea20aa52452020 (patch)
tree20471edd63ca1c23349a1c8e340155fabedf5b27 /bench
parent9404d16a4263a87559af64bfb18c91ccebaa601d (diff)
downloadamd64-simd-d850c3b7f47e58556c160f9d03ea20aa52452020.tar.gz
amd64-simd-d850c3b7f47e58556c160f9d03ea20aa52452020.tar.bz2
amd64-simd-d850c3b7f47e58556c160f9d03ea20aa52452020.zip
add more avx instructions and a bench9 benchmark file.
Diffstat (limited to 'bench')
-rw-r--r--bench/main.c134
1 files changed, 134 insertions, 0 deletions
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 <u.h>
+#include <libc.h>
+#include <thread.h>
+#include <geometry.h>
+#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);
+}