From 98ee48500f419b5592cc36537a7e6db0bbc320e9 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Mon, 8 Sep 2014 16:21:57 +0200 Subject: [PATCH 1/2] Manual part of iconvdata/* __builtin_expect cleanup --- ChangeLog | 8 ++++++++ iconv/loop.c | 2 +- iconv/skeleton.c | 4 ++-- iconvdata/8bit-generic.c | 2 +- iconvdata/ansi_x3.110.c | 5 ++--- iconvdata/big5.c | 4 ++-- iconvdata/euc-kr.c | 4 ++-- iconvdata/gb18030.c | 2 +- iconvdata/gbk.c | 2 +- iconvdata/iso-2022-jp.c | 7 +++---- iconvdata/iso646.c | 6 +++--- iconvdata/iso_6937-2.c | 3 +-- iconvdata/iso_6937.c | 3 +-- iconvdata/johab.c | 2 +- iconvdata/t.61.c | 3 +-- iconvdata/utf-16.c | 2 +- iconvdata/utf-32.c | 2 +- iconvdata/utf-7.c | 2 +- 18 files changed, 33 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5262ede..c086664 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2014-09-08 Florian Weimer + * iconv/loop.c (SINGLE(LOOPFCT)): Replace __builtin_expect with + __glibc_unlikely. + * iconv/skeleton.c (gconv_init): Replace __builtin_expect with + __glibc_likely. + (FUNCTION_NAME): Replace __builtin_expect with __glibc_unlikely. + +2014-09-08 Florian Weimer + * Makeconfig (.NOEXPORT): Remove, no longer supported by GNU Make. (CHARSET, GCONV_PATH, I18NPATH, LANG, LANGUAGE, LANGUAGES, LC_ADDRESS, LC_ALL, LC_COLLATE, LC_CTYPE, LC_IDENTIFICATION, diff --git a/iconv/loop.c b/iconv/loop.c index a480c0c..38f00ce 100644 --- a/iconv/loop.c +++ b/iconv/loop.c @@ -394,7 +394,7 @@ SINGLE(LOOPFCT) (struct __gconv_step *step, /* Are there enough bytes in the input buffer? */ if (MIN_NEEDED_INPUT > 1 - && __builtin_expect (inptr + (MIN_NEEDED_INPUT - inlen) > inend, 0)) + && __glibc_unlikely (inptr + (MIN_NEEDED_INPUT - inlen) > inend)) { *inptrp = inend; # ifdef STORE_REST diff --git a/iconv/skeleton.c b/iconv/skeleton.c index 73dc186..437da17 100644 --- a/iconv/skeleton.c +++ b/iconv/skeleton.c @@ -333,7 +333,7 @@ gconv_init (struct __gconv_step *step) step->__btowc_fct = FROM_ONEBYTE; #endif } - else if (__builtin_expect (strcmp (step->__to_name, CHARSET_NAME), 0) == 0) + else if (__glibc_likely (strcmp (step->__to_name, CHARSET_NAME) == 0)) { step->__data = TO_DIRECTION_VAL; @@ -573,7 +573,7 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data, # endif # endif - if (__builtin_expect (status, __GCONV_OK) != __GCONV_OK) + if (__glibc_unlikely (status != __GCONV_OK)) return status; } #endif diff --git a/iconvdata/8bit-generic.c b/iconvdata/8bit-generic.c index efc0fd5..f61a424 100644 --- a/iconvdata/8bit-generic.c +++ b/iconvdata/8bit-generic.c @@ -68,7 +68,7 @@ { \ uint32_t ch = get32 (inptr); \ \ - if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), 0)\ + if (__glibc_unlikely (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0])) \ || (__builtin_expect (from_ucs4[ch], '\1') == '\0' && ch != 0)) \ { \ UNICODE_TAG_HANDLER (ch, 4); \ diff --git a/iconvdata/ansi_x3.110.c b/iconvdata/ansi_x3.110.c index d602dfa..d0f3f3f 100644 --- a/iconvdata/ansi_x3.110.c +++ b/iconvdata/ansi_x3.110.c @@ -472,8 +472,7 @@ static const char from_ucs4[][2] = uint32_t ch = get32 (inptr); \ const char *cp; \ \ - if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), \ - 0)) \ + if (__glibc_unlikely (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]))) \ { \ if (ch == 0x2c7) \ cp = "\xcf\x20"; \ @@ -543,7 +542,7 @@ static const char from_ucs4[][2] = tmp[1] = '\0'; \ cp = tmp; \ } \ - else if (__builtin_expect (ch, 0x266a) == 0x266a) \ + else if (__glibc_likely (ch == 0x266a)) \ cp = "\xd5"; \ else \ { \ diff --git a/iconvdata/big5.c b/iconvdata/big5.c index ee3dede..a4b56a7 100644 --- a/iconvdata/big5.c +++ b/iconvdata/big5.c @@ -8467,8 +8467,8 @@ static const char from_ucs4_tab15[][2] = uint32_t ch = get32 (inptr); \ const char *cp; \ \ - if (__builtin_expect (ch >= (sizeof (from_ucs4_tab1) \ - / sizeof (from_ucs4_tab1[0])), 0)) \ + if (__glibc_unlikely \ + (ch >= (sizeof (from_ucs4_tab1) / sizeof (from_ucs4_tab1[0])))) \ switch (ch) \ { \ case 0x2c7 ... 0x2d9: \ diff --git a/iconvdata/euc-kr.c b/iconvdata/euc-kr.c index 3b13c2e..3025f6a 100644 --- a/iconvdata/euc-kr.c +++ b/iconvdata/euc-kr.c @@ -38,8 +38,8 @@ euckr_from_ucs4 (uint32_t ch, unsigned char *cp) cp[0] = '\xa3'; cp[1] = '\xdc'; } - else if (__builtin_expect (ucs4_to_ksc5601 (ch, cp, 2), 0) - != __UNKNOWN_10646_CHAR) + else if (__glibc_likely (ucs4_to_ksc5601 (ch, cp, 2) + != __UNKNOWN_10646_CHAR)) { cp[0] |= 0x80; cp[1] |= 0x80; diff --git a/iconvdata/gb18030.c b/iconvdata/gb18030.c index f12c451..d6fc76e 100644 --- a/iconvdata/gb18030.c +++ b/iconvdata/gb18030.c @@ -24350,7 +24350,7 @@ static const unsigned char __ucs_to_gb18030_tab2[][2] = else \ len = 0; \ \ - if (__builtin_expect (len, 2) == 0 \ + if (__glibc_unlikely (len == 0) \ || (len == 2 && __builtin_expect (cp[0], '\1') == '\0')) \ { \ /* Illegal character. */ \ diff --git a/iconvdata/gbk.c b/iconvdata/gbk.c index b1a7719..e27312e 100644 --- a/iconvdata/gbk.c +++ b/iconvdata/gbk.c @@ -13171,7 +13171,7 @@ static const char __gbk_from_ucs4_tab12[][2] = /* All second bytes of a multibyte character must be >= 0x40, and \ the __gbk_to_ucs table only covers the range up to 0xfe 0xa0. */ \ if (__builtin_expect (ch2 < 0x40, 0) \ - || (__builtin_expect (ch, 0x81) == 0xfe && ch2 > 0xa0)) \ + || (__glibc_unlikely (ch == 0xfe && ch2 > 0xa0))) \ { \ /* This is an illegal character. */ \ STANDARD_FROM_LOOP_ERR_HANDLER (1); \ diff --git a/iconvdata/iso-2022-jp.c b/iconvdata/iso-2022-jp.c index 8381c30..88ca5bb 100644 --- a/iconvdata/iso-2022-jp.c +++ b/iconvdata/iso-2022-jp.c @@ -164,7 +164,7 @@ gconv_init (struct __gconv_step *step) } result = __GCONV_NOCONV; - if (__builtin_expect (dir, from_iso2022jp) != illegal_dir) + if (__glibc_likely (dir != illegal_dir)) { new_data = (struct iso2022jp_data *) malloc (sizeof (struct iso2022jp_data)); @@ -379,7 +379,7 @@ gconv_end (struct __gconv_step *data) ch = inptr[2] | 0x80; \ inptr += 3; \ } \ - else if (__builtin_expect (set2, ISO88597_set) == ISO88597_set) \ + else if (__glibc_likely (set2 == ISO88597_set)) \ { \ /* We use the table from the ISO 8859-7 module. */ \ if (inptr[2] < 0x20 || inptr[2] >= 0x80) \ @@ -770,8 +770,7 @@ static const cvlist_t conversion_lists[4] = { \ if (set2 != ISO88597_set) \ { \ - if (__builtin_expect (outptr + 3 > outend, \ - 0)) \ + if (__glibc_unlikely (outptr + 3 > outend)) \ { \ res = __GCONV_FULL_OUTPUT; \ break; \ diff --git a/iconvdata/iso646.c b/iconvdata/iso646.c index 5a0402e..b540e7f 100644 --- a/iconvdata/iso646.c +++ b/iconvdata/iso646.c @@ -146,7 +146,7 @@ gconv_init (struct __gconv_step *step) } result = __GCONV_NOCONV; - if (__builtin_expect (dir, from_iso646) != illegal_dir) + if (__glibc_likely (dir != illegal_dir)) { new_data = (struct iso646_data *) malloc (sizeof (struct iso646_data)); @@ -406,7 +406,7 @@ gconv_end (struct __gconv_step *data) \ /* Hopefully gcc can recognize that the following `if' is only true \ when we reach the default case in the `switch' statement. */ \ - if (__builtin_expect (failure, __GCONV_OK) == __GCONV_ILLEGAL_INPUT) \ + if (__glibc_unlikely (failure == __GCONV_ILLEGAL_INPUT)) \ { \ STANDARD_FROM_LOOP_ERR_HANDLER (1); \ } \ @@ -880,7 +880,7 @@ gconv_end (struct __gconv_step *data) break; \ } \ \ - if (__builtin_expect (failure, __GCONV_OK) == __GCONV_ILLEGAL_INPUT) \ + if (__glibc_unlikely (failure == __GCONV_ILLEGAL_INPUT)) \ { \ STANDARD_TO_LOOP_ERR_HANDLER (4); \ } \ diff --git a/iconvdata/iso_6937-2.c b/iconvdata/iso_6937-2.c index 8aba77d..9090e6f 100644 --- a/iconvdata/iso_6937-2.c +++ b/iconvdata/iso_6937-2.c @@ -462,8 +462,7 @@ static const char from_ucs4[][2] = uint32_t ch = get32 (inptr); \ const char *cp; \ \ - if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), \ - 0)) \ + if (__glibc_unlikely (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]))) \ { \ switch (ch) \ { \ diff --git a/iconvdata/iso_6937.c b/iconvdata/iso_6937.c index f7bbcf0..04841bd 100644 --- a/iconvdata/iso_6937.c +++ b/iconvdata/iso_6937.c @@ -462,8 +462,7 @@ static const char from_ucs4[][2] = uint32_t ch = get32 (inptr); \ const char *cp; \ \ - if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), \ - 0)) \ + if (__glibc_unlikely (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]))) \ { \ int fail = 0; \ switch (ch) \ diff --git a/iconvdata/johab.c b/iconvdata/johab.c index 5b5f042..01375e3 100644 --- a/iconvdata/johab.c +++ b/iconvdata/johab.c @@ -225,7 +225,7 @@ johab_sym_hanja_to_ucs (uint_fast32_t idx, uint_fast32_t c1, uint_fast32_t c2) ch = init_to_ucs[i - 1]; \ else if (i == 0 && m > 0 && f == 0) \ ch = 0x314e + m; /* 0x314f + m - 1 */ \ - else if (__builtin_expect ((i | m) == 0, 1) \ + else if (__glibc_likely ((i | m) == 0) \ && __builtin_expect (f > 0, 1)) \ ch = final_to_ucs[f - 1]; /* round trip?? */ \ else \ diff --git a/iconvdata/t.61.c b/iconvdata/t.61.c index e082b50..13f1f28 100644 --- a/iconvdata/t.61.c +++ b/iconvdata/t.61.c @@ -448,8 +448,7 @@ static const char from_ucs4[][2] = uint32_t ch = get32 (inptr); \ const char *cp; \ \ - if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), \ - 0)) \ + if (__glibc_unlikely (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]))) \ { \ if (__builtin_expect (ch, 0) == 0x2126) \ cp = "\xe0"; \ diff --git a/iconvdata/utf-16.c b/iconvdata/utf-16.c index 31c2d6e..342de08 100644 --- a/iconvdata/utf-16.c +++ b/iconvdata/utf-16.c @@ -148,7 +148,7 @@ gconv_init (struct __gconv_step *step) } result = __GCONV_NOCONV; - if (__builtin_expect (dir, to_utf16) != illegal_dir) + if (__glibc_likely (dir != illegal_dir)) { new_data = (struct utf16_data *) malloc (sizeof (struct utf16_data)); diff --git a/iconvdata/utf-32.c b/iconvdata/utf-32.c index e3e4243..3e196ac 100644 --- a/iconvdata/utf-32.c +++ b/iconvdata/utf-32.c @@ -145,7 +145,7 @@ gconv_init (struct __gconv_step *step) } result = __GCONV_NOCONV; - if (__builtin_expect (dir, to_utf32) != illegal_dir) + if (__glibc_likely (dir != illegal_dir)) { new_data = (struct utf32_data *) malloc (sizeof (struct utf32_data)); diff --git a/iconvdata/utf-7.c b/iconvdata/utf-7.c index 637d85c..74a8e5b 100644 --- a/iconvdata/utf-7.c +++ b/iconvdata/utf-7.c @@ -219,7 +219,7 @@ base64 (unsigned int i) /* If accumulated data is nonzero, the input is invalid. */ \ /* Also, partial UTF-16 characters are invalid. */ \ if (__builtin_expect (statep->__value.__wch != 0, 0) \ - || __builtin_expect ((statep->__count >> 3) <= 26, 0)) \ + || __glibc_unlikely ((statep->__count >> 3) <= 26)) \ { \ STANDARD_FROM_LOOP_ERR_HANDLER ((statep->__count = 0, 1)); \ } \ -- 1.9.3