From: Alan Cox Date: Tue, 24 Oct 2017 18:26:46 +0000 (+0100) Subject: bogomips: because ... X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=5a8baf5da9c30afd00e37c6c03f9297a51d6d1ba;p=FUZIX.git bogomips: because ... Z80 4MHz 0.2 bogomips FPGA Z80 128MHz 10.55 bogomips - beats an Intel 386 ;) --- diff --git a/Applications/util/Makefile.z80 b/Applications/util/Makefile.z80 index 1519462b..603444d5 100644 --- a/Applications/util/Makefile.z80 +++ b/Applications/util/Makefile.z80 @@ -52,6 +52,7 @@ SRCSNS = \ SRCS = banner.c \ bd.c \ + bogomips.c \ cal.c \ cksum.c \ cut.c \ diff --git a/Applications/util/bogomips.c b/Applications/util/bogomips.c new file mode 100644 index 00000000..a7440d03 --- /dev/null +++ b/Applications/util/bogomips.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +#ifdef __SDCC_z80 +void delay(unsigned long r) +{ +__asm + pop hl ; return address + pop de ; low + pop bc ; high + +loop: + dec de + ld a,d + or e + jp nz,loop + ld a,b + or c + dec bc + jp nz,loop + push bc + push de + jp (hl) +__endasm; +} +#else +#error "Unsupported platform" +#endif + +int main(int argc, char *argv[]) +{ + unsigned long loops_per_sec = 1 ; + clock_t ticks; + unsigned int cps = sysconf(_SC_CLK_TCK); + + printf("Calibrating delay loop... "); + fflush(stdout); + + while (loops_per_sec <<= 1) { + ticks = clock(); + delay(loops_per_sec); + ticks = clock() - ticks; + if (ticks >= cps) { + unsigned long lps = (loops_per_sec * cps) / ticks; + printf("ok - %lu.%02lu BogoMips\n", + lps / 500000UL, (lps / 5000) % 100); + return 0; + } + } + printf("failed\n"); + return -1; +}