[PATCH 2/4] introduce region_overlap() function

Robert Jarzmik robert.jarzmik at free.fr
Fri Oct 5 15:55:04 EDT 2012


Sascha Hauer <s.hauer at pengutronix.de> writes:

> To check if two regions overlap
>
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
>  include/common.h |   13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/include/common.h b/include/common.h
> index c1f44b4..e30774a 100644
> --- a/include/common.h
> +++ b/include/common.h
> @@ -256,4 +256,17 @@ static inline void barebox_banner(void) {}
>  		(__x < 0) ? -__x : __x;         \
>  	})
>  
> +/*
> + * Check if two regions overlap. returns true if they do, false otherwise
> + */
> +static inline bool region_overlap(unsigned long starta, unsigned long lena,
> +		unsigned long startb, unsigned long lenb)
> +{
> +	if (starta + lena <= startb)
> +		return 0;
> +	if (startb + lenb <= starta)
> +		return 0;
> +	return 1;
> +}
> +
>  #endif	/* __COMMON_H_ */

Or if you look for perfomance (I presume not in barebox) :
static inline bool region_overlap(unsigned long starta, unsigned long lena,
		unsigned long startb, unsigned long lenb)
{
        return starta <= startb + lenb && starta + lena >= startb;
}

It's a bit more obfuscated, but performance wise no branch prediction :)

Cheers.

-- 
Robert



More information about the barebox mailing list