Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2003:
[Freeciv-Dev] Re: (PR#2521) general effects framework
Home

[Freeciv-Dev] Re: (PR#2521) general effects framework

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: kaufman@xxxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2521) general effects framework
From: "Raimar Falke" <rf13@xxxxxxxxxxxxxxxxx>
Date: Tue, 11 Mar 2003 23:17:26 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Tue, Mar 11, 2003 at 07:27:49PM -0800, rwetmore@xxxxxxxxxxxx wrote:
> 
> Generally, assignments are not the common use case. It might be
> more instructive to see what various expressions code looked like.
> It is quite possible the compiler will use bit test operations.
> 
> Also, most of the noise below is a result of the widening or
> narrowing of the values during assignment, i.e. int conversion.
> 
> If you changed the ints to bools, it might reduce a lot of the
> noise ops. Presumably the compiler knows a bool is 1 bit no
> matter what the storage size and will forgo a lot of the extra
> bit clearing and extending steps.
> 
> But I'm surprised it first clears, then ors the bit on set. It
> should be able to get away with `orb %al, s`.
> 
> If it knew the arg was a bool, it could get away with the first,
> 3rd and above instruction on a set.
>      movb 8(%ebp),%al
>      salb $6,%al
>      orb  %al,s
> 
> On get, it is also intriguing that it first shifts up to the
> sign bit and then downshifts to propagate an all ones or zeros.
> 
> On a get it could get away with something like this
>      bt   $6,s
>      setc %al

It turns out that the code I posted yesterday was generated by gcc
2.95.4. gcc 2.96 produces:
        movb    s+16, %al
        sall    $4, %eax
        sarb    $7, %al
        movsbl  %al,%eax
for returning bool and int.

If BV is used it produces:
        movb    s+20, %al
        shrb    $4, %al
        andl    $1, %eax

icc6 produces
        movzbl    s+16, %eax                                    #21.12
        andl      $16, %eax                                     #21.12
        shrl      $4, %eax                                      #21.12
for bitfields and 
        movzbl    s+20, %edx                                    #36.12
        xorl      %eax, %eax                                    #36.12
        testb     $16, %dl                                      #36.12
        setne     %al                                           #36.12
for BV.

void s1(void)
{
    s.has1.a4 = 1;
}

void t1(void)
{
    BV_SET(s.has2,4);
}

produce the same code for gcc and icc.

Summary: the implementation of bitfields in gcc < 2.96 is suboptimal.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  This message has been ROT-13 encrypted twice for extra security.




[Prev in Thread] Current Thread [Next in Thread]