diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-01-22 13:18:33 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-01-22 13:18:33 +0000 |
commit | 78826de04548551bfd9c3088701cba600a00a3a7 (patch) | |
tree | 09efa15d06be3a2bc707019967e3ad837f2839fb /firmware | |
parent | 0310f16005a1e98c441221bc0f0f7586d0b19763 (diff) | |
download | rockbox-78826de04548551bfd9c3088701cba600a00a3a7.tar.gz rockbox-78826de04548551bfd9c3088701cba600a00a3a7.zip |
Assembler optimized strlen() for SH1, both smaller & faster. Moved strlen() into IRAM.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5629 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 4 | ||||
-rw-r--r-- | firmware/common/strlen.c | 6 | ||||
-rwxr-xr-x | firmware/common/strlen_a.S | 94 |
3 files changed, 103 insertions, 1 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index e08d986ec1..cdd2271ba8 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -21,7 +21,11 @@ common/strcat.c | |||
21 | common/strchr.c | 21 | common/strchr.c |
22 | common/strcmp.c | 22 | common/strcmp.c |
23 | common/strcpy.c | 23 | common/strcpy.c |
24 | #if CONFIG_CPU == SH7034 | ||
25 | common/strlen_a.S | ||
26 | #else | ||
24 | common/strlen.c | 27 | common/strlen.c |
28 | #endif | ||
25 | common/strncmp.c | 29 | common/strncmp.c |
26 | common/strncpy.c | 30 | common/strncpy.c |
27 | common/strrchr.c | 31 | common/strrchr.c |
diff --git a/firmware/common/strlen.c b/firmware/common/strlen.c index 4249e14c78..932567c181 100644 --- a/firmware/common/strlen.c +++ b/firmware/common/strlen.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | FUNCTION | 2 | FUNCTION |
3 | <<strlen>>---character string length | 3 | <<strlen>>---character string length |
4 | 4 | ||
@@ -55,6 +55,10 @@ QUICKREF | |||
55 | 55 | ||
56 | size_t | 56 | size_t |
57 | _DEFUN (strlen, (str), | 57 | _DEFUN (strlen, (str), |
58 | _CONST char *str) __attribute__ ((section (".icode"))); | ||
59 | |||
60 | size_t | ||
61 | _DEFUN (strlen, (str), | ||
58 | _CONST char *str) | 62 | _CONST char *str) |
59 | { | 63 | { |
60 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) | 64 | #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) |
diff --git a/firmware/common/strlen_a.S b/firmware/common/strlen_a.S new file mode 100755 index 0000000000..34837605ac --- /dev/null +++ b/firmware/common/strlen_a.S | |||
@@ -0,0 +1,94 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 by Jens Arnold | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "config.h" | ||
20 | |||
21 | .section .icode,"ax",@progbits | ||
22 | |||
23 | .align 2 | ||
24 | .global _strlen | ||
25 | .type _strlen,@function | ||
26 | |||
27 | /* Works out the length of a string | ||
28 | * This version is optimized for speed | ||
29 | * | ||
30 | * arguments: | ||
31 | * r4 - start address | ||
32 | * | ||
33 | * return value: | ||
34 | * r0 - string length | ||
35 | * | ||
36 | * register usage: | ||
37 | * r0 - current address | ||
38 | * r1 - current value (byte/long) | ||
39 | * r2 - mask for alignment / zero (for cmp/str) | ||
40 | * r4 - start address | ||
41 | * | ||
42 | */ | ||
43 | |||
44 | _strlen: | ||
45 | mov r4,r0 /* r0 = start address */ | ||
46 | tst #3,r0 /* long aligned? */ | ||
47 | bt .start_l /* yes, jump directly to the longword loop */ | ||
48 | |||
49 | /* not long aligned: check the first 3 bytes */ | ||
50 | mov.b @r0+,r1 /* fetch first byte */ | ||
51 | tst r1,r1 /* byte == 0 ? */ | ||
52 | bt .hitzero /* yes, string end found */ | ||
53 | mov.b @r0+,r1 /* fetch second byte */ | ||
54 | mov #3,r2 /* prepare mask: r2 = 0..00000011b */ | ||
55 | tst r1,r1 /* byte == 0 ? */ | ||
56 | bt .hitzero /* yes, string end found */ | ||
57 | mov.b @r0+,r1 /* fetch third byte */ | ||
58 | not r2,r2 /* prepare mask: r2 = 1..11111100b */ | ||
59 | tst r1,r1 /* byte == 0 ? */ | ||
60 | bt .hitzero /* yes, string end found */ | ||
61 | |||
62 | /* not yet found, fall through into longword loop */ | ||
63 | and r2,r0 /* align down to long bound */ | ||
64 | |||
65 | /* main loop: check longwords */ | ||
66 | .start_l: | ||
67 | mov #0,r2 /* zero longword for cmp/str */ | ||
68 | .loop_l: | ||
69 | mov.l @r0+,r1 /* fetch long word */ | ||
70 | cmp/str r1,r2 /* any zero byte within? */ | ||
71 | bf .loop_l /* no, loop */ | ||
72 | add #-4,r0 /* set address back to start of this longword */ | ||
73 | |||
74 | /* the last longword contains the string end: figure out the byte */ | ||
75 | mov.b @r0+,r1 /* fetch first byte */ | ||
76 | tst r1,r1 /* byte == 0 ? */ | ||
77 | bt .hitzero /* yes, string end found */ | ||
78 | mov.b @r0+,r1 /* fetch second byte */ | ||
79 | tst r1,r1 /* byte == 0 ? */ | ||
80 | bt .hitzero /* yes, string end found */ | ||
81 | mov.b @r0+,r1 /* fetch third byte */ | ||
82 | tst r1,r1 /* byte == 0 ? */ | ||
83 | bt .hitzero /* yes, string end found */ | ||
84 | rts /* must be the fourth byte */ | ||
85 | sub r4,r0 /* len = string_end - string_start */ | ||
86 | |||
87 | .hitzero: | ||
88 | add #-1,r0 /* undo address increment */ | ||
89 | rts | ||
90 | sub r4,r0 /* len = string_end - string_start */ | ||
91 | |||
92 | .end: | ||
93 | .size _strlen,.end-_strlen | ||
94 | |||