string.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #ifndef __ASM_SH_STRING_H
  2. #define __ASM_SH_STRING_H
  3. /*
  4. * Copyright (C) 1999 Niibe Yutaka
  5. * But consider these trivial functions to be public domain.
  6. *
  7. * from linux kernel code.
  8. */
  9. #ifdef __KERNEL__ /* only set these up for kernel code */
  10. #define __HAVE_ARCH_STRCPY
  11. static inline char *strcpy(char *__dest, const char *__src)
  12. {
  13. register char *__xdest = __dest;
  14. unsigned long __dummy;
  15. __asm__ __volatile__("1:\n\t"
  16. "mov.b @%1+, %2\n\t"
  17. "mov.b %2, @%0\n\t"
  18. "cmp/eq #0, %2\n\t"
  19. "bf/s 1b\n\t"
  20. " add #1, %0\n\t"
  21. : "=r" (__dest), "=r" (__src), "=&z" (__dummy)
  22. : "0" (__dest), "1" (__src)
  23. : "memory", "t");
  24. return __xdest;
  25. }
  26. #define __HAVE_ARCH_STRNCPY
  27. static inline char *strncpy(char *__dest, const char *__src, size_t __n)
  28. {
  29. register char *__xdest = __dest;
  30. unsigned long __dummy;
  31. if (__n == 0)
  32. return __xdest;
  33. __asm__ __volatile__(
  34. "1:\n"
  35. "mov.b @%1+, %2\n\t"
  36. "mov.b %2, @%0\n\t"
  37. "cmp/eq #0, %2\n\t"
  38. "bt/s 2f\n\t"
  39. " cmp/eq %5,%1\n\t"
  40. "bf/s 1b\n\t"
  41. " add #1, %0\n"
  42. "2:"
  43. : "=r" (__dest), "=r" (__src), "=&z" (__dummy)
  44. : "0" (__dest), "1" (__src), "r" (__src+__n)
  45. : "memory", "t");
  46. return __xdest;
  47. }
  48. #define __HAVE_ARCH_STRCMP
  49. static inline int strcmp(const char *__cs, const char *__ct)
  50. {
  51. register int __res;
  52. unsigned long __dummy;
  53. __asm__ __volatile__(
  54. "mov.b @%1+, %3\n"
  55. "1:\n\t"
  56. "mov.b @%0+, %2\n\t"
  57. "cmp/eq #0, %3\n\t"
  58. "bt 2f\n\t"
  59. "cmp/eq %2, %3\n\t"
  60. "bt/s 1b\n\t"
  61. " mov.b @%1+, %3\n\t"
  62. "add #-2, %1\n\t"
  63. "mov.b @%1, %3\n\t"
  64. "sub %3, %2\n"
  65. "2:"
  66. : "=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
  67. : "0" (__cs), "1" (__ct)
  68. : "t");
  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. if (__n == 0)
  77. return 0;
  78. __asm__ __volatile__(
  79. "mov.b @%1+, %3\n"
  80. "1:\n\t"
  81. "mov.b @%0+, %2\n\t"
  82. "cmp/eq %6, %0\n\t"
  83. "bt/s 2f\n\t"
  84. " cmp/eq #0, %3\n\t"
  85. "bt/s 3f\n\t"
  86. " cmp/eq %3, %2\n\t"
  87. "bt/s 1b\n\t"
  88. " mov.b @%1+, %3\n\t"
  89. "add #-2, %1\n\t"
  90. "mov.b @%1, %3\n"
  91. "2:\n\t"
  92. "sub %3, %2\n"
  93. "3:"
  94. :"=r" (__cs), "=r" (__ct), "=&r" (__res), "=&z" (__dummy)
  95. : "0" (__cs), "1" (__ct), "r" (__cs+__n)
  96. : "t");
  97. return __res;
  98. }
  99. #undef __HAVE_ARCH_MEMSET
  100. extern void *memset(void *__s, int __c, size_t __count);
  101. #undef __HAVE_ARCH_MEMCPY
  102. extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
  103. #undef __HAVE_ARCH_MEMMOVE
  104. extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
  105. #undef __HAVE_ARCH_MEMCHR
  106. extern void *memchr(const void *__s, int __c, size_t __n);
  107. #undef __HAVE_ARCH_STRLEN
  108. extern size_t strlen(const char *);
  109. /* arch/sh/lib/strcasecmp.c */
  110. extern int strcasecmp(const char *, const char *);
  111. #else /* KERNEL */
  112. /*
  113. * let user libraries deal with these,
  114. * IMHO the kernel has no place defining these functions for user apps
  115. */
  116. #define __HAVE_ARCH_STRCPY 1
  117. #define __HAVE_ARCH_STRNCPY 1
  118. #define __HAVE_ARCH_STRCAT 1
  119. #define __HAVE_ARCH_STRNCAT 1
  120. #define __HAVE_ARCH_STRCMP 1
  121. #define __HAVE_ARCH_STRNCMP 1
  122. #define __HAVE_ARCH_STRNICMP 1
  123. #define __HAVE_ARCH_STRCHR 1
  124. #define __HAVE_ARCH_STRRCHR 1
  125. #define __HAVE_ARCH_STRSTR 1
  126. #define __HAVE_ARCH_STRLEN 1
  127. #define __HAVE_ARCH_STRNLEN 1
  128. #define __HAVE_ARCH_MEMSET 1
  129. #define __HAVE_ARCH_MEMCPY 1
  130. #define __HAVE_ARCH_MEMMOVE 1
  131. #define __HAVE_ARCH_MEMSCAN 1
  132. #define __HAVE_ARCH_MEMCMP 1
  133. #define __HAVE_ARCH_MEMCHR 1
  134. #define __HAVE_ARCH_STRTOK 1
  135. #endif /* KERNEL */
  136. #endif /* __ASM_SH_STRING_H */