string.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * This file is subject to the terms and conditions of the GNU General Public
  3.  * License.  See the file "COPYING" in the main directory of this archive
  4.  * for more details.
  5.  *
  6.  * Copyright (c) 1994, 1995, 1996, 1997, 1998, 2001 Ralf Baechle
  7.  * Copyright (c) 2001 MIPS Technologies, Inc.
  8.  */
  9. #ifndef __ASM_STRING_H
  10. #define __ASM_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. ".settnoreordernt"
  18. ".settnoatn"
  19. "1:tlbut$1,(%1)nt"
  20. "addiut%1,1nt"
  21. "sbt$1,(%0)nt"
  22. "bnezt$1,1bnt"
  23. "addiut%0,1nt"
  24. ".settatnt"
  25. ".settreorder"
  26. : "=r" (__dest), "=r" (__src)
  27.         : "0" (__dest), "1" (__src)
  28. : "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. ".settnoreordernt"
  39. ".settnoatn"
  40. "1:tlbut$1,(%1)nt"
  41. "subut%2,1nt"
  42. "sbt$1,(%0)nt"
  43. "beqzt$1,2fnt"
  44. "addiut%0,1nt"
  45. "bnezt%2,1bnt"
  46. "addiut%1,1n"
  47. "2:nt"
  48. ".settatnt"
  49. ".settreorder"
  50.         : "=r" (__dest), "=r" (__src), "=r" (__n)
  51.         : "0" (__dest), "1" (__src), "2" (__n)
  52.         : "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. ".settnoreordernt"
  61. ".settnoatnt"
  62. "lbut%2,(%0)n"
  63. "1:tlbut$1,(%1)nt"
  64. "addiut%0,1nt"
  65. "bnet$1,%2,2fnt"
  66. "addiut%1,1nt"
  67. "bnezt%2,1bnt"
  68. "lbut%2,(%0)nt"
  69. #if defined(CONFIG_CPU_R3000)
  70. "nopnt"
  71. #endif
  72. "movet%2,$1n"
  73. "2:tsubut%2,$1n"
  74. "3:t.settatnt"
  75. ".settreorder"
  76. : "=r" (__cs), "=r" (__ct), "=r" (__res)
  77. : "0" (__cs), "1" (__ct));
  78.   return __res;
  79. }
  80. #define __HAVE_ARCH_STRNCMP
  81. extern __inline__ int
  82. strncmp(__const__ char *__cs, __const__ char *__ct, size_t __count)
  83. {
  84. int __res;
  85. __asm__ __volatile__(
  86. ".settnoreordernt"
  87. ".settnoatn"
  88. "1:tlbut%3,(%0)nt"
  89. "beqzt%2,2fnt"
  90. "lbut$1,(%1)nt"
  91. "subut%2,1nt"
  92. "bnet$1,%3,3fnt"
  93. "addiut%0,1nt"
  94. "bnezt%3,1bnt"
  95. "addiut%1,1n"
  96. "2:nt"
  97. #if defined(CONFIG_CPU_R3000)
  98. "nopnt"
  99. #endif
  100. "movet%3,$1n"
  101. "3:tsubut%3,$1nt"
  102. ".settatnt"
  103. ".settreorder"
  104. : "=r" (__cs), "=r" (__ct), "=r" (__count), "=r" (__res)
  105. : "0" (__cs), "1" (__ct), "2" (__count));
  106. return __res;
  107. }
  108. #define __HAVE_ARCH_MEMSET
  109. extern void *memset(void *__s, int __c, size_t __count);
  110. #define __HAVE_ARCH_MEMCPY
  111. extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
  112. #define __HAVE_ARCH_MEMMOVE
  113. extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
  114. /* Don't build bcopy at all ...  */
  115. #define __HAVE_ARCH_BCOPY
  116. #define __HAVE_ARCH_MEMSCAN
  117. extern __inline__ void *memscan(void *__addr, int __c, size_t __size)
  118. {
  119. char *__end = (char *)__addr + __size;
  120. unsigned char __uc = (unsigned char) __c;
  121. __asm__(".settpushnt"
  122. ".settnoatnt"
  123. ".settreordernt"
  124. "1:tbeqt%0,%1,2fnt"
  125. "addiut%0,1nt"
  126. "lbut$1,-1(%0)nt"
  127. "bnet$1,%z4,1bn"
  128. "2:t.settpop"
  129. : "=r" (__addr), "=r" (__end)
  130. : "0" (__addr), "1" (__end), "Jr" (__uc));
  131. return __addr;
  132. }
  133. #endif /* __ASM_STRING_H */