diff options
author | Mike Frysinger <michael.frysinger@analog.com> | 2007-09-12 04:30:15 -0400 |
---|---|---|
committer | Bryan Wu <bryan.wu@analog.com> | 2007-09-12 04:30:15 -0400 |
commit | 0931ce8439365358b1cacf888ddc8fb008036125 (patch) | |
tree | a2bb7a1c7fd882fa3accbe6f636af5f57224c875 /include/asm-blackfin/string.h | |
parent | e62687f995fd7ba0b68c3b0a4f4d9fd9d1c54ec2 (diff) |
Blackfin arch: fix some bugs in lib/string.h functions found by our string testing modules
- use ints for the return value rather than char since we actually return
an int and we dont want it improperly being sign extended during the reload
http://blackfin.uclinux.org/gf/project/uclinux-dist/tracker/?action=TrackerItemEdit&tracker_item_id=3525
- if src is shorter than the requested number of copy bytes, we need to null
pad the rest
http://blackfin.uclinux.org/gf/project/uclinux-dist/tracker/?action=TrackerItemEdit&tracker_item_id=3524
- mark these as __volatile__ and add memory to the clobber list so gcc does
not optimize buffers around on us we may be using
- rewrite asm code to be readable/maintainable
Signed-off-by: Mike Frysinger <michael.frysinger@analog.com>
Signed-off-by: Bryan Wu <bryan.wu@analog.com>
Diffstat (limited to 'include/asm-blackfin/string.h')
-rw-r--r-- | include/asm-blackfin/string.h | 129 |
1 files changed, 80 insertions, 49 deletions
diff --git a/include/asm-blackfin/string.h b/include/asm-blackfin/string.h index 6f1eb7d6d3cb..e8ada91ab002 100644 --- a/include/asm-blackfin/string.h +++ b/include/asm-blackfin/string.h | |||
@@ -9,13 +9,16 @@ extern inline char *strcpy(char *dest, const char *src) | |||
9 | char *xdest = dest; | 9 | char *xdest = dest; |
10 | char temp = 0; | 10 | char temp = 0; |
11 | 11 | ||
12 | __asm__ __volatile__ | 12 | __asm__ __volatile__ ( |
13 | ("1:\t%2 = B [%1++] (Z);\n\t" | 13 | "1:" |
14 | "B [%0++] = %2;\n\t" | 14 | "%2 = B [%1++] (Z);" |
15 | "CC = %2;\n\t" | 15 | "B [%0++] = %2;" |
16 | "if cc jump 1b (bp);\n" | 16 | "CC = %2;" |
17 | : "+&a" (dest), "+&a" (src), "=&d" (temp) | 17 | "if cc jump 1b (bp);" |
18 | ::"memory", "CC"); | 18 | : "+&a" (dest), "+&a" (src), "=&d" (temp) |
19 | : | ||
20 | : "memory", "CC"); | ||
21 | |||
19 | return xdest; | 22 | return xdest; |
20 | } | 23 | } |
21 | 24 | ||
@@ -28,37 +31,56 @@ extern inline char *strncpy(char *dest, const char *src, size_t n) | |||
28 | if (n == 0) | 31 | if (n == 0) |
29 | return xdest; | 32 | return xdest; |
30 | 33 | ||
31 | __asm__ __volatile__ | 34 | __asm__ __volatile__ ( |
32 | ("1:\t%3 = B [%1++] (Z);\n\t" | 35 | "1:" |
33 | "B [%0++] = %3;\n\t" | 36 | "%3 = B [%1++] (Z);" |
34 | "CC = %3;\n\t" | 37 | "B [%0++] = %3;" |
35 | "if ! cc jump 2f;\n\t" | 38 | "CC = %3;" |
36 | "%2 += -1;\n\t" | 39 | "if ! cc jump 2f;" |
37 | "CC = %2 == 0;\n\t" | 40 | "%2 += -1;" |
38 | "if ! cc jump 1b (bp);\n" | 41 | "CC = %2 == 0;" |
39 | "2:\n" | 42 | "if ! cc jump 1b (bp);" |
40 | : "+&a" (dest), "+&a" (src), "+&da" (n), "=&d" (temp) | 43 | "jump 4f;" |
41 | ::"memory", "CC"); | 44 | "2:" |
45 | /* if src is shorter than n, we need to null pad bytes now */ | ||
46 | "%3 = 0;" | ||
47 | "3:" | ||
48 | "%2 += -1;" | ||
49 | "CC = %2 == 0;" | ||
50 | "if cc jump 4f;" | ||
51 | "B [%0++] = %3;" | ||
52 | "jump 3b;" | ||
53 | "4:" | ||
54 | : "+&a" (dest), "+&a" (src), "+&da" (n), "=&d" (temp) | ||
55 | : | ||
56 | : "memory", "CC"); | ||
57 | |||
42 | return xdest; | 58 | return xdest; |
43 | } | 59 | } |
44 | 60 | ||
45 | #define __HAVE_ARCH_STRCMP | 61 | #define __HAVE_ARCH_STRCMP |
46 | extern inline int strcmp(const char *cs, const char *ct) | 62 | extern inline int strcmp(const char *cs, const char *ct) |
47 | { | 63 | { |
48 | char __res1, __res2; | 64 | /* need to use int's here so the char's in the assembly don't get |
49 | 65 | * sign extended incorrectly when we don't want them to be | |
50 | __asm__ | 66 | */ |
51 | ("1:\t%2 = B[%0++] (Z);\n\t" /* get *cs */ | 67 | int __res1, __res2; |
52 | "%3 = B[%1++] (Z);\n\t" /* get *ct */ | 68 | |
53 | "CC = %2 == %3;\n\t" /* compare a byte */ | 69 | __asm__ __volatile__ ( |
54 | "if ! cc jump 2f;\n\t" /* not equal, break out */ | 70 | "1:" |
55 | "CC = %2;\n\t" /* at end of cs? */ | 71 | "%2 = B[%0++] (Z);" /* get *cs */ |
56 | "if cc jump 1b (bp);\n\t" /* no, keep going */ | 72 | "%3 = B[%1++] (Z);" /* get *ct */ |
57 | "jump.s 3f;\n" /* strings are equal */ | 73 | "CC = %2 == %3;" /* compare a byte */ |
58 | "2:\t%2 = %2 - %3;\n" /* *cs - *ct */ | 74 | "if ! cc jump 2f;" /* not equal, break out */ |
59 | "3:\n" | 75 | "CC = %2;" /* at end of cs? */ |
60 | : "+&a" (cs), "+&a" (ct), "=&d" (__res1), "=&d" (__res2) | 76 | "if cc jump 1b (bp);" /* no, keep going */ |
61 | : : "CC"); | 77 | "jump.s 3f;" /* strings are equal */ |
78 | "2:" | ||
79 | "%2 = %2 - %3;" /* *cs - *ct */ | ||
80 | "3:" | ||
81 | : "+&a" (cs), "+&a" (ct), "=&d" (__res1), "=&d" (__res2) | ||
82 | : | ||
83 | : "memory", "CC"); | ||
62 | 84 | ||
63 | return __res1; | 85 | return __res1; |
64 | } | 86 | } |
@@ -66,26 +88,35 @@ extern inline int strcmp(const char *cs, const char *ct) | |||
66 | #define __HAVE_ARCH_STRNCMP | 88 | #define __HAVE_ARCH_STRNCMP |
67 | extern inline int strncmp(const char *cs, const char *ct, size_t count) | 89 | extern inline int strncmp(const char *cs, const char *ct, size_t count) |
68 | { | 90 | { |
69 | char __res1, __res2; | 91 | /* need to use int's here so the char's in the assembly don't get |
92 | * sign extended incorrectly when we don't want them to be | ||
93 | */ | ||
94 | int __res1, __res2; | ||
70 | 95 | ||
71 | if (!count) | 96 | if (!count) |
72 | return 0; | 97 | return 0; |
73 | __asm__ | 98 | |
74 | ("1:\t%3 = B[%0++] (Z);\n\t" /* get *cs */ | 99 | __asm__ __volatile__ ( |
75 | "%4 = B[%1++] (Z);\n\t" /* get *ct */ | 100 | "1:" |
76 | "CC = %3 == %4;\n\t" /* compare a byte */ | 101 | "%3 = B[%0++] (Z);" /* get *cs */ |
77 | "if ! cc jump 3f;\n\t" /* not equal, break out */ | 102 | "%4 = B[%1++] (Z);" /* get *ct */ |
78 | "CC = %3;\n\t" /* at end of cs? */ | 103 | "CC = %3 == %4;" /* compare a byte */ |
79 | "if ! cc jump 4f;\n\t" /* yes, all done */ | 104 | "if ! cc jump 3f;" /* not equal, break out */ |
80 | "%2 += -1;\n\t" /* no, adjust count */ | 105 | "CC = %3;" /* at end of cs? */ |
81 | "CC = %2 == 0;\n\t" | 106 | "if ! cc jump 4f;" /* yes, all done */ |
82 | "if ! cc jump 1b;\n" /* more to do, keep going */ | 107 | "%2 += -1;" /* no, adjust count */ |
83 | "2:\t%3 = 0;\n\t" /* strings are equal */ | 108 | "CC = %2 == 0;" |
84 | "jump.s 4f;\n" | 109 | "if ! cc jump 1b;" /* more to do, keep going */ |
85 | "3:\t%3 = %3 - %4;\n" /* *cs - *ct */ | 110 | "2:" |
86 | "4:" | 111 | "%3 = 0;" /* strings are equal */ |
87 | : "+&a" (cs), "+&a" (ct), "+&da" (count), "=&d" (__res1), "=&d" (__res2) | 112 | "jump.s 4f;" |
88 | : : "CC"); | 113 | "3:" |
114 | "%3 = %3 - %4;" /* *cs - *ct */ | ||
115 | "4:" | ||
116 | : "+&a" (cs), "+&a" (ct), "+&da" (count), "=&d" (__res1), "=&d" (__res2) | ||
117 | : | ||
118 | : "memory", "CC"); | ||
119 | |||
89 | return __res1; | 120 | return __res1; |
90 | } | 121 | } |
91 | 122 | ||