linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <cutaway@bellsouth.net>
To: "Gene Heskett" <gene.heskett@verizon.net>,
	<linux-kernel@vger.kernel.org>
Subject: Re: .../asm-i386/bitops.h  performance improvements
Date: Wed, 15 Jun 2005 15:18:42 -0400	[thread overview]
Message-ID: <000a01c571df$11af6440$2800000a@pc365dualp2> (raw)
In-Reply-To: 200506150818.24465.gene.heskett@verizon.net

----- Original Message ----- 
From: "Gene Heskett" <gene.heskett@verizon.net>
To: <linux-kernel@vger.kernel.org>
> >
> To what cpu families does this apply?  eg, this may be true for intel,
> but what about amd, via etc?

You tell me -- I've included below a small benchmark that compares them.

These are the results I've gotten so far:

                      LEA       SHL/ADD
---------------------------------------
Pentium Pro 200       88sec     96sec
AMD K6/2-500          29sec     48sec
386SLC(386SX core)  2966sec   4932sec

If LEA isn't fast, those CPU's you mentioned have much bigger problems than
these two inline functions because GCC always generates (with the kernel
default -O2 at least) an LEA for things like this:

unsigned int foo(unsigned int bar)
{
return ((bar<<3)+bar);
}

----------- LEA vs SHL/ADD ----------

#include <stdio.h>
#include <time.h>

#define ITERATIONS 2000000L

#define START  start = time(&start);
#define STOP   stop = time(&stop); delta = stop - start;
#define SUMMARY(s) printf(s " [%ld] seconds\n",delta);
#define TESTLOOP for (i=0; i<ITERATIONS; i++)

static void inline shl(void)
{
__asm__("shll $3,%edi; addl %edi,%eax");
}

static void inline lea(void)
{
__asm__("leal (%eax,%edi,8),%eax");
}


int main(int argc, char *argv[], char *envp[])
{
time_t start, stop, delta;
int i;

START;
   TESTLOOP
 {
#undef  T
#define T shl();shl();shl();shl();shl();shl();shl();shl();shl();shl();
#define T100 T T T T T T T T T T T
#define T1000 T100 T100 T100 T100 T100 T100 T100 T100 T100 T100

__asm__ __volatile__("pushl %eax");
__asm__ __volatile__("pushl %edi");
 T1000 T1000 T1000 T1000 T1000 T1000
__asm__ __volatile__("popl %edi");
__asm__ __volatile__("popl %eax");
 }
STOP;
SUMMARY("SHL/ADD");


/*---------------------------------------------------*/

START;
   TESTLOOP
 {
#undef  T
#define T lea();lea();lea();lea();lea();lea();lea();lea();lea();lea();
#define T100 T T T T T T T T T T T
#define T1000 T100 T100 T100 T100 T100 T100 T100 T100 T100 T100

__asm__ __volatile__("pushl %eax");
__asm__ __volatile__("pushl %edi");
 T1000 T1000 T1000 T1000 T1000 T1000
__asm__ __volatile__("popl %edi");
__asm__ __volatile__("popl %eax");
 }
STOP;
SUMMARY("LEA");

return 0;
}



  parent reply	other threads:[~2005-06-15 18:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-15  8:53 .../asm-i386/bitops.h performance improvements cutaway
2005-06-15 12:18 ` Gene Heskett
2005-06-15 13:06   ` Richard B. Johnson
2005-06-15 19:18   ` cutaway [this message]
2005-06-15 15:34 ` Maciej W. Rozycki
2005-06-15 23:48   ` cutaway
     [not found] <4fB8l-73q-9@gated-at.bofh.it>
     [not found] ` <4fF2j-1Lo-19@gated-at.bofh.it>
2005-06-15 14:57   ` Bodo Eggert
2005-06-15 15:30     ` Maciej W. Rozycki
2005-06-15 16:06       ` Richard B. Johnson
2005-06-15 16:29         ` Maciej W. Rozycki
2005-06-15 19:10           ` Bodo Eggert
2005-06-16  3:26             ` Stephen Rothwell
2005-06-16  7:10             ` Mikael Pettersson
2005-06-15 23:53     ` cutaway

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='000a01c571df$11af6440$2800000a@pc365dualp2' \
    --to=cutaway@bellsouth.net \
    --cc=gene.heskett@verizon.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).