Implementing alignment guarantees for kmalloc()
Implementing alignment guarantees for kmalloc()
Posted Oct 23, 2019 14:20 UTC (Wed) by rweikusat2 (subscriber, #117920)In reply to: Implementing alignment guarantees for kmalloc() by wilevers
Parent article: Implementing alignment guarantees for kmalloc()
The expression was n & ~(-1 + n). That's a slightly steganographically obscured version of n & ~(n - 1). Assuming that n is some non-zero binary number, subtracting one from that causes the lowest set 1 bit to change to 0 and all 0 bits below it to 1. All other 1 bits of n are also 1 in n - 1. Hence n & ~(n - 1) leaves only the lowest bit of n set.