From patchwork Tue Jun 22 12:30:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 56467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BCD58B6F11 for ; Tue, 22 Jun 2010 22:30:15 +1000 (EST) Received: (qmail 28903 invoked by alias); 22 Jun 2010 12:30:11 -0000 Received: (qmail 28891 invoked by uid 22791); 22 Jun 2010 12:30:09 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Jun 2010 12:30:05 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 5FB889AC832; Tue, 22 Jun 2010 14:30:03 +0200 (CEST) Date: Tue, 22 Jun 2010 14:30:03 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rguenther@suse.de Subject: Micro optimize bitmap_clear_bit Message-ID: <20100622123003.GB15547@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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? * 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; }