use div_ceil instead of manual logic
This commit is contained in:
parent
226b0fbe11
commit
ed3711ea29
12 changed files with 17 additions and 18 deletions
|
|
@ -527,8 +527,7 @@ impl Size {
|
|||
/// not a multiple of 8.
|
||||
pub fn from_bits(bits: impl TryInto<u64>) -> Size {
|
||||
let bits = bits.try_into().ok().unwrap();
|
||||
// Avoid potential overflow from `bits + 7`.
|
||||
Size { raw: bits / 8 + ((bits % 8) + 7) / 8 }
|
||||
Size { raw: bits.div_ceil(8) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -172,10 +172,10 @@ fn emit_aapcs_va_arg<'ll, 'tcx>(
|
|||
|
||||
let gr_type = target_ty.is_any_ptr() || target_ty.is_integral();
|
||||
let (reg_off, reg_top, slot_size) = if gr_type {
|
||||
let nreg = (layout.size.bytes() + 7) / 8;
|
||||
let nreg = layout.size.bytes().div_ceil(8);
|
||||
(gr_offs, gr_top, nreg * 8)
|
||||
} else {
|
||||
let nreg = (layout.size.bytes() + 15) / 16;
|
||||
let nreg = layout.size.bytes().div_ceil(16);
|
||||
(vr_offs, vr_top, nreg * 16)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1744,13 +1744,13 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
|
|||
|
||||
#[inline]
|
||||
fn num_words<T: Idx>(domain_size: T) -> usize {
|
||||
(domain_size.index() + WORD_BITS - 1) / WORD_BITS
|
||||
domain_size.index().div_ceil(WORD_BITS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn num_chunks<T: Idx>(domain_size: T) -> usize {
|
||||
assert!(domain_size.index() > 0);
|
||||
(domain_size.index() + CHUNK_BITS - 1) / CHUNK_BITS
|
||||
domain_size.index().div_ceil(CHUNK_BITS)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl RWUTable {
|
|||
const WORD_RWU_COUNT: usize = Self::WORD_BITS / Self::RWU_BITS;
|
||||
|
||||
pub(super) fn new(live_nodes: usize, vars: usize) -> RWUTable {
|
||||
let live_node_words = (vars + Self::WORD_RWU_COUNT - 1) / Self::WORD_RWU_COUNT;
|
||||
let live_node_words = vars.div_ceil(Self::WORD_RWU_COUNT);
|
||||
Self { live_nodes, vars, live_node_words, words: vec![0u8; live_node_words * live_nodes] }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::serialize::Decoder;
|
|||
/// Returns the length of the longest LEB128 encoding for `T`, assuming `T` is an integer type
|
||||
pub const fn max_leb128_len<T>() -> usize {
|
||||
// The longest LEB128 encoding for an integer uses 7 bits per byte.
|
||||
(size_of::<T>() * 8 + 6) / 7
|
||||
(size_of::<T>() * 8).div_ceil(7)
|
||||
}
|
||||
|
||||
/// Returns the length of the longest LEB128 encoding of all supported integer types.
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ pub fn edit_distance_with_substrings(a: &str, b: &str, limit: usize) -> Option<u
|
|||
1 // Exact substring match, but not a total word match so return non-zero
|
||||
} else if !big_len_diff {
|
||||
// Not a big difference in length, discount cost of length difference
|
||||
score + (len_diff + 1) / 2
|
||||
score + len_diff.div_ceil(2)
|
||||
} else {
|
||||
// A big difference in length, add back the difference in length to the score
|
||||
score + len_diff
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ pub(crate) fn fill_inregs<'a, Ty, C>(
|
|||
continue;
|
||||
}
|
||||
|
||||
let size_in_regs = (arg.layout.size.bits() + 31) / 32;
|
||||
let size_in_regs = arg.layout.size.bits().div_ceil(32);
|
||||
|
||||
if size_in_regs == 0 {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ where
|
|||
Ok(())
|
||||
}
|
||||
|
||||
let n = ((arg.layout.size.bytes() + 7) / 8) as usize;
|
||||
let n = arg.layout.size.bytes().div_ceil(8) as usize;
|
||||
if n > MAX_EIGHTBYTES {
|
||||
return Err(Memory);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ where
|
|||
// Determine the number of GPRs needed to pass the current argument
|
||||
// according to the ABI. 2*XLen-aligned varargs are passed in "aligned"
|
||||
// register pairs, so may consume 3 registers.
|
||||
let mut needed_arg_gprs = (size + 32 - 1) / 32;
|
||||
let mut needed_arg_gprs = size.div_ceil(32);
|
||||
if needed_align == 64 {
|
||||
needed_arg_gprs += *arg_gprs_left % 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ fn merge_tree_scale_factor(n: usize) -> u64 {
|
|||
panic!("Platform not supported");
|
||||
}
|
||||
|
||||
((1 << 62) + n as u64 - 1) / n as u64
|
||||
(1u64 << 62).div_ceil(n as u64)
|
||||
}
|
||||
|
||||
// Note: merge_tree_depth output is < 64 when left < right as f*x and f*y must
|
||||
|
|
@ -182,7 +182,7 @@ fn sqrt_approx(n: usize) -> usize {
|
|||
// Finally we note that the exponentiation / division can be done directly
|
||||
// with shifts. We OR with 1 to avoid zero-checks in the integer log.
|
||||
let ilog = (n | 1).ilog2();
|
||||
let shift = (1 + ilog) / 2;
|
||||
let shift = ilog.div_ceil(2);
|
||||
((1 << shift) + (n >> shift)) / 2
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ impl<'a> Iterator for Chars<'a> {
|
|||
// `(len + 3)` can't overflow, because we know that the `slice::Iter`
|
||||
// belongs to a slice in memory which has a maximum length of
|
||||
// `isize::MAX` (that's well below `usize::MAX`).
|
||||
((len + 3) / 4, Some(len))
|
||||
(len.div_ceil(4), Some(len))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -1532,11 +1532,11 @@ impl<'a> Iterator for EncodeUtf16<'a> {
|
|||
// belongs to a slice in memory which has a maximum length of
|
||||
// `isize::MAX` (that's well below `usize::MAX`)
|
||||
if self.extra == 0 {
|
||||
((len + 2) / 3, Some(len))
|
||||
(len.div_ceil(3), Some(len))
|
||||
} else {
|
||||
// We're in the middle of a surrogate pair, so add the remaining
|
||||
// surrogate to the bounds.
|
||||
((len + 2) / 3 + 1, Some(len + 1))
|
||||
(len.div_ceil(3) + 1, Some(len + 1))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ pub struct LaneCount<const N: usize>;
|
|||
|
||||
impl<const N: usize> LaneCount<N> {
|
||||
/// The number of bytes in a bitmask with this many lanes.
|
||||
pub const BITMASK_LEN: usize = (N + 7) / 8;
|
||||
pub const BITMASK_LEN: usize = N.div_ceil(8);
|
||||
}
|
||||
|
||||
/// Statically guarantees that a lane count is marked as supported.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue