Skip to main content

rucc_codegen/
frame.rs

1//! The frame: what a function's stack looks like while it runs.
2//!
3//! Design: `spec/10-backend.md` section 10.7.
4//!
5//! This is worked out after register allocation and not before, because the largest area in most
6//! frames is the spill slots and nothing knows how many of those there are until the allocator has
7//! finished running out of registers. It is worked out from the rewritten function rather than
8//! from the assignment alone, because the rewrite is what decides which scratch registers a reload
9//! uses, and a scratch register a call preserves is one the prologue has to save.
10//!
11//! # What is in one
12//!
13//! Section 10.7 lists the areas and this is the order they are in, from the stack pointer upward,
14//! which is the order of increasing address on every machine here.
15//!
16//! ```text
17//!   incoming stack arguments      the caller wrote these and they are above everything
18//!   return address                the call instruction pushed it, on a machine that does
19//!   saved frame pointer           when the function keeps one
20//!   saved general purpose regs    pushed, one word each
21//!   saved vector registers        stored rather than pushed, since no machine here pushes one
22//!   locals                        what an alloca becomes, widest alignment first
23//!   spill slots                   one for every value the allocator ran out of registers for
24//!   outgoing argument area        at the bottom, because a call reads its stack arguments from
25//!                                 the stack pointer upward
26//! ```
27//!
28//! Every offset reported here is from the stack pointer as it stands in the body of the function,
29//! which is after the prologue and before the epilogue. That is the one base register always
30//! available. A frame pointer is a second way to reach the same bytes and the prologue is what
31//! knows the distance between the two, so nothing here reports an offset from it.
32//!
33//! # Where the alignment comes from
34//!
35//! A call has to leave the stack pointer on a multiple of the convention's alignment, so a
36//! function's own frame is what puts it back: the call that reached this function pushed a return
37//! address and left the stack pointer one word off, and the prologue's pushes either fix that or
38//! make it worse depending on how many there are. The size the prologue subtracts is therefore not
39//! the size of the areas. It is whatever brings the stack pointer back to a multiple of the
40//! alignment given the pushes in front of it, which is the arithmetic in [`Frame::of`].
41//!
42//! # The red zone
43//!
44//! A leaf function may use the bytes below the stack pointer without moving it, which is what
45//! `red_zone` on a convention says and what makes a small leaf function's prologue and epilogue
46//! empty. Then the offsets are negative, which is why they are signed, and the areas are in the
47//! same order as ever, below the line rather than above it. Anything that calls, or is too big for
48//! the zone, or wants more alignment than the stack pointer has for free, moves the stack pointer.
49//!
50//! # Realignment
51//!
52//! A local wanting more alignment than a call leaves the stack pointer with cannot be placed by
53//! arithmetic, because nothing in the frame knows what the caller's stack pointer was a multiple
54//! of. The prologue has to force it, and forcing it destroys the only record of where the caller's
55//! stack was, so a realigned frame needs a frame pointer and the distance from the body's stack
56//! pointer to the incoming arguments stops being a constant. [`Frame::realign`] is where that is
57//! reported and it is why [`Frame::incoming`] can answer that it does not know.
58
59use rucc_mir::Func;
60use rucc_regalloc::Allocation;
61use rucc_regalloc::assign::Place;
62use rucc_target::{CallRegs, PhysReg, RegClass, RegFile};
63
64/// A piece of memory the function needs for its own use, which is what an `alloca` becomes.
65#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66pub struct Local {
67    /// How many bytes of it there are.
68    pub size: u32,
69    /// What its address has to be a multiple of.
70    pub align: u32,
71}
72
73/// Everything about a function's frame that does not come out of its allocation.
74#[derive(Debug, Clone, Copy)]
75pub struct Layout<'a> {
76    /// Where the convention this function is compiled for puts things.
77    pub conv: &'a CallRegs,
78    /// The registers the target has, which is what says how wide a spill slot of a class is.
79    pub file: RegFile,
80    /// The memory the function asked for itself, in the order it wants it reported back.
81    pub locals: &'a [Local],
82    /// How many bytes the widest call in the function needs for arguments it passes on the stack.
83    pub outgoing: u32,
84    /// Whether the function calls nothing, which is what the alignment and the red zone turn on.
85    pub leaf: bool,
86    /// Whether the function keeps a frame pointer, which `-fno-omit-frame-pointer` asks for and
87    /// which a realigned or a dynamically grown frame requires whatever the flags say.
88    pub frame_pointer: bool,
89    /// Whether the red zone may be used at all, which `-mno-red-zone` and every kernel turns off.
90    pub red_zone: bool,
91}
92
93impl<'a> Layout<'a> {
94    /// A layout for a function with nothing in it but what its allocation says: a leaf with no
95    /// locals and no calls, which is what every function is until the pieces that produce those
96    /// exist.
97    #[must_use]
98    pub fn new(conv: &'a CallRegs, file: RegFile) -> Self {
99        Self {
100            conv,
101            file,
102            locals: &[],
103            outgoing: 0,
104            leaf: true,
105            frame_pointer: false,
106            red_zone: true,
107        }
108    }
109}
110
111/// What a function's stack looks like while it runs.
112#[derive(Debug, Clone, PartialEq, Eq)]
113pub struct Frame {
114    saved_int: Vec<PhysReg>,
115    saved_sse: Vec<PhysReg>,
116    slots: Vec<i32>,
117    locals: Vec<i32>,
118    outgoing: u32,
119    size: u32,
120    realign: Option<u32>,
121    incoming: Option<i32>,
122    frame_pointer: bool,
123}
124
125impl Frame {
126    /// Works out the frame of a function the allocator has finished with.
127    ///
128    /// # Panics
129    ///
130    /// Panics on a frame of two gigabytes or more, which is a stack no machine here gives a
131    /// thread, and on a local whose alignment is not a power of two.
132    #[must_use]
133    pub fn of(func: &Func, allocation: &Allocation, layout: &Layout<'_>) -> Self {
134        let conv = layout.conv;
135        let word = conv.word;
136        let (saved_int, saved_sse) = saved(func, allocation, layout);
137
138        // The vector registers are saved in the frame rather than pushed, because no machine here
139        // has an instruction that pushes one.
140        let vector = width(layout, conv.sse_class);
141        let mut top = u32::try_from(saved_sse.len()).expect("a frame") * vector;
142        let mut align = if saved_sse.is_empty() { word } else { vector };
143
144        let mut locals = vec![0; layout.locals.len()];
145        let mut order: Vec<usize> = (0..layout.locals.len()).collect();
146        // Widest alignment first, so that placing each one straight after the last never leaves a
147        // hole bigger than the alignment the next one asked for.
148        order.sort_by_key(|&local| std::cmp::Reverse(layout.locals[local].align));
149        for local in order {
150            let Local { size, align: want } = layout.locals[local];
151            assert!(
152                want.is_power_of_two(),
153                "a local aligned to something that is not a power of 2"
154            );
155            align = align.max(want);
156            top = top.next_multiple_of(want);
157            locals[local] = offset(top);
158            top += size;
159        }
160
161        let mut slots = Vec::with_capacity(allocation.assignment.slots().len());
162        for &class in allocation.assignment.slots() {
163            let size = width(layout, class);
164            align = align.max(size);
165            top = top.next_multiple_of(size);
166            slots.push(offset(top));
167            top += size;
168        }
169
170        // A call reads its stack arguments from the stack pointer upward, so the outgoing area is
171        // at the bottom of the frame and its size is what shifts everything else.
172        let outgoing = if layout.leaf { 0 } else { layout.outgoing.max(conv.shadow) };
173        let body = (top + outgoing).next_multiple_of(word);
174
175        // Where the stack pointer sits once the prologue has finished pushing: one return address
176        // short of aligned when the function starts, and one word further off for every push.
177        let pushed =
178            u32::from(layout.frame_pointer) + u32::try_from(saved_int.len()).expect("a frame");
179        let entry = wrap(conv.stack_align, conv.return_address);
180        let after = (entry + wrap(conv.stack_align, word * pushed)) % conv.stack_align;
181
182        let realign = (align > conv.stack_align).then_some(align);
183        let free = layout.leaf
184            && layout.red_zone
185            && realign.is_none()
186            && align <= word
187            && body <= conv.red_zone;
188        let size = match realign {
189            _ if free => 0,
190            // Once the prologue has forced the alignment, keeping the frame a multiple of it keeps
191            // everything in the frame aligned too.
192            Some(to) => body.next_multiple_of(to),
193            // A leaf owes nobody an aligned stack pointer, so it takes exactly what it uses.
194            None if layout.leaf && align <= word => body,
195            // The smallest frame that lands the stack pointer back on a multiple of the alignment
196            // given where the pushes left it.
197            None => body + (after + conv.stack_align - body % conv.stack_align) % conv.stack_align,
198        };
199
200        // With the stack pointer left where it was, the areas are the same areas in the same order
201        // and they are below it rather than above it.
202        let shift = if free { -offset(body) } else { offset(outgoing) };
203        for at in slots.iter_mut().chain(locals.iter_mut()) {
204            *at += shift;
205        }
206
207        Self {
208            saved_int,
209            saved_sse,
210            slots,
211            locals,
212            outgoing,
213            size,
214            realign,
215            incoming: realign.is_none().then(|| offset(size + word * pushed + conv.return_address)),
216            frame_pointer: layout.frame_pointer || realign.is_some(),
217        }
218    }
219
220    /// The general purpose registers the prologue pushes, in the order it pushes them.
221    ///
222    /// The frame pointer is not among them even when the convention calls it a saved register,
223    /// because a function that keeps one saves it as part of setting it up.
224    #[must_use]
225    pub fn saved_int(&self) -> &[PhysReg] {
226        &self.saved_int
227    }
228
229    /// The vector registers the prologue stores into the frame, in the order it stores them.
230    #[must_use]
231    pub fn saved_sse(&self) -> &[PhysReg] {
232        &self.saved_sse
233    }
234
235    /// Where a spill slot is, from the stack pointer in the body of the function.
236    #[must_use]
237    pub fn slot(&self, slot: u32) -> Option<i32> {
238        self.slots.get(usize::try_from(slot).ok()?).copied()
239    }
240
241    /// Where a local is, from the stack pointer in the body of the function.
242    #[must_use]
243    pub fn local(&self, local: usize) -> Option<i32> {
244        self.locals.get(local).copied()
245    }
246
247    /// How many bytes the prologue takes off the stack pointer, which is nothing for a function
248    /// small enough and quiet enough to live in the red zone.
249    #[must_use]
250    pub fn size(&self) -> u32 {
251        self.size
252    }
253
254    /// How many bytes at the bottom of the frame belong to the arguments of calls this function
255    /// makes, which is where the shadow space goes on Windows.
256    #[must_use]
257    pub fn outgoing(&self) -> u32 {
258        self.outgoing
259    }
260
261    /// What the prologue has to force the stack pointer to be a multiple of, when a local wants
262    /// more alignment than a call leaves it with.
263    #[must_use]
264    pub fn realign(&self) -> Option<u32> {
265        self.realign
266    }
267
268    /// Where the first argument the caller passed on the stack is, from the stack pointer in the
269    /// body of the function.
270    ///
271    /// A realigned frame answers that it does not know, because forcing the alignment threw away
272    /// however far the caller's stack pointer was from where the prologue wanted it, and the frame
273    /// pointer is what reaches the caller's stack afterwards.
274    #[must_use]
275    pub fn incoming(&self) -> Option<i32> {
276        self.incoming
277    }
278
279    /// Whether the function keeps a frame pointer.
280    #[must_use]
281    pub fn frame_pointer(&self) -> bool {
282        self.frame_pointer
283    }
284}
285
286/// The registers a call preserves that this function writes anyway, so the prologue has to put
287/// them back.
288///
289/// The rewritten function is what is read here rather than the assignment, because a spilled value
290/// is reloaded into a scratch register that no assignment mentions, and a scratch register the
291/// convention preserves is one this has to find.
292fn saved(
293    func: &Func,
294    allocation: &Allocation,
295    layout: &Layout<'_>,
296) -> (Vec<PhysReg>, Vec<PhysReg>) {
297    let mut used: Vec<(RegClass, PhysReg)> = Vec::new();
298    let mut note = |class: RegClass, at: PhysReg| {
299        if !used.contains(&(class, at)) {
300            used.push((class, at));
301        }
302    };
303    for block in func.blocks() {
304        for inst in func.insts(block) {
305            for operand in &func[func[inst].operands] {
306                if let Some(at) = operand.reg.phys() {
307                    note(operand.class, at);
308                }
309            }
310        }
311    }
312    for edit in &allocation.edits {
313        for place in [edit.mov.from, edit.mov.to] {
314            if let Place::Reg(at) = place {
315                note(edit.class, at);
316            }
317        }
318    }
319
320    let conv = layout.conv;
321    let wanted = |class: RegClass, at: PhysReg| used.contains(&(class, at));
322    // In the convention's order rather than the order the function happened to reach for them, so
323    // that two functions saving the same registers get the same prologue.
324    let saved_int = conv
325        .int_saved
326        .iter()
327        .copied()
328        .filter(|&at| wanted(conv.int_class, at))
329        .filter(|&at| !(layout.frame_pointer && at == conv.frame_pointer))
330        .collect();
331    let saved_sse =
332        conv.sse_saved.iter().copied().filter(|&at| wanted(conv.sse_class, at)).collect();
333    (saved_int, saved_sse)
334}
335
336/// How many bytes a value of a class takes on the stack.
337///
338/// A power of two at least a word wide, because a slot is addressed and an address that is not a
339/// multiple of the size of the thing at it is a fault on some machines and slow on the rest. An
340/// eighty bit `long double` takes sixteen bytes for that reason, which is what every compiler
341/// does with one.
342fn width(layout: &Layout<'_>, class: RegClass) -> u32 {
343    let bits = layout.file.class(class).map_or(0, |info| info.bits);
344    bits.div_ceil(8).max(layout.conv.word).next_power_of_two()
345}
346
347/// How far past a multiple of an alignment a number is, counted the other way: what has to be
348/// added to it to reach the next one.
349fn wrap(align: u32, value: u32) -> u32 {
350    (align - value % align) % align
351}
352
353/// A distance in a frame, as the signed number every offset out of here is.
354fn offset(bytes: u32) -> i32 {
355    i32::try_from(bytes).expect("a frame under two gigabytes")
356}
357
358#[cfg(test)]
359mod tests {
360    use rucc_base::Interner;
361    use rucc_mir::{Opcode, Operand, Reg};
362    use rucc_regalloc::assign::Env;
363    use rucc_target::x86_64::{GPR, RBP, REGS, SYSV, WIN64, XMM};
364
365    use super::*;
366
367    /// An environment offering that many of the convention's registers, with everything after
368    /// them held back as scratch.
369    fn env(conv: &CallRegs, count: usize) -> Env {
370        Env::new().with(GPR, &conv.int_order[..count], &conv.int_order[count..])
371    }
372
373    /// A function of that many values, every one of them written before any is read, allocated
374    /// with that many registers to hand out.
375    ///
376    /// Every value is live at the first read, so a count below the number of values is what puts
377    /// the function under enough pressure to spill, and each read wants one value so a reload
378    /// never needs more than one scratch register.
379    fn pressure(conv: &CallRegs, values: usize, count: usize) -> (Func, Allocation) {
380        let mut names = Interner::new();
381        let mut func = Func::new(names.intern("f"));
382        let opcode = Opcode::new(names.intern("x64.nop"));
383        let block = func.create_block();
384        let regs: Vec<Reg> = (0..values).map(|_| func.new_vreg(GPR)).collect();
385        for &reg in &regs {
386            func.build(block, opcode).def(reg, GPR).finish();
387        }
388        for &reg in &regs {
389            func.build(block, opcode).uses(reg, GPR).finish();
390        }
391        let allocation = rucc_regalloc::run(&mut func, &env(conv, count));
392        (func, allocation)
393    }
394
395    /// What a list of registers is called, which is what an assertion reads.
396    fn named(regs: &[PhysReg]) -> Vec<&'static str> {
397        regs.iter().map(|&reg| REGS.name(GPR, reg).expect("a register")).collect()
398    }
399
400    #[test]
401    fn a_function_that_needs_nothing_of_the_stack_has_no_frame_at_all() {
402        let (func, allocation) = pressure(&SYSV, 2, 4);
403        let frame = Frame::of(&func, &allocation, &Layout::new(&SYSV, REGS));
404
405        assert_eq!(frame.size(), 0);
406        assert_eq!(named(frame.saved_int()), Vec::<&str>::new());
407        assert_eq!(frame.slot(0), None);
408        // Nothing between the stack pointer and the return address the call pushed.
409        assert_eq!(frame.incoming(), Some(8));
410    }
411
412    #[test]
413    fn a_small_leaf_function_puts_its_spills_in_the_red_zone_and_moves_nothing() {
414        let (func, allocation) = pressure(&SYSV, 4, 2);
415        let frame = Frame::of(&func, &allocation, &Layout::new(&SYSV, REGS));
416
417        // Two registers for four values that are all live at once, so two are on the stack, and a
418        // leaf function small enough is entitled to the bytes below the stack pointer.
419        assert_eq!(frame.size(), 0);
420        assert_eq!((frame.slot(0), frame.slot(1)), (Some(-16), Some(-8)));
421        assert_eq!(frame.slot(2), None);
422        assert_eq!(frame.incoming(), Some(8));
423    }
424
425    #[test]
426    fn a_leaf_function_told_it_has_no_red_zone_takes_the_bytes_instead() {
427        let (func, allocation) = pressure(&SYSV, 4, 2);
428        let base = Layout::new(&SYSV, REGS);
429        let frame = Frame::of(&func, &allocation, &Layout { red_zone: false, ..base });
430
431        assert_eq!(frame.size(), 16);
432        assert_eq!((frame.slot(0), frame.slot(1)), (Some(0), Some(8)));
433        assert_eq!(frame.incoming(), Some(24));
434    }
435
436    #[test]
437    fn a_frame_too_big_for_the_red_zone_takes_the_bytes_whatever_else_is_true() {
438        let (func, allocation) = pressure(&SYSV, 40, 2);
439        let frame = Frame::of(&func, &allocation, &Layout::new(&SYSV, REGS));
440
441        // Thirty eight values on the stack is three hundred and four bytes, and the red zone is a
442        // hundred and twenty eight.
443        assert_eq!(frame.size(), 304);
444        assert_eq!(frame.slot(0), Some(0));
445        assert_eq!(frame.slot(37), Some(296));
446    }
447
448    #[test]
449    fn a_function_that_calls_something_leaves_the_stack_pointer_where_a_call_wants_it() {
450        let (func, allocation) = pressure(&SYSV, 4, 2);
451        let base = Layout::new(&SYSV, REGS);
452        let frame = Frame::of(&func, &allocation, &Layout { leaf: false, ..base });
453
454        // Sixteen bytes of spills, and the call that reached this function left the stack pointer
455        // eight bytes off, so the frame is eight bytes wider than the spills need and every call
456        // this function makes is correctly aligned.
457        assert_eq!(frame.size(), 24);
458        assert_eq!((frame.slot(0), frame.slot(1)), (Some(0), Some(8)));
459        assert_eq!(frame.incoming(), Some(32));
460    }
461
462    #[test]
463    fn a_push_is_counted_in_the_alignment_the_frame_has_to_produce() {
464        let (func, allocation) = pressure(&SYSV, 12, 12);
465        let base = Layout::new(&SYSV, REGS);
466        let frame = Frame::of(&func, &allocation, &Layout { leaf: false, ..base });
467
468        // Twelve values reach into the preserved end of the allocation order, so three registers
469        // are pushed, and three pushes plus the return address is a multiple of sixteen already.
470        // The frame is empty and stays empty rather than being padded for the sake of it.
471        assert_eq!(named(frame.saved_int()), ["rbx", "r12", "r13"]);
472        assert_eq!(frame.size(), 0);
473        assert_eq!(frame.incoming(), Some(32));
474    }
475
476    #[test]
477    fn the_registers_a_call_leaves_alone_are_saved_in_the_order_the_convention_lists_them() {
478        let (func, allocation) = pressure(&SYSV, 13, 13);
479        let frame = Frame::of(&func, &allocation, &Layout::new(&SYSV, REGS));
480
481        // Four of them now, in the convention's order rather than the order the allocator handed
482        // them out in, so that two functions saving the same registers get the same prologue.
483        assert_eq!(named(frame.saved_int()), ["rbx", "r12", "r13", "r14"]);
484    }
485
486    #[test]
487    fn a_function_that_keeps_a_frame_pointer_does_not_save_it_twice() {
488        let mut names = Interner::new();
489        let mut func = Func::new(names.intern("f"));
490        let opcode = Opcode::new(names.intern("x64.nop"));
491        let block = func.create_block();
492        // An instruction that names the frame pointer register outright, which is what a lowering
493        // rule for something that has to use it produces.
494        func.build(block, opcode).operand(Operand::write(Reg::physical(RBP), GPR)).finish();
495        let allocation = rucc_regalloc::run(&mut func, &env(&SYSV, 4));
496        let base = Layout::new(&SYSV, REGS);
497
498        let kept = Frame::of(&func, &allocation, &Layout { frame_pointer: true, ..base });
499        let dropped = Frame::of(&func, &allocation, &base);
500
501        // `rbp` is a register SysV preserves, so a function that leaves it alone saves it in the
502        // ordinary way, and a function that keeps a frame pointer in it saves it as part of
503        // setting the frame pointer up instead.
504        assert_eq!(named(dropped.saved_int()), ["rbp"]);
505        assert_eq!(named(kept.saved_int()), Vec::<&str>::new());
506        assert!(kept.frame_pointer());
507    }
508
509    #[test]
510    fn locals_are_placed_widest_alignment_first_and_reported_in_the_order_they_arrived() {
511        let (func, allocation) = pressure(&SYSV, 2, 4);
512        let locals = [
513            Local { size: 1, align: 1 },
514            Local { size: 16, align: 16 },
515            Local { size: 8, align: 8 },
516        ];
517        let base = Layout::new(&SYSV, REGS);
518        let frame = Frame::of(&func, &allocation, &Layout { locals: &locals, ..base });
519
520        // The sixteen byte one is placed first, so nothing is padded to reach it, and the one
521        // byte one goes last where the padding after it costs nothing.
522        assert_eq!((frame.local(1), frame.local(2), frame.local(0)), (Some(0), Some(16), Some(24)));
523        assert_eq!(frame.local(3), None);
524        // A local wanting sixteen byte alignment is more than the stack pointer has for free, so
525        // the frame is taken rather than the red zone used, and it is padded to keep the local
526        // where it was put.
527        assert_eq!(frame.size(), 40);
528        assert_eq!(frame.realign(), None);
529    }
530
531    #[test]
532    fn a_local_wanting_more_alignment_than_a_call_gives_makes_the_prologue_force_it() {
533        let (func, allocation) = pressure(&SYSV, 2, 4);
534        let locals = [Local { size: 64, align: 32 }];
535        let base = Layout::new(&SYSV, REGS);
536        let frame = Frame::of(&func, &allocation, &Layout { locals: &locals, ..base });
537
538        assert_eq!(frame.realign(), Some(32));
539        assert_eq!(frame.local(0), Some(0));
540        assert_eq!(frame.size(), 64);
541        // Forcing the alignment throws away how far the caller's stack pointer was from where the
542        // prologue wanted it, so a frame pointer is needed and the caller's stack is no longer a
543        // constant distance away.
544        assert!(frame.frame_pointer());
545        assert_eq!(frame.incoming(), None);
546    }
547
548    #[test]
549    fn a_call_reads_its_stack_arguments_from_the_bottom_of_the_frame() {
550        let (func, allocation) = pressure(&SYSV, 4, 2);
551        let base = Layout::new(&SYSV, REGS);
552        let frame = Frame::of(&func, &allocation, &Layout { leaf: false, outgoing: 24, ..base });
553
554        // The outgoing area is at the stack pointer, because that is where the callee will look
555        // for it, and the spills sit above it.
556        assert_eq!(frame.outgoing(), 24);
557        assert_eq!((frame.slot(0), frame.slot(1)), (Some(24), Some(32)));
558        assert_eq!(frame.size(), 40);
559    }
560
561    #[test]
562    fn a_windows_call_gets_the_thirty_two_bytes_below_it_even_when_it_passes_nothing() {
563        let (func, allocation) = pressure(&WIN64, 2, 4);
564        let base = Layout::new(&WIN64, REGS);
565        let frame = Frame::of(&func, &allocation, &Layout { leaf: false, ..base });
566
567        // Windows has no red zone and every caller reserves thirty two bytes below the call for
568        // the callee to spill its register arguments into.
569        assert_eq!(frame.outgoing(), 32);
570        assert_eq!(frame.size(), 40);
571        assert_eq!(frame.incoming(), Some(48));
572    }
573
574    #[test]
575    fn a_slot_is_as_wide_as_the_widest_thing_of_its_class() {
576        let base = Layout::new(&SYSV, REGS);
577
578        assert_eq!(width(&base, GPR), 8);
579        assert_eq!(width(&base, XMM), 16);
580        // A long double is eighty bits and takes sixteen bytes, because an address has to be a
581        // multiple of the size of what is at it.
582        assert_eq!(width(&base, REGS.class_named("x87").expect("a class")), 16);
583    }
584}