This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Micro optimize bitmap_clear_bit


On Tue, 22 Jun 2010, Jan Hubicka wrote:

> Hi,
> this is small change I noticed while looking into bitmap_clear_bit (that is also
> amonght top 10 most hot GCC functions).  We test if the bit was previously
> clear but then we go for bitmap_element_zerop.  Since there is branch anyway
> (I am still not convinced that reducing store bandwidth is worth the hard to
> predict branches here), it is probably good idea to branch around the
> bitmap_element_zerop too.  I also added nonzero test for !ptr->bits[word_num]
> since the value will be conveniently in register.
> 
> The patch seems to save about 10% of samples on bitmap_clear_bit, but it is
> within noise factor.
> 
> Bootstrapped/regtested x86_64-linux, OK?

Ok.

Thanks,
Richard.

> 	* bitmap.c (bitmap_clear_bit): Micro optimize.
> Index: bitmap.c
> ===================================================================
> --- bitmap.c	(revision 161163)
> +++ bitmap.c	(working copy)
> @@ -624,11 +624,13 @@ bitmap_clear_bit (bitmap head, int bit)
>        BITMAP_WORD bit_val = ((BITMAP_WORD) 1) << bit_num;
>        bool res = (ptr->bits[word_num] & bit_val) != 0;
>        if (res)
> -	ptr->bits[word_num] &= ~bit_val;
> -
> -      /* If we cleared the entire word, free up the element.  */
> -      if (bitmap_element_zerop (ptr))
> -	bitmap_element_free (head, ptr);
> +	{
> +	  ptr->bits[word_num] &= ~bit_val;
> +	  /* If we cleared the entire word, free up the element.  */
> +	  if (!ptr->bits[word_num]
> +	      && bitmap_element_zerop (ptr))
> +	    bitmap_element_free (head, ptr);
> +	}
>  
>        return res;
>      }
> 
> 

-- 
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]