lkml.org 
[lkml]   [2010]   [Jan]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 22/37] move round_up/down to kernel.h
    On Fri, 15 Jan 2010, Yinghai Lu wrote:

    >
    > #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
    >
    > +/*
    > + * This looks more complex than it should be. But we need to
    > + * get the type for the ~ right in round_down (it needs to be
    > + * as wide as the result!), and we want to evaluate the macro
    > + * arguments just once each.
    > + */
    > +#define __round_mask(x,y) ((__typeof__(x))((y)-1))
    > +#define round_up(x,y) ((((x)-1) | __round_mask(x,y))+1)
    > +#define round_down(x,y) ((x) & ~__round_mask(x,y))
    > +
    > #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
    > #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
    > #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))

    Note the last two lines! We already have roundup(), DIV_ROUND_UP and
    DIV_ROUND_CLOSEST. Please integrate them properly. Maybe extract
    __round_mask() from all of them.



    \
     
     \ /
      Last update: 2010-01-19 19:01    [W:4.031 / U:0.668 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site