Word-RAM code for the state operations of the packed 4n - 9d refuter #
Standard-basis Word-RAM routines for the state operations of PackedOps on the memory image of a
packed state (Stored of InputLayout), each with an execution theorem in the library's Word-RAM
cost model (Cslib.WordRAM.ExecWithin: every instruction is charged). The execution theorems are
stated for the image at a layout L, with the addresses of Layout; each routine reads the sizes
it needs from Reg.base, Reg.argN, Reg.numE and Reg.numIn. This file continues
PackedCode (issue #4322, Milestone 4); it claims no running time for a step or for the
refuter.
Main definitions #
Cslib.Algorithms.WordRAM.Refuter4n.Reg.numIn,Reg.eqnIdx,Reg.argQ,Reg.pairFst,Reg.pairSnd: the registers of the number of parameter rows, an equation name, the auxiliary variable of a swap and a pair record;Reg.tmp₁,Reg.tmp₂: temporaries.Cslib.Algorithms.WordRAM.Refuter4n.dropTrivialEqnCode,dropEqnCode,deleteGateCode,deleteEqnCode,addPairCode,swapCode,moveAffineCode,restrictCode: the state operationsdropTrivialEqn,dropEqn,deleteGate,deleteEqn,addPair,swap,moveAffineandrestrictAvoidofPackedOpson the memory image, fixedCode .standard 32.
Main results #
Cslib.Algorithms.WordRAM.Refuter4n.exec_dropTrivialEqnCode,exec_dropEqnCode,exec_deleteGateCode,exec_deleteEqnCode,exec_addPairCode,exec_swapCode,exec_moveAffineCode,exec_restrictCode: each state operation turns the image ofPatLinto the image of the operated state, with its instruction count, register frame and memory frame, under the table lengths that its writes need.
The number n of parameter rows.
An equation name.
The auxiliary variable of a swap.
The first word of a pair record.
The second word of a pair record.
A temporary register of the state operations.
A temporary register of the state operations.
Updates of the stored state #
How Stored changes when a mask, an equation word, the parameter rows or the pair records change,
at any layout L. Stored is over the full tables of the state, so a lemma that writes a table
cell takes the lengths of the tables stored before that cell. The lemmas read the old state with
Stored.gateRow, Stored.eqnRow, Stored.phiRow and Stored.pair, and build the new one with
Stored.of_words.
Mask and equation-word routines #
Dropping and deleting equations, deleting gates, adding pairs #
PackedState.dropTrivialEqn on the image: the equation word Reg.eqnIdx becomes 0
(exec_dropTrivialEqnCode).
dropTrivialEqn on the memory image. With the equation name e < L.E in Reg.eqnIdx,
dropTrivialEqnCode turns the image of P at the layout L, a state with at most L.N gate
rows, into the image of P.dropTrivialEqn e within 8 instructions, at every width at which
L.phiAddr 0 fits, changing no register from 14 on except Reg.passWord and no cell outside the
equation table.
PackedState.dropEqn on the image: clear the auxiliary bit Reg.argB, then drop the
equation word Reg.eqnIdx (exec_dropEqnCode).
dropEqn on the memory image. With the auxiliary name v in Reg.argB and the
equation name e < L.E in Reg.eqnIdx, dropEqnCode turns the image of P at the layout L,
a state with at most L.N gate rows and a word-sized auxiliary mask, into the image of
P.dropEqn e v within 18 instructions, at every width at which L.phiAddr 0 and 2 ^ v fit,
changing no register from 14 on except Reg.argA and Reg.passWord, and no cell below
L.base or from L.phiAddr 0 on.
PackedState.deleteGate on the image: the substitution step with the gate name in
Reg.passVar, then clear its bit in the gate mask (exec_deleteGateCode).
deleteGate on the memory image. Under the hypotheses of exec_substStateCode with the
gate name J as the rerouted name, and a word-sized gate mask, deleteGateCode turns the image of
P at the layout L into the image of P.deleteGate L.N J la ln within 37 L.N + 14 L.E + 60
instructions, changing no register from 14 on except Reg.passBase, Reg.passLen,
Reg.passWord, Reg.argA, Reg.argB and Reg.argD, and no cell below L.base or from
L.phiAddr 0 on.
PackedState.deleteEqn on the image: the substitution step with the auxiliary name in
Reg.passVar, then dropEqnCode (exec_deleteEqnCode).
deleteEqn on the memory image. Under the hypotheses of exec_substStateCode with the
auxiliary name v as the rerouted name, the equation name e < L.E in Reg.eqnIdx and a
word-sized auxiliary mask, deleteEqnCode turns the image of P at the layout L into the image
of P.deleteEqn L.N e v la ln within 37 L.N + 14 L.E + 68 instructions, changing no register
from 14 on except Reg.passBase, Reg.passLen, Reg.passWord, Reg.argA, Reg.argB and
Reg.argD, and no cell below L.base or from L.phiAddr 0 on.
PackedState.addPair on the image: after pairBase, write the record
(Reg.pairFst, Reg.pairSnd) after the k records and store the count k + 1
(exec_addPairCode).
addPair on the memory image. With the record c in Reg.pairFst, Reg.pairSnd,
addPairCode turns the image of P at the layout L, a state with L.N gate rows, L.E
equation words and L.n parameter rows, into the image of P.addPair c within 18
instructions, changing no register from 14 on and no cell other than the count and the two new
words, at every width at which the address L.pairAddr k 1 of the last new word fits, where k
is the number of records.
Swapping a parameter and an auxiliary variable #
PackedState.swap on the image: the parameter Reg.passVar and the auxiliary variable
Reg.argQ exchange their mask bits, and the row Reg.passWord is substituted for the parameter
in every parameter row (exec_swapCode).
swap on the memory image. With the parameter x < L.N in Reg.passVar, the auxiliary
variable Q < L.N in Reg.argQ and a row u < 2 ^ (L.N + 1) in Reg.passWord, swapCode turns
the image of P at the layout L into the image of P.swap x Q u within 14 L.n + 57
instructions, at every width w ≥ L.N + 2 at which the end L.phiAddr L.n of the parameter rows
fits, for a word-sized parameter mask and auxiliary mask, L.N gate rows, L.E equation words
and L.n parameter rows below 2 ^ (L.N + 1). It changes no register from 14 on except
Reg.passBase, Reg.passLen, Reg.argA and Reg.argB, and no cell other than the two masks
and the parameter rows.
Moving an affine gate into the system #
PackedState.moveAffine on the image: the equation word affWord of the gate Reg.argB
becomes the equation Reg.eqnIdx, the gate bit is cleared and the auxiliary bit set
(exec_moveAffineCode).
moveAffine on the memory image. With the gate name J < L.N in Reg.argB and the
equation name e < L.E in Reg.eqnIdx, for a gate row of J within range, a word-sized gate
mask and auxiliary mask and L.N gate rows, moveAffineCode turns the image of P at the
layout L into the image of P.moveAffine L.N J e within 73 instructions, at every width
w ≥ max 4 (L.N + 2) at which L.phiAddr 0 fits. It changes no register from 14 on except
Reg.argA, Reg.argD, Reg.passWord, Reg.tmp₁ and Reg.tmp₂, and no cell below L.base or
from L.phiAddr 0 on.
Restriction: filtering the pair records #
PackedState.restrictAvoid on the image: the substitution step for the parameter
Reg.passVar, the substitution pass on the parameter rows with the row of the literal that the
substitution step leaves in Reg.passWord, the parameter bit, and the pair records avoiding the
parameter (exec_restrictCode).
restrictAvoid on the memory image. Let the caller's state hold the base address
L.base, the name bound L.N, the numbers L.E and L.n of equation words and parameter rows,
a parameter x < L.N, an argument code la < L.N + 2 and a negation bit ln ≤ 1 in Reg.base,
Reg.argN, Reg.numE, Reg.numIn, Reg.passVar, Reg.argB and Reg.argC, and let the memory
hold the image of P at the layout L, with L.N gate rows, L.E equation words below
2 ^ (L.N + 2), L.n parameter rows below 2 ^ (L.N + 1), word-sized truth tables, output code,
parameter mask and pair records. At every width w ≥ max 4 (L.N + 2) at which the end
L.pairAddr m 0 of the pair records fits, where m is the number of pair records, restrictCode
leaves the image of P.restrictAvoid L.N x la ln within 37 L.N + 14 L.E + 14 L.n + 20 m + 93
instructions. It changes no register from 14 on except Reg.passBase, Reg.passLen,
Reg.passWord, Reg.argA, Reg.argB and Reg.argD, and no cell below L.base or from
L.pairAddr m 0 on.