Skip to content

RFC: util: Add IS_ALIGNED macro

Alyssa Rosenzweig requested to merge alyssa/mesa:util/is-aligned-rfc into main

This idiom comes up a lot, add a macro to make it clearer. Questions to bike shed:

  • Name. IS_ALIGNED? Or simply ALIGNED? The kernel uses IS_ALIGNED.
  • Must alignments be a power-of-two? This influences whether we define with & or with %
  • Once we settle on the name and semantics, should the tree be updated to use the new macro instead of open-coding the checks? This would be an easy Coccinelle script but I don't want to stomp on people's code. (Right now, just a few representative uses in Panfrost are changed, there are piles more within Panfrost alone that I didn't bother to change in case we bike shed the name.)

For comparison, the kernel definition is

#define IS_ALIGNED(x, a)		(((x) & ((typeof(x))(a) - 1)) == 0)
Edited by Alyssa Rosenzweig

Merge request reports