[Mesa-dev] [PATCH v4 02/23] util: Make vma.c support non-power-of-two alignments.

Jason Ekstrand jason at jlekstrand.net
Thu May 31 15:46:23 UTC 2018


From: Kenneth Graunke <kenneth at whitecape.org>

I want to use this in a bucketing allocator for i965.
---
 src/util/vma.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/util/vma.c b/src/util/vma.c
index bedad6e..c8f5503 100644
--- a/src/util/vma.c
+++ b/src/util/vma.c
@@ -90,8 +90,7 @@ util_vma_heap_alloc(struct util_vma_heap *heap,
 {
    /* The caller is expected to reject zero-size allocations */
    assert(size > 0);
-
-   assert(util_is_power_of_two_nonzero(alignment));
+   assert(alignment > 0);
 
    util_vma_heap_validate(heap);
 
@@ -110,7 +109,7 @@ util_vma_heap_alloc(struct util_vma_heap *heap,
       /* Align the offset.  We align down and not up because we are allocating
        * from the top of the hole and not the bottom.
        */
-      offset &= ~(alignment - 1);
+      offset = (offset / alignment) * alignment;
 
       if (offset < hole->offset)
          continue;
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list