summaryrefslogtreecommitdiff
path: root/include/linux/overflow-arith.h
diff options
context:
space:
mode:
authorHannes Frederic Sowa <hannes@stressinduktion.org>2015-10-16 12:32:42 +0300
committerDavid S. Miller <davem@davemloft.net>2015-10-23 12:49:35 +0300
commit79907146fb5b1778035870db895fb2bf64061284 (patch)
treede48a8a1009dc237100ccdfff795da27aae4e61c /include/linux/overflow-arith.h
parentc80dbe04612986fd6104b4a1be21681b113b5ac9 (diff)
downloadlinux-79907146fb5b1778035870db895fb2bf64061284.tar.xz
overflow-arith: begin to add support for overflow builtin functions
The idea of the overflow-arith.h header is to collect overflow checking functions in one central place. If gcc compiler supports the __builtin_overflow_* builtins we use them because they might give better performance, otherwise the code falls back to normal overflow checking functions. The builtin_overflow functions are supported by gcc-5 and clang. The matter of supporting clang is to just provide a corresponding CC_HAVE_BUILTIN_OVERFLOW, because the specific overflow checking builtins don't differ between gcc and clang. I just provide overflow_usub function here as I intend this to get merged into net, more functions will definitely follow as they are needed. Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/overflow-arith.h')
-rw-r--r--include/linux/overflow-arith.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/overflow-arith.h b/include/linux/overflow-arith.h
new file mode 100644
index 000000000000..e12ccf854a70
--- /dev/null
+++ b/include/linux/overflow-arith.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <linux/kernel.h>
+
+#ifdef CC_HAVE_BUILTIN_OVERFLOW
+
+#define overflow_usub __builtin_usub_overflow
+
+#else
+
+static inline bool overflow_usub(unsigned int a, unsigned int b,
+ unsigned int *res)
+{
+ *res = a - b;
+ return *res > a ? true : false;
+}
+
+#endif