From patchwork Tue Sep 9 19:08:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 2711 Received: (qmail 1120 invoked by alias); 9 Sep 2014 19:08:26 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 1109 invoked by uid 89); 9 Sep 2014 19:08:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Message-ID: <540F501B.2080808@redhat.com> Date: Tue, 09 Sep 2014 21:08:11 +0200 From: Florian Weimer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: libc-alpha@sourceware.org Subject: [PATCH v2] __builtin_expect cleanup for iconv{, data}/*.c (was: Re: [PATCH] __builtin_expect cleanup for iconvdata/*.c) References: <540E06B0.50406@redhat.com> In-Reply-To: <540E06B0.50406@redhat.com> This is the second iteration of these patches. The rewriting script has grown considerably and seems useful for subsequent clean-ups. The first patch installs it as scripts/builtin_expect.py. The second patch is the automated part of the conversion. The changes look reasonable to me, but double-checking is certainly welcome. The third patch contains the manual part. It is now much smaller because the rewriting script is more sophisticated. Again, I used a preprocessor #define to disable __builtin_expect and objdump -d --reloc to compare the results. Because of a line merge and the resulting line number difference in an assert statement, there was one assembly difference. Testing on Fedora 20 x86_64 also revealed no regressions. From 25282e6d2d0bb5d9314ec02845747aa9c86c5606 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Tue, 9 Sep 2014 20:37:28 +0200 Subject: [PATCH 3/3] Manual cleanups after __builtin_expect conversion of iconv/ and iconvdata/ This commit removes the one remaining __builtin_expect expressions which can be converted, and fixes long lines introduces by the automated rewriting. 2014-09-09 Florian Weimer * iconv/gconv_dl.c (__gconv_find_shlib): Wrap long line resulting from the automated __builtin_expect conversion. * iconvdata/euc-kr.c (euckr_from_ucs4): Likewise. * iconv/gconv_cache.c (__gconv_load_cache): Replace multi-line __builtin_expect with __glibc_unlikely. diff --git a/iconv/gconv_cache.c b/iconv/gconv_cache.c index cb48eca..dab5ac6 100644 --- a/iconv/gconv_cache.c +++ b/iconv/gconv_cache.c @@ -116,9 +116,9 @@ __gconv_load_cache (void) || __glibc_unlikely (header->string_offset >= cache_size) || __glibc_unlikely (header->hash_offset >= cache_size) || __glibc_unlikely (header->hash_size == 0) - || __builtin_expect ((header->hash_offset + || __glibc_unlikely ((header->hash_offset + header->hash_size * sizeof (struct hash_entry)) - > cache_size, 0) + > cache_size) || __glibc_unlikely (header->module_offset >= cache_size) || __glibc_unlikely (header->otherconv_offset > cache_size)) { diff --git a/iconv/gconv_dl.c b/iconv/gconv_dl.c index 840793d..05448b3 100644 --- a/iconv/gconv_dl.c +++ b/iconv/gconv_dl.c @@ -93,7 +93,8 @@ __gconv_find_shlib (const char *name) found->counter = -TRIES_BEFORE_UNLOAD - 1; found->handle = NULL; - if (__glibc_unlikely (__tsearch (found, &loaded, known_compare) == NULL)) + if (__glibc_unlikely (__tsearch (found, &loaded, known_compare) + == NULL)) { /* Something went wrong while inserting the entry. */ free (found); diff --git a/iconvdata/euc-kr.c b/iconvdata/euc-kr.c index 50d1a8c..2f10453 100644 --- a/iconvdata/euc-kr.c +++ b/iconvdata/euc-kr.c @@ -38,7 +38,8 @@ euckr_from_ucs4 (uint32_t ch, unsigned char *cp) cp[0] = '\xa3'; cp[1] = '\xdc'; } - else if (__glibc_likely (ucs4_to_ksc5601 (ch, cp, 2) != __UNKNOWN_10646_CHAR)) + else if (__glibc_likely (ucs4_to_ksc5601 (ch, cp, 2) + != __UNKNOWN_10646_CHAR)) { cp[0] |= 0x80; cp[1] |= 0x80; -- 1.9.3