[Mesa-dev] [PATCH] util/macros: Simplify DIV_ROUND_UP() definition

Glenn Kennard glenn.kennard at gmail.com
Thu Dec 17 03:05:46 PST 2015


On Wed, 16 Dec 2015 20:57:51 +0100, Nanley Chery <nanleychery at gmail.com> wrote:

> From: Nanley Chery <nanley.g.chery at intel.com>
>
> Commit 64880d073ab21ae1abad0c049ea2d6a1169a3cfa consolidated two
> DIV_ROUND_UP() definitions to one, but chose the more
> compute-intensive version in the process. Use the simpler version
> instead. Reduces .text size by 1360 bytes.
>
> Output of `size lib/i965_dri.so`:
>       text    data     bss     dec     hex filename
>    7850440  219264   27240 8096944  7b8cb0 lib/i965_dri.so (before)
>    7849080  219264   27240 8095584  7b8760 lib/i965_dri.so (after)
>
> Cc: Axel Davy <axel.davy at ens.fr>
> Signed-off-by: Nanley Chery <nanley.g.chery at intel.com>
> ---
>  src/util/macros.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/util/macros.h b/src/util/macros.h
> index 0c8958f..53a98a0 100644
> --- a/src/util/macros.h
> +++ b/src/util/macros.h
> @@ -211,6 +211,6 @@ do {                       \
>  #endif
> /** Compute ceiling of integer quotient of A divided by B. */
> -#define DIV_ROUND_UP( A, B )  ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
> +#define DIV_ROUND_UP(A, B)  (((A) + (B) - 1) / (B))
> #endif /* UTIL_MACROS_H */

I'll point out that these are not equivalent, one can overflow and the other doesn't. You
probably want to check if the call sites have sufficient checks for that before
substituting one for the other.


/Glenn


More information about the mesa-dev mailing list