18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * include/asm-xtensa/string.h 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * These trivial string functions are considered part of the public domain. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 78c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 88c2ecf20Sopenharmony_ci * for more details. 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * Copyright (C) 2001 - 2005 Tensilica Inc. 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* We should optimize these. See arch/xtensa/lib/strncpy_user.S */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#ifndef _XTENSA_STRING_H 168c2ecf20Sopenharmony_ci#define _XTENSA_STRING_H 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRCPY 198c2ecf20Sopenharmony_cistatic inline char *strcpy(char *__dest, const char *__src) 208c2ecf20Sopenharmony_ci{ 218c2ecf20Sopenharmony_ci register char *__xdest = __dest; 228c2ecf20Sopenharmony_ci unsigned long __dummy; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci __asm__ __volatile__("1:\n\t" 258c2ecf20Sopenharmony_ci "l8ui %2, %1, 0\n\t" 268c2ecf20Sopenharmony_ci "s8i %2, %0, 0\n\t" 278c2ecf20Sopenharmony_ci "addi %1, %1, 1\n\t" 288c2ecf20Sopenharmony_ci "addi %0, %0, 1\n\t" 298c2ecf20Sopenharmony_ci "bnez %2, 1b\n\t" 308c2ecf20Sopenharmony_ci : "=r" (__dest), "=r" (__src), "=&r" (__dummy) 318c2ecf20Sopenharmony_ci : "0" (__dest), "1" (__src) 328c2ecf20Sopenharmony_ci : "memory"); 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci return __xdest; 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRNCPY 388c2ecf20Sopenharmony_cistatic inline char *strncpy(char *__dest, const char *__src, size_t __n) 398c2ecf20Sopenharmony_ci{ 408c2ecf20Sopenharmony_ci register char *__xdest = __dest; 418c2ecf20Sopenharmony_ci unsigned long __dummy; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci if (__n == 0) 448c2ecf20Sopenharmony_ci return __xdest; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci __asm__ __volatile__( 478c2ecf20Sopenharmony_ci "1:\n\t" 488c2ecf20Sopenharmony_ci "l8ui %2, %1, 0\n\t" 498c2ecf20Sopenharmony_ci "s8i %2, %0, 0\n\t" 508c2ecf20Sopenharmony_ci "addi %1, %1, 1\n\t" 518c2ecf20Sopenharmony_ci "addi %0, %0, 1\n\t" 528c2ecf20Sopenharmony_ci "beqz %2, 2f\n\t" 538c2ecf20Sopenharmony_ci "bne %1, %5, 1b\n" 548c2ecf20Sopenharmony_ci "2:" 558c2ecf20Sopenharmony_ci : "=r" (__dest), "=r" (__src), "=&r" (__dummy) 568c2ecf20Sopenharmony_ci : "0" (__dest), "1" (__src), "r" ((uintptr_t)__src+__n) 578c2ecf20Sopenharmony_ci : "memory"); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci return __xdest; 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRCMP 638c2ecf20Sopenharmony_cistatic inline int strcmp(const char *__cs, const char *__ct) 648c2ecf20Sopenharmony_ci{ 658c2ecf20Sopenharmony_ci register int __res; 668c2ecf20Sopenharmony_ci unsigned long __dummy; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci __asm__ __volatile__( 698c2ecf20Sopenharmony_ci "1:\n\t" 708c2ecf20Sopenharmony_ci "l8ui %3, %1, 0\n\t" 718c2ecf20Sopenharmony_ci "addi %1, %1, 1\n\t" 728c2ecf20Sopenharmony_ci "l8ui %2, %0, 0\n\t" 738c2ecf20Sopenharmony_ci "addi %0, %0, 1\n\t" 748c2ecf20Sopenharmony_ci "beqz %2, 2f\n\t" 758c2ecf20Sopenharmony_ci "beq %2, %3, 1b\n" 768c2ecf20Sopenharmony_ci "2:\n\t" 778c2ecf20Sopenharmony_ci "sub %2, %2, %3" 788c2ecf20Sopenharmony_ci : "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&r" (__dummy) 798c2ecf20Sopenharmony_ci : "0" (__cs), "1" (__ct)); 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci return __res; 828c2ecf20Sopenharmony_ci} 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci#define __HAVE_ARCH_STRNCMP 858c2ecf20Sopenharmony_cistatic inline int strncmp(const char *__cs, const char *__ct, size_t __n) 868c2ecf20Sopenharmony_ci{ 878c2ecf20Sopenharmony_ci register int __res; 888c2ecf20Sopenharmony_ci unsigned long __dummy; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci __asm__ __volatile__( 918c2ecf20Sopenharmony_ci "mov %2, %3\n" 928c2ecf20Sopenharmony_ci "1:\n\t" 938c2ecf20Sopenharmony_ci "beq %0, %6, 2f\n\t" 948c2ecf20Sopenharmony_ci "l8ui %3, %1, 0\n\t" 958c2ecf20Sopenharmony_ci "addi %1, %1, 1\n\t" 968c2ecf20Sopenharmony_ci "l8ui %2, %0, 0\n\t" 978c2ecf20Sopenharmony_ci "addi %0, %0, 1\n\t" 988c2ecf20Sopenharmony_ci "beqz %2, 2f\n\t" 998c2ecf20Sopenharmony_ci "beqz %3, 2f\n\t" 1008c2ecf20Sopenharmony_ci "beq %2, %3, 1b\n" 1018c2ecf20Sopenharmony_ci "2:\n\t" 1028c2ecf20Sopenharmony_ci "sub %2, %2, %3" 1038c2ecf20Sopenharmony_ci : "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&r" (__dummy) 1048c2ecf20Sopenharmony_ci : "0" (__cs), "1" (__ct), "r" ((uintptr_t)__cs+__n)); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci return __res; 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMSET 1108c2ecf20Sopenharmony_ciextern void *memset(void *__s, int __c, size_t __count); 1118c2ecf20Sopenharmony_ciextern void *__memset(void *__s, int __c, size_t __count); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMCPY 1148c2ecf20Sopenharmony_ciextern void *memcpy(void *__to, __const__ void *__from, size_t __n); 1158c2ecf20Sopenharmony_ciextern void *__memcpy(void *__to, __const__ void *__from, size_t __n); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define __HAVE_ARCH_MEMMOVE 1188c2ecf20Sopenharmony_ciextern void *memmove(void *__dest, __const__ void *__src, size_t __n); 1198c2ecf20Sopenharmony_ciextern void *__memmove(void *__dest, __const__ void *__src, size_t __n); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* Don't build bcopy at all ... */ 1228c2ecf20Sopenharmony_ci#define __HAVE_ARCH_BCOPY 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci/* 1278c2ecf20Sopenharmony_ci * For files that are not instrumented (e.g. mm/slub.c) we 1288c2ecf20Sopenharmony_ci * should use not instrumented version of mem* functions. 1298c2ecf20Sopenharmony_ci */ 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#define memcpy(dst, src, len) __memcpy(dst, src, len) 1328c2ecf20Sopenharmony_ci#define memmove(dst, src, len) __memmove(dst, src, len) 1338c2ecf20Sopenharmony_ci#define memset(s, c, n) __memset(s, c, n) 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#ifndef __NO_FORTIFY 1368c2ecf20Sopenharmony_ci#define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */ 1378c2ecf20Sopenharmony_ci#endif 1388c2ecf20Sopenharmony_ci#endif 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci#endif /* _XTENSA_STRING_H */ 141