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.
Accumulator, supplied and returned in the same register.
One actual copy and accumulation, including both address computations.
Copy and sum a runtime span, retaining the old accumulator for zero-length spans.
Copied destination, retained span arguments and the accumulated sum of the original source.
- memory : y.mem = ArrayCopy.copyPrefix x.mem (x.regs (f Reg.src)) (x.regs (f Reg.dst)) (x.regs (f Reg.len))
The destination contains the original source prefix.
The source pointer survives the loop.
The destination pointer survives the loop.
The original span length survives the loop.
- total : y.regs (f Reg.total) = x.regs (f Reg.total) + wordSum x.mem (x.regs (f Reg.src)) (x.regs (f Reg.len))
The accumulator adds precisely the original source words.
Read a native postcondition through the caller's selected registers.
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.