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

Matt Turner mattst88 at gmail.com
Wed Dec 16 17:47:13 PST 2015


On Wed, Dec 16, 2015 at 11:57 AM, 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))

This *is* the definition the Linux kernel uses, so I think it's
probably the right thing to do.

As a data point (and not necessarily an objection) this actually
increases .text size for me:

   text   data    bss    dec    hex filename
5314834 221988  27912 5564734 54e93e lib/i965_dri.so (before)
5320490 221988  27912 5570390 54ff56 lib/i965_dri.so (after)

by about 5.5k. I've configured with -O2 -march=native -pipe on a
Haswell with gcc 4.9.3. I'm curious what the discrepancy is.

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the mesa-dev mailing list