Fix potential overflow when we're nearing 4G blocks..

This commit is contained in:
2026-06-09 23:24:57 +02:00
parent 2b4660f7d5
commit 627c6d16ca
4 changed files with 84 additions and 52 deletions
+4 -3
View File
@@ -104,11 +104,12 @@ typedef unsigned __int128 U128;
(const type *)((const void *)(const unsigned char *)__mptr - offsetof(const type, member)); \
})
#define AlignUpPow2(val, align) (((val) + (align) - 1UL) & ~((align) - 1UL))
#define AlignDownPow2(val, align) ((val) & ~((align) - 1UL))
// align needs to be pow2
#define AlignUp(val, align) (((val) + (align) - 1UL) & ~((align) - 1UL))
#define AlignDown(val, align) ((val) & ~((align) - 1UL))
#define IsPow2(x) ((x) && !((x) & ((x) - 1UL)))
#define IsPow2OrZero(x) (!((x) & ((x) - 1UL)))
#define IsAlignedToPow2(x, y) (IsPow2(y) && !((x) & ((y) - 1UL)))
#define IsAlignedTo(x, align) (IsPow2(align) && !((x) & ((align) - 1UL)))
#define GetBit(val, idx) (((val) >> (idx)) & 1)
// Get n_bits starting at idx going left