Skip to content

Instantly share code, notes, and snippets.

@binshengliu
Last active October 2, 2015 05:37
Show Gist options
  • Save binshengliu/2181472 to your computer and use it in GitHub Desktop.
Save binshengliu/2181472 to your computer and use it in GitHub Desktop.
align x to 16
/* from genromfs.c */
#define ALIGNUP16(x) (((x)+15)&~15)
/* from zfs */
#define P2ALIGN(x, align) ((x) & -(align))
#define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1)
#define P2ROUNDUP(x, align) (-(-(x) & -(align)))
#define P2PHASE(x, align) ((x) & ((align) - 1))
#define P2NPHASE(x, align) (-(x) & ((align) - 1))
#define ISP2(x) (((x) & ((x) - 1)) == 0)
#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1))==0)
#define P2BOUNDARY(off, len, align) \
(((off) ^ ((off) + (len) - 1)) > (align) - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment