* iconv/gconv_dl.c: Add __builtin_expect in many places.
	* iconv/skeleton.c: Add more __builtin_expect.
	* iconv/gconv_simple.c: Add __builtin_expect in many places.
This commit is contained in:
Ulrich Drepper 2000-06-06 05:02:18 +00:00
parent 85830c4c46
commit 365afefc6b
4 changed files with 43 additions and 35 deletions

View File

@ -1,5 +1,9 @@
2000-06-05 Ulrich Drepper <drepper@redhat.com> 2000-06-05 Ulrich Drepper <drepper@redhat.com>
* iconv/gconv_dl.c: Add __builtin_expect in many places.
* iconv/skeleton.c: Add more __builtin_expect.
* iconv/gconv_simple.c: Add __builtin_expect in many places.
* iconv/gconv.h (__GCONV_IS_LAST, __GCONV_IGNORE_ERRORS): Define. * iconv/gconv.h (__GCONV_IS_LAST, __GCONV_IGNORE_ERRORS): Define.
(struct __gconv_step_data): Rename __is_last to __flags. (struct __gconv_step_data): Rename __is_last to __flags.
* iconv/gconv_close.c: Change all uses of __is_last. * iconv/gconv_close.c: Change all uses of __is_last.

View File

@ -91,7 +91,8 @@ __gconv_find_shlib (const char *name)
found->counter = -TRIES_BEFORE_UNLOAD - 1; found->counter = -TRIES_BEFORE_UNLOAD - 1;
found->handle = NULL; found->handle = NULL;
if (__tsearch (found, &loaded, known_compare) == NULL) if (__builtin_expect (__tsearch (found, &loaded, known_compare)
== NULL, 0))
{ {
/* Something went wrong while inserting the entry. */ /* Something went wrong while inserting the entry. */
free (found); free (found);

View File

@ -159,7 +159,7 @@ internal_ucs4_loop_single (const unsigned char **inptrp,
while (*inptrp < inend && cnt < 4) while (*inptrp < inend && cnt < 4)
state->__value.__wchb[cnt++] = *(*inptrp)++; state->__value.__wchb[cnt++] = *(*inptrp)++;
if (cnt < 4) if (__builtin_expect (cnt, 4) < 4)
{ {
/* Still not enough bytes. Store the ones in the input buffer. */ /* Still not enough bytes. Store the ones in the input buffer. */
state->__count &= ~7; state->__count &= ~7;
@ -224,7 +224,7 @@ ucs4_internal_loop (const unsigned char **inptrp, const unsigned char *inend,
inval = *(uint32_t *) inptr; inval = *(uint32_t *) inptr;
#endif #endif
if (inval > 0x7fffffff) if (__builtin_expect (inval, 0) > 0x7fffffff)
{ {
if (flags & __GCONV_IGNORE_ERRORS) if (flags & __GCONV_IGNORE_ERRORS)
{ {
@ -271,7 +271,7 @@ ucs4_internal_loop_unaligned (const unsigned char **inptrp,
for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4, outptr += 4) for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4, outptr += 4)
{ {
if (inptr[0] > 0x80) if (__builtin_expect (inptr[0], 0) > 0x80)
{ {
/* The value is too large. */ /* The value is too large. */
if (flags & __GCONV_IGNORE_ERRORS) if (flags & __GCONV_IGNORE_ERRORS)
@ -339,7 +339,7 @@ ucs4_internal_loop_single (const unsigned char **inptrp,
while (*inptrp < inend && cnt < 4) while (*inptrp < inend && cnt < 4)
state->__value.__wchb[cnt++] = *(*inptrp)++; state->__value.__wchb[cnt++] = *(*inptrp)++;
if (cnt < 4) if (__builtin_expect (cnt, 4) < 4)
{ {
/* Still not enough bytes. Store the ones in the input buffer. */ /* Still not enough bytes. Store the ones in the input buffer. */
state->__count &= ~7; state->__count &= ~7;
@ -348,7 +348,8 @@ ucs4_internal_loop_single (const unsigned char **inptrp,
return __GCONV_INCOMPLETE_INPUT; return __GCONV_INCOMPLETE_INPUT;
} }
if (((unsigned char *) state->__value.__wchb)[0] > 0x80) if (__builtin_expect (((unsigned char *) state->__value.__wchb)[0], 0)
> 0x80)
{ {
/* The value is too large. */ /* The value is too large. */
if (!(flags & __GCONV_IGNORE_ERRORS)) if (!(flags & __GCONV_IGNORE_ERRORS))
@ -490,7 +491,7 @@ internal_ucs4le_loop_single (const unsigned char **inptrp,
while (*inptrp < inend && cnt < 4) while (*inptrp < inend && cnt < 4)
state->__value.__wchb[cnt++] = *(*inptrp)++; state->__value.__wchb[cnt++] = *(*inptrp)++;
if (cnt < 4) if (__builtin_expect (cnt, 4) < 4)
{ {
/* Still not enough bytes. Store the ones in the input buffer. */ /* Still not enough bytes. Store the ones in the input buffer. */
state->__count &= ~7; state->__count &= ~7;
@ -553,7 +554,7 @@ ucs4le_internal_loop (const unsigned char **inptrp, const unsigned char *inend,
inval = *(uint32_t *) inptr; inval = *(uint32_t *) inptr;
#endif #endif
if (inval > 0x7fffffff) if (__builtin_expect (inval, 0) > 0x7fffffff)
{ {
if (flags & __GCONV_IGNORE_ERRORS) if (flags & __GCONV_IGNORE_ERRORS)
{ {
@ -598,7 +599,7 @@ ucs4le_internal_loop_unaligned (const unsigned char **inptrp,
for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4) for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4)
{ {
if (inptr[3] > 0x80) if (__builtin_expect (inptr[3], 0) > 0x80)
{ {
/* The value is too large. */ /* The value is too large. */
if (flags & __GCONV_IGNORE_ERRORS) if (flags & __GCONV_IGNORE_ERRORS)
@ -656,7 +657,7 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
while (*inptrp < inend && cnt < 4) while (*inptrp < inend && cnt < 4)
state->__value.__wchb[cnt++] = *(*inptrp)++; state->__value.__wchb[cnt++] = *(*inptrp)++;
if (cnt < 4) if (__builtin_expect (cnt, 4) < 4)
{ {
/* Still not enough bytes. Store the ones in the input buffer. */ /* Still not enough bytes. Store the ones in the input buffer. */
state->__count &= ~7; state->__count &= ~7;
@ -665,7 +666,8 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
return __GCONV_INCOMPLETE_INPUT; return __GCONV_INCOMPLETE_INPUT;
} }
if (((unsigned char *) state->__value.__wchb)[3] > 0x80) if (__builtin_expect (((unsigned char *) state->__value.__wchb)[3], 0)
> 0x80)
{ {
/* The value is too large. */ /* The value is too large. */
if (!(flags & __GCONV_IGNORE_ERRORS)) if (!(flags & __GCONV_IGNORE_ERRORS))
@ -713,7 +715,7 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
#define LOOPFCT FROM_LOOP #define LOOPFCT FROM_LOOP
#define BODY \ #define BODY \
{ \ { \
if (*inptr > '\x7f') \ if (__builtin_expect (*inptr, 0) > '\x7f') \
{ \ { \
if (! ignore_errors_p ()) \ if (! ignore_errors_p ()) \
{ \ { \
@ -750,7 +752,7 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
#define LOOPFCT FROM_LOOP #define LOOPFCT FROM_LOOP
#define BODY \ #define BODY \
{ \ { \
if (*((uint32_t *) inptr) > 0x7f) \ if (__builtin_expect (*((uint32_t *) inptr), 0) > 0x7f) \
{ \ { \
if (! ignore_errors_p ()) \ if (! ignore_errors_p ()) \
{ \ { \
@ -806,7 +808,7 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
if ((wc & encoding_mask[step - 2]) == 0) \ if ((wc & encoding_mask[step - 2]) == 0) \
break; \ break; \
\ \
if (outptr + step > outend) \ if (__builtin_expect (outptr + step > outend, 0)) \
{ \ { \
/* Too long. */ \ /* Too long. */ \
result = __GCONV_FULL_OUTPUT; \ result = __GCONV_FULL_OUTPUT; \
@ -873,25 +875,25 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
cnt = 2; \ cnt = 2; \
ch &= 0x1f; \ ch &= 0x1f; \
} \ } \
else if ((ch & 0xf0) == 0xe0) \ else if (__builtin_expect (ch & 0xf0, 0xf0) == 0xe0) \
{ \ { \
/* We expect three bytes. */ \ /* We expect three bytes. */ \
cnt = 3; \ cnt = 3; \
ch &= 0x0f; \ ch &= 0x0f; \
} \ } \
else if ((ch & 0xf8) == 0xf0) \ else if (__builtin_expect (ch & 0xf8, 0xf8) == 0xf0) \
{ \ { \
/* We expect four bytes. */ \ /* We expect four bytes. */ \
cnt = 4; \ cnt = 4; \
ch &= 0x07; \ ch &= 0x07; \
} \ } \
else if ((ch & 0xfc) == 0xf8) \ else if (__builtin_expect (ch & 0xfc, 0xf8) == 0xf8) \
{ \ { \
/* We expect five bytes. */ \ /* We expect five bytes. */ \
cnt = 5; \ cnt = 5; \
ch &= 0x03; \ ch &= 0x03; \
} \ } \
else if ((ch & 0xfe) == 0xfc) \ else if (__builtin_expect (ch & 0xfe, 0xfc) == 0xfc) \
{ \ { \
/* We expect six bytes. */ \ /* We expect six bytes. */ \
cnt = 6; \ cnt = 6; \
@ -921,7 +923,7 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
continue; \ continue; \
} \ } \
\ \
if (NEED_LENGTH_TEST && inptr + cnt > inend) \ if (NEED_LENGTH_TEST && __builtin_expect (inptr + cnt > inend, 0)) \
{ \ { \
/* We don't have enough input. But before we report that check \ /* We don't have enough input. But before we report that check \
that all the bytes are correct. */ \ that all the bytes are correct. */ \
@ -929,7 +931,7 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
if ((inptr[i] & 0xc0) != 0x80) \ if ((inptr[i] & 0xc0) != 0x80) \
break; \ break; \
\ \
if (inptr + i == inend) \ if (__builtin_expect (inptr + i == inend, 1)) \
{ \ { \
result = __GCONV_INCOMPLETE_INPUT; \ result = __GCONV_INCOMPLETE_INPUT; \
break; \ break; \
@ -1004,19 +1006,19 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
cnt = 2; \ cnt = 2; \
ch &= 0x1f; \ ch &= 0x1f; \
} \ } \
else if ((ch & 0xf0) == 0xe0) \ else if (__builtin_expect (ch & 0xf0, 0xe0) == 0xe0) \
{ \ { \
/* We expect three bytes. */ \ /* We expect three bytes. */ \
cnt = 3; \ cnt = 3; \
ch &= 0x0f; \ ch &= 0x0f; \
} \ } \
else if ((ch & 0xf8) == 0xf0) \ else if (__builtin_expect (ch & 0xf8, 0xf8) == 0xf0) \
{ \ { \
/* We expect four bytes. */ \ /* We expect four bytes. */ \
cnt = 4; \ cnt = 4; \
ch &= 0x07; \ ch &= 0x07; \
} \ } \
else if ((ch & 0xfc) == 0xf8) \ else if (__builtin_expect (ch & 0xfc, 0xfc) == 0xf8) \
{ \ { \
/* We expect five bytes. */ \ /* We expect five bytes. */ \
cnt = 5; \ cnt = 5; \
@ -1056,17 +1058,17 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
bytebuf[0] = 0xc0; \ bytebuf[0] = 0xc0; \
ntotal = 2; \ ntotal = 2; \
} \ } \
else if (state->__value.__wch <= 0xffff) \ else if (__builtin_expect (state->__value.__wch, 0) <= 0xffff) \
{ \ { \
bytebuf[0] = 0xe0; \ bytebuf[0] = 0xe0; \
ntotal = 3; \ ntotal = 3; \
} \ } \
else if (state->__value.__wch <= 0x1fffff) \ else if (__builtin_expect (state->__value.__wch, 0) <= 0x1fffff) \
{ \ { \
bytebuf[0] = 0xf0; \ bytebuf[0] = 0xf0; \
ntotal = 4; \ ntotal = 4; \
} \ } \
else if (state->__value.__wch <= 0x3ffffff) \ else if (__builtin_expect (state->__value.__wch, 0) <= 0x3ffffff) \
{ \ { \
bytebuf[0] = 0xf8; \ bytebuf[0] = 0xf8; \
ntotal = 5; \ ntotal = 5; \
@ -1128,7 +1130,7 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
#define LOOPFCT FROM_LOOP #define LOOPFCT FROM_LOOP
#define BODY \ #define BODY \
{ \ { \
if (*((uint32_t *) inptr) >= 0x10000) \ if (__builtin_expect (*((uint32_t *) inptr), 0) >= 0x10000) \
{ \ { \
if (! ignore_errors_p ()) \ if (! ignore_errors_p ()) \
{ \ { \
@ -1184,7 +1186,7 @@ ucs4le_internal_loop_single (const unsigned char **inptrp,
#define BODY \ #define BODY \
{ \ { \
uint32_t val = *((uint32_t *) inptr); \ uint32_t val = *((uint32_t *) inptr); \
if (val >= 0x10000) \ if (__builtin_expect (val, 0) >= 0x10000) \
{ \ { \
if (! ignore_errors_p ()) \ if (! ignore_errors_p ()) \
{ \ { \

View File

@ -221,7 +221,7 @@ gconv_init (struct __gconv_step *step)
step->__min_needed_to = MIN_NEEDED_TO; step->__min_needed_to = MIN_NEEDED_TO;
step->__max_needed_to = MAX_NEEDED_TO; step->__max_needed_to = MAX_NEEDED_TO;
} }
else if (strcmp (step->__to_name, CHARSET_NAME) == 0) else if (__builtin_expect (strcmp (step->__to_name, CHARSET_NAME), 0) == 0)
{ {
step->__data = &to_object; step->__data = &to_object;
@ -348,7 +348,7 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
EXTRA_LOOP_ARGS); EXTRA_LOOP_ARGS);
# endif # endif
if (status != __GCONV_OK) if (__builtin_expect (status, __GCONV_OK) != __GCONV_OK)
return status; return status;
} }
#endif #endif
@ -382,7 +382,7 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
SAVE_RESET_STATE (1); SAVE_RESET_STATE (1);
#endif #endif
if (!unaligned) if (__builtin_expect (!unaligned, 1))
{ {
if (FROM_DIRECTION) if (FROM_DIRECTION)
/* Run the conversion loop. */ /* Run the conversion loop. */
@ -422,7 +422,7 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
/* If this is the last step leave the loop, there is nothing /* If this is the last step leave the loop, there is nothing
we can do. */ we can do. */
if (data->__flags & __GCONV_IS_LAST) if (__builtin_expect (data->__flags & __GCONV_IS_LAST, 0))
{ {
/* Store information about how many bytes are available. */ /* Store information about how many bytes are available. */
data->__outbuf = outbuf; data->__outbuf = outbuf;
@ -434,7 +434,7 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
} }
/* Write out all output which was produced. */ /* Write out all output which was produced. */
if (outbuf > outstart) if (__builtin_expect (outbuf > outstart, 1))
{ {
const unsigned char *outerr = data->__outbuf; const unsigned char *outerr = data->__outbuf;
int result; int result;
@ -490,7 +490,7 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
/* If we haven't consumed a single byte decrement /* If we haven't consumed a single byte decrement
the invocation counter. */ the invocation counter. */
if (outbuf == outstart) if (__builtin_expect (outbuf == outstart, 0))
--data->__invocation_counter; --data->__invocation_counter;
#endif /* reset input buffer */ #endif /* reset input buffer */
} }
@ -516,7 +516,8 @@ FUNCTION_NAME (struct __gconv_step *step, struct __gconv_step_data *data,
#if MAX_NEEDED_FROM > 1 || MAX_NEEDED_TO > 1 #if MAX_NEEDED_FROM > 1 || MAX_NEEDED_TO > 1
if (((MAX_NEEDED_FROM > 1 && FROM_DIRECTION) if (((MAX_NEEDED_FROM > 1 && FROM_DIRECTION)
|| (MAX_NEEDED_TO > 1 && !FROM_DIRECTION)) || (MAX_NEEDED_TO > 1 && !FROM_DIRECTION))
&& consume_incomplete && status == __GCONV_INCOMPLETE_INPUT) && __builtin_expect (consume_incomplete, 0)
&& status == __GCONV_INCOMPLETE_INPUT)
{ {
# ifdef STORE_REST # ifdef STORE_REST
mbstate_t *state = data->__statep; mbstate_t *state = data->__statep;