summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2009-08-03 01:38:58 +0000
committerThomas Martitz <kugel@rockbox.org>2009-08-03 01:38:58 +0000
commit85ece84b1c955e2304e8519eb40ad8212a32a3ba (patch)
tree2b70dd38cfa86f04028556eaaeff383e3afc381e /firmware
parentaf6060a987a2ad6ecdf62eb6b13dca61d65d7318 (diff)
downloadrockbox-85ece84b1c955e2304e8519eb40ad8212a32a3ba.tar.gz
rockbox-85ece84b1c955e2304e8519eb40ad8212a32a3ba.tar.bz2
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
Diffstat (limited to 'firmware')
-rw-r--r--firmware/include/stdlib.h10
1 files changed, 9 insertions, 1 deletions
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);
void srand(unsigned int seed);
int rand(void);
-#define abs(x) ((x)>0?(x):-(x))
+#ifndef ABS
+#if defined(__GNUC__)
+#define ABS(a) ({typeof (a) ___a = (a); ___a < 0 ? -___a: ___a; })
+#else
+#define ABS(a) (((a) < 0) ? -(a) : (a))
+#endif /* __GNUC__ */
+#endif
+
+#define abs(x) (ABS(x))
#define labs(x) abs(x)
#ifdef SIMULATOR