string.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* $Id: string.h,v 1.13 2000/02/19 14:12:14 harald Exp $
  2. *
  3. * This file is subject to the terms and conditions of the GNU General Public
  4. * License. See the file "COPYING" in the main directory of this archive
  5. * for more details.
  6. *
  7. * Copyright (c) 1994, 1995, 1996, 1997, 1998 by Ralf Baechle
  8. */
  9. #ifndef __ASM_MIPS_STRING_H
  10. #define __ASM_MIPS_STRING_H
  11. #include <linux/config.h>
  12. #define __HAVE_ARCH_STRCPY
  13. extern __inline__ char *strcpy(char *__dest, __const__ char *__src)
  14. {
  15. char *__xdest = __dest;
  16. __asm__ __volatile__(
  17. ".set\tnoreorder\n\t"
  18. ".set\tnoat\n"
  19. "1:\tlbu\t$1,(%1)\n\t"
  20. "addiu\t%1,1\n\t"
  21. "sb\t$1,(%0)\n\t"
  22. "bnez\t$1,1b\n\t"
  23. "addiu\t%0,1\n\t"
  24. ".set\tat\n\t"
  25. ".set\treorder"
  26. : "=r" (__dest), "=r" (__src)
  27. : "0" (__dest), "1" (__src)
  28. : "$1","memory");
  29. return __xdest;
  30. }
  31. #define __HAVE_ARCH_STRNCPY
  32. extern __inline__ char *strncpy(char *__dest, __const__ char *__src, size_t __n)
  33. {
  34. char *__xdest = __dest;
  35. if (__n == 0)
  36. return __xdest;
  37. __asm__ __volatile__(
  38. ".set\tnoreorder\n\t"
  39. ".set\tnoat\n"
  40. "1:\tlbu\t$1,(%1)\n\t"
  41. "subu\t%2,1\n\t"
  42. "sb\t$1,(%0)\n\t"
  43. "beqz\t$1,2f\n\t"
  44. "addiu\t%0,1\n\t"
  45. "bnez\t%2,1b\n\t"
  46. "addiu\t%1,1\n"
  47. "2:\n\t"
  48. ".set\tat\n\t"
  49. ".set\treorder"
  50. : "=r" (__dest), "=r" (__src), "=r" (__n)
  51. : "0" (__dest), "1" (__src), "2" (__n)
  52. : "$1","memory");
  53. return __dest;
  54. }
  55. #define __HAVE_ARCH_STRCMP
  56. extern __inline__ int strcmp(__const__ char *__cs, __const__ char *__ct)
  57. {
  58. int __res;
  59. __asm__ __volatile__(
  60. ".set\tnoreorder\n\t"
  61. ".set\tnoat\n\t"
  62. "lbu\t%2,(%0)\n"
  63. "1:\tlbu\t$1,(%1)\n\t"
  64. "addiu\t%0,1\n\t"
  65. "bne\t$1,%2,2f\n\t"
  66. "addiu\t%1,1\n\t"
  67. "bnez\t%2,1b\n\t"
  68. "lbu\t%2,(%0)\n\t"
  69. #if defined(CONFIG_CPU_R3000)
  70. "nop\n\t"
  71. #endif
  72. "move\t%2,$1\n"
  73. "2:\tsubu\t%2,$1\n"
  74. "3:\t.set\tat\n\t"
  75. ".set\treorder"
  76. : "=r" (__cs), "=r" (__ct), "=r" (__res)
  77. : "0" (__cs), "1" (__ct)
  78. : "$1");
  79. return __res;
  80. }
  81. #define __HAVE_ARCH_STRNCMP
  82. extern __inline__ int
  83. strncmp(__const__ char *__cs, __const__ char *__ct, size_t __count)
  84. {
  85. int __res;
  86. __asm__ __volatile__(
  87. ".set\tnoreorder\n\t"
  88. ".set\tnoat\n"
  89. "1:\tlbu\t%3,(%0)\n\t"
  90. "beqz\t%2,2f\n\t"
  91. "lbu\t$1,(%1)\n\t"
  92. "subu\t%2,1\n\t"
  93. "bne\t$1,%3,3f\n\t"
  94. "addiu\t%0,1\n\t"
  95. "bnez\t%3,1b\n\t"
  96. "addiu\t%1,1\n"
  97. "2:\n\t"
  98. #if defined(CONFIG_CPU_R3000)
  99. "nop\n\t"
  100. #endif
  101. "move\t%3,$1\n"
  102. "3:\tsubu\t%3,$1\n\t"
  103. ".set\tat\n\t"
  104. ".set\treorder"
  105. : "=r" (__cs), "=r" (__ct), "=r" (__count), "=r" (__res)
  106. : "0" (__cs), "1" (__ct), "2" (__count)
  107. : "$1");
  108. return __res;
  109. }
  110. #undef __HAVE_ARCH_MEMSET
  111. extern void *memset(void *__s, int __c, size_t __count);
  112. #undef __HAVE_ARCH_MEMCPY
  113. extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
  114. #undef __HAVE_ARCH_MEMMOVE
  115. extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
  116. /* Don't build bcopy at all ... */
  117. #define __HAVE_ARCH_BCOPY
  118. #define __HAVE_ARCH_MEMSCAN
  119. extern __inline__ void *memscan(void *__addr, int __c, size_t __size)
  120. {
  121. char *__end = (char *)__addr + __size;
  122. __asm__(".set\tpush\n\t"
  123. ".set\tnoat\n\t"
  124. ".set\treorder\n\t"
  125. "1:\tbeq\t%0,%1,2f\n\t"
  126. "addiu\t%0,1\n\t"
  127. "lb\t$1,-1(%0)\n\t"
  128. "bne\t$1,%4,1b\n"
  129. "2:\t.set\tpop"
  130. : "=r" (__addr), "=r" (__end)
  131. : "0" (__addr), "1" (__end), "r" (__c)
  132. : "$1");
  133. return __addr;
  134. }
  135. #endif /* __ASM_MIPS_STRING_H */