shithub: bench9

Download patch

ref: 05188cb08b4304e34a7d822bb0f80ef5b780aa72
parent: 6ae1a31f6bf06c488ff6d1bdf7af04e961c76225
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sat Sep 17 15:09:18 EDT 2022

add arm64 implementation; silently ignore bad clock runs

--- a/b.c
+++ b/b.c
@@ -13,14 +13,15 @@
 
 static uvlong adj;
 
+#if defined(__386__) || defined(__amd64__)
 typedef struct Res {
 	ulong ax, bx, cx, dx;
 }Res;
-
 Res cpuid(ulong ax, ulong cx);
+void _tendp(uvlong *c);
+#endif
 
 void _tend(uvlong *c);
-void _tendp(uvlong *c);
 void (*tend)(uvlong *c);
 
 uvlong
@@ -57,7 +58,6 @@
 B *
 benchinit(B *b, char *name)
 {
-	Res r;
 	int i;
 
 	fmtinstall(L'σ', σfmt);
@@ -64,8 +64,13 @@
 	fmtinstall(L'τ', τfmt);
 
 	if(tend == nil){
+		tend = _tend;
+#if defined(__386__) || defined(__amd64__)
+		Res r;
 		r = cpuid(0x80000001, 2);
-		tend = (r.dx & (1<<27)) != 0 ? _tendp : _tend;
+		if(r.dx & (1<<27))
+			tend = _tendp;
+#endif
 	}
 
 	memset(b, 0, sizeof(*b));
@@ -177,7 +182,7 @@
 {
 	uvlong c;
 
-	if(b->n < 1)
+	if(b->n < 1 || b->tout <= b->tin)
 		return;
 
 	if(b->step == 0)
@@ -185,8 +190,6 @@
 	b->step++;
 	b->n--;
 
-	if(b->tout <= b->tin)
-		sysfatal("%ulld ≤ %ulld → t₁ ≤ t₀", b->tout, b->tin);
 	if(b->tout - b->tin < adj) /* sometimes this happens */
 		adj = b->tout - b->tin;
 	c = b->tout - b->tin - adj;
--- /dev/null
+++ b/b_arm64.s
@@ -1,0 +1,12 @@
+#define	SYSREG(op0,op1,Cn,Cm,op2)	SPR(((op0)<<19|(op1)<<16|(Cn)<<12|(Cm)<<8|(op2)<<5))
+#define CNTVCT_EL0			SYSREG(3,3,14,0,2)
+
+TEXT tstart(SB), 1, $-4
+	MRS	CNTVCT_EL0, R1
+	MOV	R1, (R0)
+	RETURN
+
+TEXT _tend(SB), 1, $-4
+	MRS	CNTVCT_EL0, R1
+	MOV	R1, (R0)
+	RETURN
--- a/mkfile
+++ b/mkfile
@@ -2,6 +2,8 @@
 
 TARG=bench9
 BIN=/$objtype/bin
+arch=`{echo __^$objtype^__}
+CFLAGS=$CFLAGS -D$arch -p
 
 HFILES=\
 	b.h\