8ae002
From 6806b6f3b4870204737e5d465bab2fdbc1c15de0 Mon Sep 17 00:00:00 2001
8ae002
From: Stefan Liebler <stli@linux.vnet.ibm.com>
8ae002
Date: Mon, 7 Nov 2016 16:03:46 +0100
8ae002
Subject: [PATCH 06/17] Use glibc_likely instead __builtin_expect.
8ae002
8ae002
Upstream commit a1ffb40e32741f992c743e7b16c061fefa3747ac
8ae002
8ae002
This part is a prerequirement for the s390 iconv patches.
8ae002
---
8ae002
 sysdeps/s390/s390-64/utf16-utf32-z9.c | 10 +++++-----
8ae002
 sysdeps/s390/s390-64/utf8-utf16-z9.c  | 26 +++++++++++++-------------
8ae002
 sysdeps/s390/s390-64/utf8-utf32-z9.c  | 32 ++++++++++++++++----------------
8ae002
 3 files changed, 34 insertions(+), 34 deletions(-)
8ae002
8ae002
diff --git a/sysdeps/s390/s390-64/utf16-utf32-z9.c b/sysdeps/s390/s390-64/utf16-utf32-z9.c
8ae002
index 9eaa1a5..94a1a33 100644
8ae002
--- a/sysdeps/s390/s390-64/utf16-utf32-z9.c
8ae002
+++ b/sysdeps/s390/s390-64/utf16-utf32-z9.c
8ae002
@@ -54,7 +54,7 @@
8ae002
       if (dir == to_utf16)						\
8ae002
 	{								\
8ae002
           /* Emit the UTF-16 Byte Order Mark.  */			\
8ae002
-          if (__builtin_expect (outbuf + 2 > outend, 0))		\
8ae002
+          if (__glibc_unlikely (outbuf + 2 > outend))			      \
8ae002
 	    return __GCONV_FULL_OUTPUT;					\
8ae002
 									\
8ae002
 	  put16u (outbuf, BOM_UTF16);					\
8ae002
@@ -63,7 +63,7 @@
8ae002
       else								\
8ae002
 	{								\
8ae002
           /* Emit the UTF-32 Byte Order Mark.  */			\
8ae002
-	  if (__builtin_expect (outbuf + 4 > outend, 0))		\
8ae002
+	  if (__glibc_unlikely (outbuf + 4 > outend))			      \
8ae002
 	    return __GCONV_FULL_OUTPUT;					\
8ae002
 									\
8ae002
 	  put32u (outbuf, BOM_UTF32);					\
8ae002
@@ -236,13 +236,13 @@ gconv_end (struct __gconv_step *data)
8ae002
       {									\
8ae002
         /* An isolated low-surrogate was found.  This has to be         \
8ae002
 	   considered ill-formed.  */					\
8ae002
-        if (__builtin_expect (u1 >= 0xdc00, 0))				\
8ae002
+        if (__glibc_unlikely (u1 >= 0xdc00))				      \
8ae002
 	  {								\
8ae002
 	    STANDARD_FROM_LOOP_ERR_HANDLER (2);				\
8ae002
 	  }								\
8ae002
 	/* It's a surrogate character.  At least the first word says	\
8ae002
 	   it is.  */							\
8ae002
-	if (__builtin_expect (inptr + 4 > inend, 0))			\
8ae002
+	if (__glibc_unlikely (inptr + 4 > inend))			      \
8ae002
 	  {								\
8ae002
 	    /* We don't have enough input for another complete input	\
8ae002
 	       character.  */						\
8ae002
@@ -306,7 +306,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 	uint16_t out;							\
8ae002
 									\
8ae002
 	/* Generate a surrogate character.  */				\
8ae002
-	if (__builtin_expect (outptr + 4 > outend, 0))			\
8ae002
+	if (__glibc_unlikely (outptr + 4 > outend))			      \
8ae002
 	  {								\
8ae002
 	    /* Overflow in the output buffer.  */			\
8ae002
 	    result = __GCONV_FULL_OUTPUT;				\
8ae002
diff --git a/sysdeps/s390/s390-64/utf8-utf16-z9.c b/sysdeps/s390/s390-64/utf8-utf16-z9.c
8ae002
index 9f59177..8e0515c 100644
8ae002
--- a/sysdeps/s390/s390-64/utf8-utf16-z9.c
8ae002
+++ b/sysdeps/s390/s390-64/utf8-utf16-z9.c
8ae002
@@ -50,7 +50,7 @@
8ae002
       && data->__invocation_counter == 0)				\
8ae002
     {									\
8ae002
       /* Emit the UTF-16 Byte Order Mark.  */				\
8ae002
-      if (__builtin_expect (outbuf + 2 > outend, 0))			\
8ae002
+      if (__glibc_unlikely (outbuf + 2 > outend))			      \
8ae002
 	return __GCONV_FULL_OUTPUT;					\
8ae002
 									\
8ae002
       put16u (outbuf, BOM_UTF16);					\
8ae002
@@ -197,7 +197,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 	      if ((inptr[i] & 0xc0) != 0x80)				\
8ae002
 		break;							\
8ae002
 								\
8ae002
-	    if (__builtin_expect (inptr + i == inend, 1))		\
8ae002
+	    if (__glibc_likely (inptr + i == inend))			      \
8ae002
 	      {								\
8ae002
 		result = __GCONV_INCOMPLETE_INPUT;			\
8ae002
 		break;							\
8ae002
@@ -210,7 +210,7 @@ gconv_end (struct __gconv_step *data)
8ae002
     /* Next input byte.  */						\
8ae002
     uint16_t ch = *inptr;						\
8ae002
 									\
8ae002
-    if (__builtin_expect (ch < 0x80, 1))				\
8ae002
+    if (__glibc_likely (ch < 0x80))					      \
8ae002
       {									\
8ae002
 	/* One byte sequence.  */					\
8ae002
 	++inptr;							\
8ae002
@@ -228,13 +228,13 @@ gconv_end (struct __gconv_step *data)
8ae002
 	    cnt = 2;							\
8ae002
 	    ch &= 0x1f;							\
8ae002
 	  }								\
8ae002
-        else if (__builtin_expect ((ch & 0xf0) == 0xe0, 1))		\
8ae002
+        else if (__glibc_likely ((ch & 0xf0) == 0xe0))			      \
8ae002
 	  {								\
8ae002
 	    /* We expect three bytes.  */				\
8ae002
 	    cnt = 3;							\
8ae002
 	    ch &= 0x0f;							\
8ae002
 	  }								\
8ae002
-	else if (__builtin_expect ((ch & 0xf8) == 0xf0, 1))		\
8ae002
+	else if (__glibc_likely ((ch & 0xf8) == 0xf0))			      \
8ae002
 	  {								\
8ae002
 	    /* We expect four bytes.  */				\
8ae002
 	    cnt = 4;							\
8ae002
@@ -255,7 +255,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 	    STANDARD_FROM_LOOP_ERR_HANDLER (i);				\
8ae002
 	  }								\
8ae002
 									\
8ae002
-	if (__builtin_expect (inptr + cnt > inend, 0))			\
8ae002
+	if (__glibc_unlikely (inptr + cnt > inend))			      \
8ae002
 	  {								\
8ae002
 	    /* We don't have enough input.  But before we report	\
8ae002
 	       that check that all the bytes are correct.  */		\
8ae002
@@ -263,7 +263,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 	      if ((inptr[i] & 0xc0) != 0x80)				\
8ae002
 		break;							\
8ae002
 									\
8ae002
-	    if (__builtin_expect (inptr + i == inend, 1))		\
8ae002
+	    if (__glibc_likely (inptr + i == inend))			      \
8ae002
 	      {								\
8ae002
 		result = __GCONV_INCOMPLETE_INPUT;			\
8ae002
 		break;							\
8ae002
@@ -278,7 +278,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 	       low) are needed.  */					\
8ae002
 	    uint16_t zabcd, high, low;					\
8ae002
 									\
8ae002
-	    if (__builtin_expect (outptr + 4 > outend, 0))		\
8ae002
+	    if (__glibc_unlikely (outptr + 4 > outend))			      \
8ae002
 	      {								\
8ae002
 		/* Overflow in the output buffer.  */			\
8ae002
 		result = __GCONV_FULL_OUTPUT;				\
8ae002
@@ -368,7 +368,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 									\
8ae002
     uint16_t c = get16 (inptr);						\
8ae002
 									\
8ae002
-    if (__builtin_expect (c <= 0x007f, 1))				\
8ae002
+    if (__glibc_likely (c <= 0x007f))					      \
8ae002
       {									\
8ae002
 	/* Single byte UTF-8 char.  */					\
8ae002
 	*outptr = c & 0xff;						\
8ae002
@@ -378,7 +378,7 @@ gconv_end (struct __gconv_step *data)
8ae002
       {									\
8ae002
         /* Two byte UTF-8 char.  */					\
8ae002
 									\
8ae002
-	if (__builtin_expect (outptr + 2 > outend, 0))			\
8ae002
+	if (__glibc_unlikely (outptr + 2 > outend))			      \
8ae002
 	  {								\
8ae002
 	    /* Overflow in the output buffer.  */			\
8ae002
 	    result = __GCONV_FULL_OUTPUT;				\
8ae002
@@ -397,7 +397,7 @@ gconv_end (struct __gconv_step *data)
8ae002
       {									\
8ae002
 	/* Three byte UTF-8 char.  */					\
8ae002
 									\
8ae002
-	if (__builtin_expect (outptr + 3 > outend, 0))			\
8ae002
+	if (__glibc_unlikely (outptr + 3 > outend))			      \
8ae002
 	  {								\
8ae002
 	    /* Overflow in the output buffer.  */			\
8ae002
 	    result = __GCONV_FULL_OUTPUT;				\
8ae002
@@ -419,14 +419,14 @@ gconv_end (struct __gconv_step *data)
8ae002
         /* Four byte UTF-8 char.  */					\
8ae002
 	uint16_t low, uvwxy;						\
8ae002
 									\
8ae002
-	if (__builtin_expect (outptr + 4 > outend, 0))			\
8ae002
+	if (__glibc_unlikely (outptr + 4 > outend))			      \
8ae002
 	  {								\
8ae002
 	    /* Overflow in the output buffer.  */			\
8ae002
 	    result = __GCONV_FULL_OUTPUT;				\
8ae002
 	    break;							\
8ae002
 	  }								\
8ae002
 	inptr += 2;							\
8ae002
-	if (__builtin_expect (inptr + 2 > inend, 0))			\
8ae002
+	if (__glibc_unlikely (inptr + 2 > inend))			      \
8ae002
 	  {								\
8ae002
 	    result = __GCONV_INCOMPLETE_INPUT;				\
8ae002
 	    break;							\
8ae002
diff --git a/sysdeps/s390/s390-64/utf8-utf32-z9.c b/sysdeps/s390/s390-64/utf8-utf32-z9.c
8ae002
index a807980..c657a38 100644
8ae002
--- a/sysdeps/s390/s390-64/utf8-utf32-z9.c
8ae002
+++ b/sysdeps/s390/s390-64/utf8-utf32-z9.c
8ae002
@@ -52,7 +52,7 @@
8ae002
       && data->__invocation_counter == 0)				\
8ae002
     {									\
8ae002
       /* Emit the Byte Order Mark.  */					\
8ae002
-      if (__builtin_expect (outbuf + 4 > outend, 0))			\
8ae002
+      if (__glibc_unlikely (outbuf + 4 > outend))			      \
8ae002
 	return __GCONV_FULL_OUTPUT;					\
8ae002
 									\
8ae002
       put32u (outbuf, BOM);						\
8ae002
@@ -201,7 +201,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 	      if ((inptr[i] & 0xc0) != 0x80)				\
8ae002
 		break;							\
8ae002
 									\
8ae002
-	    if (__builtin_expect (inptr + i == inend, 1))		\
8ae002
+	    if (__glibc_likely (inptr + i == inend))			      \
8ae002
 	      {								\
8ae002
 		result = __GCONV_INCOMPLETE_INPUT;			\
8ae002
 		break;							\
8ae002
@@ -214,7 +214,7 @@ gconv_end (struct __gconv_step *data)
8ae002
     /* Next input byte.  */						\
8ae002
     uint32_t ch = *inptr;						\
8ae002
 									\
8ae002
-    if (__builtin_expect (ch < 0x80, 1))				\
8ae002
+    if (__glibc_likely (ch < 0x80))					      \
8ae002
       {									\
8ae002
 	/* One byte sequence.  */					\
8ae002
 	++inptr;							\
8ae002
@@ -232,25 +232,25 @@ gconv_end (struct __gconv_step *data)
8ae002
 	    cnt = 2;							\
8ae002
 	    ch &= 0x1f;							\
8ae002
 	  }								\
8ae002
-        else if (__builtin_expect ((ch & 0xf0) == 0xe0, 1))		\
8ae002
+        else if (__glibc_likely ((ch & 0xf0) == 0xe0))			      \
8ae002
 	  {								\
8ae002
 	    /* We expect three bytes.  */				\
8ae002
 	    cnt = 3;							\
8ae002
 	    ch &= 0x0f;							\
8ae002
 	  }								\
8ae002
-	else if (__builtin_expect ((ch & 0xf8) == 0xf0, 1))		\
8ae002
+	else if (__glibc_likely ((ch & 0xf8) == 0xf0))			      \
8ae002
 	  {								\
8ae002
 	    /* We expect four bytes.  */				\
8ae002
 	    cnt = 4;							\
8ae002
 	    ch &= 0x07;							\
8ae002
 	  }								\
8ae002
-	else if (__builtin_expect ((ch & 0xfc) == 0xf8, 1))		\
8ae002
+	else if (__glibc_likely ((ch & 0xfc) == 0xf8))			      \
8ae002
 	  {								\
8ae002
 	    /* We expect five bytes.  */				\
8ae002
 	    cnt = 5;							\
8ae002
 	    ch &= 0x03;							\
8ae002
 	  }								\
8ae002
-	else if (__builtin_expect ((ch & 0xfe) == 0xfc, 1))		\
8ae002
+	else if (__glibc_likely ((ch & 0xfe) == 0xfc))			      \
8ae002
 	  {								\
8ae002
 	    /* We expect six bytes.  */					\
8ae002
 	    cnt = 6;							\
8ae002
@@ -271,7 +271,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 	    STANDARD_FROM_LOOP_ERR_HANDLER (i);				\
8ae002
 	  }								\
8ae002
 									\
8ae002
-	if (__builtin_expect (inptr + cnt > inend, 0))			\
8ae002
+	if (__glibc_unlikely (inptr + cnt > inend))			      \
8ae002
 	  {								\
8ae002
 	    /* We don't have enough input.  But before we report	\
8ae002
 	       that check that all the bytes are correct.  */		\
8ae002
@@ -279,7 +279,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 	      if ((inptr[i] & 0xc0) != 0x80)				\
8ae002
 		break;							\
8ae002
 									\
8ae002
-	    if (__builtin_expect (inptr + i == inend, 1))		\
8ae002
+	    if (__glibc_likely (inptr + i == inend))			      \
8ae002
 	      {								\
8ae002
 		result = __GCONV_INCOMPLETE_INPUT;			\
8ae002
 		break;							\
8ae002
@@ -338,19 +338,19 @@ gconv_end (struct __gconv_step *data)
8ae002
 	cnt = 2;							      \
8ae002
 	ch &= 0x1f;							      \
8ae002
       }									      \
8ae002
-    else if (__builtin_expect ((ch & 0xf0) == 0xe0, 1))			      \
8ae002
+    else if (__glibc_likely ((ch & 0xf0) == 0xe0))			      \
8ae002
       {									      \
8ae002
 	/* We expect three bytes.  */					      \
8ae002
 	cnt = 3;							      \
8ae002
 	ch &= 0x0f;							      \
8ae002
       }									      \
8ae002
-    else if (__builtin_expect ((ch & 0xf8) == 0xf0, 1))			      \
8ae002
+    else if (__glibc_likely ((ch & 0xf8) == 0xf0))			      \
8ae002
       {									      \
8ae002
 	/* We expect four bytes.  */					      \
8ae002
 	cnt = 4;							      \
8ae002
 	ch &= 0x07;							      \
8ae002
       }									      \
8ae002
-    else if (__builtin_expect ((ch & 0xfc) == 0xf8, 1))			      \
8ae002
+    else if (__glibc_likely ((ch & 0xfc) == 0xf8))			      \
8ae002
       {									      \
8ae002
 	/* We expect five bytes.  */					      \
8ae002
 	cnt = 5;							      \
8ae002
@@ -431,7 +431,7 @@ gconv_end (struct __gconv_step *data)
8ae002
 								\
8ae002
     uint32_t wc = *((const uint32_t *) inptr);			\
8ae002
 								\
8ae002
-    if (__builtin_expect (wc <= 0x7f, 1))			\
8ae002
+    if (__glibc_likely (wc <= 0x7f))					      \
8ae002
       {								\
8ae002
         /* Single UTF-8 char.  */				\
8ae002
         *outptr = (uint8_t)wc;					\
8ae002
@@ -440,7 +440,7 @@ gconv_end (struct __gconv_step *data)
8ae002
     else if (wc <= 0x7ff)					\
8ae002
       {								\
8ae002
         /* Two UTF-8 chars.  */					\
8ae002
-        if (__builtin_expect (outptr + 2 > outend, 0))		\
8ae002
+        if (__glibc_unlikely (outptr + 2 > outend))			      \
8ae002
 	  {							\
8ae002
 	    /* Overflow in the output buffer.  */		\
8ae002
 	    result = __GCONV_FULL_OUTPUT;			\
8ae002
@@ -458,7 +458,7 @@ gconv_end (struct __gconv_step *data)
8ae002
     else if (wc <= 0xffff)					\
8ae002
       {								\
8ae002
 	/* Three UTF-8 chars.  */				\
8ae002
-	if (__builtin_expect (outptr + 3 > outend, 0))		\
8ae002
+	if (__glibc_unlikely (outptr + 3 > outend))			      \
8ae002
 	  {							\
8ae002
 	    /* Overflow in the output buffer.  */		\
8ae002
 	    result = __GCONV_FULL_OUTPUT;			\
8ae002
@@ -478,7 +478,7 @@ gconv_end (struct __gconv_step *data)
8ae002
       else if (wc <= 0x10ffff)					\
8ae002
 	{							\
8ae002
 	  /* Four UTF-8 chars.  */				\
8ae002
-	  if (__builtin_expect (outptr + 4 > outend, 0))	\
8ae002
+	  if (__glibc_unlikely (outptr + 4 > outend))			      \
8ae002
 	    {							\
8ae002
 	      /* Overflow in the output buffer.  */		\
8ae002
 	      result = __GCONV_FULL_OUTPUT;			\
8ae002
-- 
8ae002
1.8.3.1
8ae002