lkml.org 
[lkml]   [2018]   [Apr]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH 08/45] C++: Implement abs() as an inline template function
From
Date
Implement abs() as an C++ inline template function as that greatly
simplifies the source.

Signed-off-by: David Howells <dhowells@redhat.com>
---

include/linux/kernel.h | 19 +++++--------------
1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index e779a7487c34..59089f76c7d8 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -246,20 +246,11 @@ extern int _cond_resched(void);
*
* Return: an absolute value of x.
*/
-#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)
+template<typename T>
+static inline T abs(T v)
+{
+ return v < 0 ? -v : v;
+}

/**
* reciprocal_scale - "scale" a value into range [0, ep_ro)
\
 
 \ /
  Last update: 2018-04-01 23:03    [W:0.151 / U:6.448 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site