www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/10/13/13:02:40

From: cnc AT netcom DOT com (Christopher Christensen)
Date: Thu, 13 Oct 1994 02:09:28 PDT
To: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>, djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: 32/16bit?

Here is the benchmark program I used.  It times a 32-bit "xor eax, eax"
instruction versus a 16-bit "xor ax, ax" instruction.  I ran it on my
system which is a 486sx 33Mhz.  My results showed that the 16-bit
instruction executs in 2 clocks and the 32-bit instruction executes in
only 1.

Note, I ran this benchmark program under Linux.  I have not even tried
to compile it for djgpp, but it should work.  In order to get sufficiently
accurate results, you may need to increase the value for ICOUNT depending
on your machine's speed and timer resolution.


/* the benchmark program  (for GCC on i386 boxes) */
#include <stdio.h>
#include <time.h>

/* a tenth of my clock rate */
#define ICOUNT 3333333
#define BCOUNT 1


/* reference loop */
void test0()
{
asm("mov %0, %%ecx\n"
    "0: \n"
    "	decl %%ecx\n"
    "	jnz 0b\n"
    :: "i" (ICOUNT));
}


/* 32-bit loop */
void test1()
{
asm("mov %0, %%ecx\n"
    "0: \n"
    "	xorl %%eax, %%eax\n"
    "	xorl %%eax, %%eax\n"
    "	xorl %%eax, %%eax\n"
    "	xorl %%eax, %%eax\n"
    "	xorl %%eax, %%eax\n"
    "	xorl %%eax, %%eax\n"
    "	xorl %%eax, %%eax\n"
    "	xorl %%eax, %%eax\n"
    "	xorl %%eax, %%eax\n"
    "	xorl %%eax, %%eax\n"
    "	decl %%ecx\n"
    "	jnz 0b\n"
    :: "i" (ICOUNT));
}


/* 16-bit loop */
void test2()
{
asm("mov %0, %%ecx\n"
    "0: \n"
    "	xorw %%ax, %%ax\n"
    "	xorw %%ax, %%ax\n"
    "	xorw %%ax, %%ax\n"
    "	xorw %%ax, %%ax\n"
    "	xorw %%ax, %%ax\n"
    "	xorw %%ax, %%ax\n"
    "	xorw %%ax, %%ax\n"
    "	xorw %%ax, %%ax\n"
    "	xorw %%ax, %%ax\n"
    "	xorw %%ax, %%ax\n"
    "	decl %%ecx\n"
    "	jnz 0b\n"
    :: "i" (ICOUNT));
}


int benchmark(void (*fptr)())
{
int i;
clock_t t1, t2;

(*fptr)();
t1=clock();
for(i=0; i<BCOUNT; i++) (*fptr)();
t2=clock();
return (int) t2-t1;
}


int main()
{
int t0, t1, t2;
t0=benchmark(test0);
t1=benchmark(test1);
t2=benchmark(test2);
printf(" 32-bit ops:  %d ticks\n 16-bit ops:  %d ticks\n", t1-t0, t2-t0);
return 0;
}



-- 
----------------------------------------------------------------------
:  Christopher  :  Huntington Beach California, USA                  :
:  Christensen  :  email:  cnc AT netcom DOT com                            :
----------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019