OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [string/] [strchr.c] - Diff between revs 39 and 56

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 39 Rev 56
Line 56... Line 56...
/* DETECTCHAR returns nonzero if (long)X contains the byte used
/* DETECTCHAR returns nonzero if (long)X contains the byte used
   to fill (long)MASK. */
   to fill (long)MASK. */
#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK))
#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK))
 
 
char *
char *
_DEFUN (strchr, (s, i),
_DEFUN (strchr, (s1, i),
        _CONST char *s _AND
        _CONST char *s1 _AND
        int i)
        int i)
{
{
#ifdef PREFER_SIZE_OVER_SPEED
  _CONST unsigned char *s = (_CONST unsigned char *)s1;
 
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
  unsigned char c = (unsigned int)i;
  unsigned char c = (unsigned int)i;
 
 
  while (*s && *s != c)
  while (*s && *s != c)
    {
    {
      s++;
      s++;
Line 75... Line 76...
      s = NULL;
      s = NULL;
    }
    }
 
 
  return (char *) s;
  return (char *) s;
#else
#else
  unsigned char c = (unsigned int)i;
  unsigned char c = (unsigned char)i;
  unsigned long mask,j;
  unsigned long mask,j;
  unsigned long *aligned_addr;
  unsigned long *aligned_addr;
 
 
  if (UNALIGNED (s))
  if (!UNALIGNED (s))
    {
    {
      while (*s && *s != c)
      mask = 0;
        s++;
 
      if (*s != c)
 
        s = NULL;
 
      return (char *) s;
 
    }
 
 
 
  for (j = 0; j < LBLOCKSIZE; j++)
  for (j = 0; j < LBLOCKSIZE; j++)
    ((unsigned char*)(&mask))[j] = c;
        mask = (mask << 8) | c;
 
 
  aligned_addr = (unsigned long*)s;
  aligned_addr = (unsigned long*)s;
  while (!DETECTNULL (*aligned_addr) && !DETECTCHAR (*aligned_addr, mask))
  while (!DETECTNULL (*aligned_addr) && !DETECTCHAR (*aligned_addr, mask))
    aligned_addr++;
    aligned_addr++;
 
 
  /* The block of bytes currently pointed to by aligned_addr
  /* The block of bytes currently pointed to by aligned_addr
     contains either a null or the target char, or both.  We
     contains either a null or the target char, or both.  We
     catch it using the bytewise search.  */
     catch it using the bytewise search.  */
 
 
  s = (unsigned char*)aligned_addr;
  s = (unsigned char*)aligned_addr;
 
    }
 
 
  while (*s && *s != c)
  while (*s && *s != c)
    s++;
    s++;
  if (*s != c)
  if (*s == c)
    s = NULL;
 
  return (char *)s;
  return (char *)s;
 
  return NULL;
#endif /* not PREFER_SIZE_OVER_SPEED */
#endif /* not PREFER_SIZE_OVER_SPEED */
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.