string.h 3.3 KB

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