From 70b16963fc6aa5f8c0e947ea48095bb679a3fa74 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 29 Jun 2018 14:59:56 -0700 Subject: [PATCH] util/macros: Import ALIGN_POT from ralloc.c v2 (Jason Ekstrand): - Rename y to pot_align (Brian) - Also use ALIGN_POT in build_id.c and slab.c (Brian) Reviewed-by: Timothy Arceri Reviewed-by: Iago Toral Quiroga Reviewed-by: Brian Paul Reviewed-by: Kenneth Graunke --- 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 fb67d16..8b4f8f3 100644 --- a/src/util/build_id.c +++ b/src/util/build_id.c @@ -28,6 +28,7 @@ #include #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 6d3df90..fb522ee 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 42cfa2e..5d77f75 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 4ce0e9a..5f04866 100644 --- a/src/util/slab.c +++ b/src/util/slab.c @@ -28,8 +28,6 @@ #include #include -#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.7.4