lkml.org 
[lkml]   [2010]   [Aug]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 1/2] kernel.h: add {min,max}3 macros
    Date
    Introduce two additional min/max macros to compare three operands.
    This will save some cycles as well as some bytes on the stack and last
    but not least more pleasing as macro nesting.

    Signed-off-by: Hagen Paul Pfeifer <hagen@jauu.net>
    Cc: Andrew Morton <akpm@linux-foundation.org>
    Cc: Joe Perches <joe@perches.com>
    Cc: Ingo Molnar <mingo@elte.hu>
    ---
    include/linux/kernel.h | 16 ++++++++++++++++
    1 files changed, 16 insertions(+), 0 deletions(-)

    diff --git a/include/linux/kernel.h b/include/linux/kernel.h
    index 2b0a35e..9a9b52c 100644
    --- a/include/linux/kernel.h
    +++ b/include/linux/kernel.h
    @@ -640,6 +640,22 @@ static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
    (void) (&_max1 == &_max2); \
    _max1 > _max2 ? _max1 : _max2; })

    +#define min3(x, y, z) ({ \
    + typeof(x) _min1 = (x); \
    + typeof(y) _min2 = (y); \
    + typeof(z) _min3 = (z); \
    + (void) (&_min1 == &_min2 == &_min3); \
    + _min1 < _min2 ? (_min1 < _min3 ? _min1 : _min3) : \
    + (_min2 < _min3 ? _min2 : _min3); })
    +
    +#define max3(x, y, z) ({ \
    + typeof(x) _max1 = (x); \
    + typeof(y) _max2 = (y); \
    + typeof(z) _max3 = (z); \
    + (void) (&_max1 == &_max2 == &_max3); \
    + _max1 > _max2 ? (_max1 > _max3 ? _max1 : _max3) : \
    + (_max2 > _max3 ? _max2 : _max3); })
    +
    /**
    * clamp - return a value clamped to a given range with strict typechecking
    * @val: current value
    --
    1.7.2.1.95.g3d045.dirty


    \
     
     \ /
      Last update: 2010-08-19 19:29    [W:0.022 / U:0.092 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site