string.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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:\t%2 = B [%1++] (Z);\n\t"
  11. "B [%0++] = %2;\n\t"
  12. "CC = %2;\n\t"
  13. "if cc jump 1b (bp);\n"
  14. : "+&a" (dest), "+&a" (src), "=&d" (temp)
  15. ::"memory", "CC");
  16. return xdest;
  17. }
  18. #define __HAVE_ARCH_STRNCPY
  19. extern inline char *strncpy(char *dest, const char *src, size_t n)
  20. {
  21. char *xdest = dest;
  22. char temp = 0;
  23. if (n == 0)
  24. return xdest;
  25. __asm__ __volatile__
  26. ("1:\t%3 = B [%1++] (Z);\n\t"
  27. "B [%0++] = %3;\n\t"
  28. "CC = %3;\n\t"
  29. "if ! cc jump 2f;\n\t"
  30. "%2 += -1;\n\t"
  31. "CC = %2 == 0;\n\t"
  32. "if ! cc jump 1b (bp);\n"
  33. "2:\n"
  34. : "+&a" (dest), "+&a" (src), "+&da" (n), "=&d" (temp)
  35. ::"memory", "CC");
  36. return xdest;
  37. }
  38. #define __HAVE_ARCH_STRCMP
  39. extern inline int strcmp(const char *cs, const char *ct)
  40. {
  41. char __res1, __res2;
  42. __asm__
  43. ("1:\t%2 = B[%0++] (Z);\n\t" /* get *cs */
  44. "%3 = B[%1++] (Z);\n\t" /* get *ct */
  45. "CC = %2 == %3;\n\t" /* compare a byte */
  46. "if ! cc jump 2f;\n\t" /* not equal, break out */
  47. "CC = %2;\n\t" /* at end of cs? */
  48. "if cc jump 1b (bp);\n\t" /* no, keep going */
  49. "jump.s 3f;\n" /* strings are equal */
  50. "2:\t%2 = %2 - %3;\n" /* *cs - *ct */
  51. "3:\n"
  52. : "+&a" (cs), "+&a" (ct), "=&d" (__res1), "=&d" (__res2)
  53. : : "CC");
  54. return __res1;
  55. }
  56. #define __HAVE_ARCH_STRNCMP
  57. extern inline int strncmp(const char *cs, const char *ct, size_t count)
  58. {
  59. char __res1, __res2;
  60. if (!count)
  61. return 0;
  62. __asm__
  63. ("1:\t%3 = B[%0++] (Z);\n\t" /* get *cs */
  64. "%4 = B[%1++] (Z);\n\t" /* get *ct */
  65. "CC = %3 == %4;\n\t" /* compare a byte */
  66. "if ! cc jump 3f;\n\t" /* not equal, break out */
  67. "CC = %3;\n\t" /* at end of cs? */
  68. "if ! cc jump 4f;\n\t" /* yes, all done */
  69. "%2 += -1;\n\t" /* no, adjust count */
  70. "CC = %2 == 0;\n\t"
  71. "if ! cc jump 1b;\n" /* more to do, keep going */
  72. "2:\t%3 = 0;\n\t" /* strings are equal */
  73. "jump.s 4f;\n"
  74. "3:\t%3 = %3 - %4;\n" /* *cs - *ct */
  75. "4:"
  76. : "+&a" (cs), "+&a" (ct), "+&da" (count), "=&d" (__res1), "=&d" (__res2)
  77. : : "CC");
  78. return __res1;
  79. }
  80. #define __HAVE_ARCH_MEMSET
  81. extern void *memset(void *s, int c, size_t count);
  82. #define __HAVE_ARCH_MEMCPY
  83. extern void *memcpy(void *d, const void *s, size_t count);
  84. #define __HAVE_ARCH_MEMCMP
  85. extern int memcmp(const void *, const void *, __kernel_size_t);
  86. #define __HAVE_ARCH_MEMCHR
  87. extern void *memchr(const void *s, int c, size_t n);
  88. #define __HAVE_ARCH_MEMMOVE
  89. extern void *memmove(void *dest, const void *src, size_t count);
  90. #endif /*__KERNEL__*/
  91. #endif /* _BLACKFIN_STRING_H_ */