linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Richard B. Johnson" <linux-os@analogic.com>
To: Gene Heskett <gene.heskett@verizon.net>
Cc: Linux kernel <linux-kernel@vger.kernel.org>, cutaway@bellsouth.net
Subject: Re: .../asm-i386/bitops.h  performance improvements
Date: Wed, 15 Jun 2005 09:06:21 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.61.0506150849380.20514@chaos.analogic.com> (raw)
In-Reply-To: <200506150818.24465.gene.heskett@verizon.net>


LEA was designed for address calculation on ix86 processors.
If it is used to ready the value of an index register for the
next memory access, it can run in parallel with the next operations.
However, if it is just used to put a value into a register, where
the CPU can't proceed until that value is finalized, it does
nothing more useful than shifts and adds.

In other words, don't substitute LEA for INC or ADD just because
you can.

 	leal	0x04(%ebx), %ebx
... and
 	addl	$0x04, %ebx

... are functionally the same if the CPU needs the value in ebx
immediately. In the code sequence....

 	movl	(%ebx), %eax
 	leal	0x04(%ebx), %ebx	# Next address
 	xorl	%ecx, %eax
 	movl	%eax, (%ebx)

... the address calculation for the marked next address can proceed
in parallel with the xorl operation that follows. This makes LEA
helpful. However, in the following...

>> leal (%%eax,%%edi,8),%%eax

... the CPU needs to complete the whole operation before proceeding.
If you measure this, LEA with two index registers, you will find
that the shift and add is faster, guaranteed.

On Wed, 15 Jun 2005, Gene Heskett wrote:

> On Wednesday 15 June 2005 04:53, cutaway@bellsouth.net wrote:
>> In find_first_bit() there exists this the sequence:
>>
>> shll $3,%%edi
>> addl %%edi,%%eax
>>
>> LEA knows how to multiply by small powers of 2 and add all in one
>> shot very efficiently:
>>
>> leal (%%eax,%%edi,8),%%eax
>>
>>
>> In find_first_zero_bit() the sequence:
>>
>> shll $3,%%edi
>> addl %%edi,%%edx
>>
>> could similarly become:
>>
>> leal (%%edx,%%edi,8),%%edx
>>
> To what cpu families does this apply?  eg, this may be true for intel,
> but what about amd, via etc?
>>
>>
>> -
>> To unsubscribe from this list: send the line "unsubscribe
>> linux-kernel" in the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>
> -- 
> Cheers, Gene
> "There are four boxes to be used in defense of liberty:
> soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author)
> 99.35% setiathome rank, not too shabby for a WV hillbilly
> Yahoo.com and AOL/TW attorneys please note, additions to the above
> message by Gene Heskett are:
> Copyright 2005 by Maurice Eugene Heskett, all rights reserved.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

Cheers,
Dick Johnson
Penguin : Linux version 2.6.11.9 on an i686 machine (5537.79 BogoMips).
  Notice : All mail here is now cached for review by Dictator Bush.
                  98.36% of all statistics are fiction.

  reply	other threads:[~2005-06-15 13:06 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 [this message]
2005-06-15 19:18   ` cutaway
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=Pine.LNX.4.61.0506150849380.20514@chaos.analogic.com \
    --to=linux-os@analogic.com \
    --cc=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).