about summary refs log tree commit diff
path: root/iconvdata
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-06-06 22:58:45 +0000
committerUlrich Drepper <drepper@redhat.com>2000-06-06 22:58:45 +0000
commitee4ce289076db8fec41bf651c9e10688eaa96154 (patch)
tree5bbe393711f0892ea7e6a14e79235e1399e14169 /iconvdata
parent1d280d9f1e4d4c889d8123663a81b49256cf6fd6 (diff)
downloadglibc-ee4ce289076db8fec41bf651c9e10688eaa96154.tar.gz
glibc-ee4ce289076db8fec41bf651c9e10688eaa96154.tar.xz
glibc-ee4ce289076db8fec41bf651c9e10688eaa96154.zip
Add __builtin_expect in many places.
Diffstat (limited to 'iconvdata')
-rw-r--r--iconvdata/sjis.c27
-rw-r--r--iconvdata/t.61.c34
-rw-r--r--iconvdata/uhc.c27
-rw-r--r--iconvdata/unicode.c4
-rw-r--r--iconvdata/utf-16.c32
5 files changed, 69 insertions, 55 deletions
diff --git a/iconvdata/sjis.c b/iconvdata/sjis.c
index 07f03f78d7..172246843c 100644
--- a/iconvdata/sjis.c
+++ b/iconvdata/sjis.c
@@ -4337,12 +4337,12 @@ static const char from_ucs4_extra[0x100][2] =
   {									      \
     uint32_t ch = *inptr;						      \
 									      \
-    if (ch == 0x5c)							      \
+    if (__builtin_expect (ch, 0) == 0x5c)				      \
       {									      \
 	ch = 0xa5;							      \
 	++inptr;							      \
       }									      \
-    else if (ch == 0x7e)						      \
+    else if (__builtin_expect (ch, 0) == 0x7e)				      \
       {									      \
 	ch = 0x203e;							      \
 	++inptr;							      \
@@ -4354,7 +4354,9 @@ static const char from_ucs4_extra[0x100][2] =
 	ch = halfkana_to_ucs4[ch - 0xa1];				      \
 	++inptr;							      \
       }									      \
-    else if (ch > 0xea || ch == 0xa0 || ch <= 0x80)			      \
+    else if (__builtin_expect (ch, 0) > 0xea				      \
+	     || __builtin_expect (ch, 0) == 0xa0			      \
+	     || __builtin_expect (ch, 0x81) <= 0x80)			      \
       {									      \
 	/* These are illegal.  */					      \
 	if (! ignore_errors_p ())					      \
@@ -4375,7 +4377,7 @@ static const char from_ucs4_extra[0x100][2] =
 	uint32_t ch2;							      \
 	uint_fast32_t idx;						      \
 									      \
-	if (NEED_LENGTH_TEST && inptr + 1 >= inend)			      \
+	if (NEED_LENGTH_TEST && __builtin_expect (inptr + 1 >= inend, 0))     \
 	  {								      \
 	    /* The second character is not available.  Store		      \
 	       the intermediate result.  */				      \
@@ -4385,9 +4387,11 @@ static const char from_ucs4_extra[0x100][2] =
 									      \
 	ch2 = inptr[1];							      \
 	idx = ch * 256 + ch2;						      \
-	if (idx < 0x8140 || (idx > 0x84be && idx < 0x889f)		      \
-	    || (idx > 0x88fc && idx < 0x8940)				      \
-	    || (idx > 0x9ffc && idx < 0xe040) || idx > 0xeaa4)		      \
+	if (__builtin_expect (idx, 0x8140) < 0x8140			      \
+	    || (__builtin_expect (idx, 0x8140) > 0x84be && idx < 0x889f)      \
+	    || (__builtin_expect (idx, 0x8140) > 0x88fc && idx < 0x8940)      \
+	    || (__builtin_expect (idx, 0x8140) > 0x9ffc && idx < 0xe040)      \
+	    || __builtin_expect (idx, 0x8140) > 0xeaa4)			      \
 	  {								      \
 	    /* This is illegal.  */					      \
 	    if (! ignore_errors_p ())					      \
@@ -4418,7 +4422,7 @@ static const char from_ucs4_extra[0x100][2] =
 	    inptr += 2;							      \
 	  }								      \
 									      \
-	if (ch == 0)							      \
+	if (__builtin_expect (ch, 1) == 0)				      \
 	  {								      \
 	    /* This is an illegal character.  */			      \
 	    if (! ignore_errors_p ())					      \
@@ -4456,7 +4460,8 @@ static const char from_ucs4_extra[0x100][2] =
 	  cp = from_ucs4_greek[ch - 0x391];				      \
 	else if (ch >= 0x2010 && ch <= 0x9fa0)				      \
 	  cp = from_ucs4_cjk[ch - 0x02010];				      \
-	else if (ch >= 0xff01 && ch <= 0xffef)				      \
+	else if (__builtin_expect (ch, 0xff01) >= 0xff01		      \
+		 && __builtin_expect (ch, 0xff01) <= 0xffef)		      \
 	  cp = from_ucs4_extra[ch - 0xff00];				      \
 	else								      \
 	  {								      \
@@ -4476,7 +4481,7 @@ static const char from_ucs4_extra[0x100][2] =
     else								      \
       cp = from_ucs4_lat1[ch];						      \
 									      \
-    if (cp[0] == '\0' && ch != 0)					      \
+    if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0)		      \
       {									      \
 	/* Illegal character.  */					      \
 	if (! ignore_errors_p ())					      \
@@ -4494,7 +4499,7 @@ static const char from_ucs4_extra[0x100][2] =
 	/* Now test for a possible second byte and write this if possible.  */\
 	if (cp[1] != '\0')						      \
 	  {								      \
-	    if (NEED_LENGTH_TEST && outptr >= outend)			      \
+	    if (NEED_LENGTH_TEST && __builtin_expect (outptr >= outend, 0))   \
 	      {								      \
 		/* The result does not fit into the buffer.  */		      \
 		result = __GCONV_FULL_OUTPUT;				      \
diff --git a/iconvdata/t.61.c b/iconvdata/t.61.c
index 1623606496..766dd0fe97 100644
--- a/iconvdata/t.61.c
+++ b/iconvdata/t.61.c
@@ -382,14 +382,15 @@ static const char from_ucs4[][2] =
 #define BODY \
   {									      \
     uint32_t ch = *inptr;						      \
+    int increment = 1;							      \
 									      \
-    if (ch >= 0xc1 && ch <= 0xcf)					      \
+    if (__builtin_expect (ch, 0x20) >= 0xc1 && ch <= 0xcf)		      \
       {									      \
 	/* Composed character.  First test whether the next character	      \
 	   is also available.  */					      \
 	uint32_t ch2;							      \
 									      \
-	if (NEED_LENGTH_TEST && inptr + 1 >= inend)			      \
+	if (NEED_LENGTH_TEST && __builtin_expect (inptr + 1 >= inend, 0))     \
 	  {								      \
 	    /* The second character is not available.  */		      \
 	    result = __GCONV_INCOMPLETE_INPUT;				      \
@@ -398,7 +399,8 @@ static const char from_ucs4[][2] =
 									      \
 	ch2 = inptr[1];							      \
 									      \
-	if (ch2 < 0x20 || ch2 >= 0x80)					      \
+	if (__builtin_expect (ch2, 0x20) < 0x20				      \
+	    || __builtin_expect (ch2, 0x20) >= 0x80)			      \
 	  {								      \
 	    /* This is illegal.  */					      \
 	    if (! ignore_errors_p ())					      \
@@ -415,21 +417,17 @@ static const char from_ucs4[][2] =
 									      \
 	ch = to_ucs4_comb[ch - 0xc1][ch2 - 0x20];			      \
 									      \
-	inptr += 2;							      \
+	increment = 2;							      \
       }									      \
     else								      \
-      {									      \
-	ch = to_ucs4[ch];						      \
-	++inptr;							      \
-      }									      \
+      ch = to_ucs4[ch];							      \
 									      \
-    if (ch == 0 && *inptr != '\0')					      \
+    if (__builtin_expect (ch, 1) == 0 && *inptr != '\0')		      \
       {									      \
 	/* This is an illegal character.  */				      \
 	if (! ignore_errors_p ())					      \
 	  {								      \
 	    /* This is an illegal character.  */			      \
-	    --inptr;							      \
 	    result = __GCONV_ILLEGAL_INPUT;				      \
 	    break;							      \
 	  }								      \
@@ -441,6 +439,7 @@ static const char from_ucs4[][2] =
 	put32 (outptr, ch);						      \
 	outptr += 4;							      \
       }									      \
+    inptr += increment;							      \
   }
 #include <iconv/loop.c>
 
@@ -456,13 +455,16 @@ static const char from_ucs4[][2] =
     uint32_t ch = get32 (inptr);					      \
     const char *cp;							      \
 									      \
-    if (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]))		      \
+    if (__builtin_expect (ch, 0)					      \
+	>= sizeof (from_ucs4) / sizeof (from_ucs4[0]))			      \
       {									      \
-	if (ch == 0x2126)						      \
+	if (__builtin_expect (ch, 0) == 0x2126)				      \
 	  cp = "\xe0";							      \
-	else if (ch == 0x2c7)						      \
+	else if (__builtin_expect (ch, 0) == 0x2c7)			      \
 	  cp = "\xcf\x20";						      \
-	else if (ch < 0x2d8 || ch > 0x2dd || ch == 0x02dc)		      \
+	else if (__builtin_expect (ch, 0x2d8) < 0x2d8			      \
+		 || __builtin_expect (ch, 0x2d8) > 0x2dd		      \
+		 || __builtin_expect (ch, 0x2d8) == 0x02dc)		      \
 	  {								      \
 	    /* Illegal characters.  */					      \
 	    if (! ignore_errors_p ())					      \
@@ -489,7 +491,7 @@ static const char from_ucs4[][2] =
       {									      \
 	cp = from_ucs4[ch];						      \
 									      \
-	if (cp[0] == '\0' && ch != 0)					      \
+	if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0)		      \
 	  {								      \
 	    /* Illegal.  */						      \
 	    if (! ignore_errors_p ())					      \
@@ -509,7 +511,7 @@ static const char from_ucs4[][2] =
     /* Now test for a possible second byte and write this if possible.  */    \
     if (cp[1] != '\0')							      \
       {									      \
-	if (NEED_LENGTH_TEST && outptr >= outend)			      \
+	if (NEED_LENGTH_TEST && __builtin_expect (outptr >= outend, 0))	      \
 	  {								      \
 	    /* The result does not fit into the buffer.  */		      \
 	    --outptr;							      \
diff --git a/iconvdata/uhc.c b/iconvdata/uhc.c
index 15faf1ea89..767c21f513 100644
--- a/iconvdata/uhc.c
+++ b/iconvdata/uhc.c
@@ -3063,7 +3063,9 @@ static const char uhc_hangul_from_ucs[11172][2] =
 */									      \
     if (ch <= 0x7f)							      \
       ++inptr;								      \
-    else if (ch <= 0x80 || ch >= 0xfe || ch == 0xc9)			      \
+    else if (__builtin_expect (ch, 0x81) <= 0x80			      \
+	     || __builtin_expect (ch, 0x81) >= 0xfe			      \
+	     || __builtin_expect (ch, 0x81) == 0xc9)			      \
       {									      \
 	/* This is illegal.  */						      \
 	if (! ignore_errors_p ())					      \
@@ -3083,7 +3085,7 @@ static const char uhc_hangul_from_ucs[11172][2] =
 	   is also available.  */					      \
 	uint32_t ch2;							      \
 									      \
-	if (NEED_LENGTH_TEST && inptr + 1 >= inend)			      \
+	if (NEED_LENGTH_TEST && __builtin_expect (inptr + 1 >= inend, 0))     \
 	  {								      \
 	    /* The second character is not available.  Store		      \
 	       the intermediate result.  */				      \
@@ -3113,8 +3115,11 @@ static const char uhc_hangul_from_ucs[11172][2] =
 									      \
 	if (ch < 0xa1 || ch2 < 0xa1)					      \
 	  {								      \
-	    if (ch > 0xc6 || ch2 <0x41 || (ch2 > 0x5a && ch2 < 0x61)	      \
-		|| (ch2 > 0x7a && ch2 < 0x81) || (ch == 0xc6 && ch2 > 0x52))  \
+	    if (__builtin_expect (ch, 0xc5) > 0xc6			      \
+		|| __builtin_expect (ch2, 0x41) < 0x41			      \
+		|| (__builtin_expect (ch2, 0x41) > 0x5a && ch2 < 0x61)	      \
+		|| (__builtin_expect (ch2, 0x41) > 0x7a && ch2 < 0x81)	      \
+		|| (__builtin_expect (ch, 0xc5) == 0xc6 && ch2 > 0x52))	      \
 	      {								      \
 		/* This is not legal.  */				      \
 		if (! ignore_errors_p ())				      \
@@ -3135,7 +3140,7 @@ static const char uhc_hangul_from_ucs[11172][2] =
 				     ? (ch - 0x81) * 178		      \
 				     : 5696 + (ch - 0xa1) * 84)];	      \
 									      \
-	    if (ch == 0)						      \
+	    if (__builtin_expect (ch, 1) == 0)				      \
 	      {								      \
 		/* This is an illegal character.  */			      \
 		if (! ignore_errors_p ())				      \
@@ -3155,7 +3160,7 @@ static const char uhc_hangul_from_ucs[11172][2] =
 	else								      \
 	  {								      \
 	    ch = ksc5601_to_ucs4 (&inptr, 2, 0x80);			      \
-	    if (ch == __UNKNOWN_10646_CHAR)				      \
+	    if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR)	      \
 	      {								      \
 		/* Illegal.  */						      \
 		if (! ignore_errors_p ())				      \
@@ -3194,7 +3199,7 @@ static const char uhc_hangul_from_ucs[11172][2] =
       {									      \
 	const char *s = uhc_hangul_from_ucs[ch - 0xac00];		      \
 									      \
-	if (NEED_LENGTH_TEST && outptr + 2 > outend)			      \
+	if (NEED_LENGTH_TEST && __builtin_expect (outptr + 2 > outend, 0))    \
 	  {								      \
 	    result = __GCONV_FULL_OUTPUT;				      \
 	    break;							      \
@@ -3209,12 +3214,12 @@ static const char uhc_hangul_from_ucs[11172][2] =
 						(NEED_LENGTH_TEST	      \
 						 ? outend - outptr : 2));     \
 									      \
-	if (NEED_LENGTH_TEST && written == 0)				      \
+	if (NEED_LENGTH_TEST && __builtin_expect (written, 1) == 0)	      \
 	  {								      \
 	    result = __GCONV_FULL_OUTPUT;				      \
 	    break;							      \
 	  }								      \
-	if (written == __UNKNOWN_10646_CHAR)				      \
+	if (__builtin_expect (written, 0) == __UNKNOWN_10646_CHAR)	      \
 	  {								      \
 	    if (! ignore_errors_p ())					      \
 	      {								      \
@@ -3241,12 +3246,12 @@ static const char uhc_hangul_from_ucs[11172][2] =
 					      (NEED_LENGTH_TEST		      \
 					       ? outend - outptr : 2));	      \
 									      \
-	if (NEED_LENGTH_TEST && written == 0)				      \
+	if (NEED_LENGTH_TEST && __builtin_expect (written, 1) == 0)	      \
 	  {								      \
 	    result = __GCONV_FULL_OUTPUT;				      \
 	    break;							      \
 	  }								      \
-	if (written == __UNKNOWN_10646_CHAR)				      \
+	if (__builtin_expect (written, 0) == __UNKNOWN_10646_CHAR)	      \
 	  {								      \
 	    if (! ignore_errors_p ())					      \
 	      {								      \
diff --git a/iconvdata/unicode.c b/iconvdata/unicode.c
index 7f2aca51b4..34c563bd79 100644
--- a/iconvdata/unicode.c
+++ b/iconvdata/unicode.c
@@ -63,7 +63,7 @@
   else if (!data->__internal_use && data->__invocation_counter == 0)	      \
     {									      \
       /* Emit the Byte Order Mark.  */					      \
-      if (outbuf + 2 > outend)						      \
+      if (__builtin_expect (outbuf + 2 > outend, 0))			      \
 	return __GCONV_FULL_OUTPUT;					      \
 									      \
       put16u (outbuf, BOM);						      \
@@ -149,7 +149,7 @@ gconv_end (struct __gconv_step *data)
   {									      \
     uint32_t c = get32 (inptr);						      \
 									      \
-    if (c >= 0x10000)							      \
+    if (__builtin_expect (c, 0) >= 0x10000)				      \
       {									      \
 	if (! ignore_errors_p ())					      \
 	  {								      \
diff --git a/iconvdata/utf-16.c b/iconvdata/utf-16.c
index 9ca2e0bc42..0be1108113 100644
--- a/iconvdata/utf-16.c
+++ b/iconvdata/utf-16.c
@@ -66,7 +66,7 @@
 	   && data->__invocation_counter == 0)				      \
     {									      \
       /* Emit the Byte Order Mark.  */					      \
-      if (outbuf + 2 > outend)						      \
+      if (__builtin_expect (outbuf + 2 > outend, 0))			      \
 	return __GCONV_FULL_OUTPUT;					      \
 									      \
       put16u (outbuf, BOM);						      \
@@ -140,7 +140,7 @@ gconv_init (struct __gconv_step *step)
     }
 
   result = __GCONV_NOCONV;
-  if (dir != illegal_dir)
+  if (__builtin_expect (dir, to_utf16) != illegal_dir)
     {
       new_data = (struct utf16_data *) malloc (sizeof (struct utf16_data));
 
@@ -197,9 +197,9 @@ gconv_end (struct __gconv_step *data)
 									      \
     if (swap)								      \
       {									      \
-	if (c >= 0x10000)						      \
+	if (__builtin_expect (c, 0) >= 0x10000)				      \
 	  {								      \
-	    if (c >= 0x110000)						      \
+	    if (__builtin_expect (c, 0) >= 0x110000)			      \
 	      {								      \
 		if (! ignore_errors_p ())				      \
 		  {							      \
@@ -214,7 +214,7 @@ gconv_end (struct __gconv_step *data)
 	      }								      \
 									      \
 	    /* Generate a surrogate character.  */			      \
-	    if (NEED_LENGTH_TEST && outptr + 4 > outend)		      \
+	    if (NEED_LENGTH_TEST && __builtin_expect (outptr + 4 > outend, 0))\
 	      {								      \
 		/* Overflow in the output buffer.  */			      \
 		result = __GCONV_FULL_OUTPUT;				      \
@@ -230,9 +230,9 @@ gconv_end (struct __gconv_step *data)
       }									      \
     else								      \
       {									      \
-	if (c >= 0x10000)						      \
+	if (__builtin_expect (c, 0) >= 0x10000)				      \
 	  {								      \
-	    if (c >= 0x110000)						      \
+	    if (__builtin_expect (c, 0) >= 0x110000)			      \
 	      {								      \
 		if (! ignore_errors_p ())				      \
 		  {							      \
@@ -247,7 +247,7 @@ gconv_end (struct __gconv_step *data)
 	      }								      \
 									      \
 	    /* Generate a surrogate character.  */			      \
-	    if (NEED_LENGTH_TEST && outptr + 4 > outend)		      \
+	    if (NEED_LENGTH_TEST && __builtin_expect (outptr + 4 > outend, 0))\
 	      {								      \
 		/* Overflow in the output buffer.  */			      \
 		result = __GCONV_FULL_OUTPUT;				      \
@@ -282,10 +282,10 @@ gconv_end (struct __gconv_step *data)
       {									      \
 	u1 = bswap_16 (u1);						      \
 									      \
-	if (u1 < 0xd800 || u1 > 0xdfff)					      \
+	if (__builtin_expect (u1, 0) < 0xd800 || u1 > 0xdfff)		      \
 	  {								      \
 	    /* No surrogate.  */					      \
-	    put32 (outptr, u1);				      \
+	    put32 (outptr, u1);						      \
 	    inptr += 2;							      \
 	  }								      \
 	else								      \
@@ -294,7 +294,7 @@ gconv_end (struct __gconv_step *data)
 									      \
 	    /* It's a surrogate character.  At least the first word says      \
 	       it is.  */						      \
-	    if (NEED_LENGTH_TEST && inptr + 4 > inend)			      \
+	    if (NEED_LENGTH_TEST && __builtin_expect (inptr + 4 > inend, 0))  \
 	      {								      \
 		/* We don't have enough input for another complete input      \
 		   character.  */					      \
@@ -304,7 +304,8 @@ gconv_end (struct __gconv_step *data)
 									      \
 	    inptr += 2;							      \
 	    u2 = bswap_16 (get16 (inptr));				      \
-	    if (u2 < 0xdc00 || u2 >= 0xdfff)				      \
+	    if (__builtin_expect (u2, 0xdc00) < 0xdc00			      \
+		|| __builtin_expect (u2, 0xdc00) >= 0xdfff)		      \
 	      {								      \
 		/* This is no valid second word for a surrogate.  */	      \
 		if (! ignore_errors_p ())				      \
@@ -324,7 +325,7 @@ gconv_end (struct __gconv_step *data)
       }									      \
     else								      \
       {									      \
-	if (u1 < 0xd800 || u1 > 0xdfff)					      \
+	if (__builtin_expect (u1, 0) < 0xd800 || u1 > 0xdfff)		      \
 	  {								      \
 	    /* No surrogate.  */					      \
 	    put32 (outptr, u1);						      \
@@ -336,7 +337,7 @@ gconv_end (struct __gconv_step *data)
 									      \
 	    /* It's a surrogate character.  At least the first word says      \
 	       it is.  */						      \
-	    if (NEED_LENGTH_TEST && inptr + 4 > inend)			      \
+	    if (NEED_LENGTH_TEST && __builtin_expect (inptr + 4 > inend, 0))  \
 	      {								      \
 		/* We don't have enough input for another complete input      \
 		   character.  */					      \
@@ -346,7 +347,8 @@ gconv_end (struct __gconv_step *data)
 									      \
 	    inptr += 2;							      \
 	    u2 = get16 (inptr);						      \
-	    if (u2 < 0xdc00 || u2 >= 0xdfff)				      \
+	    if (__builtin_expect (u2, 0xdc00) < 0xdc00			      \
+		|| __builtin_expect (u2, 0xdc00) >= 0xdfff)		      \
 	      {								      \
 		/* This is no valid second word for a surrogate.  */	      \
 		if (! ignore_errors_p ())				      \