Add swap utility

This commit is contained in:
2026-09-21 22:03:54 +01:00
parent 8da18774f0
commit b014ffa3b1
+19 -14
View File
@@ -31,24 +31,29 @@ BEGIN_C_LINKAGE
#define U64_RSHIFT_OR_8(X) (((u64)X) | (((u64)X) >> 8)) #define U64_RSHIFT_OR_8(X) (((u64)X) | (((u64)X) >> 8))
#define U64_RSHIFT_OR_16(X) (((u64)X) | (((u64)X) >> 16)) #define U64_RSHIFT_OR_16(X) (((u64)X) | (((u64)X) >> 16))
#define U64_RSHIFT_OR_32(X) (((u64)X) | (((u64)X) >> 32)) #define U64_RSHIFT_OR_32(X) (((u64)X) | (((u64)X) >> 32))
#define wpMiscUtilsU64RoundUpPow2(X) ( \ #define wpMiscUtilsU64RoundUpPow2(X) ( \
( \ ( \
U64_RSHIFT_OR_32( \ U64_RSHIFT_OR_32( \
U64_RSHIFT_OR_16( \ U64_RSHIFT_OR_16( \
U64_RSHIFT_OR_8( \ U64_RSHIFT_OR_8( \
U64_RSHIFT_OR_4( \ U64_RSHIFT_OR_4( \
U64_RSHIFT_OR_2( \ U64_RSHIFT_OR_2( \
U64_RSHIFT_OR_1(X - 1) \ U64_RSHIFT_OR_1(X - 1) \
) \ ) \
) \ ) \
) \ ) \
) \ ) \
) \ ) \
) + 1 \ ) + 1 \
) )
#define wpMiscUtilsIsPowerOfTwo(NUM) ((NUM & (NUM - 1)) == 0) #define wpMiscUtilsIsPowerOfTwo(NUM) ((NUM & (NUM - 1)) == 0)
#define wpMiscUtilsOffsetPointer(PTR, OFFSET) ((void *)((uptr)(PTR) + (OFFSET))) #define wpMiscUtilsOffsetPointer(PTR, OFFSET) ((void *)((uptr)(PTR) + (OFFSET)))
#define wpMiscUtilsSwap(TYPE, A_PTR, B_PTR) do { \
TYPE tmp = *(A_PTR); \
*(A_PTR) = *(B_PTR); \
*(B_PTR) = tmp; \
} while(0)
wp_intern inline u64 wpMiscUtilsRotl64(u64 x, i8 rotation) { wp_intern inline u64 wpMiscUtilsRotl64(u64 x, i8 rotation) {
return (x << rotation) | (x >> (64 - rotation)); return (x << rotation) | (x >> (64 - rotation));