Subject: Re: CVS commit: src/sys/arch/sgimips
To: None <petrov@netbsd.org>
From: None <cgd@broadcom.com>
List: port-mips
Date: 10/08/2003 12:49:27
At Wed, 8 Oct 2003 19:31:12 +0000 (UTC), "Andrey Petrov" wrote:
> I used 3.3.1 and this example is all right on sparc64 too.
> here is my test
> 
> int test2(int *p)
> {
> 
> 	if (((*p >> 16) & 0xffff) == 123)
> 		return 1;
> 
> 	return 2;
> }
> [ ... ]
> Interesting that gcc indeed does access it as a halfword but still wants
> to apply mask. It certainly looks like gcc optimizes this, just not
> always successfully. Seems that I got to take back my performance argument:-)

it accessed it as a signed halfword.  if you change your source to:

int test2(int *p)
{

      if ((unsigned short)((*p >> 16) & 0xffff) == 123)
              return 1;

      return 2;
}

you get code more like:

        lduh    [%o0], %o1
        xor     %o1, 123, %o1
        subcc   %g0, %o1, %g0
        addx    %g0, 0, %o0
        retl
        add     %o0, 1, %o0

FWIW.  Likewise for:

      if ((unsigned short)(*p >> 16) == 123)
              return 1;


Not sure why it doesn't do that automatically.  Perhaps a C-Language
reason, perhaps just doesn't recognize the opportunity for (signed int
& 0xffff) --> unsigned short optimization.


cgd