summaryrefslogtreecommitdiff
path: root/include/linux/math.h
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-08-01 20:18:33 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-08-01 22:13:03 -0400
commit87179c7a6e2a210ea57951d444a3055e883d08fa (patch)
tree3445e8b5d6724518cbc6f659f9d0b0ff59b08bfa /include/linux/math.h
parent2d7982de784b24e24baa20eee0a97dea451b8fa7 (diff)
Update bcachefs sources to 33a60d9b05 bcachefs: Assorted fixes for clang
Diffstat (limited to 'include/linux/math.h')
-rw-r--r--include/linux/math.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/math.h b/include/linux/math.h
index db7cdd23..85c8c8aa 100644
--- a/include/linux/math.h
+++ b/include/linux/math.h
@@ -153,4 +153,19 @@ static inline u32 int_sqrt64(u64 x)
}
#endif
+#define abs(x) __abs_choose_expr(x, long long, \
+ __abs_choose_expr(x, long, \
+ __abs_choose_expr(x, int, \
+ __abs_choose_expr(x, short, \
+ __abs_choose_expr(x, char, \
+ __builtin_choose_expr( \
+ __builtin_types_compatible_p(typeof(x), char), \
+ (char)({ signed char __x = (x); __x<0?-__x:__x; }), \
+ ((void)0)))))))
+
+#define __abs_choose_expr(x, type, other) __builtin_choose_expr( \
+ __builtin_types_compatible_p(typeof(x), signed type) || \
+ __builtin_types_compatible_p(typeof(x), unsigned type), \
+ ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other)
+
#endif /* _LINUX_MATH_H */