Documentation

CslibFrontier.Computability.WordRAM.CopySum

Copying an array while accumulating its original words #

The fixed eight-register program performs the same forward stores as ArrayCopy.program, with one additional addition per word. The running sum can carry across successive arrays. Its sum is computed by the program, rather than supplied as an input magnitude certificate. All memory outside the destination remains unchanged, including dirty caller memory.

@[reducible, inline]

Source pointer.

@[reducible, inline]

Destination pointer.

@[reducible, inline]

Number of words.

@[reducible, inline]

Current offset.

@[reducible, inline]

Address temporary.

@[reducible, inline]

Loaded original word.

@[reducible, inline]

Constant one.

@[reducible, inline]

Accumulator, supplied and returned in the same register.

def Cslib.WordRAM.ArrayCopySum.wordSum (mem : ℕ → ℕ) (base length : ℕ) :

The mathematical sum of the original source span.

One actual copy and accumulation, including both address computations.

Copy and sum a runtime span, retaining the old accumulator for zero-length spans.

structure Cslib.WordRAM.ArrayCopySum.Post {r : ℕ} (f : Fin 8 → Fin r) (x y : Data r) :

Copied destination, retained span arguments and the accumulated sum of the original source.

theorem Cslib.WordRAM.ArrayCopySum.Post.of_comap {r : ℕ} {f : Fin 8 → Fin r} {x y : Data r} (post : Post id (Data.comap f x) (Data.comap f y)) :
Post f x y

Read a native postcondition through the caller's selected registers.

theorem Cslib.WordRAM.ArrayCopySum.exec {w : ℕ} (x : Data 8) (h1 : Fits w 1) (hs : Fits w (x.regs Reg.src + x.regs Reg.len)) (hd : Fits w (x.regs Reg.dst + x.regs Reg.len)) (ht : Fits w (x.regs Reg.total + wordSum x.mem (x.regs Reg.src) (x.regs Reg.len))) (hsep : x.regs Reg.src + x.regs Reg.len ≤ x.regs Reg.dst) :
∃ (y : Data 8), ExecWithin w program x y (8 * x.regs Reg.len + 4) ∧ Post id x y

Copy a separated source span and accumulate its original words. Every loop test, load, store and sum is charged; only actual source/destination and total-sum numerical fits are premises. This does not require a clean destination.