cranelift_codegen/machinst/
helpers.rs1use crate::ir::Type;
4use std::ops::{Add, BitAnd, Not, Sub};
5
6pub fn ty_bits(ty: Type) -> usize {
8 ty.bits() as usize
9}
10
11pub(crate) fn ty_has_int_representation(ty: Type) -> bool {
13 ty.is_int() || ty.is_ref()
14}
15
16pub(crate) fn ty_has_float_or_vec_representation(ty: Type) -> bool {
18 ty.is_vector() || ty.is_float()
19}
20
21pub(crate) fn align_to<N>(x: N, alignment: N) -> N
23where
24 N: Not<Output = N>
25 + BitAnd<N, Output = N>
26 + Add<N, Output = N>
27 + Sub<N, Output = N>
28 + From<u8>
29 + Copy,
30{
31 let alignment_mask = alignment - 1.into();
32 (x + alignment_mask) & !alignment_mask
33}