string_32.h 2.7 KB

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