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