The native x86-64 backend. Loading this plugin (mim foo.mim -p x86) appends instruction selection, register allocation, and emission to the compilation pipeline. Instruction selection rewrites core, math, and mem into the axioms below and mach.slot; register allocation is the phases of mach. A literal operand of an instruction is an immediate and has to fit its encoding; mov puts any other constant into a register. Registers are no concern of these types; register allocation introduces them later. The schedule is the mem.M 0 chain: memory instructions sit on it, and scheduling threads all other instructions onto it via sched.
A memory operand disp(base, index, scale); the Bool states whether it has an index. It is no value and occupies no register of its own; only memory instructions and lea take one.
An address disp(base) without an index.
An address disp(base, index, scale).
addr (disp, base) addresses disp + base, like AT&T's disp(base). A literal 0I64 as base means there is none. A literal base folds into disp if the sum fits, else it goes into a register.
index a (i, scale) addresses a + (i << scale), like AT&T's disp(base, index, scale). An address has at most one index.
These lets name the scales.
Instructions are polymorphic in the operand size s and state which sizes they support via refly.check in their codomain. A literal s folds the check away; an unsupported one is an error.
i8, i16, i32, or i64.
i16, i32, or i64.
Bool or a gpr size.
The plugin pretends that x86 uses three-address code and copes with x86's two-address code later on. However, some artifacts shine through: for two-address instructions the tied value operand comes first; the tie is only a register-assignment constraint (add (a, b) computes a + b), and x86.emit reverses the value operands for its AT&T output.
op r, addr: rm f (m, a, addr) is f (a, b) with b loaded from addr.
op r, addr of a unary operation: rm1 f (m, addr) is f b with b loaded from addr.
op addr, r: mr f (m, addr, b) stores f (a, b) to addr with a loaded from addr.
The general-purpose registers in hardware encoding order, as the register r of mach.in r v; the operand size selects the subregister. A register's subtag is its hardware encoding, so they have to stay in this order.
The floating-point registers in hardware encoding order, as the register r of mach.in r v for a math.F pe value v. A register's subtag is its hardware encoding, so they have to stay in this order.
lea r, addr materializes an address as a value. The address addr (0, b) is b, and addr (d, 0) the literal d.
mov r, imm materializes a constant.
mov r, addr.
mov addr, r.
Two-address arithmetic op r, r/imm.
Three-address add as lea, so neither operand is overwritten; it leaves the flags alone.
rsub (a, b) is a - b overwriting b instead of a, as neg b; add a, b. Only mach.constrain introduces it, where a stays live and b dies.
imul3 (a, b) is imul $b, a, r: a product with the literal b that does not overwrite a. Only mach.constrain introduces it, where a stays live.
div/idiv yield the quotient (rax) and the remainder (rdx).
Shifts by cl or an immediate.
movzx, movsx, and truncation to the low bits of the register; they fold a literal. The extensions take their source size explicitly, since a folded load (x86.rm1) leaves no operand to infer it from.
zero x is x with the bits of its register above s cleared, as mach.zext expects.
cmp r, r/imm and test r, r/imm.
The condition codes in hardware encoding order:
| Subtag | cc |
|---|---|
| o | 0 |
| no | 1 |
| b | 2 |
| ae | 3 |
| e | 4 |
| ne | 5 |
| be | 6 |
| a | 7 |
| s | 8 |
| ns | 9 |
| p | 10 |
| np | 11 |
| l | 12 |
| ge | 13 |
| le | 14 |
| g | 15 |
Tests a condition code on the flags: jcc as a branch condition, setcc otherwise.
cmovcc.l (f, x, y) yields y if l holds on f, else x, like (x, y)#cond.
cmovcc.ne (test (cc.l f, cc.l f), x, y) normalizes to cmovcc.l (f, x, y).
Floating-point values live in the XMM registers; the type math.F pe is one value, so its format depends on pe. An operand is never an immediate: a literal is materialized by fmov first.
mov r, imm materializes a floating-point constant from the constant pool.
movss/movsd r, addr.
movss/movsd addr, r.
Two-address arithmetic op r, r.
sqrtss/sqrtsd and andps/andpd with a mask clearing the sign bit.
Floating-point comparison; the predicates are those of math.cmp in its order:
| Subtag | Meaning |
|---|---|
| f | always false |
| e | ordered and equal |
| l | ordered and less |
| le | ordered and less or equal |
| g | ordered and greater |
| ge | ordered and greater or equal |
| ne | ordered and not equal |
| o | ordered (no NaNs) |
| u | unordered (either is NaN) |
| ue | unordered or equal |
| ul | unordered or less |
| ule | unordered or less or equal |
| ug | unordered or greater |
| uge | unordered or greater or equal |
| une | unordered or not equal |
| t | always true |
fsel (c, x, y) yields y if c holds, else x, like (x, y)#c.
Both formats and sizes are explicit, since a folded load (x86.rm1) leaves no operand to infer them from. The instances of x86_isel name the sizes; only i32 and i64 are supported.
Instruction selection. -X x86:isel-dot=<file> writes the PBQP graph in Graphviz DOT format, with the chosen options highlighted.
Emits GNU assembler code (AT&T syntax) to <world>.s.