From dde478ce985b24b2e9fdcd297633e269e2b29e81 Mon Sep 17 00:00:00 2001 From: Dhruv Mark Collins Date: Thu, 9 Oct 2025 13:56:30 +0000 Subject: [PATCH] util/math: Add ROUND_DOWN_TO_NPOT The default ROUND_DOWN_TO only handles POT alignment values, so an additional variant was added which handles NPOT alignment too. Signed-off-by: Dhruv Mark Collins Part-of: --- src/util/u_math.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/util/u_math.h b/src/util/u_math.h index 5f1fcc89a38..dbd0aa68a73 100644 --- a/src/util/u_math.h +++ b/src/util/u_math.h @@ -705,6 +705,12 @@ ROUND_DOWN_TO(uint64_t value, uint32_t alignment) return ((value) & ~(uint64_t)(alignment - 1)); } +static inline uint64_t +ROUND_DOWN_TO_NPOT(uint64_t value, uint32_t alignment) +{ + return value - (value % alignment); +} + /** * Align a value, only works pot alignemnts. */