diff options
Diffstat (limited to 'firmware/asm')
-rw-r--r-- | firmware/asm/ffs.c | 29 | ||||
-rw-r--r-- | firmware/asm/m68k/ffs.S | 4 |
2 files changed, 9 insertions, 24 deletions
diff --git a/firmware/asm/ffs.c b/firmware/asm/ffs.c index f68a9cef8c..6826f42e94 100644 --- a/firmware/asm/ffs.c +++ b/firmware/asm/ffs.c | |||
@@ -21,9 +21,7 @@ | |||
21 | #include "config.h" | 21 | #include "config.h" |
22 | #include <inttypes.h> | 22 | #include <inttypes.h> |
23 | 23 | ||
24 | /* find_first_set_bit() - this is a C version of the ffs algorithm devised | 24 | /* |
25 | * by D.Seal and posted to comp.sys.arm on 16 Feb 1994. | ||
26 | * | ||
27 | * Find the index of the least significant set bit in the word. | 25 | * Find the index of the least significant set bit in the word. |
28 | * return values: | 26 | * return values: |
29 | * 0 - bit 0 is set | 27 | * 0 - bit 0 is set |
@@ -32,25 +30,12 @@ | |||
32 | * 31 - bit 31 is set | 30 | * 31 - bit 31 is set |
33 | * 32 - no bits set | 31 | * 32 - no bits set |
34 | */ | 32 | */ |
35 | |||
36 | /* Table shared with assembly code */ | ||
37 | const uint8_t L_ffs_table[64] ICONST_ATTR = | ||
38 | { | ||
39 | /* 0 1 2 3 4 5 6 7 */ | ||
40 | /* ----------------------------------------- */ | ||
41 | 32, 0, 1, 12, 2, 6, 0, 13, /* 0- 7 */ | ||
42 | 3, 0, 7, 0, 0, 0, 0, 14, /* 8-15 */ | ||
43 | 10, 4, 0, 0, 8, 0, 0, 25, /* 16-23 */ | ||
44 | 0, 0, 0, 0, 0, 21, 27, 15, /* 24-31 */ | ||
45 | 31, 11, 5, 0, 0, 0, 0, 0, /* 32-39 */ | ||
46 | 9, 0, 0, 24, 0, 0, 20, 26, /* 40-47 */ | ||
47 | 30, 0, 0, 0, 0, 23, 0, 19, /* 48-55 */ | ||
48 | 29, 0, 22, 18, 28, 17, 16, 0, /* 56-63 */ | ||
49 | }; | ||
50 | |||
51 | #if !defined(CPU_COLDFIRE) | ||
52 | int find_first_set_bit(uint32_t val) | 33 | int find_first_set_bit(uint32_t val) |
53 | { | 34 | { |
54 | return L_ffs_table[((val & -val)*0x0450fbaf) >> 26]; | 35 | if (val == 0) |
36 | return 32; | ||
37 | |||
38 | /* __builtin_ffs(l(l)): Returns one plus the index of the least significant | ||
39 | 1-bit of x, or if x is zero, returns zero. */ | ||
40 | return __builtin_ffs(val) - 1; | ||
55 | } | 41 | } |
56 | #endif | ||
diff --git a/firmware/asm/m68k/ffs.S b/firmware/asm/m68k/ffs.S index 2a39ae5bcd..87421ffe10 100644 --- a/firmware/asm/m68k/ffs.S +++ b/firmware/asm/m68k/ffs.S | |||
@@ -61,6 +61,7 @@ find_first_set_bit: | |||
61 | | the top 24 bits of d0 are 0 so just load the value over it | 61 | | the top 24 bits of d0 are 0 so just load the value over it |
62 | move.b (%a0, %d1.l), %d0 | | 62 | move.b (%a0, %d1.l), %d0 | |
63 | rts | | 63 | rts | |
64 | .size find_first_set_bit, .-find_first_set_bit | ||
64 | 65 | ||
65 | .section .irodata | 66 | .section .irodata |
66 | L_ffs_table: | 67 | L_ffs_table: |
@@ -74,5 +75,4 @@ L_ffs_table: | |||
74 | .byte 9, 0, 0, 24, 0, 0, 20, 26 | 40-47 | 75 | .byte 9, 0, 0, 24, 0, 0, 20, 26 | 40-47 |
75 | .byte 30, 0, 0, 0, 0, 23, 0, 19 | 48-55 | 76 | .byte 30, 0, 0, 0, 0, 23, 0, 19 | 48-55 |
76 | .byte 29, 0, 22, 18, 28, 17, 16, 0 | 56-63 | 77 | .byte 29, 0, 22, 18, 28, 17, 16, 0 | 56-63 |
77 | 78 | .size L_ffs_table, .-L_ffs_table | |
78 | .size find_first_set_bit, .-find_first_set_bit | ||