From 8777add24efaffa45adf02cff6e2eef198a8c5a4 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 7 Jul 2020 17:01:32 -0700 Subject: [PATCH] ircd::buffer: Added padded() alignment query util. --- include/ircd/buffer/buffer.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/ircd/buffer/buffer.h b/include/ircd/buffer/buffer.h index 8b99bf7df..d7b2a9cfb 100644 --- a/include/ircd/buffer/buffer.h +++ b/include/ircd/buffer/buffer.h @@ -73,6 +73,7 @@ namespace ircd::buffer template bool operator!(const buffer &buffer); template size_t size(const buffer &buffer); template const it &data(const buffer &buffer); + template bool padded(const buffer &buffer, const size_t &alignment); template bool aligned(const buffer &buffer, const size_t &alignment); template buffer operator+(const buffer &buffer, const size_t &bytes); size_t overlap_count(const const_buffer &, const const_buffer &); @@ -320,7 +321,18 @@ ircd::buffer::aligned(const buffer &buffer, const size_t &a) { return likely(a)? - uintptr_t(data(buffer)) % a == 0 && size(buffer) % a == 0: + uintptr_t(data(buffer)) % a == 0 && padded(buffer, a): + true; +} + +template +inline bool +__attribute__((always_inline)) +ircd::buffer::padded(const buffer &buffer, + const size_t &a) +{ + return likely(a)? + size(buffer) % a == 0: true; }