~ft/bench9

05188cb08b4304e34a7d822bb0f80ef5b780aa72 — Sigrid Solveig Haflínudóttir 2 months ago 6ae1a31 master
add arm64 implementation; silently ignore bad clock runs
3 files changed, 24 insertions(+), 7 deletions(-)

M b.c
A b_arm64.s
M mkfile
M b.c => b.c +10 -7
@@ 13,14 13,15 @@ enum {

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,15 58,19 @@ static int
B *
benchinit(B *b, char *name)
{
	Res r;
	int i;

	fmtinstall(L'σ', σfmt);
	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 @@ benchstep(B *b)
{
	uvlong c;

	if(b->n < 1)
	if(b->n < 1 || b->tout <= b->tin)
		return;

	if(b->step == 0)


@@ 185,8 190,6 @@ benchstep(B *b)
	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;

A b_arm64.s => b_arm64.s +12 -0
@@ 0,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

M mkfile => mkfile +2 -0
@@ 2,6 2,8 @@

TARG=bench9
BIN=/$objtype/bin
arch=`{echo __^$objtype^__}
CFLAGS=$CFLAGS -D$arch -p

HFILES=\
	b.h\