[Mesa-dev] [PATCH v2 1/9] util/macros: Import ALIGN_POT from ralloc.c
Jason Ekstrand
jason at jlekstrand.net
Mon Jul 2 14:59:31 UTC 2018
v2 (Jason Ekstrand):
- Rename y to pot_align (Brian)
- Also use ALIGN_POT in build_id.c and slab.c (Brian)
Cc: Brian Paul <brianp at vmware.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
---
src/util/build_id.c | 7 +++----
src/util/macros.h | 3 +++
src/util/ralloc.c | 2 --
src/util/slab.c | 6 ++----
4 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/src/util/build_id.c b/src/util/build_id.c
index fb67d160e38..8b4f8f30afb 100644
--- a/src/util/build_id.c
+++ b/src/util/build_id.c
@@ -28,6 +28,7 @@
#include <string.h>
#include "build_id.h"
+#include "macros.h"
#ifndef NT_GNU_BUILD_ID
#define NT_GNU_BUILD_ID 3
@@ -37,8 +38,6 @@
#define ElfW(type) Elf_##type
#endif
-#define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1))
-
struct build_id_note {
ElfW(Nhdr) nhdr;
@@ -90,8 +89,8 @@ build_id_find_nhdr_callback(struct dl_phdr_info *info, size_t size, void *data_)
}
size_t offset = sizeof(ElfW(Nhdr)) +
- ALIGN(note->nhdr.n_namesz, 4) +
- ALIGN(note->nhdr.n_descsz, 4);
+ ALIGN_POT(note->nhdr.n_namesz, 4) +
+ ALIGN_POT(note->nhdr.n_descsz, 4);
note = (struct build_id_note *)((char *)note + offset);
len -= offset;
}
diff --git a/src/util/macros.h b/src/util/macros.h
index 6d3df904082..fb522ee3d3e 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -285,6 +285,9 @@ do { \
#define MIN3( A, B, C ) ((A) < (B) ? MIN2(A, C) : MIN2(B, C))
#define MAX3( A, B, C ) ((A) > (B) ? MAX2(A, C) : MAX2(B, C))
+/** Align a value to a power of two */
+#define ALIGN_POT(x, pot_align) (((x) + (pot_align) - 1) & ~((pot_align) - 1))
+
/**
* Macro for declaring an explicit conversion operator. Defaults to an
* implicit conversion if C++11 is not supported.
diff --git a/src/util/ralloc.c b/src/util/ralloc.c
index 42cfa2e391d..5d77f75ee85 100644
--- a/src/util/ralloc.c
+++ b/src/util/ralloc.c
@@ -553,8 +553,6 @@ ralloc_vasprintf_rewrite_tail(char **str, size_t *start, const char *fmt,
* other buffers.
*/
-#define ALIGN_POT(x, y) (((x) + (y) - 1) & ~((y) - 1))
-
#define MIN_LINEAR_BUFSIZE 2048
#define SUBALLOC_ALIGNMENT sizeof(uintptr_t)
#define LMAGIC 0x87b9c7d3
diff --git a/src/util/slab.c b/src/util/slab.c
index 4ce0e9a3485..5f048666b56 100644
--- a/src/util/slab.c
+++ b/src/util/slab.c
@@ -28,8 +28,6 @@
#include <stdbool.h>
#include <string.h>
-#define ALIGN(value, align) (((value) + (align) - 1) & ~((align) - 1))
-
#define SLAB_MAGIC_ALLOCATED 0xcafe4321
#define SLAB_MAGIC_FREE 0x7ee01234
@@ -109,8 +107,8 @@ slab_create_parent(struct slab_parent_pool *parent,
unsigned num_items)
{
mtx_init(&parent->mutex, mtx_plain);
- parent->element_size = ALIGN(sizeof(struct slab_element_header) + item_size,
- sizeof(intptr_t));
+ parent->element_size = ALIGN_POT(sizeof(struct slab_element_header) + item_size,
+ sizeof(intptr_t));
parent->num_elements = num_items;
}
--
2.17.1
More information about the mesa-dev
mailing list