18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __ALPHA_STRING_H__
38c2ecf20Sopenharmony_ci#define __ALPHA_STRING_H__
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#ifdef __KERNEL__
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci/*
88c2ecf20Sopenharmony_ci * GCC of any recent vintage doesn't do stupid things with bcopy.
98c2ecf20Sopenharmony_ci * EGCS 1.1 knows all about expanding memcpy inline, others don't.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * Similarly for a memset with data = 0.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMCPY
158c2ecf20Sopenharmony_ciextern void * memcpy(void *, const void *, size_t);
168c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMMOVE
178c2ecf20Sopenharmony_ciextern void * memmove(void *, const void *, size_t);
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* For backward compatibility with modules.  Unused otherwise.  */
208c2ecf20Sopenharmony_ciextern void * __memcpy(void *, const void *, size_t);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define memcpy __builtin_memcpy
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMSET
258c2ecf20Sopenharmony_ciextern void * __constant_c_memset(void *, unsigned long, size_t);
268c2ecf20Sopenharmony_ciextern void * ___memset(void *, int, size_t);
278c2ecf20Sopenharmony_ciextern void * __memset(void *, int, size_t);
288c2ecf20Sopenharmony_ciextern void * memset(void *, int, size_t);
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* For gcc 3.x, we cannot have the inline function named "memset" because
318c2ecf20Sopenharmony_ci   the __builtin_memset will attempt to resolve to the inline as well,
328c2ecf20Sopenharmony_ci   leading to a "sorry" about unimplemented recursive inlining.  */
338c2ecf20Sopenharmony_ciextern inline void *__memset(void *s, int c, size_t n)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	if (__builtin_constant_p(c)) {
368c2ecf20Sopenharmony_ci		if (__builtin_constant_p(n)) {
378c2ecf20Sopenharmony_ci			return __builtin_memset(s, c, n);
388c2ecf20Sopenharmony_ci		} else {
398c2ecf20Sopenharmony_ci			unsigned long c8 = (c & 0xff) * 0x0101010101010101UL;
408c2ecf20Sopenharmony_ci			return __constant_c_memset(s, c8, n);
418c2ecf20Sopenharmony_ci		}
428c2ecf20Sopenharmony_ci	}
438c2ecf20Sopenharmony_ci	return ___memset(s, c, n);
448c2ecf20Sopenharmony_ci}
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define memset __memset
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRCPY
498c2ecf20Sopenharmony_ciextern char * strcpy(char *,const char *);
508c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRNCPY
518c2ecf20Sopenharmony_ciextern char * strncpy(char *, const char *, size_t);
528c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRCAT
538c2ecf20Sopenharmony_ciextern char * strcat(char *, const char *);
548c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRNCAT
558c2ecf20Sopenharmony_ciextern char * strncat(char *, const char *, size_t);
568c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRCHR
578c2ecf20Sopenharmony_ciextern char * strchr(const char *,int);
588c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRRCHR
598c2ecf20Sopenharmony_ciextern char * strrchr(const char *,int);
608c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRLEN
618c2ecf20Sopenharmony_ciextern size_t strlen(const char *);
628c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMCHR
638c2ecf20Sopenharmony_ciextern void * memchr(const void *, int, size_t);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci/* The following routine is like memset except that it writes 16-bit
668c2ecf20Sopenharmony_ci   aligned values.  The DEST and COUNT parameters must be even for
678c2ecf20Sopenharmony_ci   correct operation.  */
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMSET16
708c2ecf20Sopenharmony_ciextern void * __memset16(void *dest, unsigned short, size_t count);
718c2ecf20Sopenharmony_cistatic inline void *memset16(uint16_t *p, uint16_t v, size_t n)
728c2ecf20Sopenharmony_ci{
738c2ecf20Sopenharmony_ci	if (__builtin_constant_p(v))
748c2ecf20Sopenharmony_ci		return __constant_c_memset(p, 0x0001000100010001UL * v, n * 2);
758c2ecf20Sopenharmony_ci	return __memset16(p, v, n * 2);
768c2ecf20Sopenharmony_ci}
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#endif /* __ALPHA_STRING_H__ */
81