string.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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, 95, 96, 97, 98, 2000, 01 Ralf Baechle
  7. * Copyright (c) 2000 by Silicon Graphics, Inc.
  8. * Copyright (c) 2001 MIPS Technologies, Inc.
  9. */
  10. #ifndef _ASM_STRING_H
  11. #define _ASM_STRING_H
  12. /*
  13. * Most of the inline functions are rather naive implementations so I just
  14. * didn't bother updating them for 64-bit ...
  15. */
  16. #ifdef CONFIG_32BIT
  17. #ifndef IN_STRING_C
  18. #define __HAVE_ARCH_STRCPY
  19. static __inline__ char *strcpy(char *__dest, __const__ char *__src)
  20. {
  21. char *__xdest = __dest;
  22. __asm__ __volatile__(
  23. ".set\tnoreorder\n\t"
  24. ".set\tnoat\n"
  25. "1:\tlbu\t$1,(%1)\n\t"
  26. "addiu\t%1,1\n\t"
  27. "sb\t$1,(%0)\n\t"
  28. "bnez\t$1,1b\n\t"
  29. "addiu\t%0,1\n\t"
  30. ".set\tat\n\t"
  31. ".set\treorder"
  32. : "=r" (__dest), "=r" (__src)
  33. : "0" (__dest), "1" (__src)
  34. : "memory");
  35. return __xdest;
  36. }
  37. #define __HAVE_ARCH_STRNCPY
  38. static __inline__ char *strncpy(char *__dest, __const__ char *__src, size_t __n)
  39. {
  40. char *__xdest = __dest;
  41. if (__n == 0)
  42. return __xdest;
  43. __asm__ __volatile__(
  44. ".set\tnoreorder\n\t"
  45. ".set\tnoat\n"
  46. "1:\tlbu\t$1,(%1)\n\t"
  47. "subu\t%2,1\n\t"
  48. "sb\t$1,(%0)\n\t"
  49. "beqz\t$1,2f\n\t"
  50. "addiu\t%0,1\n\t"
  51. "bnez\t%2,1b\n\t"
  52. "addiu\t%1,1\n"
  53. "2:\n\t"
  54. ".set\tat\n\t"
  55. ".set\treorder"
  56. : "=r" (__dest), "=r" (__src), "=r" (__n)
  57. : "0" (__dest), "1" (__src), "2" (__n)
  58. : "memory");
  59. return __xdest;
  60. }
  61. #define __HAVE_ARCH_STRCMP
  62. static __inline__ int strcmp(__const__ char *__cs, __const__ char *__ct)
  63. {
  64. int __res;
  65. __asm__ __volatile__(
  66. ".set\tnoreorder\n\t"
  67. ".set\tnoat\n\t"
  68. "lbu\t%2,(%0)\n"
  69. "1:\tlbu\t$1,(%1)\n\t"
  70. "addiu\t%0,1\n\t"
  71. "bne\t$1,%2,2f\n\t"
  72. "addiu\t%1,1\n\t"
  73. "bnez\t%2,1b\n\t"
  74. "lbu\t%2,(%0)\n\t"
  75. #if defined(CONFIG_CPU_R3000)
  76. "nop\n\t"
  77. #endif
  78. "move\t%2,$1\n"
  79. "2:\tsubu\t%2,$1\n"
  80. "3:\t.set\tat\n\t"
  81. ".set\treorder"
  82. : "=r" (__cs), "=r" (__ct), "=r" (__res)
  83. : "0" (__cs), "1" (__ct));
  84. return __res;
  85. }
  86. #endif /* !defined(IN_STRING_C) */
  87. #define __HAVE_ARCH_STRNCMP
  88. static __inline__ int
  89. strncmp(__const__ char *__cs, __const__ char *__ct, size_t __count)
  90. {
  91. int __res;
  92. __asm__ __volatile__(
  93. ".set\tnoreorder\n\t"
  94. ".set\tnoat\n"
  95. "1:\tlbu\t%3,(%0)\n\t"
  96. "beqz\t%2,2f\n\t"
  97. "lbu\t$1,(%1)\n\t"
  98. "subu\t%2,1\n\t"
  99. "bne\t$1,%3,3f\n\t"
  100. "addiu\t%0,1\n\t"
  101. "bnez\t%3,1b\n\t"
  102. "addiu\t%1,1\n"
  103. "2:\n\t"
  104. #if defined(CONFIG_CPU_R3000)
  105. "nop\n\t"
  106. #endif
  107. "move\t%3,$1\n"
  108. "3:\tsubu\t%3,$1\n\t"
  109. ".set\tat\n\t"
  110. ".set\treorder"
  111. : "=r" (__cs), "=r" (__ct), "=r" (__count), "=r" (__res)
  112. : "0" (__cs), "1" (__ct), "2" (__count));
  113. return __res;
  114. }
  115. #endif /* CONFIG_32BIT */
  116. #define __HAVE_ARCH_MEMSET
  117. extern void *memset(void *__s, int __c, size_t __count);
  118. #define __HAVE_ARCH_MEMCPY
  119. extern void *memcpy(void *__to, __const__ void *__from, size_t __n);
  120. #define __HAVE_ARCH_MEMMOVE
  121. extern void *memmove(void *__dest, __const__ void *__src, size_t __n);
  122. #endif /* _ASM_STRING_H */