string.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * include/asm-xtensa/string.h
  3. *
  4. * These trivial string functions are considered part of the public domain.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (C) 2001 - 2005 Tensilica Inc.
  11. */
  12. /* We should optimize these. See arch/xtensa/lib/strncpy_user.S */
  13. #ifndef _XTENSA_STRING_H
  14. #define _XTENSA_STRING_H
  15. #define __HAVE_ARCH_STRCPY
  16. static inline char *strcpy(char *__dest, const char *__src)
  17. {
  18. register char *__xdest = __dest;
  19. unsigned long __dummy;
  20. __asm__ __volatile__("1:\n\t"
  21. "l8ui %2, %1, 0\n\t"
  22. "s8i %2, %0, 0\n\t"
  23. "addi %1, %1, 1\n\t"
  24. "addi %0, %0, 1\n\t"
  25. "bnez %2, 1b\n\t"
  26. : "=r" (__dest), "=r" (__src), "=&r" (__dummy)
  27. : "0" (__dest), "1" (__src)
  28. : "memory");
  29. return __xdest;
  30. }
  31. #define __HAVE_ARCH_STRNCPY
  32. static inline char *strncpy(char *__dest, const char *__src, size_t __n)
  33. {
  34. register char *__xdest = __dest;
  35. unsigned long __dummy;
  36. if (__n == 0)
  37. return __xdest;
  38. __asm__ __volatile__(
  39. "1:\n\t"
  40. "l8ui %2, %1, 0\n\t"
  41. "s8i %2, %0, 0\n\t"
  42. "addi %1, %1, 1\n\t"
  43. "addi %0, %0, 1\n\t"
  44. "beqz %2, 2f\n\t"
  45. "bne %1, %5, 1b\n"
  46. "2:"
  47. : "=r" (__dest), "=r" (__src), "=&r" (__dummy)
  48. : "0" (__dest), "1" (__src), "r" (__src+__n)
  49. : "memory");
  50. return __xdest;
  51. }
  52. #define __HAVE_ARCH_STRCMP
  53. static inline int strcmp(const char *__cs, const char *__ct)
  54. {
  55. register int __res;
  56. unsigned long __dummy;
  57. __asm__ __volatile__(
  58. "1:\n\t"
  59. "l8ui %3, %1, 0\n\t"
  60. "addi %1, %1, 1\n\t"
  61. "l8ui %2, %0, 0\n\t"
  62. "addi %0, %0, 1\n\t"
  63. "beqz %2, 2f\n\t"
  64. "beq %2, %3, 1b\n"
  65. "2:\n\t"
  66. "sub %2, %2, %3"
  67. : "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&r" (__dummy)
  68. : "0" (__cs), "1" (__ct));
  69. return __res;
  70. }
  71. #define __HAVE_ARCH_STRNCMP
  72. static inline int strncmp(const char *__cs, const char *__ct, size_t __n)
  73. {
  74. register int __res;
  75. unsigned long __dummy;
  76. __asm__ __volatile__(
  77. "mov %2, %3\n"
  78. "1:\n\t"
  79. "beq %0, %6, 2f\n\t"
  80. "l8ui %3, %1, 0\n\t"
  81. "addi %1, %1, 1\n\t"
  82. "l8ui %2, %0, 0\n\t"
  83. "addi %0, %0, 1\n\t"
  84. "beqz %2, 2f\n\t"
  85. "beqz %3, 2f\n\t"
  86. "beq %2, %3, 1b\n"
  87. "2:\n\t"
  88. "sub %2, %2, %3"
  89. : "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&r" (__dummy)
  90. : "0" (__cs), "1" (__ct), "r" (__cs+__n));
  91. return __res;
  92. }
  93. #define __HAVE_ARCH_MEMSET
  94. extern void *memset(void *__s, int __c, size_t __count);
  95. #define __HAVE_ARCH_MEMCPY
  96. extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
  97. #define __HAVE_ARCH_MEMMOVE
  98. extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
  99. /* Don't build bcopy at all ... */
  100. #define __HAVE_ARCH_BCOPY
  101. #endif /* _XTENSA_STRING_H */