[Mesa-dev] [PATCH] mesa: Rename the CEILING() macro to DIV_ROUND_UP().

Francisco Jerez currojerez at riseup.net
Mon Feb 9 08:02:44 PST 2015


Some people have complained that code using the CEILING() macro is
difficult to understand because it's not immediately obvious what it
is supposed to do until you go and look up its definition.  Use a more
descriptive name that matches the similar utility macro in the Linux
kernel.
---
 src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 2 +-
 src/mesa/main/image.c                          | 2 +-
 src/mesa/main/macros.h                         | 2 +-
 src/mesa/main/pack.c                           | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index fe05110..9d5e648 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -3628,7 +3628,7 @@ vec4_visitor::vec4_visitor(struct brw_context *brw,
     */
    this->uniform_array_size = 1;
    if (prog_data) {
-      this->uniform_array_size = MAX2(CEILING(stage_prog_data->nr_params, 4),
+      this->uniform_array_size = MAX2(DIV_ROUND_UP(stage_prog_data->nr_params, 4),
                                       1);
    }
 
diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c
index c37900c..e97b006 100644
--- a/src/mesa/main/image.c
+++ b/src/mesa/main/image.c
@@ -151,7 +151,7 @@ _mesa_image_offset( GLuint dimensions,
       assert(format == GL_COLOR_INDEX || format == GL_STENCIL_INDEX);
 
       bytes_per_row = alignment
-                    * CEILING( comp_per_pixel*pixels_per_row, 8*alignment );
+                    * DIV_ROUND_UP( comp_per_pixel*pixels_per_row, 8*alignment );
 
       bytes_per_image = bytes_per_row * rows_per_image;
 
diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
index cd5f2d6..2d59c6f 100644
--- a/src/mesa/main/macros.h
+++ b/src/mesa/main/macros.h
@@ -808,7 +808,7 @@ DIFFERENT_SIGNS(GLfloat x, GLfloat y)
 
 
 /** Compute ceiling of integer quotient of A divided by B. */
-#define CEILING( A, B )  ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
+#define DIV_ROUND_UP( A, B )  ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
 
 
 /** casts to silence warnings with some compilers */
diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 4cc8468..2111a76 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -155,7 +155,7 @@ _mesa_pack_bitmap( GLint width, GLint height, const GLubyte *source,
    if (!source)
       return;
 
-   width_in_bytes = CEILING( width, 8 );
+   width_in_bytes = DIV_ROUND_UP( width, 8 );
    src = source;
    for (row = 0; row < height; row++) {
       GLubyte *dst = (GLubyte *) _mesa_image_address2d(packing, dest,
-- 
2.1.3



More information about the mesa-dev mailing list