[v2,5/6] wcsmbs: Use loop_unroll on wcsrchr

Message ID 20190313140317.8894-5-adhemerval.zanella@linaro.org
State New
Headers show
Series
  • [v2,1/6] wcsmbs: Add wcscpy loop unroll option
Related show

Commit Message

Adhemerval Zanella March 13, 2019, 2:03 p.m.
This allows an architecture to set explicit loop unrolling.

Checked on aarch64-linux-gnu.

	* wcsmbs/wcsrchr.c (WCSRCHR): Use loop_unroll.h to parametrize
	the loop unroll.
---
 wcsmbs/wcsrchr.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

-- 
2.17.1

Comments

Gabriel F. T. Gomes March 23, 2019, 3 p.m. | #1
On Wed, Mar 13 2019, Adhemerval Zanella wrote:
> 

> 	* wcsmbs/wcsrchr.c (WCSRCHR): Use loop_unroll.h to parametrize

> 	the loop unroll.


Looks good to me with a minor fix below.

Reviewed-by: Gabriel F. T. Gomes <gabriel@inconstante.eti.br>


> +  while (1)

> +    UNROLL_REPEAT(UNROLL_NTIMES, ITERATION);

                    ^
Missing space between macro name and parentheses?

Patch

diff --git a/wcsmbs/wcsrchr.c b/wcsmbs/wcsrchr.c
index 0d4bad0704..3175df357d 100644
--- a/wcsmbs/wcsrchr.c
+++ b/wcsmbs/wcsrchr.c
@@ -17,6 +17,7 @@ 
    <http://www.gnu.org/licenses/>.  */
 
 #include <wchar.h>
+#include <loop_unroll.h>
 
 #ifndef WCSRCHR
 # define WCSRCHR wcsrchr
@@ -26,12 +27,21 @@ 
 wchar_t *
 WCSRCHR (const wchar_t *wcs, const wchar_t wc)
 {
-  const wchar_t *retval = NULL;
+  wchar_t *retval = NULL;
 
-  do
-    if (*wcs == wc)
-      retval = wcs;
-  while (*wcs++ != L'\0');
+#define ITERATION(index)		\
+  ({					\
+    if (*wcs == wc)			\
+      retval = (wchar_t*) wcs;		\
+    *wcs++ != L'\0';	\
+  })
 
-  return (wchar_t *) retval;
+#ifndef UNROLL_NTIMES
+# define UNROLL_NTIMES 1
+#endif
+
+  while (1)
+    UNROLL_REPEAT(UNROLL_NTIMES, ITERATION);
+
+  return retval;
 }