Documentation

CslibFrontier.Computability.WordRAM.Multiword.Workspace

Shared workspace for multiword operations #

Register zero stores an arithmetic total, register one a carry, register two the half-word radix, and register three a preserved zero. All operand digits lie outside this workspace. Multiplication, transfers, bitwise operations and shifts share this layout.

Main definitions #

Main results #

References #

@[reducible, inline]

Arithmetic total and partial-sum workspace.

@[reducible, inline]

Carry workspace.

@[reducible, inline]

Half-word radix.

@[reducible, inline]

A preserved zero, used for padding and shifts.

Registers outside the four reserved workspace registers.

Digit registers are disjoint from the four reserved workspace registers.

def Cslib.WordRAM.Multiword.Workspace.Frame {r : ℕ} (x y : Data (r + 4)) (ds : List (Fin (r + 4))) :

A routine changes only its destination digits and the total and carry workspace.

theorem Cslib.WordRAM.Multiword.Workspace.frame_mono {r : ℕ} {x y : Data (r + 4)} {ds es : List (Fin (r + 4))} (h : Frame x y ds) (hsub : ds ⊆ es) :
Frame x y es

Enlarging the destination set weakens the preservation requirement.

theorem Cslib.WordRAM.Multiword.Workspace.frame_trans {r : ℕ} {x y z : Data (r + 4)} {ds : List (Fin (r + 4))} (h : Frame x y ds) (h' : Frame y z ds) :
Frame x z ds

Two routines with the same frame compose.

theorem Cslib.WordRAM.Multiword.Workspace.Frame.digit_regs {r : ℕ} {x y : Data (r + 4)} {ds : List (Fin (r + 4))} (hf : Frame x y ds) {i : Fin (r + 4)} (hi : IsDigit i) (hid : i ∉ ds) :
y.regs i = x.regs i

A routine frame preserves any digit register outside its destination list.

theorem Cslib.WordRAM.Multiword.Workspace.Frame.base_regs {r : ℕ} {x y : Data (r + 4)} {ds : List (Fin (r + 4))} (hf : Frame x y ds) (hds : ∀ d ∈ ds, IsDigit d) :

A routine whose destinations are all digit registers preserves base.

theorem Cslib.WordRAM.Multiword.Workspace.Frame.zero_regs {r : ℕ} {x y : Data (r + 4)} {ds : List (Fin (r + 4))} (hf : Frame x y ds) (hds : ∀ d ∈ ds, IsDigit d) :

A routine whose destinations are all digit registers preserves zero.

theorem Cslib.WordRAM.Multiword.Workspace.Frame.value_eq {r β : ℕ} {x y : Data (r + 4)} {ds as : List (Fin (r + 4))} (hf : Frame x y ds) (has : ∀ i ∈ as, i ∉ ds ∧ i ≠ total ∧ i ≠ carry) :
value β y as = value β x as

A routine frame preserves the reconstructed value of any register list disjoint from its destinations and the total and carry scratch registers.

theorem Cslib.WordRAM.Multiword.Workspace.Frame.value_eq_of_digits {r β : ℕ} {x y : Data (r + 4)} {ds as : List (Fin (r + 4))} (hf : Frame x y ds) (has : ∀ i ∈ as, IsDigit i) (hdis : ∀ i ∈ as, i ∉ ds) :
value β y as = value β x as

A routine frame preserves the reconstructed value of any disjoint list of digit registers.

theorem Cslib.WordRAM.Multiword.Workspace.Frame.bounded_of_digits {r β : ℕ} {x y : Data (r + 4)} {ds as : List (Fin (r + 4))} (hf : Frame x y ds) (has : ∀ i ∈ as, IsDigit i) (hdis : ∀ i ∈ as, i ∉ ds) (hb : Bounded β x as) :
Bounded β y as

A routine frame preserves digit bounds on any disjoint list of digit registers.

theorem Cslib.WordRAM.Multiword.Workspace.Frame.cons_step {r β : ℕ} {x z y : Data (r + 4)} {d : Fin (r + 4)} {ds : List (Fin (r + 4))} (hzf : Frame x z [d]) (hyf : Frame z y ds) (hd : IsDigit d) (hds : ∀ i ∈ ds, IsDigit i) (hdnot : d ∉ ds) (hzd : z.regs d < β) (hyd : Bounded β y ds) :
y.regs d = z.regs d ∧ value β z ds = value β x ds ∧ Bounded β y (d :: ds) ∧ Frame x y (d :: ds)

Composing a single-digit step on d with a tail routine on ds yields a framed, bounded result on d :: ds while preserving d across the tail and ds across the head step.

theorem Cslib.WordRAM.Multiword.Workspace.Frame.step_cons {r β : ℕ} {x z y : Data (r + 4)} {d : Fin (r + 4)} {ds : List (Fin (r + 4))} (hzf : Frame x z ds) (hyf : Frame z y [d]) (hds : ∀ i ∈ ds, IsDigit i) (hdnot : d ∉ ds) (hzb : Bounded β z ds) (hyd : y.regs d < β) :
Bounded β y (d :: ds) ∧ value β y ds = value β z ds ∧ Frame x y (d :: ds)

Composing a tail routine on ds with a single-digit step on d yields a framed, bounded result on d :: ds while preserving ds across the final step.

Compute the half-word radix and a preserved zero in six standard instructions.

def Cslib.WordRAM.Multiword.Workspace.setupResult {r : ℕ} (w : ℕ) (x : Data (r + 4)) :
Data (r + 4)

Exact workspace contents after initialization.

theorem Cslib.WordRAM.Multiword.Workspace.exec_setup {r w : ℕ} (hw : 2 ≤ w) (x : Data (r + 4)) :
Exec w setup x (setupResult w x) 6

Initialization executes in exactly six instructions for every width at least two.

theorem Cslib.WordRAM.Multiword.Workspace.setup_digit {r : ℕ} (w : ℕ) (x : Data (r + 4)) {i : Fin (r + 4)} (hi : IsDigit i) :
(setupResult w x).regs i = x.regs i

Initialization preserves every register outside the reserved workspace.

theorem Cslib.WordRAM.Multiword.Workspace.frame_set_total {r : ℕ} (x : Data (r + 4)) (v : ℕ) (ds : List (Fin (r + 4))) :
Frame x (x.set total v) ds

Setting the total workspace register preserves the routine frame.

theorem Cslib.WordRAM.Multiword.Workspace.frame_set_carry {r : ℕ} (x : Data (r + 4)) (v : ℕ) (ds : List (Fin (r + 4))) :
Frame x (x.set carry v) ds

Setting the carry workspace register preserves the routine frame.

theorem Cslib.WordRAM.Multiword.Workspace.frame_set_mem {r : ℕ} {d : Fin (r + 4)} {ds : List (Fin (r + 4))} (x : Data (r + 4)) (v : ℕ) (hd : d ∈ ds := by simp) :
Frame x (x.set d v) ds

Setting a listed destination register preserves the routine frame.