[Mesa-dev] [PATCH 3/6] mesa: use c11_stdlib.h' aligned_alloc/free

Emil Velikov emil.l.velikov at gmail.com
Fri Mar 6 08:32:52 PST 2015


Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/mesa/main/bufferobj.c         |  8 +++++---
 src/mesa/math/m_debug_norm.c      |  6 ++++--
 src/mesa/math/m_debug_xform.c     |  6 ++++--
 src/mesa/math/m_matrix.c          | 10 ++++++----
 src/mesa/math/m_vector.c          |  5 +++--
 src/mesa/program/prog_parameter.c | 11 ++++++-----
 src/mesa/swrast/s_texture.c       |  5 +++--
 src/mesa/tnl/t_vb_program.c       |  5 +++--
 src/mesa/tnl/t_vb_vertex.c        |  5 +++--
 src/mesa/tnl/t_vertex.c           |  6 ++++--
 src/mesa/vbo/vbo_exec_api.c       |  8 +++++---
 11 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index e1c5877..d54d37d 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -32,6 +32,8 @@
 
 #include <stdbool.h>
 #include <inttypes.h>  /* for PRId64 macro */
+#include "c11_stdlib.h"
+
 #include "glheader.h"
 #include "enums.h"
 #include "hash.h"
@@ -417,7 +419,7 @@ _mesa_delete_buffer_object(struct gl_context *ctx,
 {
    (void) ctx;
 
-   _mesa_align_free(bufObj->Data);
+   aligned_free(bufObj->Data);
 
    /* assign strange values here to help w/ debugging */
    bufObj->RefCount = -1000;
@@ -569,9 +571,9 @@ _mesa_buffer_data( struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
 
    (void) target;
 
-   _mesa_align_free( bufObj->Data );
+   aligned_free( bufObj->Data );
 
-   new_data = _mesa_align_malloc( size, ctx->Const.MinMapBufferAlignment );
+   new_data = aligned_alloc( ctx->Const.MinMapBufferAlignment, size );
    if (new_data) {
       bufObj->Data = (GLubyte *) new_data;
       bufObj->Size = size;
diff --git a/src/mesa/math/m_debug_norm.c b/src/mesa/math/m_debug_norm.c
index 197b43c..ed61c44 100644
--- a/src/mesa/math/m_debug_norm.c
+++ b/src/mesa/math/m_debug_norm.c
@@ -27,6 +27,8 @@
  */
 
 #include "c99_math.h"
+#include "c11_stdlib.h"
+
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/macros.h"
@@ -209,7 +211,7 @@ static int test_norm_function( normal_func func, int mtype, long *cycles )
 
    (void) cycles;
 
-   mat->m = _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
+   mat->m = aligned_alloc( 16, 16 * sizeof(GLfloat) );
    mat->inv = m = mat->m;
 
    init_matrix( m );
@@ -328,7 +330,7 @@ static int test_norm_function( normal_func func, int mtype, long *cycles )
       }
    }
 
-   _mesa_align_free( mat->m );
+   aligned_free( mat->m );
    return 1;
 }
 
diff --git a/src/mesa/math/m_debug_xform.c b/src/mesa/math/m_debug_xform.c
index 632c82e..2a0778b 100644
--- a/src/mesa/math/m_debug_xform.c
+++ b/src/mesa/math/m_debug_xform.c
@@ -26,6 +26,8 @@
  * Updated for P6 architecture by Gareth Hughes.
  */
 
+#include "c11_stdlib.h"
+
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/macros.h"
@@ -183,7 +185,7 @@ static int test_transform_function( transform_func func, int psize,
       return 0;
    }
 
-   mat->m = _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
+   mat->m = aligned_alloc( 16, 16 * sizeof(GLfloat) );
    mat->type = mtypes[mtype];
 
    m = mat->m;
@@ -273,7 +275,7 @@ static int test_transform_function( transform_func func, int psize,
       }
    }
 
-   _mesa_align_free( mat->m );
+   aligned_free( mat->m );
    return 1;
 }
 
diff --git a/src/mesa/math/m_matrix.c b/src/mesa/math/m_matrix.c
index 0475a7a..ebee5b9 100644
--- a/src/mesa/math/m_matrix.c
+++ b/src/mesa/math/m_matrix.c
@@ -35,6 +35,8 @@
 
 
 #include "c99_math.h"
+#include "c11_stdlib.h"
+
 #include "main/glheader.h"
 #include "main/imports.h"
 #include "main/macros.h"
@@ -1469,10 +1471,10 @@ _math_matrix_loadf( GLmatrix *mat, const GLfloat *m )
 void
 _math_matrix_ctr( GLmatrix *m )
 {
-   m->m = _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
+   m->m = aligned_alloc( 16, 16 * sizeof(GLfloat) );
    if (m->m)
       memcpy( m->m, Identity, sizeof(Identity) );
-   m->inv = _mesa_align_malloc( 16 * sizeof(GLfloat), 16 );
+   m->inv = aligned_alloc( 16, 16 * sizeof(GLfloat) );
    if (m->inv)
       memcpy( m->inv, Identity, sizeof(Identity) );
    m->type = MATRIX_IDENTITY;
@@ -1489,10 +1491,10 @@ _math_matrix_ctr( GLmatrix *m )
 void
 _math_matrix_dtr( GLmatrix *m )
 {
-   _mesa_align_free( m->m );
+   aligned_free( m->m );
    m->m = NULL;
 
-   _mesa_align_free( m->inv );
+   aligned_free( m->inv );
    m->inv = NULL;
 }
 
diff --git a/src/mesa/math/m_vector.c b/src/mesa/math/m_vector.c
index 831f953..e1d5c27 100644
--- a/src/mesa/math/m_vector.c
+++ b/src/mesa/math/m_vector.c
@@ -27,6 +27,7 @@
  */
 
 #include <stdio.h>
+#include "c11_stdlib.h"
 
 #include "main/glheader.h"
 #include "main/imports.h"
@@ -101,7 +102,7 @@ _mesa_vector4f_alloc( GLvector4f *v, GLbitfield flags, GLuint count,
 {
    v->stride = 4 * sizeof(GLfloat);
    v->size = 2;
-   v->storage = _mesa_align_malloc( count * 4 * sizeof(GLfloat), alignment );
+   v->storage = aligned_alloc( alignment, count * 4 * sizeof(GLfloat) );
    v->storage_count = count;
    v->start = (GLfloat *) v->storage;
    v->data = (GLfloat (*)[4]) v->storage;
@@ -119,7 +120,7 @@ void
 _mesa_vector4f_free( GLvector4f *v )
 {
    if (v->flags & VEC_MALLOC) {
-      _mesa_align_free( v->storage );
+      aligned_free( v->storage );
       v->data = NULL;
       v->start = NULL;
       v->storage = NULL;
diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c
index edb5389..be72c05 100644
--- a/src/mesa/program/prog_parameter.c
+++ b/src/mesa/program/prog_parameter.c
@@ -28,6 +28,7 @@
  * \author Brian Paul
  */
 
+#include "c11_stdlib.h"
 
 #include "main/glheader.h"
 #include "main/imports.h"
@@ -57,12 +58,12 @@ _mesa_new_parameter_list_sized(unsigned size)
 	 calloc(size, sizeof(struct gl_program_parameter));
 
       p->ParameterValues = (gl_constant_value (*)[4])
-         _mesa_align_malloc(size * 4 *sizeof(gl_constant_value), 16);
+         aligned_alloc(16, size * 4 *sizeof(gl_constant_value));
 
 
       if ((p->Parameters == NULL) || (p->ParameterValues == NULL)) {
 	 free(p->Parameters);
-	 _mesa_align_free(p->ParameterValues);
+	 aligned_free(p->ParameterValues);
 	 free(p);
 	 p = NULL;
       }
@@ -83,7 +84,7 @@ _mesa_free_parameter_list(struct gl_program_parameter_list *paramList)
       free((void *)paramList->Parameters[i].Name);
    }
    free(paramList->Parameters);
-   _mesa_align_free(paramList->ParameterValues);
+   aligned_free(paramList->ParameterValues);
    free(paramList);
 }
 
@@ -130,12 +131,12 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
          realloc(paramList->Parameters,
                  paramList->Size * sizeof(struct gl_program_parameter));
 
-      newBuf = _mesa_align_malloc(newSize, 16);
+      newBuf = aligned_alloc(16, newSize);
       if (newBuf && paramList->ParameterValues && copySize > 0) {
          memcpy(newBuf, paramList->ParameterValues, copySize);
       }
 
-      _mesa_align_free(paramList->ParameterValues);
+      aligned_free(paramList->ParameterValues);
       paramList->ParameterValues = (gl_constant_value (*)[4]) newBuf;
    }
 
diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c
index 9ccd0e3..508cfe6 100644
--- a/src/mesa/swrast/s_texture.c
+++ b/src/mesa/swrast/s_texture.c
@@ -26,6 +26,7 @@
  * Functions for mapping/unmapping texture images.
  */
 
+#include "c11_stdlib.h"
 
 #include "main/context.h"
 #include "main/fbobject.h"
@@ -99,7 +100,7 @@ _swrast_alloc_texture_image_buffer(struct gl_context *ctx,
                                            _swrast_teximage_slice_height(texImage), 1);
 
    assert(!swImg->Buffer);
-   swImg->Buffer = _mesa_align_malloc(bytesPerSlice * slices, 512);
+   swImg->Buffer = aligned_alloc(512, bytesPerSlice * slices);
    if (!swImg->Buffer)
       return GL_FALSE;
 
@@ -165,7 +166,7 @@ _swrast_free_texture_image_buffer(struct gl_context *ctx,
 {
    struct swrast_texture_image *swImage = swrast_texture_image(texImage);
 
-   _mesa_align_free(swImage->Buffer);
+   aligned_free(swImage->Buffer);
    swImage->Buffer = NULL;
 
    free(swImage->ImageSlices);
diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c
index 464a4cd..471a8fa 100644
--- a/src/mesa/tnl/t_vb_program.c
+++ b/src/mesa/tnl/t_vb_program.c
@@ -30,6 +30,7 @@
  * \author Brian Paul,  Keith Whitwell
  */
 
+#include "c11_stdlib.h"
 
 #include "main/glheader.h"
 #include "main/colormac.h"
@@ -484,7 +485,7 @@ init_vp(struct gl_context *ctx, struct tnl_pipeline_stage *stage)
 
    /* a few other misc allocations */
    _mesa_vector4f_alloc( &store->ndcCoords, 0, size, 32 );
-   store->clipmask = _mesa_align_malloc(sizeof(GLubyte)*size, 32 );
+   store->clipmask = aligned_alloc(32, sizeof(GLubyte)*size);
 
    return GL_TRUE;
 }
@@ -507,7 +508,7 @@ dtr(struct tnl_pipeline_stage *stage)
 
       /* free misc arrays */
       _mesa_vector4f_free( &store->ndcCoords );
-      _mesa_align_free( store->clipmask );
+      aligned_free( store->clipmask );
 
       free( store );
       stage->privatePtr = NULL;
diff --git a/src/mesa/tnl/t_vb_vertex.c b/src/mesa/tnl/t_vb_vertex.c
index ea3a56c..fd25fac 100644
--- a/src/mesa/tnl/t_vb_vertex.c
+++ b/src/mesa/tnl/t_vb_vertex.c
@@ -25,6 +25,7 @@
  *    Keith Whitwell <keithw at vmware.com>
  */
 
+#include "c11_stdlib.h"
 
 #include "main/glheader.h"
 #include "main/colormac.h"
@@ -245,7 +246,7 @@ static GLboolean init_vertex_stage( struct gl_context *ctx,
    _mesa_vector4f_alloc( &store->clip, 0, size, 32 );
    _mesa_vector4f_alloc( &store->proj, 0, size, 32 );
 
-   store->clipmask = _mesa_align_malloc(sizeof(GLubyte)*size, 32 );
+   store->clipmask = aligned_alloc( 32, sizeof(GLubyte)*size );
 
    if (!store->clipmask ||
        !store->eye.data ||
@@ -264,7 +265,7 @@ static void dtr( struct tnl_pipeline_stage *stage )
       _mesa_vector4f_free( &store->eye );
       _mesa_vector4f_free( &store->clip );
       _mesa_vector4f_free( &store->proj );
-      _mesa_align_free( store->clipmask );
+      aligned_free( store->clipmask );
       free(store);
       stage->privatePtr = NULL;
       stage->run = init_vertex_stage;
diff --git a/src/mesa/tnl/t_vertex.c b/src/mesa/tnl/t_vertex.c
index 607977c..8939c16 100644
--- a/src/mesa/tnl/t_vertex.c
+++ b/src/mesa/tnl/t_vertex.c
@@ -27,6 +27,8 @@
 
 #include <stdio.h>
 #include <string.h>
+#include "c11_stdlib.h"
+
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/colormac.h"
@@ -514,7 +516,7 @@ void _tnl_init_vertices( struct gl_context *ctx,
       _tnl_free_vertices( ctx );
       vtx->max_vertex_size = max_vertex_size;
       vtx->vertex_buf =
-         memset(_mesa_align_malloc(total_vb_size, 32), 0, total_vb_size);
+         memset(aligned_alloc(32, total_vb_size), 0, total_vb_size);
       invalidate_funcs(vtx);
    }
 
@@ -560,7 +562,7 @@ void _tnl_free_vertices( struct gl_context *ctx )
       struct tnl_clipspace *vtx = GET_VERTEX_STATE(ctx);
       struct tnl_clipspace_fastpath *fp, *tmp;
 
-      _mesa_align_free(vtx->vertex_buf);
+      aligned_free(vtx->vertex_buf);
       vtx->vertex_buf = NULL;
 
       for (fp = vtx->fastpath ; fp ; fp = tmp) {
diff --git a/src/mesa/vbo/vbo_exec_api.c b/src/mesa/vbo/vbo_exec_api.c
index 9669abe..14339ef 100644
--- a/src/mesa/vbo/vbo_exec_api.c
+++ b/src/mesa/vbo/vbo_exec_api.c
@@ -30,6 +30,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
  *   Keith Whitwell <keithw at vmware.com>
  */
 
+#include "c11_stdlib.h"
+
 #include "main/glheader.h"
 #include "main/bufferobj.h"
 #include "main/context.h"
@@ -991,7 +993,7 @@ void vbo_use_buffer_objects(struct gl_context *ctx)
    /* Make sure this func is only used once */
    assert(exec->vtx.bufferobj == ctx->Shared->NullBufferObj);
 
-   _mesa_align_free(exec->vtx.buffer_map);
+   aligned_free(exec->vtx.buffer_map);
    exec->vtx.buffer_map = NULL;
    exec->vtx.buffer_ptr = NULL;
 
@@ -1037,7 +1039,7 @@ void vbo_exec_vtx_init( struct vbo_exec_context *exec )
                                  ctx->Shared->NullBufferObj);
 
    assert(!exec->vtx.buffer_map);
-   exec->vtx.buffer_map = _mesa_align_malloc(VBO_VERT_BUFFER_SIZE, 64);
+   exec->vtx.buffer_map = aligned_alloc(64, VBO_VERT_BUFFER_SIZE);
    exec->vtx.buffer_ptr = exec->vtx.buffer_map;
 
    vbo_exec_vtxfmt_init( exec );
@@ -1102,7 +1104,7 @@ void vbo_exec_vtx_destroy( struct vbo_exec_context *exec )
       assert(exec->vtx.bufferobj->Name == 0 ||
              exec->vtx.bufferobj->Name == IMM_BUFFER_NAME);
       if (exec->vtx.bufferobj->Name == 0) {
-         _mesa_align_free(exec->vtx.buffer_map);
+         aligned_free(exec->vtx.buffer_map);
          exec->vtx.buffer_map = NULL;
          exec->vtx.buffer_ptr = NULL;
       }
-- 
2.1.3



More information about the mesa-dev mailing list