diff options
author | Thomas Martitz <kugel@rockbox.org> | 2012-01-07 19:56:09 +0100 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2012-01-22 18:46:45 +0100 |
commit | a035261089403de259e74ce4dd196e2715138ed2 (patch) | |
tree | 440d75109a7ebfefef2a58076b38b1bfe9db8f63 /firmware/asm/m68k/strlen.S | |
parent | 8e8e978de6b6283b66a6829fa8c5e3b94674ce7d (diff) | |
download | rockbox-a035261089403de259e74ce4dd196e2715138ed2.tar.gz rockbox-a035261089403de259e74ce4dd196e2715138ed2.zip |
Move optimized memcpy and friends and strlen to firmware/asm,
using the new automatic-asm-picking infrastructure.
Diffstat (limited to 'firmware/asm/m68k/strlen.S')
-rw-r--r-- | firmware/asm/m68k/strlen.S | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/firmware/asm/m68k/strlen.S b/firmware/asm/m68k/strlen.S new file mode 100644 index 0000000000..765969da04 --- /dev/null +++ b/firmware/asm/m68k/strlen.S | |||
@@ -0,0 +1,71 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Nils Wallménius | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | /* size_t strlen(const char *str) */ | ||
23 | |||
24 | .section .text,"ax",@progbits | ||
25 | .align 2 | ||
26 | .globl strlen | ||
27 | .type strlen, @function | ||
28 | |||
29 | strlen: | ||
30 | move.l 4(%sp), %a0 /* %a0 = *str */ | ||
31 | move.l %a0, %a1 /* %a1 = start address */ | ||
32 | move.l %a0, %d0 | ||
33 | andi.l #3, %d0 /* %d0 = %a0 & 3 */ | ||
34 | beq.b 1f /* already aligned */ | ||
35 | jmp.l (-2,%pc,%d0.l*4) | ||
36 | tst.b (%a0)+ | ||
37 | beq.b .done | ||
38 | tst.b (%a0)+ | ||
39 | beq.b .done | ||
40 | tst.b (%a0)+ | ||
41 | beq.b .done | ||
42 | |||
43 | 1: | ||
44 | move.l (%a0)+, %d0 /* load %d0 increment %a0 */ | ||
45 | /* use trick to test the whole word for null bytes */ | ||
46 | move.l %d0, %d1 | ||
47 | subi.l #0x01010101, %d1 | ||
48 | not.l %d0 | ||
49 | and.l %d1, %d0 | ||
50 | andi.l #0x80808080, %d0 | ||
51 | beq.b 1b /* if the test was false repeat */ | ||
52 | |||
53 | /* ok, so the last word contained a 0 byte, test individual bytes */ | ||
54 | subq.l #4, %a0 | ||
55 | tst.b (%a0)+ | ||
56 | beq.b .done | ||
57 | tst.b (%a0)+ | ||
58 | beq.b .done | ||
59 | tst.b (%a0)+ | ||
60 | beq.b .done | ||
61 | /* last byte must be 0 so we don't need to load it, so we don't increment a0 | ||
62 | so we jump past the subq instr */ | ||
63 | .word 0x51fa /* trapf.w, shadow next instr */ | ||
64 | |||
65 | .done: | ||
66 | subq.l #1, %a0 /* %a0 is 1 too large due to the last increment */ | ||
67 | sub.l %a1, %a0 /* how many times did we repeat? */ | ||
68 | move.l %a0, %d0 /* return value in %d0 */ | ||
69 | rts | ||
70 | .size strlen, .-strlen | ||
71 | |||