Skip to content

Commit

Permalink
SSE4.2 strstr/strcasestr for x86-64.
Browse files Browse the repository at this point in the history
This patch implements SSE4.2 strstr/strcasestr, using Knuth-Morris-Pratt
string searching algorithm.
  • Loading branch information
H.J. Lu authored and Ulrich Drepper committed Jul 21, 2009
1 parent 63fbc91 commit 2b7a866
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 5 deletions.
17 changes: 17 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
2009-07-20 H.J. Lu <hongjiu.lu@intel.com>

* string/strcasestr.c (STRCASESTR): New macro.
(__strcasestr): Renamed to ..
(STRCASESTR): ...this.
* string/strstr.c (STRSTR): New macro.
(strstr): Renamed to ..
(STRSTR): ...this.
* sysdeps/x86_64/multiarch/Makefile (sysdep_routines): Add
strstr-c strcasestr-c
(CFLAGS-strstr.c): New.
(CFLAGS-strcasestr.c): Likewise.
* sysdeps/x86_64/multiarch/strcasestr-c.c: New file.
* sysdeps/x86_64/multiarch/strcasestr.c: New file.
* sysdeps/x86_64/multiarch/strstr-c.c: New file.
* sysdeps/x86_64/multiarch/strstr.c: New file.

2009-07-20 Ulrich Drepper <drepper@redhat.com>

* locale/localeinfo.h (LIMAGIC): Update value for LC_CTYPE.
Expand Down
10 changes: 8 additions & 2 deletions string/strcasestr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Return the offset of one string within another.
Copyright (C) 1994, 1996-2000, 2004, 2008 Free Software Foundation, Inc.
Copyright (C) 1994, 1996-2000, 2004, 2008, 2009
Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -52,11 +53,16 @@
#undef strcasestr
#undef __strcasestr

#ifndef STRCASESTR
#define STRCASESTR __strcasestr
#endif


/* Find the first occurrence of NEEDLE in HAYSTACK, using
case-insensitive comparison. This function gives unspecified
results in multibyte locales. */
char *
__strcasestr (const char *haystack_start, const char *needle_start)
STRCASESTR (const char *haystack_start, const char *needle_start)
{
const char *haystack = haystack_start;
const char *needle = needle_start;
Expand Down
9 changes: 7 additions & 2 deletions string/strstr.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Return the offset of one string within another.
Copyright (C) 1994,1996,1997,2000,2001,2003,2008 Free Software Foundation, Inc.
Copyright (C) 1994,1996,1997,2000,2001,2003,2008,2009
Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -40,11 +41,15 @@

#undef strstr

#ifndef STRSTR
#define STRSTR strstr
#endif

/* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK
if NEEDLE is empty, otherwise NULL if NEEDLE is not found in
HAYSTACK. */
char *
strstr (const char *haystack_start, const char *needle_start)
STRSTR (const char *haystack_start, const char *needle_start)
{
const char *haystack = haystack_start;
const char *needle = needle_start;
Expand Down
4 changes: 3 additions & 1 deletion sysdeps/x86_64/multiarch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ endif
ifeq ($(subdir),string)
sysdep_routines += stpncpy-c strncpy-c strncmp-c
ifeq (yes,$(config-cflags-sse4))
sysdep_routines += strcspn-c strpbrk-c strspn-c
sysdep_routines += strcspn-c strpbrk-c strspn-c strstr-c strcasestr-c
CFLAGS-strcspn-c.c += -msse4
CFLAGS-strpbrk-c.c += -msse4
CFLAGS-strspn-c.c += -msse4
CFLAGS-strstr.c += -msse4
CFLAGS-strcasestr.c += -msse4
endif
endif
18 changes: 18 additions & 0 deletions sysdeps/x86_64/multiarch/strcasestr-c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "init-arch.h"

#define STRCASESTR __strcasestr_sse2
#undef libc_hidden_builtin_def
#define libc_hidden_builtin_def(name) \
__hidden_ver1 (__strcasestr_sse2, __GI_strcasestr, __strcasestr_sse2);

#include "string/strcasestr.c"

extern char *__strcasestr_sse42 (const char *, const char *);

#if 1
libc_ifunc (__strcasestr,
HAS_SSE4_2 ? __strcasestr_sse42 : __strcasestr_sse2);
#else
libc_ifunc (__strcasestr,
0 ? __strcasestr_sse42 : __strcasestr_sse2);
#endif
3 changes: 3 additions & 0 deletions sysdeps/x86_64/multiarch/strcasestr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define USE_AS_STRCASESTR
#define STRSTR_SSE42 __strcasestr_sse42
#include "strstr.c"
12 changes: 12 additions & 0 deletions sysdeps/x86_64/multiarch/strstr-c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "init-arch.h"

#define STRSTR __strstr_sse2
#undef libc_hidden_builtin_def
#define libc_hidden_builtin_def(name) \
__hidden_ver1 (__strstr_sse2, __GI_strstr, __strstr_sse2);

#include "string/strstr.c"

extern char *__strstr_sse42 (const char *, const char *);

libc_ifunc (strstr, HAS_SSE4_2 ? __strstr_sse42 : __strstr_sse2);
Loading

0 comments on commit 2b7a866

Please sign in to comment.