Skip to main content

rucc_codegen/select/
x86_64.rs

1//! The x86-64 lowering table.
2//!
3//! Everything below the module comment is generated from `rules/x86-64.rules` by `rucc-rules`
4//! when this crate is built, and none of it is in the repository. The rule file is the only
5//! place the rules are written, which is what makes the table that is matched with and the
6//! table `rucc-verify` proves things about the same table.
7//!
8//! To read the rules, read the rule file. To read the automaton they compile into, build the
9//! crate and read `x86-64.rs` under the build directory, which is a file worth looking at once
10//! for the shape of it and never again.
11
12// A guard is emitted as the comparison the rule writes, so a rule saying a shift count is at
13// least zero and less than the width comes out as two comparisons rather than as a range. That
14// is deliberate: the generated line and the rule it came from should read the same, and the
15// suggestion to write it another way is advice for somebody editing code, which nobody here is.
16#![allow(clippy::manual_range_contains)]
17
18include!(concat!(env!("OUT_DIR"), "/x86-64.rs"));
19
20#[cfg(test)]
21mod tests {
22    use rucc_target::x86_64;
23
24    use super::TABLE;
25    use crate::select::Piece;
26
27    /// The prefix a rule file puts in front of a machine term, which is how it says which target
28    /// the term belongs to. It is not part of the opcode.
29    const PREFIX: &str = "x64.";
30
31    /// The two address constructors, which are not instructions. An addressing mode is an
32    /// argument to `lea` and to every memory operand after it, so it is written as a term in the
33    /// rule file and built by the selector into the instruction that takes it.
34    const AMODES: &[&str] =
35        &["amode_base_index_scale", "amode_index_scale", "amode_base", "amode_base_offset"];
36
37    /// Every head this table can write, in and under the replacements.
38    fn heads() -> Vec<&'static str> {
39        let mut found: Vec<&'static str> = TABLE
40            .rules
41            .iter()
42            .flat_map(|rule| rule.replacement.iter())
43            .filter_map(|piece| match piece {
44                Piece::App { head, .. } => Some(*head),
45                _ => None,
46            })
47            .collect();
48        found.sort_unstable();
49        found.dedup();
50        found
51    }
52
53    #[test]
54    fn every_instruction_the_table_writes_is_described() {
55        for head in heads() {
56            if AMODES.contains(&head) {
57                continue;
58            }
59            let opcode = head.strip_prefix(PREFIX).unwrap_or_else(|| {
60                panic!("{head} is neither an x86-64 term nor an addressing mode")
61            });
62            assert!(
63                x86_64::form(opcode).is_some(),
64                "{head} is selected by a rule and `rucc_target::x86_64` does not say what it \
65                 does with its operands"
66            );
67        }
68    }
69
70    /// The order the operands of a store are written in, which is the IR's and not a choice this
71    /// file makes.
72    ///
73    /// A pattern is matched against an instruction's operand list by position, so a rule that
74    /// names the address where the IR holds the value is a rule that stores to the value and
75    /// writes the address into memory. Nothing in a proof would catch it, because a proof is
76    /// about the rule file agreeing with itself, and both halves would be wrong in the same way.
77    /// `rucc_ir::Builder::store` takes the value first and the machine instruction takes it last,
78    /// which is why the two halves of one of these rules read in opposite orders.
79    #[test]
80    fn a_store_is_written_with_the_value_first_because_that_is_where_the_ir_keeps_it() {
81        let mut seen = 0;
82        for rule in TABLE.rules {
83            let Some(rest) = rule.pattern.strip_prefix("(store.") else { continue };
84            let (width, operands) = rest.split_once(' ').expect("a store takes operands");
85            assert!(
86                operands.starts_with(&format!("(value.{width} ")),
87                "line {}: {} binds something other than the value it is storing first",
88                rule.line,
89                rule.pattern
90            );
91            assert!(
92                operands.contains("(value.i64 "),
93                "line {}: {} reaches no address",
94                rule.line,
95                rule.pattern
96            );
97            seen += 1;
98        }
99        assert_eq!(seen, 14, "the store rules moved and this test did not follow them");
100    }
101
102    /// Every comparison can be made against a constant as well as against a register.
103    ///
104    /// Four comparisons in five in the corpus are against a constant, and without a rule for one
105    /// the constant is loaded into a register first, which is an instruction and a register the
106    /// machine never needed. A missing width or a missing condition would not fail anything else:
107    /// the register rule still matches, the output is still correct, and the only sign is code
108    /// that is one instruction longer in a place nobody is looking. So the two lists are counted
109    /// against each other here.
110    ///
111    /// What this cannot check is that the condition on the immediate rule is the right one, since
112    /// both halves of a wrong pair would be a consistent pair. That is what the `spec` clause is
113    /// for, and `rucc-verify` is what reads it.
114    #[test]
115    fn a_comparison_against_a_constant_is_written_for_every_one_against_a_register() {
116        let mut against_register = Vec::new();
117        let mut against_constant = Vec::new();
118        for rule in TABLE.rules {
119            let Some(rest) = rule.pattern.strip_prefix("(icmp_") else { continue };
120            let (condition, operands) = rest.split_once(".i1 ").expect("a comparison takes two");
121            let width = operands
122                .strip_prefix("(value.")
123                .and_then(|rest| rest.split_once(' '))
124                .map(|(width, _)| width)
125                .expect("a comparison reads a value first");
126            let named = format!("{condition}.{width}");
127            if operands.contains("(iconst.") {
128                // The constant is the second operand and never the first, because a comparison is
129                // not symmetric and the same condition on the other side means the opposite.
130                assert!(
131                    !operands.starts_with("(iconst."),
132                    "line {}: {} compares a constant against a value",
133                    rule.line,
134                    rule.pattern
135                );
136                against_constant.push(named);
137            } else {
138                against_register.push(named);
139            }
140        }
141        against_register.sort_unstable();
142        against_constant.sort_unstable();
143        assert_eq!(against_register, against_constant);
144        assert_eq!(against_register.len(), 40, "ten conditions at four widths");
145    }
146
147    /// The instructions the calling convention writes rather than a rule.
148    ///
149    /// Three kinds of them. Naming the register an argument arrived in, where an argument is
150    /// depends on its position in the signature and on the classification of every argument before
151    /// it, and a rule pattern sees one term and has no way to say any of that, so `crate::abi`
152    /// builds these from the convention instead. Calling a name is the same the other way round:
153    /// what its operands are is whatever the signature made them, and a call through an address is
154    /// the same instruction with one operand more.
155    ///
156    /// The second half of a value that comes back in two registers is the third. A return of one
157    /// value is a rule, because where that value goes depends on nothing but the value, which is
158    /// exactly what a rule can say. A return of two is not, because which register the second half
159    /// is in depends on the first half: the two register files are counted separately, so a
160    /// `double` and a `long` both come back at place zero and two `long`s do not.
161    const CONVENTION: &[&str] = &[
162        "arg_val_8",
163        "arg_val_16",
164        "arg_val_32",
165        "arg_val_64",
166        "arg_val_f32",
167        "arg_val_f64",
168        "ret_val2_8",
169        "ret_val2_16",
170        "ret_val2_32",
171        "ret_val2_64",
172        "ret_val2_f32",
173        "ret_val2_f64",
174        "call",
175        "call_reg",
176    ];
177
178    /// The instructions the block layout writes rather than a rule.
179    ///
180    /// A rule sees one branch and the layout is about the order of every block in the function, so
181    /// which arm falls through is not something any pattern could say. That answer is what decides
182    /// whether the jump goes to the arm the condition is true for or the other one, and whether
183    /// there is a second jump after it, so all of these are written where the answer is.
184    ///
185    /// The comparisons are here for a second reason on top of that one. A branch on a comparison
186    /// is a comparison and a jump on the flags it set, and the flags are not a value: no pattern
187    /// could bind one and no `spec` clause could say anything about one. So the pair is put
188    /// together by the layout, out of a comparison a rule did select and the branch behind it,
189    /// which is the same argument `rucc_target::x86_64::Form::CmpSet` is one form rather than two
190    /// under.
191    const LAYOUT: &[&str] = &[
192        "test_rr_8",
193        "cmp_rr_8",
194        "cmp_rr_16",
195        "cmp_rr_32",
196        "cmp_rr_64",
197        "cmp_ri_8",
198        "cmp_ri_16",
199        "cmp_ri_32",
200        "cmp_ri_64",
201        "jcc_e",
202        "jcc_ne",
203        "jcc_l",
204        "jcc_le",
205        "jcc_g",
206        "jcc_ge",
207        "jcc_b",
208        "jcc_be",
209        "jcc_a",
210        "jcc_ae",
211        "jmp",
212    ];
213
214    /// The instruction the memory model writes rather than a rule.
215    ///
216    /// A barrier computes nothing, so there is no equality for the solver to discharge and no
217    /// pattern for a rule to be written as. What makes it the right answer is what the machine
218    /// promises about the order two other instructions become visible in, which is a claim about
219    /// the program around it rather than about any value. `crate::lower` writes it by name, at the
220    /// strongest ordering and nowhere else, and `crate::expand` says why the strongest is the only
221    /// one that costs anything here.
222    const BARRIER: &[&str] = &["mfence"];
223
224    /// The instructions that produce two values, which is one more than a rule can name.
225    ///
226    /// A rule replaces a term with a term, and a term is the value one instruction computes. A
227    /// compare and exchange computes two: what it found at the address, and whether what it found
228    /// was what the program expected. There is no way to write the second one down in the rule
229    /// language, and inventing one would be inventing a language for a single instruction.
230    ///
231    /// So `crate::lower` writes it by name, the way it writes the barrier by name, and for a reason
232    /// that is about the rule language rather than about the machine. What the solver would have
233    /// been asked to prove about it is the easy half in any case: the arithmetic is a comparison
234    /// and a select, and what is hard is that the whole of it happens at once, which is the same
235    /// claim about the program around it that a barrier makes.
236    const ATOMIC: &[&str] = &["cmpxchg_8", "cmpxchg_16", "cmpxchg_32", "cmpxchg_64"];
237
238    /// The instructions whose operation is in the payload rather than in the head.
239    ///
240    /// A different exemption from the one above, on instructions that produce one value each and so
241    /// could be named by a rule if the rule had anything to match on. The head a pattern matches is
242    /// an opcode and a type, and every read modify write in the IR is the one opcode `atomic_rmw`.
243    /// Which of the thirteen operations it performs is carried beside the instruction rather than in
244    /// its name, so a pattern written for the exchange would match the add and the nand as well, and
245    /// the rule language has no way to look at what a rule matched to tell them apart.
246    ///
247    /// Giving each operation its own opcode is the other way out and is a worse trade: it is
248    /// thirteen opcodes at four widths where the IR wants one, and every pass that treats a read
249    /// modify write as one thing would then have a list of fifty two.
250    ///
251    /// So `crate::lower` writes these by name too. Three operations here, out of the thirteen: the
252    /// bitwise ones need a loop around a compare and exchange, which is control flow and so is built
253    /// before selection rather than during it, and they are the rest of `tamnd/rucc#311`.
254    const PAYLOAD: &[&str] =
255        &["xchg_8", "xchg_16", "xchg_32", "xchg_64", "xadd_8", "xadd_16", "xadd_32", "xadd_64"];
256
257    /// The instructions a frame writes rather than a rule.
258    ///
259    /// A prologue, an epilogue, a copy, a spill and a reload are not in the program. They are what
260    /// the allocator's answer costs, so they are written after it, by `crate::finish` reading
261    /// `x86_64::FRAME`. Six of the names that describes are already reachable from a rule, since a
262    /// prologue taking its frame is a subtraction and a spill is a store, and those are not here:
263    /// this is only the ones nothing else can reach.
264    const FRAME: &[&str] = &[
265        "push_64",
266        "pop_64",
267        "ret",
268        "mov_rr_64",
269        "movaps_rr",
270        "movaps_rm",
271        "movaps_mr",
272        // The touch a probing prologue puts on each page as it reaches it, the landing pad a
273        // prologue opens with, and the byte that does nothing which one reserves room with. All
274        // three are written by a frame and none on a command line that did not ask for it.
275        "or_mi_8",
276        "endbr64",
277        "nop",
278    ];
279
280    /// The instructions that reach the x87 stack, which are selected but not from here.
281    ///
282    /// A third kind of exemption, and the same reason all the way down the list.
283    ///
284    /// Every one of these is written by `crate::lower`, as part of a group rather than on its own.
285    /// What one of them leaves behind and the next picks up is the top of the x87 stack, which is
286    /// not a register anything allocates from and not a value a pattern could bind, so a rule
287    /// could neither match the middle of a group nor name what its replacement produced. And an
288    /// add here reads two addresses and writes a third, where one machine IR instruction carries
289    /// one addressing mode, so the group cannot be folded into a single opcode the way
290    /// `ucomisd_set_e` folds a comparison and a `setcc` either.
291    ///
292    /// So these are exempt for the reason `FRAME` is exempt rather than for the reason the list
293    /// below is, and they will stay exempt. Two of them are not reached by anything yet all the
294    /// same: `fsub_p` and `fdiv_p` are the other direction of the subtraction and the division,
295    /// which a code generator that pushed its operands the other way round would need and this one
296    /// does not. `fabs` is a third, since C spells that as a call to a library function.
297    const X87: &[&str] = &[
298        "fld_t",
299        "fstp_t",
300        "fld_s",
301        "fld_l",
302        "fild_l",
303        "fild_ll",
304        "fstp_s",
305        "fstp_l",
306        "fistp_l",
307        "fistp_ll",
308        "fnstcw",
309        "fldcw",
310        "fadd_p",
311        "fsub_p",
312        "fsubr_p",
313        "fmul_p",
314        "fdiv_p",
315        "fdivr_p",
316        "fchs",
317        "fabs",
318        "fucomip_set_a",
319        "fucomip_set_ae",
320        "fucomip_set_b",
321        "fucomip_set_be",
322        "fucomip_set_e",
323        "fucomip_set_ne",
324        "fucomip_set_p",
325        "fucomip_set_np",
326        "fucomip_set_e_and_np",
327        "fucomip_set_ne_or_p",
328    ];
329
330    /// The instructions no rule selects yet, because the rules that selected them were taken out.
331    ///
332    /// A different kind of exemption from the three above. Those say an instruction is written
333    /// somewhere a rule cannot reach and always will be. These say nobody reaches one at all right
334    /// now, and name the work that puts the rules back.
335    ///
336    /// The rules went out under `tamnd/rucc#368`. C promotes the operands of an arithmetic
337    /// operator to `int`, so a byte add and a two byte compare are things no C program asks the
338    /// back end for, and the rules at those widths sat proved and never selected over the whole
339    /// torture corpus at every optimization level. The width narrowing pass in `tamnd/rucc#375` is
340    /// what asks for them, and the rules come back with it.
341    ///
342    /// The descriptions stayed. A description says what an x86-64 instruction is, how long it is
343    /// and how it encodes, and that is true whether or not anything selects it. Taking them out
344    /// would be deleting a correct account of the machine to make a list shorter, and putting them
345    /// back is then a second thing to get right rather than a line of a rule file.
346    const NARROW: &[&str] = &[
347        // Three of the two address forms against an immediate. The `narrow` pass does write the
348        // shape, since `char c = a | 1;` narrows to a byte `or` against a byte constant, and no
349        // rule selects these yet: the constant goes into a register and the register with
350        // register rule takes it. Their `add`, `sub` and `and` siblings do have rules and are
351        // reached by the bitfield lowering, so this is six rules missing rather than a shape
352        // nothing writes.
353        "or_ri_8",
354        "or_ri_16",
355        "xor_ri_8",
356        "xor_ri_16",
357        "imul_ri_8",
358        "imul_ri_16",
359        // The divides, which are four instructions per width because the quotient and the
360        // remainder come out of one division in two different registers. `narrow` refuses these
361        // on purpose: the most negative byte over minus one is a defined hundred and twenty eight
362        // at four bytes and is the overflow that raises at one, so narrowing a division wants a
363        // range that rules the pair out and there is no range analysis yet.
364        "idiv_quo_8",
365        "idiv_quo_16",
366        "idiv_rem_8",
367        "idiv_rem_16",
368        "div_quo_8",
369        "div_quo_16",
370        "div_rem_8",
371        "div_rem_16",
372        // The shifts by a value, whose count is in `cl` whatever the width being shifted is. The
373        // same refusal for the same kind of reason: a count of twenty is a defined shift to zero
374        // at four bytes and is poison at one, so only a count that is a constant below the narrow
375        // width narrows, and that one selects the immediate forms which do have rules.
376        "shl_rcl_8",
377        "shl_rcl_16",
378        "shr_rcl_8",
379        "shr_rcl_16",
380        "sar_rcl_8",
381        "sar_rcl_16",
382    ];
383
384    #[test]
385    fn every_instruction_exempt_from_a_rule_is_one_a_frame_really_writes() {
386        // The same claim as the one about the convention, so that this list cannot grow an opcode
387        // that no frame asks for. In the order `x86_64::FRAME` names them, the moves last because
388        // there is one set of them per class the allocator may spill.
389        let frame = &x86_64::FRAME;
390        let mut written = vec![frame.push, frame.pop, frame.ret];
391        for class in frame.classes {
392            written.extend([class.mov, class.load, class.store]);
393        }
394        // And the touch a probing prologue puts on a page, which the target names as an option
395        // because a target with no instruction that writes an address without changing it takes
396        // every frame in one subtraction and has nothing to exempt.
397        written.extend(frame.probe.map(|probe| probe.inst));
398        // And the landing pad and the byte that does nothing, which are options for the same
399        // reason.
400        written.extend(frame.landing);
401        written.extend(frame.pad);
402        // What is left after the ones a rule already reaches, which are the loads and the stores
403        // of a general purpose register, since those are the same instructions a program's own
404        // reads and writes of memory are.
405        written.retain(|opcode| !heads().contains(&format!("{PREFIX}{opcode}").as_str()));
406        assert_eq!(written, FRAME);
407    }
408
409    #[test]
410    fn every_instruction_exempt_from_a_rule_is_one_the_convention_really_writes() {
411        // An exemption list that nothing checks is a hole, since an opcode dropped into it stops
412        // being covered by either direction of the pinning. These are the ones `crate::abi` can
413        // name, at the four integer widths and the two float formats it has names for an
414        // argument in, and no others.
415        let strip = |head: &'static str| head.strip_prefix(PREFIX).expect("an x86-64 term");
416        let named = |ty| strip(crate::abi::head_of(ty).expect("every width the pseudos cover"));
417        // The second half of a pair at place one, which is the place a rule cannot name. The first
418        // half at place zero is `ret_val_*` and is reached by a rule, so it is not on this list.
419        let second = |ty| strip(crate::abi::ret_of(ty, 1).expect("every width the pseudos cover"));
420        let widths = || {
421            [8, 16, 32, 64]
422                .into_iter()
423                .map(rucc_ir::Type::int)
424                .chain([rucc_ir::Float::F32, rucc_ir::Float::F64].map(rucc_ir::Type::float))
425        };
426        let written: Vec<&str> = widths()
427            .map(named)
428            .chain(widths().map(second))
429            .chain([strip(crate::abi::CALL), strip(crate::abi::CALL_REG)])
430            .collect();
431        assert_eq!(written, CONVENTION);
432    }
433
434    /// The same claim about the block layout's list, which is longer than it looks.
435    ///
436    /// A name here that the layout does not write is an opcode exempted from needing a rule and
437    /// reached by nothing, and a name the layout writes that is not here is a failing test in
438    /// `every_described_instruction_is_reachable_from_a_rule` with a misleading message. Both are
439    /// avoided by taking the list from `rucc_target::x86_64::BRANCH` rather than believing it.
440    #[test]
441    fn every_instruction_exempt_from_a_rule_is_one_the_block_layout_really_writes() {
442        let branch = &x86_64::BRANCH;
443        // Eighty entries name sixteen instructions between them, so this is a set rather than a
444        // list and both sides are sorted before they are held against each other. What the order
445        // of the list itself is for is reading it.
446        let mut written: Vec<&str> = vec![branch.test, branch.jump];
447        written.extend(branch.fused.iter().map(|fusion| fusion.cmp));
448        written.extend(branch.fused.iter().flat_map(|fusion| [fusion.if_true, fusion.if_false]));
449        written.sort_unstable();
450        written.dedup();
451        let mut exempt = LAYOUT.to_vec();
452        exempt.sort_unstable();
453        assert_eq!(written, exempt);
454    }
455
456    #[test]
457    fn every_described_instruction_is_reachable_from_a_rule() {
458        let written = heads();
459        for &(opcode, _) in x86_64::INSTS {
460            if CONVENTION.contains(&opcode) || LAYOUT.contains(&opcode) || FRAME.contains(&opcode) {
461                continue;
462            }
463            if NARROW.contains(&opcode) || BARRIER.contains(&opcode) || X87.contains(&opcode) {
464                continue;
465            }
466            if ATOMIC.contains(&opcode) || PAYLOAD.contains(&opcode) {
467                continue;
468            }
469            let head = format!("{PREFIX}{opcode}");
470            assert!(
471                written.contains(&head.as_str()),
472                "{opcode} is described and no rule in {} selects it",
473                TABLE.source
474            );
475        }
476    }
477
478    /// The same claim about the barrier as the ones above make about the convention and the frame:
479    /// the list holds instructions this target really describes, and holds only the ones that have
480    /// no operands, since an instruction with an operand is one a rule could have been written for.
481    #[test]
482    fn every_instruction_exempt_from_a_rule_is_one_the_memory_model_really_writes() {
483        for &opcode in BARRIER {
484            let form = x86_64::form(opcode).expect("an instruction this target describes");
485            assert!(form.operands().is_empty(), "{opcode} has operands, so a rule could name it");
486        }
487    }
488
489    /// The same claim about the atomic list, read off the thing that put the entry there: an
490    /// instruction is exempt for this reason exactly when it writes more than one value, and an
491    /// instruction that writes one is one a rule could have been written for.
492    #[test]
493    fn every_instruction_exempt_from_a_rule_is_one_that_writes_more_than_one_value() {
494        let written = heads();
495        for &opcode in ATOMIC {
496            let form = x86_64::form(opcode).expect("an instruction this target describes");
497            let writes = form.operands().iter().filter(|desc| desc.role.is_def()).count();
498            assert!(writes > 1, "{opcode} writes one value, so a rule could name it");
499            assert!(
500                !written.contains(&format!("{PREFIX}{opcode}").as_str()),
501                "a rule in {} selects {opcode}, which `crate::lower` also writes by hand",
502                TABLE.source
503            );
504        }
505    }
506
507    /// The same claim about the payload list, read off the thing that puts an entry there.
508    ///
509    /// Two halves. Each of these writes one value, which is what says the reason above is not the
510    /// reason here, so a list that grew to cover an instruction the atomic list should have had
511    /// fails. And there really is more than one operation behind the one IR opcode, which is the
512    /// whole of why a pattern cannot name any of them, and is a fact about the IR that would stop
513    /// being true if the operations were ever given opcodes of their own.
514    #[test]
515    fn every_instruction_exempt_because_its_operation_is_beside_it_writes_one_value() {
516        assert!(
517            rucc_ir::RmwOp::all().count() > 1,
518            "one operation per opcode would be a head a rule could match"
519        );
520        let written = heads();
521        for &opcode in PAYLOAD {
522            let form = x86_64::form(opcode).expect("an instruction this target describes");
523            let writes = form.operands().iter().filter(|desc| desc.role.is_def()).count();
524            assert_eq!(writes, 1, "{opcode} writes more than one value, so it is the other list's");
525            assert!(
526                !written.contains(&format!("{PREFIX}{opcode}").as_str()),
527                "a rule in {} selects {opcode}, which `crate::lower` also writes by hand",
528                TABLE.source
529            );
530        }
531    }
532
533    /// The staleness rule every list in this project is kept under, on the one list here whose
534    /// entries are meant to leave. A rule that starts selecting one of these is `tamnd/rucc#375`
535    /// arriving, and the entry goes with it. An entry naming an instruction nothing describes is a
536    /// misspelling, and it would sit here exempting nothing.
537    #[test]
538    fn an_instruction_a_rule_now_selects_is_off_the_list_of_the_ones_left_for_later() {
539        let written = heads();
540        for &opcode in NARROW {
541            let head = format!("{PREFIX}{opcode}");
542            assert!(
543                !written.contains(&head.as_str()),
544                "a rule in {} selects {opcode} now, so it is not waiting on tamnd/rucc#375",
545                TABLE.source
546            );
547            assert!(
548                x86_64::INSTS.iter().any(|&(described, _)| described == opcode),
549                "{opcode} is not an instruction anything describes"
550            );
551        }
552    }
553
554    /// The same staleness rule on the x87 pair, and one thing more that is particular to them.
555    ///
556    /// They are a pair. An instruction that pushes onto the x87 stack and nothing that pops off it
557    /// again would leave the stack one deeper than the function found it, which is not a mistake
558    /// the allocator or the block layout could catch, since neither of them knows the stack is
559    /// there. So the two arrive together and leave together, and that is what this says.
560    #[test]
561    fn the_x87_stack_is_reached_by_a_pair_and_by_nothing_else() {
562        let written = heads();
563        for &opcode in X87 {
564            assert!(
565                x86_64::INSTS.iter().any(|&(described, _)| described == opcode),
566                "{opcode} is not an instruction anything describes"
567            );
568            assert!(
569                !written.contains(&format!("{PREFIX}{opcode}").as_str()),
570                "a rule in {} selects {opcode}, which `crate::lower` also writes by hand",
571                TABLE.source
572            );
573        }
574        // One way onto the stack per format a value can be read from, one way off it per format a
575        // value can be written to, the control word pair that is neither, and the arithmetic. The
576        // count is here as well as in the target description because this list is what says none
577        // of them is reachable, and a name that arrived here without its partner would be a format
578        // this target can convert in one direction and not the other.
579        assert_eq!(X87.len(), 30, "twelve that move a value and eighteen that work on one");
580    }
581}