string.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef _BLACKFIN_STRING_H_
  2. #define _BLACKFIN_STRING_H_
  3. #ifdef __KERNEL__ /* only set these up for kernel code */
  4. #define __HAVE_ARCH_STRCPY
  5. extern inline char *strcpy(char *dest, const char *src)
  6. {
  7. char *xdest = dest;
  8. char temp = 0;
  9. __asm__ __volatile__ (
  10. "1:"
  11. "%2 = B [%1++] (Z);"
  12. "B [%0++] = %2;"
  13. "CC = %2;"
  14. "if cc jump 1b (bp);"
  15. : "+&a" (dest), "+&a" (src), "=&d" (temp)
  16. :
  17. : "memory", "CC");
  18. return xdest;
  19. }
  20. #define __HAVE_ARCH_STRNCPY
  21. extern inline char *strncpy(char *dest, const char *src, size_t n)
  22. {
  23. char *xdest = dest;
  24. char temp = 0;
  25. if (n == 0)
  26. return xdest;
  27. __asm__ __volatile__ (
  28. "1:"
  29. "%3 = B [%1++] (Z);"
  30. "B [%0++] = %3;"
  31. "CC = %3;"
  32. "if ! cc jump 2f;"
  33. "%2 += -1;"
  34. "CC = %2 == 0;"
  35. "if ! cc jump 1b (bp);"
  36. "jump 4f;"
  37. "2:"
  38. /* if src is shorter than n, we need to null pad bytes now */
  39. "%3 = 0;"
  40. "3:"
  41. "%2 += -1;"
  42. "CC = %2 == 0;"
  43. "if cc jump 4f;"
  44. "B [%0++] = %3;"
  45. "jump 3b;"
  46. "4:"
  47. : "+&a" (dest), "+&a" (src), "+&da" (n), "=&d" (temp)
  48. :
  49. : "memory", "CC");
  50. return xdest;
  51. }
  52. #define __HAVE_ARCH_STRCMP
  53. extern inline int strcmp(const char *cs, const char *ct)
  54. {
  55. /* need to use int's here so the char's in the assembly don't get
  56. * sign extended incorrectly when we don't want them to be
  57. */
  58. int __res1, __res2;
  59. __asm__ __volatile__ (
  60. "1:"
  61. "%2 = B[%0++] (Z);" /* get *cs */
  62. "%3 = B[%1++] (Z);" /* get *ct */
  63. "CC = %2 == %3;" /* compare a byte */
  64. "if ! cc jump 2f;" /* not equal, break out */
  65. "CC = %2;" /* at end of cs? */
  66. "if cc jump 1b (bp);" /* no, keep going */
  67. "jump.s 3f;" /* strings are equal */
  68. "2:"
  69. "%2 = %2 - %3;" /* *cs - *ct */
  70. "3:"
  71. : "+&a" (cs), "+&a" (ct), "=&d" (__res1), "=&d" (__res2)
  72. :
  73. : "memory", "CC");
  74. return __res1;
  75. }
  76. #define __HAVE_ARCH_STRNCMP
  77. extern inline int strncmp(const char *cs, const char *ct, size_t count)
  78. {
  79. /* need to use int's here so the char's in the assembly don't get
  80. * sign extended incorrectly when we don't want them to be
  81. */
  82. int __res1, __res2;
  83. if (!count)
  84. return 0;
  85. __asm__ __volatile__ (
  86. "1:"
  87. "%3 = B[%0++] (Z);" /* get *cs */
  88. "%4 = B[%1++] (Z);" /* get *ct */
  89. "CC = %3 == %4;" /* compare a byte */
  90. "if ! cc jump 3f;" /* not equal, break out */
  91. "CC = %3;" /* at end of cs? */
  92. "if ! cc jump 4f;" /* yes, all done */
  93. "%2 += -1;" /* no, adjust count */
  94. "CC = %2 == 0;"
  95. "if ! cc jump 1b;" /* more to do, keep going */
  96. "2:"
  97. "%3 = 0;" /* strings are equal */
  98. "jump.s 4f;"
  99. "3:"
  100. "%3 = %3 - %4;" /* *cs - *ct */
  101. "4:"
  102. : "+&a" (cs), "+&a" (ct), "+&da" (count), "=&d" (__res1), "=&d" (__res2)
  103. :
  104. : "memory", "CC");
  105. return __res1;
  106. }
  107. #define __HAVE_ARCH_MEMSET
  108. extern void *memset(void *s, int c, size_t count);
  109. #define __HAVE_ARCH_MEMCPY
  110. extern void *memcpy(void *d, const void *s, size_t count);
  111. #define __HAVE_ARCH_MEMCMP
  112. extern int memcmp(const void *, const void *, __kernel_size_t);
  113. #define __HAVE_ARCH_MEMCHR
  114. extern void *memchr(const void *s, int c, size_t n);
  115. #define __HAVE_ARCH_MEMMOVE
  116. extern void *memmove(void *dest, const void *src, size_t count);
  117. #endif /*__KERNEL__*/
  118. #endif /* _BLACKFIN_STRING_H_ */