Skip to content
Snippets Groups Projects
Commit de5bd830 authored by Mitchel Humpherys's avatar Mitchel Humpherys
Browse files

lrdp-v2: bitops: Add align function

Aligning addresses is a handy thing to do when working with memory maps,
etc.  Add an `align' function to the bitops module for this purpose.

Change-Id: I582e8c763119d13b718146f4ff837bfa75e9aa01
parent 75e18b5e
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,8 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import ctypes
def bm(msb, lsb):
'Creates a bitmask from msb to lsb'
......@@ -25,3 +27,10 @@ def is_set(val, bit):
if (val >> bit) & 0x1:
return True
return False
def align(x, a):
"""Round x up to the nearest multiple of a"""
# See include/uapi/linux/kernel.h
notmask = ctypes.c_uint64(~(a - 1)).value
return (x + a - 1) & notmask
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment