Skip to content

Commit 757042c

Browse files
committed
Make Alloc use only 30 bits.
This is useful in the in-progress Cranelift glue in particular, where we wrap `Operand` and `Allocation` together in one 32-bit union, using the MSB to disambiguate. In the `Allocation` case, we still want to carry def/use info so we can tell reads and writes apart for machine-code-level analyses. So stealing an extra bit from `Allocation` is necessary; this just reduces our stack-slot limit to 2^28 slots, which should be no problem.
1 parent 33ac6cb commit 757042c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub struct Operand {
204204
/// Bit-pack into 31 bits. This allows a `Reg` to encode an
205205
/// `Operand` or an `Allocation` in 32 bits.
206206
///
207-
/// op-or-alloc:1 pos:2 kind:1 policy:2 class:1 preg:5 vreg:20
207+
/// free:1 pos:2 kind:1 policy:2 class:1 preg:5 vreg:20
208208
bits: u32,
209209
}
210210

@@ -422,9 +422,9 @@ pub enum OperandPos {
422422
/// Operand.
423423
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
424424
pub struct Allocation {
425-
/// Bit-pack in 31 bits:
425+
/// Bit-pack in 30 bits:
426426
///
427-
/// op-or-alloc:1 kind:2 index:29
427+
/// free:2 kind:2 index:28
428428
bits: u32,
429429
}
430430

@@ -452,8 +452,9 @@ impl std::fmt::Display for Allocation {
452452
impl Allocation {
453453
#[inline(always)]
454454
pub(crate) fn new(kind: AllocationKind, index: usize) -> Self {
455+
assert!(index < (1 << 28));
455456
Self {
456-
bits: ((kind as u8 as u32) << 29) | (index as u32),
457+
bits: ((kind as u8 as u32) << 28) | (index as u32),
457458
}
458459
}
459460

@@ -474,7 +475,7 @@ impl Allocation {
474475

475476
#[inline(always)]
476477
pub fn kind(self) -> AllocationKind {
477-
match (self.bits >> 29) & 3 {
478+
match (self.bits >> 28) & 3 {
478479
0 => AllocationKind::None,
479480
1 => AllocationKind::Reg,
480481
2 => AllocationKind::Stack,
@@ -484,7 +485,7 @@ impl Allocation {
484485

485486
#[inline(always)]
486487
pub fn index(self) -> usize {
487-
(self.bits & ((1 << 29) - 1)) as usize
488+
(self.bits & ((1 << 28) - 1)) as usize
488489
}
489490

490491
#[inline(always)]

0 commit comments

Comments
 (0)