]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/linux/kernel.h
Merge branch 'akpm/master'
[karo-tx-linux.git] / include / linux / kernel.h
index 2c13f747ac2e8727b090f26f085f8cc79972c6b3..350dfb08aee36bdce54c8ecf683dd7afed7b46ab 100644 (file)
@@ -200,28 +200,28 @@ extern int _cond_resched(void);
 
 #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
 
-/*
- * abs() handles unsigned and signed longs, ints, shorts and chars.  For all
- * input types abs() returns a signed long.
- * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64()
- * for those.
+/**
+ * abs - return absolute value of an argument
+ * @x: the value.  If it is unsigned type, it is converted to signed type first
+ *   (s64, long or int depending on its size).
+ *
+ * Return: an absolute value of x.  If x is 64-bit, macro's return type is s64,
+ *   otherwise it is signed long.
  */
-#define abs(x) ({                                              \
-               long ret;                                       \
-               if (sizeof(x) == sizeof(long)) {                \
-                       long __x = (x);                         \
-                       ret = (__x < 0) ? -__x : __x;           \
-               } else {                                        \
-                       int __x = (x);                          \
-                       ret = (__x < 0) ? -__x : __x;           \
-               }                                               \
-               ret;                                            \
-       })
-
-#define abs64(x) ({                            \
-               s64 __x = (x);                  \
-               (__x < 0) ? -__x : __x;         \
-       })
+#define abs(x) __builtin_choose_expr(sizeof(x) == sizeof(s64), ({      \
+               s64 __x = (x);                                          \
+               (__x < 0) ? -__x : __x;                                 \
+       }), ({                                                          \
+               long ret;                                               \
+               if (sizeof(x) == sizeof(long)) {                        \
+                       long __x = (x);                                 \
+                       ret = (__x < 0) ? -__x : __x;                   \
+               } else {                                                \
+                       int __x = (x);                                  \
+                       ret = (__x < 0) ? -__x : __x;                   \
+               }                                                       \
+               ret;                                                    \
+       }))
 
 /**
  * reciprocal_scale - "scale" a value into range [0, ep_ro)