Documentation

Complexity.Computability.WordRAM.Signed.Operations

Translating signed RAM data operations and tests #

All five operations of GenericRAM.Signed.Arithmetic (addition, subtraction, multiplication, Euclidean division and Euclidean remainder), together with constants, copies, memory operations and signed comparisons, are translated to unsigned word-RAM code. The existing source interpreter, including its signed range and address checks, determines successful source steps. The target blocks operate on the separate register bank and encode every memory value.

Main definitions #

Main results #

References #

The translation is an original implementation using the existing signed RAM semantics.

Unsigned instruction block implementing each of the five signed arithmetic operations.

Instances For

    Decode a nonnegative signed address into scratch register left.

    Instances For

      Copy both operands to scratch before updating any source register.

      Instances For

        Translate one data operation, retaining source memory addresses.

        Instances For

          Translate equality or signed ordering. result holds zero or one and two holds one.

          Instances For
            theorem Cslib.GenericRAM.Signed.ToWordRAM.exec_address {r w : ℕ} {s : Data model r} {x : WordRAM.Data (r + 9)} (hx : Represents w s x) (a : Fin r) (ha : 0 ≤ s.regs a) :

            Nonnegative signed addresses are decoded in two instructions without changing source data.

            Copy the operands to the arithmetic workspace without changing represented source data.

            theorem Cslib.GenericRAM.Signed.ToWordRAM.exec_compileOp {r w : ℕ} {s t : Data model r} {x : WordRAM.Data (r + 9)} (o : Op model r) (hx : Represents w s x) (he : Op.eval w o s = some t) :
            ∃ (y : WordRAM.Data (r + 9)), WordRAM.ExecWithin (w + 2) (compileOp o) x y 23 ∧ Represents w t y

            Every successful source data operation has an unsigned implementation in at most twenty-three instructions at width w + 2. Aliased source/destination registers are allowed.

            theorem Cslib.GenericRAM.Signed.ToWordRAM.exec_compileCond {r w : ℕ} {s : Data model r} {x : WordRAM.Data (r + 9)} (c : Cond model r) (hx : Represents w s x) {b : Bool} (he : Cond.eval w c s = some b) :

            Every successful source test is implemented within fourteen instructions, returning its Boolean result and preserving the source data. Scratch register two is set to one.