Subject: Re: dev/ic/am7990.c
To: Gordon W. Ross <gwr@mc.com>
From: Matt Thomas <matt@lkg.dec.com>
List: tech-net
Date: 05/13/1996 08:55:48
In  <9605101717.AA23623@bach> , you wrote:

> Hi Jason,
> 
> In the file dev/ic/am7990.c  your comment asks:
> /* XXX what do we do about this?!  --thorpej */
> 
> I'm pretty sure the following code will work on any machine
> (even the sparc) because the memory addresses passed to this
> are always aligned to at least a 2-byte boundary.  Therefore,
> we could just enable it for all machines.  Alternatively, we
> could make this a real MD function like oc_cksum() and such,
> but I think using an inline like this will be faster.
> 
> Note that the avoidance of branches in this implementation is
> largely responsible for reducing the generated code.  My hope
> was also to avoid pipelines stalls where that is an issue.
> 
> Does anyone see problems with enabling the code section below?
> Should we include this in any other ethernet drivers?
> 
> Gordon
> 
> 
> #if 0	/* XXX what do we do about this?!  --thorpej */
> static inline u_int16_t ether_cmp __P((void *, void *));
> 
> /*
>  * Compare two Ether/802 addresses for equality, inlined and
>  * unrolled for speed.  I'd love to have an inline assembler
>  * version of this...   XXX: Who wanted that? mycroft?
>  * I wrote one, but the following is just as efficient.
>  * This expands to 10 short m68k instructions! -gwr
>  * Note: use this like bcmp()
>  */
> static inline u_short
> ether_cmp(one, two)
> 	void *one, *two;
> {
> 	register u_int16_t *a = (u_short *) one;
> 	register u_int16_t *b = (u_short *) two;
> 	register u_int16_t diff;
> 
> 	diff  = *a++ - *b++;
> 	diff |= *a++ - *b++;
> 	diff |= *a++ - *b++;

If you really want this to be inlined efficiently, then
remove the ++

	diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]);

Removing the ;'s will give compiler a better chance for optimizing since
you are removeing sequence points.  Removing the autoincrement means
there are two variables that the compiler goes not have to modify.

The later sequence is 4 instructions shorter on alpha.

-- 
Matt Thomas               Internet:   matt@3am-software.com
3am Software Foundry      WWW URL:    http://www.3am-software.com/bio/matt.html
Westford, MA              Disclaimer: I disavow all knowledge of this message