diff mbox series

[v2,3/6] wcsmbs: Use loop_unroll on wcschr

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

Commit Message

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

Checked on aarch64-linux-gnu.

	* wcsmbs/wcschr.c (WCSCHR): Use loop_unroll.h to parametrize
	the loop unroll.
---
 wcsmbs/wcschr.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

-- 
2.17.1

Comments

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

> 	* wcsmbs/wcschr.c (WCSCHR): 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?
diff mbox series

Patch

diff --git a/wcsmbs/wcschr.c b/wcsmbs/wcschr.c
index cd66b2a58c..9de302298d 100644
--- a/wcsmbs/wcschr.c
+++ b/wcsmbs/wcschr.c
@@ -16,6 +16,7 @@ 
    <http://www.gnu.org/licenses/>.  */
 
 #include <wchar.h>
+#include <loop_unroll.h>
 
 #ifndef WCSCHR
 # define WCSCHR __wcschr
@@ -25,12 +26,23 @@ 
 wchar_t *
 WCSCHR (const wchar_t *wcs, const wchar_t wc)
 {
-  do
-    if (*wcs == wc)
-      return (wchar_t *) wcs;
-  while (*wcs++ != L'\0');
+  wchar_t *dest = NULL;
 
-  return NULL;
+#define ITERATION(index)		\
+  ({					\
+    if (*wcs == wc)			\
+      dest = (wchar_t*) wcs;		\
+    dest == NULL && *wcs++ != L'\0';	\
+  })
+
+#ifndef UNROLL_NTIMES
+# define UNROLL_NTIMES 1
+#endif
+
+  while (1)
+    UNROLL_REPEAT(UNROLL_NTIMES, ITERATION);
+
+  return dest;
 }
 libc_hidden_def (__wcschr)
 weak_alias (__wcschr, wcschr)