1 | // Derived from code in LLVM, which is: |
2 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
3 | // See https://llvm.org/LICENSE.txt for license information. |
4 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
5 | |
6 | // Derived from https://github.com/llvm/llvm-project/blob/8ef3e895ad8ab1724e2b87cabad1dacdc7a397a3/llvm/include/llvm/Support/Alignment.h |
7 | |
8 | /// Returns a multiple of `align` needed to store `size` bytes. |
9 | pub(crate) fn align_to(size: u64, align: u64) -> u64 { |
10 | (size + align - 1) & !(align - 1) |
11 | } |
12 | |
13 | /* |
14 | /// Returns the offset to the next integer (mod 2**64) that is greater than |
15 | /// or equal to \p Value and is a multiple of \p Align. |
16 | inline uint64_t offsetToAlignment(uint64_t Value, Align Alignment) { |
17 | return alignTo(Value, Alignment) - Value; |
18 | } |
19 | */ |
20 | |
21 | pub(crate) fn offset_to_alignment(value: u64, alignment: u64) -> u64 { |
22 | align_to(size:value, align:alignment) - value |
23 | } |
24 | |