diff options
author | Andrew Mahone <andrew.mahone@gmail.com> | 2009-06-06 00:00:58 +0000 |
---|---|---|
committer | Andrew Mahone <andrew.mahone@gmail.com> | 2009-06-06 00:00:58 +0000 |
commit | de7c5711c5d67e7e69386d6e35e42c8ce15de69b (patch) | |
tree | 22f58338387ae6ac662e43fe83ef60105f97d627 | |
parent | fe72c890a76c1f227ef749adbdcf964bb166d74c (diff) | |
download | rockbox-de7c5711c5d67e7e69386d6e35e42c8ce15de69b.tar.gz rockbox-de7c5711c5d67e7e69386d6e35e42c8ce15de69b.zip |
Add a system-wide BIT_N macro, implemented via an LUT on SH, and use it in the TAGCACHE_IS_* macros in place of per-set LUTs, removing duplication of data between those LUTs and the mask values used on other targets.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21195 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/tagcache.c | 30 | ||||
-rw-r--r-- | apps/tagcache.h | 8 | ||||
-rw-r--r-- | firmware/export/system.h | 4 | ||||
-rw-r--r-- | firmware/target/sh/system-sh.c | 11 | ||||
-rw-r--r-- | firmware/target/sh/system-target.h | 7 |
5 files changed, 29 insertions, 31 deletions
diff --git a/apps/tagcache.c b/apps/tagcache.c index 3d0ab7fbd3..afe55f18a2 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -108,29 +108,10 @@ static long tempbuf_left; /* Buffer space left. */ | |||
108 | static long tempbuf_pos; | 108 | static long tempbuf_pos; |
109 | 109 | ||
110 | #define SORTED_TAGS_COUNT 8 | 110 | #define SORTED_TAGS_COUNT 8 |
111 | #ifdef CPU_SH /* SH lacks a variable shift instruction */ | 111 | #define TAGCACHE_IS_UNIQUE(tag) (BIT_N(tag) & TAGCACHE_UNIQUE_TAGS) |
112 | /* Numeric tags (we can use these tags with conditional clauses). */ | 112 | #define TAGCACHE_IS_SORTED(tag) (BIT_N(tag) & TAGCACHE_SORTED_TAGS) |
113 | const char tagcache_numeric_tags[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, | 113 | #define TAGCACHE_IS_NUMERIC_OR_NONUNIQUE(tag) \ |
114 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, | 114 | (BIT_N(tag) & (TAGCACHE_NUMERIC_TAGS | ~TAGCACHE_UNIQUE_TAGS)) |
115 | 1, 1, 1, 1, 1 }; | ||
116 | |||
117 | /* Uniqued tags (we can use these tags with filters and conditional clauses). */ | ||
118 | static const char tagcache_unique_tags[] = { 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, | ||
119 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
120 | 0, 0, 0, 0, 0 }; | ||
121 | |||
122 | /* Tags we want to get sorted (loaded to the tempbuf). */ | ||
123 | static const char tagcache_sorted_tags[] = { 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, | ||
124 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
125 | 0, 0, 0, 0, 0 }; | ||
126 | |||
127 | #define TAGCACHE_IS_UNIQUE(tag) ((bool)tagcache_unique_tags[tag]) | ||
128 | #define TAGCACHE_IS_SORTED(tag) ((bool)tagcache_sorted_tags[tag]) | ||
129 | |||
130 | #else | ||
131 | #define TAGCACHE_IS_UNIQUE(tag) ((1LU << tag) & TAGCACHE_UNIQUE_TAGS) | ||
132 | #define TAGCACHE_IS_SORTED(tag) ((1LU << tag) & TAGCACHE_SORTED_TAGS) | ||
133 | |||
134 | /* Tags we want to get sorted (loaded to the tempbuf). */ | 115 | /* Tags we want to get sorted (loaded to the tempbuf). */ |
135 | #define TAGCACHE_SORTED_TAGS ((1LU << tag_artist) | (1LU << tag_album) | \ | 116 | #define TAGCACHE_SORTED_TAGS ((1LU << tag_artist) | (1LU << tag_album) | \ |
136 | (1LU << tag_genre) | (1LU << tag_composer) | (1LU << tag_comment) | \ | 117 | (1LU << tag_genre) | (1LU << tag_composer) | (1LU << tag_comment) | \ |
@@ -140,7 +121,6 @@ static const char tagcache_sorted_tags[] = { 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, | |||
140 | #define TAGCACHE_UNIQUE_TAGS ((1LU << tag_artist) | (1LU << tag_album) | \ | 121 | #define TAGCACHE_UNIQUE_TAGS ((1LU << tag_artist) | (1LU << tag_album) | \ |
141 | (1LU << tag_genre) | (1LU << tag_composer) | (1LU << tag_comment) | \ | 122 | (1LU << tag_genre) | (1LU << tag_composer) | (1LU << tag_comment) | \ |
142 | (1LU << tag_albumartist) | (1LU << tag_grouping)) | 123 | (1LU << tag_albumartist) | (1LU << tag_grouping)) |
143 | #endif | ||
144 | 124 | ||
145 | /* String presentation of the tags defined in tagcache.h. Must be in correct order! */ | 125 | /* String presentation of the tags defined in tagcache.h. Must be in correct order! */ |
146 | static const char *tags_str[] = { "artist", "album", "genre", "title", | 126 | static const char *tags_str[] = { "artist", "album", "genre", "title", |
@@ -1248,7 +1228,7 @@ bool tagcache_search_add_filter(struct tagcache_search *tcs, | |||
1248 | if (tcs->filter_count == TAGCACHE_MAX_FILTERS) | 1228 | if (tcs->filter_count == TAGCACHE_MAX_FILTERS) |
1249 | return false; | 1229 | return false; |
1250 | 1230 | ||
1251 | if (!TAGCACHE_IS_UNIQUE(tag) || TAGCACHE_IS_NUMERIC(tag)) | 1231 | if (TAGCACHE_IS_NUMERIC_OR_NONUNIQUE(tag)) |
1252 | return false; | 1232 | return false; |
1253 | 1233 | ||
1254 | tcs->filter_tag[tcs->filter_count] = tag; | 1234 | tcs->filter_tag[tcs->filter_count] = tag; |
diff --git a/apps/tagcache.h b/apps/tagcache.h index d7047178e1..f2b975c566 100644 --- a/apps/tagcache.h +++ b/apps/tagcache.h | |||
@@ -22,6 +22,7 @@ | |||
22 | #ifndef _TAGCACHE_H | 22 | #ifndef _TAGCACHE_H |
23 | #define _TAGCACHE_H | 23 | #define _TAGCACHE_H |
24 | 24 | ||
25 | #include "system.h" | ||
25 | #include "metadata.h" | 26 | #include "metadata.h" |
26 | 27 | ||
27 | /** | 28 | /** |
@@ -103,12 +104,7 @@ enum tag_type { tag_artist = 0, tag_album, tag_genre, tag_title, | |||
103 | (1LU << tag_virt_playtime_min) | (1LU << tag_virt_playtime_sec) | \ | 104 | (1LU << tag_virt_playtime_min) | (1LU << tag_virt_playtime_sec) | \ |
104 | (1LU << tag_virt_entryage) | (1LU << tag_virt_autoscore)) | 105 | (1LU << tag_virt_entryage) | (1LU << tag_virt_autoscore)) |
105 | 106 | ||
106 | #ifdef CPU_SH | 107 | #define TAGCACHE_IS_NUMERIC(tag) (BIT_N(tag) & TAGCACHE_NUMERIC_TAGS) |
107 | extern const char tagcache_numeric_tags[]; | ||
108 | #define TAGCACHE_IS_NUMERIC(tag) ((bool)tagcache_numeric_tags[tag]) | ||
109 | #else | ||
110 | #define TAGCACHE_IS_NUMERIC(tag) ((1LU << tag) & TAGCACHE_NUMERIC_TAGS) | ||
111 | #endif | ||
112 | 108 | ||
113 | /* Flags */ | 109 | /* Flags */ |
114 | #define FLAG_DELETED 0x0001 /* Entry has been removed from db */ | 110 | #define FLAG_DELETED 0x0001 /* Entry has been removed from db */ |
diff --git a/firmware/export/system.h b/firmware/export/system.h index b44600d2c2..489ed8dc12 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h | |||
@@ -266,6 +266,10 @@ static inline uint32_t swap_odd_even32(uint32_t value) | |||
266 | 266 | ||
267 | #endif /* !SIMULATOR */ | 267 | #endif /* !SIMULATOR */ |
268 | 268 | ||
269 | #ifndef TEST_BIT_N | ||
270 | #define TEST_BIT_N(n, mask) ((1UL << (n)) & (mask)) | ||
271 | #endif | ||
272 | |||
269 | /* Declare this as HIGHEST_IRQ_LEVEL if they don't differ */ | 273 | /* Declare this as HIGHEST_IRQ_LEVEL if they don't differ */ |
270 | #ifndef DISABLE_INTERRUPTS | 274 | #ifndef DISABLE_INTERRUPTS |
271 | #define DISABLE_INTERRUPTS HIGHEST_IRQ_LEVEL | 275 | #define DISABLE_INTERRUPTS HIGHEST_IRQ_LEVEL |
diff --git a/firmware/target/sh/system-sh.c b/firmware/target/sh/system-sh.c index 02af40282f..7779c975a7 100644 --- a/firmware/target/sh/system-sh.c +++ b/firmware/target/sh/system-sh.c | |||
@@ -27,6 +27,17 @@ | |||
27 | #include "font.h" | 27 | #include "font.h" |
28 | #include "led.h" | 28 | #include "led.h" |
29 | 29 | ||
30 | const unsigned bit_n_table[32] = { | ||
31 | 1LU<< 0, 1LU<< 1, 1LU<< 2, 1LU<< 3, | ||
32 | 1LU<< 4, 1LU<< 5, 1LU<< 6, 1LU<< 7, | ||
33 | 1LU<< 8, 1LU<< 9, 1LU<<10, 1LU<<11, | ||
34 | 1LU<<12, 1LU<<13, 1LU<<14, 1LU<<15, | ||
35 | 1LU<<16, 1LU<<17, 1LU<<18, 1LU<<19, | ||
36 | 1LU<<20, 1LU<<21, 1LU<<22, 1LU<<23, | ||
37 | 1LU<<24, 1LU<<25, 1LU<<26, 1LU<<27, | ||
38 | 1LU<<28, 1LU<<29, 1LU<<30, 1LU<<31 | ||
39 | }; | ||
40 | |||
30 | static const char* const irqname[] = { | 41 | static const char* const irqname[] = { |
31 | "", "", "", "", "IllInstr", "", "IllSltIn","","", | 42 | "", "", "", "", "IllInstr", "", "IllSltIn","","", |
32 | "CPUAdrEr", "DMAAdrEr", "NMI", "UserBrk", | 43 | "CPUAdrEr", "DMAAdrEr", "NMI", "UserBrk", |
diff --git a/firmware/target/sh/system-target.h b/firmware/target/sh/system-target.h index 3c225fbb69..2568911a1e 100644 --- a/firmware/target/sh/system-target.h +++ b/firmware/target/sh/system-target.h | |||
@@ -126,4 +126,11 @@ static inline uint32_t swap_odd_even32(uint32_t value) | |||
126 | return value; | 126 | return value; |
127 | } | 127 | } |
128 | 128 | ||
129 | extern const unsigned bit_n_table[32]; | ||
130 | #define BIT_N(n) ( \ | ||
131 | __builtin_constant_p(n) \ | ||
132 | ? (1LU << (n)) \ | ||
133 | : bit_n_table[n] \ | ||
134 | ) | ||
135 | |||
129 | #endif /* SYSTEM_TARGET_H */ | 136 | #endif /* SYSTEM_TARGET_H */ |