/* Machine-independant string function optimizations.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _STRING_H
# error "Never use <bits/string2.h> directly; include <string.h> instead."
#endif
#ifndef __NO_STRING_INLINES
/* Unlike the definitions in the header <bits/string.h> the
definitions contained here are not optimized down to assembler
level. Those optimizations are not always a good idea since this
means the code size increases a lot. Instead the definitions here
optimize some functions in a way which do not dramatically
increase the code size and which do not use assembler. The main
trick is to use GNU CC's `__builtin_constant_p' function.
Every function XXX which has a defined version in
<bits/string.h> must be accompanied by a symbol _HAVE_STRING_ARCH_XXX
to make sure we don't get redefinitions.
We must use here macros instead of inline functions since the
trick won't work with the later. */
#ifdef __cplusplus
# define __STRING_INLINE inline
#else
# define __STRING_INLINE extern __inline
#endif
#if _STRING_ARCH_unaligned
/* If we can do unaligned memory accesses we must know the endianess. */
# include <endian.h>
# include <bits/types.h>
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define __STRING2_SMALL_GET16(src, idx) \
(((__const unsigned char *) (__const char *) (src))[idx + 1] << 8 \
| ((__const unsigned char *) (__const char *) (src))[idx])
# define __STRING2_SMALL_GET32(src, idx) \
(((((__const unsigned char *) (__const char *) (src))[idx + 3] << 8 \
| ((__const unsigned char *) (__const char *) (src))[idx + 2]) << 8 \
| ((__const unsigned char *) (__const char *) (src))[idx + 1]) << 8 \
| ((__const unsigned char *) (__const char *) (src))[idx])
# else
# define __STRING2_SMALL_GET16(src, idx) \
(((__const unsigned char *) (__const char *) (src))[idx] << 8 \
| ((__const unsigned char *) (__const char *) (src))[idx + 1])
# define __STRING2_SMALL_GET32(src, idx) \
(((((__const unsigned char *) (__const char *) (src))[idx] << 8 \
| ((__const unsigned char *) (__const char *) (src))[idx + 1]) << 8 \
| ((__const unsigned char *) (__const char *) (src))[idx + 2]) << 8 \
| ((__const unsigned char *) (__const char *) (src))[idx + 3])
# endif
#else
/* These are a few types we need for the optimizations if we cannot
use unaligned memory accesses. */
# define __STRING2_COPY_TYPE(N) \
typedef struct { unsigned char __arr[N]; } \
__STRING2_COPY_ARR##N __attribute__ ((packed))
__STRING2_COPY_TYPE (2);
__STRING2_COPY_TYPE (3);
__STRING2_COPY_TYPE (4);
__STRING2_COPY_TYPE (5