ref: 6ae1a31f6bf06c488ff6d1bdf7af04e961c76225
parent: 42e3ee2d9508932863c789041c71b7ae6c813f49
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 26 03:00:31 EST 2021
add 386 support (thanks foura and Amavect)
--- a/b.c
+++ b/b.c
@@ -41,7 +41,7 @@
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 @@
c = va_arg(f->args, Cns);
- return fmtprint(f, "%zd", c.ns);
+ return fmtprint(f, "%ulld", c.ns);
}
B *
@@ -158,10 +158,14 @@
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 @@
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;
--- /dev/null
+++ b/b_386.s
@@ -1,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
+
+