~ft/bench9

6ae1a31f6bf06c488ff6d1bdf7af04e961c76225 — Sigrid Solveig Haflínudóttir 1 year, 9 months ago 42e3ee2
add 386 support (thanks foura and Amavect)
2 files changed, 50 insertions(+), 7 deletions(-)

M b.c
A b_386.s
M b.c => b.c +11 -7
@@ 41,7 41,7 @@ static int

	b = va_arg(f->args, B*);

	return fmtprint(f, "%zd", OneS/(b->tot.ns/b->ic));
	return fmtprint(f, "%ulld", OneS/(b->tot.ns/b->ic));
}

static int


@@ 51,7 51,7 @@ static int

	c = va_arg(f->args, Cns);

	return fmtprint(f,	"%zd", c.ns);
	return fmtprint(f,	"%ulld", c.ns);
}

B *


@@ 158,10 158,14 @@ benchcalc(B *b)
		m = b->c[b->ic/2];
	else
		m = (b->c[b->ic/2-1] + b->c[b->ic/2])/2;
	b->med.ns = cycles2ns(b->med.c = m);
	b->avg.ns = cycles2ns(b->avg.c = b->tot.c / b->step);
	b->min.ns = cycles2ns(b->min.c = b->c[0]);
	b->max.ns = cycles2ns(b->max.c = b->c[b->ic-1]);
	b->med.c = m;
	b->med.ns = cycles2ns(b->med.c);
	b->avg.c = b->tot.c / b->step;
	b->avg.ns = cycles2ns(b->avg.c);
	b->min.c = b->c[0];
	b->min.ns = cycles2ns(b->min.c);
	b->max.c = b->c[b->ic-1];
	b->max.ns = cycles2ns(b->max.c);
	for(i = 1; i < 100; i++){
		n = MAX(0, b->ic*i/100 - 1);
		b->p[i].ns = cycles2ns(b->c[n]);


@@ 182,7 186,7 @@ benchstep(B *b)
	b->n--;

	if(b->tout <= b->tin)
		sysfatal("%zd ≤ %zd → t₁ ≤ t₀", 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_386.s => b_386.s +39 -0
@@ 0,0 1,39 @@
#define RDTSCP WORD $0x010F; BYTE $0xF9
#define RDTSC  WORD $0x310F

TEXT tstart(SB), 1, $0
	CPUID
	RDTSC
	MOVL c+0(FP), CX
	MOVL AX, 0(CX)
	MOVL DX, 4(CX)
	RET

TEXT _tend(SB), 1, $0
	RDTSC
	MOVL c+0(FP), CX
	MOVL AX, 0(CX)
	MOVL DX, 4(CX)
	CPUID
	RET

TEXT _tendp(SB), 1, $0
	RDTSCP
	MOVL c+0(FP), CX
	MOVL AX, 0(CX)
	MOVL DX, 4(CX)
	CPUID
	RET

TEXT cpuid(SB), 1, $0
	MOVL rep+0(FP), BP
	MOVL ax+4(FP), AX
	MOVL cx+8(FP), CX
	CPUID
	MOVL AX, 0(BP)
	MOVL BX, 4(BP)
	MOVL CX, 8(BP)
	MOVL DX, 12(BP)
	RET