Skip to content

Commit 6690122

Browse files
committed
Only cache limits as u8
To avoid possible cache issues, Chris [asked] to store a smaller size for the cached limit. This change drops the `Option<usize>` to a `Option<u8>` adding conversions between `usize` and `u8` as needed. The `usize` is retained for consistency in the public API (`OperandConstraint::Limit`) and for ease of use in comparing with HW encodings and slice indexes (all `usize`). [asked]: #239 (comment)
1 parent 4511ac6 commit 6690122

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

src/ion/data_structures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ pub struct LiveBundle {
203203
pub allocation: Allocation,
204204
pub prio: u32, // recomputed after every bulk update
205205
pub spill_weight_and_props: u32,
206-
pub limit: Option<usize>,
206+
pub limit: Option<u8>,
207207
}
208208

209209
pub const BUNDLE_MAX_SPILL_WEIGHT: u32 = (1 << 28) - 1;

src/ion/merge.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::ion::data_structures::{
1818
};
1919
use crate::{Function, Inst, OperandConstraint, OperandKind, PReg, ProgPoint};
2020
use alloc::format;
21+
use core::convert::TryFrom;
2122

2223
impl<'a, F: Function> Env<'a, F> {
2324
fn merge_bundle_properties(&mut self, from: LiveBundleIndex, to: LiveBundleIndex) {
@@ -282,7 +283,7 @@ impl<'a, F: Function> Env<'a, F> {
282283
let mut fixed = false;
283284
let mut fixed_def = false;
284285
let mut stack = false;
285-
let mut limit: Option<usize> = None;
286+
let mut limit: Option<u8> = None;
286287
for entry in &self.bundles[bundle].ranges {
287288
for u in &self.ranges[entry.index].uses {
288289
use OperandConstraint::*;
@@ -294,10 +295,14 @@ impl<'a, F: Function> Env<'a, F> {
294295
}
295296
}
296297
Stack => stack = true,
297-
Limit(current) => match limit {
298-
Some(prev) => limit = Some(prev.min(current)),
299-
None => limit = Some(current),
300-
},
298+
Limit(current) => {
299+
let current = u8::try_from(current)
300+
.expect("the current limit is too large to fit in a u8");
301+
match limit {
302+
Some(prev) => limit = Some(prev.min(current)),
303+
None => limit = Some(current),
304+
}
305+
}
301306
Any | Reg | Reuse(_) => {
302307
continue;
303308
}
@@ -392,16 +397,20 @@ impl<'a, F: Function> Env<'a, F> {
392397
total
393398
}
394399

395-
pub fn compute_bundle_limit(&self, bundle: LiveBundleIndex) -> Option<usize> {
396-
let mut limit: Option<usize> = None;
400+
pub fn compute_bundle_limit(&self, bundle: LiveBundleIndex) -> Option<u8> {
401+
let mut limit: Option<u8> = None;
397402
for entry in &self.bundles[bundle].ranges {
398403
for u in &self.ranges[entry.index].uses {
399404
use OperandConstraint::*;
400405
match u.operand.constraint() {
401-
Limit(current) => match limit {
402-
Some(prev) => limit = Some(prev.min(current)),
403-
None => limit = Some(current),
404-
},
406+
Limit(current) => {
407+
let current = u8::try_from(current)
408+
.expect("the current limit is too large to fit in a u8");
409+
match limit {
410+
Some(prev) => limit = Some(prev.min(current)),
411+
None => limit = Some(current),
412+
}
413+
}
405414
FixedReg(_) | Stack => {
406415
break;
407416
}

src/ion/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ impl<'a, F: Function> Env<'a, F> {
10731073
+ bundle.index();
10741074

10751075
self.ctx.output.stats.process_bundle_reg_probe_start_any += 1;
1076-
let limit = self.bundles[bundle].limit;
1076+
let limit = self.bundles[bundle].limit.map(|l| l as usize);
10771077
for preg in RegTraversalIter::new(
10781078
self.env,
10791079
class,

src/ion/spill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'a, F: Function> Env<'a, F> {
4242

4343
let mut success = false;
4444
self.ctx.output.stats.spill_bundle_reg_probes += 1;
45-
let limit = self.bundles[bundle].limit;
45+
let limit = self.bundles[bundle].limit.map(|l| l as usize);
4646
for preg in RegTraversalIter::new(self.env, class, None, hint, bundle.index(), limit) {
4747
trace!("trying bundle {:?} to preg {:?}", bundle, preg);
4848
let preg_idx = PRegIndex::new(preg.index());

0 commit comments

Comments
 (0)