xref: /openbmc/u-boot/arch/riscv/include/asm/string.h (revision 0ca0a546b186478b9de80cbd27fa8baf17e30863)
16020faf6SRick Chen /*
26020faf6SRick Chen  * Copyright (C) 2011 Andes Technology Corporation
36020faf6SRick Chen  * Copyright (C) 2010 Shawn Lin (nobuhiro@andestech.com)
46020faf6SRick Chen  * Copyright (C) 2011 Macpaul Lin (macpaul@andestech.com)
56020faf6SRick Chen  * Copyright (C) 2017 Rick Chen (rick@andestech.com)
66020faf6SRick Chen  *
76020faf6SRick Chen  * This file is subject to the terms and conditions of the GNU General Public
86020faf6SRick Chen  * License.  See the file "COPYING" in the main directory of this archive
96020faf6SRick Chen  * for more details.
106020faf6SRick Chen  */
116020faf6SRick Chen 
126020faf6SRick Chen #ifndef __ASM_RISCV_STRING_H
136020faf6SRick Chen #define __ASM_RISCV_STRING_H
146020faf6SRick Chen 
156020faf6SRick Chen /*
166020faf6SRick Chen  * We don't do inline string functions, since the
176020faf6SRick Chen  * optimised inline asm versions are not small.
186020faf6SRick Chen  */
196020faf6SRick Chen 
206020faf6SRick Chen #undef __HAVE_ARCH_STRRCHR
216020faf6SRick Chen #undef __HAVE_ARCH_STRCHR
226020faf6SRick Chen #undef __HAVE_ARCH_MEMCPY
236020faf6SRick Chen #undef __HAVE_ARCH_MEMMOVE
246020faf6SRick Chen #undef __HAVE_ARCH_MEMCHR
256020faf6SRick Chen #undef __HAVE_ARCH_MEMZERO
266020faf6SRick Chen #undef __HAVE_ARCH_MEMSET
276020faf6SRick Chen 
286020faf6SRick Chen #ifdef CONFIG_MARCO_MEMSET
29*bc0818a6SRick Chen #define memset(_p, _v, _n)	\
30*bc0818a6SRick Chen 	(typeof(_p) (p) = (_p); \
31*bc0818a6SRick Chen 	 typeof(_v) (v) = (_v); \
32*bc0818a6SRick Chen 	 typeof(_n) (n) = (_n); \
33*bc0818a6SRick Chen 	 {								\
346020faf6SRick Chen 		if ((n) != 0) {						\
356020faf6SRick Chen 			if (__builtin_constant_p((v)) && (v) == 0)	\
366020faf6SRick Chen 				__memzero((p), (n));			\
376020faf6SRick Chen 			else						\
386020faf6SRick Chen 				memset((p), (v), (n));			\
396020faf6SRick Chen 		}							\
406020faf6SRick Chen 		(p);							\
416020faf6SRick Chen 	})
426020faf6SRick Chen 
43*bc0818a6SRick Chen #define memzero(_p, _n) \
44*bc0818a6SRick Chen 	(typeof(_p) (p) = (_p); \
45*bc0818a6SRick Chen 	 typeof(_n) (n) = (_n); \
46*bc0818a6SRick Chen 	 { if ((n) != 0) __memzero((p), (n)); (p); })
476020faf6SRick Chen #endif
486020faf6SRick Chen 
496020faf6SRick Chen #endif /* __ASM_RISCV_STRING_H */
50