[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Minios-devel] [UNIKRAFT PATCH v2 5/8] include/essentials: Introduce range test macros



Hi Simon,

This patch looks good.

Reviewed-by: Felipe Huici <felipe.huici@xxxxxxxxx>

-- Felipe

On 09.05.19, 16:27, "Simon Kuenzer" <simon.kuenzer@xxxxxxxxx> wrote:

    Introduce macros to test if:
    - a value is part of a number range
    - two ranges are overlapping
    
    Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
    ---
     include/uk/essentials.h | 20 ++++++++++++++++++++
     1 file changed, 20 insertions(+)
    
    diff --git a/include/uk/essentials.h b/include/uk/essentials.h
    index d9b24fcb..f20245b4 100644
    --- a/include/uk/essentials.h
    +++ b/include/uk/essentials.h
    @@ -195,6 +195,26 @@ extern "C" {
     #define ALIGN_DOWN(v, a) ((v) & ~((a)-1))
     #endif
     
    +/**
    + * Tests if `val` is part of the range defined by `base` and `len`
    + */
    +#define IN_RANGE(val, base, len)                   \
    +   (((val) >= (base)) && ((val) < (base) + (len)))
    +
    +/**
    + * Tests if two ranges overlap
    + * This is the case when at least one of the following conditions is true:
    + *  - The start of range 1 is within range 0
    + *  - The end of range 1 is within range 0
    + *  - The start of range 1 is smaller than the start of range 0 while
    + *    the end of range 1 is bigger than the end of range 0
    + */
    +#define RANGE_OVERLAP(base0, len0, base1, len1)                            
\
    +   (IN_RANGE((base1), (base0), (len0))                             \
    +    || IN_RANGE((base1) + (len1), (base0), (len0))                 \
    +    || (((base1) <= (base0))                                       \
    +        && (((base1) + (len1)) >= ((base0) + (len0)))))
    +
     #ifndef ARRAY_SIZE
     #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
     #endif
    -- 
    2.20.1
    
    

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.