Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/cranelift/codegen/src/machinst/helpers.rs
1693 views
1
//! Miscellaneous helpers for machine backends.
2
3
use crate::ir::Type;
4
use std::ops::{Add, BitAnd, Not, Sub};
5
6
/// Returns the size (in bits) of a given type.
7
pub fn ty_bits(ty: Type) -> usize {
8
ty.bits() as usize
9
}
10
11
/// Align a size up to a power-of-two alignment.
12
pub(crate) fn align_to<N>(x: N, alignment: N) -> N
13
where
14
N: Not<Output = N>
15
+ BitAnd<N, Output = N>
16
+ Add<N, Output = N>
17
+ Sub<N, Output = N>
18
+ From<u8>
19
+ Copy,
20
{
21
let alignment_mask = alignment - 1.into();
22
(x + alignment_mask) & !alignment_mask
23
}
24
25