summaryrefslogtreecommitdiff
path: root/firmware/asm/m68k
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2012-01-08 00:22:58 +0100
committerThomas Martitz <kugel@rockbox.org>2012-01-22 18:46:45 +0100
commitc94cf3b8885c8a9e192b95125ce4b8470a1aa3c3 (patch)
tree6ca83258616b00428b58e1e31c10dce020fbc310 /firmware/asm/m68k
parent5e9b62cd8ad4d38c7ca43c916b5bc831454bc267 (diff)
Move optimized ffs to firmware/asm, using the new automatic-asm-picking infrastructure.
Change-Id: I5e7bdc8be7de50ef604c16078857fff1b84650dc
Diffstat (limited to 'firmware/asm/m68k')
-rw-r--r--firmware/asm/m68k/ffs.S78
1 files changed, 78 insertions, 0 deletions
diff --git a/firmware/asm/m68k/ffs.S b/firmware/asm/m68k/ffs.S
new file mode 100644
index 0000000000..2a39ae5bcd
--- /dev/null
+++ b/firmware/asm/m68k/ffs.S
@@ -0,0 +1,78 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2008 by Michael Sevakis
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+ #include "config.h"
+
+/****************************************************************************
+ * int find_first_set_bit(uint32_t val);
+ *
+ * Find the index of the least significant set bit in the 32-bit word.
+ *
+ * return values:
+ * 0 - bit 0 is set
+ * 1 - bit 1 is set
+ * ...
+ * 31 - bit 31 is set
+ * 32 - no bits set
+ ****************************************************************************/
+ .text
+ .align 2
+ .global find_first_set_bit
+ .type find_first_set_bit,@function
+find_first_set_bit:
+ | this is a coldfire version of the ffs algorithm devised by D.Seal
+ | and posted to comp.sys.arm on 16 Feb 1994.
+ |
+ | Output modified to suit rockbox purposes.
+
+ | Standard trick to isolate bottom bit in r0 or 0 if r0 = 0 on entry
+ move.l 4(%sp), %d1 | %d1 = %d1 & -%d1
+ lea.l L_ffs_table, %a0 | %a0 = table address
+ move.l %d1, %d0 |
+ neg.l %d1 |
+ and.l %d0, %d1 |
+
+ | now %d1 has at most one set bit, call this X
+
+ move.l #0x0450fbaf, %d0 | %d0 = multiplier
+ mulu.l %d0, %d1 | %d1 = X * 0x0450fbaf
+
+ | now lookup in table indexed on top 6 bits of %d0
+ moveq.l #26, %d0 | %d0 = final shift count
+ lsr.l %d0, %d1 |
+
+ | the top 24 bits of d0 are 0 so just load the value over it
+ move.b (%a0, %d1.l), %d0 |
+ rts |
+
+ .section .irodata
+L_ffs_table:
+ | 0 1 2 3 4 5 6 7
+ |----------------------------------------------
+ .byte 32, 0, 1, 12, 2, 6, 0, 13 | 0- 7
+ .byte 3, 0, 7, 0, 0, 0, 0, 14 | 8-15
+ .byte 10, 4, 0, 0, 8, 0, 0, 25 | 16-23
+ .byte 0, 0, 0, 0, 0, 21, 27, 15 | 24-31
+ .byte 31, 11, 5, 0, 0, 0, 0, 0 | 32-39
+ .byte 9, 0, 0, 24, 0, 0, 20, 26 | 40-47
+ .byte 30, 0, 0, 0, 0, 23, 0, 19 | 48-55
+ .byte 29, 0, 22, 18, 28, 17, 16, 0 | 56-63
+
+ .size find_first_set_bit, .-find_first_set_bit