diff options
author | Thomas Martitz <kugel@rockbox.org> | 2009-08-03 01:38:58 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2009-08-03 01:38:58 +0000 |
commit | 85ece84b1c955e2304e8519eb40ad8212a32a3ba (patch) | |
tree | 2b70dd38cfa86f04028556eaaeff383e3afc381e | |
parent | af6060a987a2ad6ecdf62eb6b13dca61d65d7318 (diff) | |
download | rockbox-85ece84b1c955e2304e8519eb40ad8212a32a3ba.tar.gz rockbox-85ece84b1c955e2304e8519eb40ad8212a32a3ba.zip |
Remove various ABS() definitions with a single one using typeof (if using gcc) to avoid multiple evaluations of the input expressions. Speex still uses its own as I didn't want to change this imported code too much.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22129 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/codecs/lib/codeclib.h | 3 | ||||
-rw-r--r-- | apps/codecs/libspeex/arch.h | 1 | ||||
-rw-r--r-- | apps/gui/pitchscreen.c | 3 | ||||
-rw-r--r-- | apps/plugins/calculator.c | 1 | ||||
-rw-r--r-- | apps/plugins/chessbox/gnuchess.c | 2 | ||||
-rw-r--r-- | apps/plugins/invadrox.c | 5 | ||||
-rw-r--r-- | apps/plugins/lib/buflib.c | 7 | ||||
-rw-r--r-- | apps/plugins/spacerocks.c | 2 | ||||
-rw-r--r-- | firmware/include/stdlib.h | 10 |
9 files changed, 12 insertions, 22 deletions
diff --git a/apps/codecs/lib/codeclib.h b/apps/codecs/lib/codeclib.h index 52bf72f7dc..e7f45d3572 100644 --- a/apps/codecs/lib/codeclib.h +++ b/apps/codecs/lib/codeclib.h | |||
@@ -58,9 +58,6 @@ int strcmp(const char *, const char *); | |||
58 | 58 | ||
59 | void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); | 59 | void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); |
60 | 60 | ||
61 | #define abs(x) ((x)>0?(x):-(x)) | ||
62 | #define labs(x) abs(x) | ||
63 | |||
64 | /*MDCT library functions*/ | 61 | /*MDCT library functions*/ |
65 | 62 | ||
66 | extern void mdct_backward(int n, int32_t *in, int32_t *out); | 63 | extern void mdct_backward(int n, int32_t *in, int32_t *out); |
diff --git a/apps/codecs/libspeex/arch.h b/apps/codecs/libspeex/arch.h index 9f81e0c51e..35b5363837 100644 --- a/apps/codecs/libspeex/arch.h +++ b/apps/codecs/libspeex/arch.h | |||
@@ -80,6 +80,7 @@ | |||
80 | #include "speex/speex_types.h" | 80 | #include "speex/speex_types.h" |
81 | #endif | 81 | #endif |
82 | 82 | ||
83 | #undef ABS | ||
83 | #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ | 84 | #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ |
84 | #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ | 85 | #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ |
85 | #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */ | 86 | #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */ |
diff --git a/apps/gui/pitchscreen.c b/apps/gui/pitchscreen.c index 8215da2a97..78d049be10 100644 --- a/apps/gui/pitchscreen.c +++ b/apps/gui/pitchscreen.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <string.h> | 23 | #include <string.h> |
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #include <math.h> | 25 | #include <math.h> |
26 | #include <stdlib.h> /* for ABS() */ | ||
26 | #include "config.h" | 27 | #include "config.h" |
27 | #include "sprintf.h" | 28 | #include "sprintf.h" |
28 | #include "action.h" | 29 | #include "action.h" |
@@ -42,8 +43,6 @@ | |||
42 | #include "tdspeed.h" | 43 | #include "tdspeed.h" |
43 | #endif | 44 | #endif |
44 | 45 | ||
45 | #define ABS(x) ((x) > 0 ? (x) : -(x)) | ||
46 | |||
47 | #define ICON_BORDER 12 /* icons are currently 7x8, so add ~2 pixels */ | 46 | #define ICON_BORDER 12 /* icons are currently 7x8, so add ~2 pixels */ |
48 | /* on both sides when drawing */ | 47 | /* on both sides when drawing */ |
49 | 48 | ||
diff --git a/apps/plugins/calculator.c b/apps/plugins/calculator.c index 079a6e500c..3d0105e33d 100644 --- a/apps/plugins/calculator.c +++ b/apps/plugins/calculator.c | |||
@@ -102,7 +102,6 @@ PLUGIN_HEADER | |||
102 | #define X_5_POS (X_4_POS + REC_WIDTH) /* x5 = 110, column 111 left blank */ | 102 | #define X_5_POS (X_4_POS + REC_WIDTH) /* x5 = 110, column 111 left blank */ |
103 | 103 | ||
104 | #define SIGN(x) ((x)<0?-1:1) | 104 | #define SIGN(x) ((x)<0?-1:1) |
105 | #define ABS(x) ((x)<0?-(x):(x)) | ||
106 | 105 | ||
107 | /* variable button definitions */ | 106 | /* variable button definitions */ |
108 | #if CONFIG_KEYPAD == RECORDER_PAD | 107 | #if CONFIG_KEYPAD == RECORDER_PAD |
diff --git a/apps/plugins/chessbox/gnuchess.c b/apps/plugins/chessbox/gnuchess.c index b8fef724fc..5c30c6a6df 100644 --- a/apps/plugins/chessbox/gnuchess.c +++ b/apps/plugins/chessbox/gnuchess.c | |||
@@ -60,7 +60,7 @@ | |||
60 | #define maxdepth 30 | 60 | #define maxdepth 30 |
61 | #define true 1 | 61 | #define true 1 |
62 | #define false 0 | 62 | #define false 0 |
63 | #define absv(x) ((x) < 0 ? -(x) : (x)) | 63 | #define absv(x) (ABS(x)) |
64 | #define taxicab(a,b) (abs(column[a]-column[b]) + abs(row[a]-row[b])) | 64 | #define taxicab(a,b) (abs(column[a]-column[b]) + abs(row[a]-row[b])) |
65 | 65 | ||
66 | /* ---- Chess datatypes and variables ---- */ | 66 | /* ---- Chess datatypes and variables ---- */ |
diff --git a/apps/plugins/invadrox.c b/apps/plugins/invadrox.c index d07bf2878b..d424f1f4cb 100644 --- a/apps/plugins/invadrox.c +++ b/apps/plugins/invadrox.c | |||
@@ -167,11 +167,6 @@ PLUGIN_HEADER | |||
167 | #define UNUSED __attribute__ ((unused)) | 167 | #define UNUSED __attribute__ ((unused)) |
168 | #endif | 168 | #endif |
169 | 169 | ||
170 | #ifndef ABS | ||
171 | #define ABS(x) (((x) < 0) ? (-(x)) : (x)) | ||
172 | #endif | ||
173 | |||
174 | |||
175 | /* Defines common to all models */ | 170 | /* Defines common to all models */ |
176 | #define UFO_Y (SCORENUM_Y + FONT_HEIGHT + ALIEN_HEIGHT) | 171 | #define UFO_Y (SCORENUM_Y + FONT_HEIGHT + ALIEN_HEIGHT) |
177 | #define PLAYFIELD_Y (LCD_HEIGHT - SHIP_HEIGHT - 2) | 172 | #define PLAYFIELD_Y (LCD_HEIGHT - SHIP_HEIGHT - 2) |
diff --git a/apps/plugins/lib/buflib.c b/apps/plugins/lib/buflib.c index ddfc82c521..5d03ca4bb9 100644 --- a/apps/plugins/lib/buflib.c +++ b/apps/plugins/lib/buflib.c | |||
@@ -40,13 +40,6 @@ | |||
40 | * case that use a predefined context. | 40 | * case that use a predefined context. |
41 | */ | 41 | */ |
42 | 42 | ||
43 | #define ABS(x) \ | ||
44 | ({ \ | ||
45 | typeof(x) xtmp_abs_ = x; \ | ||
46 | xtmp_abs_ = xtmp_abs_ < 0 ? -xtmp_abs_ : xtmp_abs_; \ | ||
47 | xtmp_abs_; \ | ||
48 | }) | ||
49 | |||
50 | /* Initialize buffer manager */ | 43 | /* Initialize buffer manager */ |
51 | void | 44 | void |
52 | buflib_init(struct buflib_context *ctx, void *buf, size_t size) | 45 | buflib_init(struct buflib_context *ctx, void *buf, size_t size) |
diff --git a/apps/plugins/spacerocks.c b/apps/plugins/spacerocks.c index 7ceec16372..32d48862ae 100644 --- a/apps/plugins/spacerocks.c +++ b/apps/plugins/spacerocks.c | |||
@@ -246,8 +246,6 @@ PLUGIN_HEADER | |||
246 | #endif | 246 | #endif |
247 | #endif | 247 | #endif |
248 | 248 | ||
249 | #define ABS(x) ((x)>0?(x):-(x)) | ||
250 | |||
251 | #define RES MAX(LCD_WIDTH, LCD_HEIGHT) | 249 | #define RES MAX(LCD_WIDTH, LCD_HEIGHT) |
252 | #define LARGE_LCD RES >= 200 | 250 | #define LARGE_LCD RES >= 200 |
253 | #define ENEMY_MISSILE_SURVIVAL_LENGTH RES/2 | 251 | #define ENEMY_MISSILE_SURVIVAL_LENGTH RES/2 |
diff --git a/firmware/include/stdlib.h b/firmware/include/stdlib.h index 504b59247a..a287889c6a 100644 --- a/firmware/include/stdlib.h +++ b/firmware/include/stdlib.h | |||
@@ -35,7 +35,15 @@ void *realloc(void *, size_t); | |||
35 | void srand(unsigned int seed); | 35 | void srand(unsigned int seed); |
36 | int rand(void); | 36 | int rand(void); |
37 | 37 | ||
38 | #define abs(x) ((x)>0?(x):-(x)) | 38 | #ifndef ABS |
39 | #if defined(__GNUC__) | ||
40 | #define ABS(a) ({typeof (a) ___a = (a); ___a < 0 ? -___a: ___a; }) | ||
41 | #else | ||
42 | #define ABS(a) (((a) < 0) ? -(a) : (a)) | ||
43 | #endif /* __GNUC__ */ | ||
44 | #endif | ||
45 | |||
46 | #define abs(x) (ABS(x)) | ||
39 | #define labs(x) abs(x) | 47 | #define labs(x) abs(x) |
40 | 48 | ||
41 | #ifdef SIMULATOR | 49 | #ifdef SIMULATOR |