xref: /openbmc/linux/arch/sh/include/asm/string_32.h (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1*6a0abce4SKuninori Morimoto /* SPDX-License-Identifier: GPL-2.0 */
2f15cbe6fSPaul Mundt #ifndef __ASM_SH_STRING_H
3f15cbe6fSPaul Mundt #define __ASM_SH_STRING_H
4f15cbe6fSPaul Mundt 
5f15cbe6fSPaul Mundt /*
6f15cbe6fSPaul Mundt  * Copyright (C) 1999 Niibe Yutaka
7f15cbe6fSPaul Mundt  * But consider these trivial functions to be public domain.
8f15cbe6fSPaul Mundt  */
9f15cbe6fSPaul Mundt 
10f15cbe6fSPaul Mundt #define __HAVE_ARCH_STRCPY
strcpy(char * __dest,const char * __src)11f15cbe6fSPaul Mundt static inline char *strcpy(char *__dest, const char *__src)
12f15cbe6fSPaul Mundt {
13f15cbe6fSPaul Mundt 	register char *__xdest = __dest;
14f15cbe6fSPaul Mundt 	unsigned long __dummy;
15f15cbe6fSPaul Mundt 
16f15cbe6fSPaul Mundt 	__asm__ __volatile__("1:\n\t"
17f15cbe6fSPaul Mundt 			     "mov.b	@%1+, %2\n\t"
18f15cbe6fSPaul Mundt 			     "mov.b	%2, @%0\n\t"
19f15cbe6fSPaul Mundt 			     "cmp/eq	#0, %2\n\t"
20f15cbe6fSPaul Mundt 			     "bf/s	1b\n\t"
21f15cbe6fSPaul Mundt 			     " add	#1, %0\n\t"
22f15cbe6fSPaul Mundt 			     : "=r" (__dest), "=r" (__src), "=&z" (__dummy)
23f15cbe6fSPaul Mundt 			     : "0" (__dest), "1" (__src)
24f15cbe6fSPaul Mundt 			     : "memory", "t");
25f15cbe6fSPaul Mundt 
26f15cbe6fSPaul Mundt 	return __xdest;
27f15cbe6fSPaul Mundt }
28f15cbe6fSPaul Mundt 
29f15cbe6fSPaul Mundt #define __HAVE_ARCH_STRCMP
strcmp(const char * __cs,const char * __ct)30f15cbe6fSPaul Mundt static inline int strcmp(const char *__cs, const char *__ct)
31f15cbe6fSPaul Mundt {
32f15cbe6fSPaul Mundt 	register int __res;
33f15cbe6fSPaul Mundt 	unsigned long __dummy;
34f15cbe6fSPaul Mundt 
35f15cbe6fSPaul Mundt 	__asm__ __volatile__(
36f15cbe6fSPaul Mundt 		"mov.b	@%1+, %3\n"
37f15cbe6fSPaul Mundt 		"1:\n\t"
38f15cbe6fSPaul Mundt 		"mov.b	@%0+, %2\n\t"
39f15cbe6fSPaul Mundt 		"cmp/eq #0, %3\n\t"
40f15cbe6fSPaul Mundt 		"bt	2f\n\t"
41f15cbe6fSPaul Mundt 		"cmp/eq %2, %3\n\t"
42f15cbe6fSPaul Mundt 		"bt/s	1b\n\t"
43f15cbe6fSPaul Mundt 		" mov.b	@%1+, %3\n\t"
44f15cbe6fSPaul Mundt 		"add	#-2, %1\n\t"
45f15cbe6fSPaul Mundt 		"mov.b	@%1, %3\n\t"
46f15cbe6fSPaul Mundt 		"sub	%3, %2\n"
47f15cbe6fSPaul Mundt 		"2:"
48f15cbe6fSPaul Mundt 		: "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
49f15cbe6fSPaul Mundt 		: "0" (__cs), "1" (__ct)
50f15cbe6fSPaul Mundt 		: "t");
51f15cbe6fSPaul Mundt 
52f15cbe6fSPaul Mundt 	return __res;
53f15cbe6fSPaul Mundt }
54f15cbe6fSPaul Mundt 
55f15cbe6fSPaul Mundt #define __HAVE_ARCH_STRNCMP
strncmp(const char * __cs,const char * __ct,size_t __n)56f15cbe6fSPaul Mundt static inline int strncmp(const char *__cs, const char *__ct, size_t __n)
57f15cbe6fSPaul Mundt {
58f15cbe6fSPaul Mundt 	register int __res;
59f15cbe6fSPaul Mundt 	unsigned long __dummy;
60f15cbe6fSPaul Mundt 
61f15cbe6fSPaul Mundt 	if (__n == 0)
62f15cbe6fSPaul Mundt 		return 0;
63f15cbe6fSPaul Mundt 
64f15cbe6fSPaul Mundt 	__asm__ __volatile__(
65f15cbe6fSPaul Mundt 		"mov.b	@%1+, %3\n"
66f15cbe6fSPaul Mundt 		"1:\n\t"
67f15cbe6fSPaul Mundt 		"mov.b	@%0+, %2\n\t"
68f15cbe6fSPaul Mundt 		"cmp/eq %6, %0\n\t"
69f15cbe6fSPaul Mundt 		"bt/s	2f\n\t"
70f15cbe6fSPaul Mundt 		" cmp/eq #0, %3\n\t"
71f15cbe6fSPaul Mundt 		"bt/s	3f\n\t"
72f15cbe6fSPaul Mundt 		" cmp/eq %3, %2\n\t"
73f15cbe6fSPaul Mundt 		"bt/s	1b\n\t"
74f15cbe6fSPaul Mundt 		" mov.b	@%1+, %3\n\t"
75f15cbe6fSPaul Mundt 		"add	#-2, %1\n\t"
76f15cbe6fSPaul Mundt 		"mov.b	@%1, %3\n"
77f15cbe6fSPaul Mundt 		"2:\n\t"
78f15cbe6fSPaul Mundt 		"sub	%3, %2\n"
79f15cbe6fSPaul Mundt 		"3:"
80f15cbe6fSPaul Mundt 		:"=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
81f15cbe6fSPaul Mundt 		: "0" (__cs), "1" (__ct), "r" (__cs+__n)
82f15cbe6fSPaul Mundt 		: "t");
83f15cbe6fSPaul Mundt 
84f15cbe6fSPaul Mundt 	return __res;
85f15cbe6fSPaul Mundt }
86f15cbe6fSPaul Mundt 
87f15cbe6fSPaul Mundt #define __HAVE_ARCH_MEMSET
88f15cbe6fSPaul Mundt extern void *memset(void *__s, int __c, size_t __count);
89f15cbe6fSPaul Mundt 
90f15cbe6fSPaul Mundt #define __HAVE_ARCH_MEMCPY
91f15cbe6fSPaul Mundt extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
92f15cbe6fSPaul Mundt 
93f15cbe6fSPaul Mundt #define __HAVE_ARCH_MEMMOVE
94f15cbe6fSPaul Mundt extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
95f15cbe6fSPaul Mundt 
96f15cbe6fSPaul Mundt #define __HAVE_ARCH_MEMCHR
97f15cbe6fSPaul Mundt extern void *memchr(const void *__s, int __c, size_t __n);
98f15cbe6fSPaul Mundt 
99f15cbe6fSPaul Mundt #define __HAVE_ARCH_STRLEN
100f15cbe6fSPaul Mundt extern size_t strlen(const char *);
101f15cbe6fSPaul Mundt 
102f15cbe6fSPaul Mundt #endif /* __ASM_SH_STRING_H */
103