Exemple #1
0
lambdaInstructionsArg2 = Param(lambdaRegisterNum)[lambdaLength]
lambdaInstructionsCondition = Param(registerNum)[lambdaLength]
lambdaReturnReg = Param(registerNum)

# Suffix instructions and arguments
suffixInstructions = Param(numInstructions)[suffixLength]
suffixInstructionsArg1 = Param(registerNum)[suffixLength]
suffixInstructionsArg2 = Param(registerNum)[suffixLength]
suffixInstructionsCondition = Param(registerNum)[suffixLength]
suffixInstructionsOut = Param(registerNum)[suffixLength]

programReturnReg = Param(registerNum)

#### Execution data description
## Stack
stackCarVal = Var(maxScalar)[stackSize]
stackCdrVal = Var(stackSize)[stackSize]

## Program registers
regVal = Var(maxScalar)[numTimesteps, registerNum]

## Aggregator values, one after each loop iteration (+ an initial value)
aggregatorVal = Var(maxScalar)[maxLoopsteps + 1]
curCombinatorElementPtr1 = Var(maxScalar)[maxLoopsteps + 1]
curCombinatorElementIntVal1 = Var(maxScalar)[maxLoopsteps + 1]
curCombinatorElementPtr2 = Var(maxScalar)[maxLoopsteps + 1]
curCombinatorElementIntVal2 = Var(maxScalar)[maxLoopsteps + 1]

## Temporary things:
# Temp variable that marks that we've reached the end of the list (and
# just sit out the remaining loop steps)
loopBodyInstructionsArg1 = Param(loopRegisterNum)[loopBodyLength]
loopBodyInstructionsArg2 = Param(loopRegisterNum)[loopBodyLength]
loopBodyInstructionsCondition = Param(registerNum)[loopBodyLength]

# Suffix instructions and arguments
suffixInstructions = Param(numInstructions)[suffixLength]
suffixInstructionsArg1 = Param(registerNum)[suffixLength]
suffixInstructionsArg2 = Param(registerNum)[suffixLength]
suffixInstructionsCondition = Param(registerNum)[suffixLength]
suffixInstructionsOut = Param(registerNum)[suffixLength]

programReturnReg = Param(registerNum)

#### Execution data description
## Stack
stackCarVal = Var(maxScalar)[stackSize]
stackCdrVal = Var(stackSize)[stackSize]

## Program registers
regVal = Var(maxScalar)[numTimesteps, registerNum]

## Pointers to the current loop element, and values:
curLoopElementPtr1 = Var(stackSize)[maxLoopsteps + 1]
curLoopElementPtr2 = Var(stackSize)[maxLoopsteps + 1]
curLoopElementVal1 = Var(maxScalar)[maxLoopsteps]
curLoopElementVal2 = Var(maxScalar)[maxLoopsteps]

## Temporary things:
# Temp variable that marks that we've reached the end of the list (and
# just sit out the remaining loop steps)
listIsOver = Var(boolSize)[maxLoopsteps + 1]
Exemple #3
0
def EqualityTestReg(a, b): return 1 if a == b else 0
@Runtime([maxInt], boolSize)
def GreaterThanZero(a): return 1 if a > 0 else 0

# Program parameters
numBlocksWithHalt = numBlocks + 1
instructions = Param(numInstructions)[numBlocksWithHalt]
thenBlock = Param(numBlocksWithHalt)[numBlocksWithHalt]
elseBlock = Param(numBlocksWithHalt)[numBlocksWithHalt]
arg1Reg = Param(numRegisters)[numBlocksWithHalt]
arg2Reg = Param(numRegisters)[numBlocksWithHalt]
outReg = Param(numRegisters)[numBlocksWithHalt]
condReg = Param(numRegisters)[numBlocksWithHalt]

# State of registers, memory and program pointer during execution:
blockPointer = Var(numBlocksWithHalt)[numTimesteps + 1]
registers = Var(maxInt)[numTimesteps + 1, numRegisters]
memory = Var(maxInt)[numTimesteps + 1, maxInt]

# Temporary values:
tmpOutput = Var(maxInt)[numTimesteps]
tmpArg1Val = Var(maxInt)[numTimesteps]
tmpArg2Val = Var(maxInt)[numTimesteps]
tmpIsMemoryWrite = Var(boolSize)[numTimesteps]
tmpDoWriteRegister = Var(boolSize)[numTimesteps, numRegisters]
tmpDoWriteMemoryCell = Var(boolSize)[numTimesteps, maxInt]
tmpGoToThenBlock = Var(boolSize)[numTimesteps]

# Set up halting block:
instructions[0].set_to_constant(0)  # MAKE SURE THIS IS POINTING TO NOOP
thenBlock[0].set_to_constant(0)
Exemple #4
0
mutableStackSize = maxScalar - inputStackSize - 1

# Inputs
inputRegVal = Input(maxScalar)[inputNum]
inputStackCarVal = Input(maxScalar)[inputStackSize]
inputStackCdrVal = Input(maxScalar)[inputStackSize]

# Outputs
expectListOutput = Input(2)
outputTermState = Output(2)
outputRegVal = Output(maxScalar)
outputListVal = Output(maxScalar)[maxScalar]
outputListIsDone = Output(2)[maxScalar]

# Runtime state
stackCarValue = Var(maxScalar)[numTimesteps + 1, mutableStackSize]
stackCdrValue = Var(maxScalar)[numTimesteps + 1, mutableStackSize]
stackPtr      = Var(mutableStackSize)[numTimesteps + 1]

registers = Var(maxScalar)[numTimesteps + 1, numRegisters]

instrPtr = Var(programLen)[numTimesteps + 1]
returnValue = Var(maxScalar)[numTimesteps + 1]
isHalted = Var(2)[numTimesteps + 1]

# Program
# Register Instructions: cons, car, cdr, zero/nil, add, inc, eq, gt, and, dec, or
# Branch Instructions: jz, jnz, halt
instructions = Param(numInstructions)[programLen]
arg1s        = Param(numRegisters)[programLen]
arg2s        = Param(numRegisters)[programLen]
stackPtrAtLoopStart = stackPtrAtPrefixStart + prefixLength
stackSize = stackPtrAtLoopStart + maxLoopsteps * loopBodyLength + suffixLength

# Registers allow the inputs, the extras, and three additional ones in the loop:
registerNum = inputNum + extraRegisterNum
loopRegisterNum = registerNum + 2

inputRegIntVal = Input(maxInt)[inputNum]
inputRegPtrVal = Input(stackSize)[inputNum]
inputRegBoolVal = Input(2)[inputNum]
inputStackIntVal = Input(maxInt)[inputStackSize]
inputStackPtrVal = Input(stackSize)[inputStackSize]

#### Outputs
outputRegIntVal = Output(maxInt)
outputRegPtrVal = Var(
    stackSize)  #Data structure output is special, see end of file
outputRegBoolVal = Output(2)
outputListVal = Output(maxInt)[stackSize]

#### Execution model description
## Loops: foreach in l, foreach in zip l1, l2
numLoops = 2

#### Instructions: cons, cdr, car, nil/zero/false, add, inc, eq, gt, and, ite, one/true, noop / copy, dec, or
numInstructions = 14
boolSize = 2


@Runtime([maxInt, maxInt], maxInt)
def Add(x, y):
    return (x + y) % maxInt
Exemple #6
0
    elif dir == 2:
        return (pos - 1) % tapeLength


@Runtime([tapeLength, tapeLength], boolSize)
def EqualityTest(a, b):
    return 1 if a == b else 0


@Runtime([numHeadStates, numHeadStates], boolSize)
def EqualityTestState(a, b):
    return 1 if a == b else 0


# State of tape and head during execution:
tape = Var(numTapeSymbols)[numTimesteps, tapeLength]
curPos = Var(tapeLength)[numTimesteps]
curState = Var(numHeadStates)[numTimesteps]
isHalted = Var(boolSize)[numTimesteps]

# Temporary values:
tmpActiveCell = Var(boolSize)[numTimesteps - 1, tapeLength]
tmpCurSymbol = Var(numTapeSymbols)[numTimesteps - 1]

# Constant start state
curPos[0].set_to(0)
curState[0].set_to(1)
isHalted[0].set_to(0)

for p in range(tapeLength):
    tape[0, p].set_to(initial_tape[p])
Exemple #7
0

@Runtime([numWires, numWires], 2)
def equalityTest(a, b):
    return 1 if a == b else 0


gate = Param(numGateTypes)[numGates]
in1 = Param(numWires)[numGates]
in2 = Param(numWires)[numGates]
out = Param(numWires)[numGates]

initial_wires = Input(2)[numWires]
final_wires = Output(2)[numOutputs]

wires = Var(2)[numGates + 1, numWires]
tmpOutput = Var(2)[numGates]
tmpDoWrite = Var(2)[numGates, numWires]
tmpArg1 = Var(2)[numGates]
tmpArg2 = Var(2)[numGates]

for w in range(numWires):
    wires[0, w].set_to(initial_wires[w])

for g in range(numGates):
    with in1[g] as i1:
        tmpArg1[g].set_to(wires[g, i1])

    with in2[g] as i2:
        tmpArg2[g].set_to(wires[g, i2])
lambdaInstructionsArg2 = Param(lambdaRegisterNum)[lambdaLength]
lambdaInstructionsCondition = Param(registerNum)[lambdaLength]
lambdaReturnReg = Param(registerNum)

# Suffix instructions and arguments
suffixInstructions = Param(numInstructions)[suffixLength]
suffixInstructionsArg1 = Param(registerNum)[suffixLength]
suffixInstructionsArg2 = Param(registerNum)[suffixLength]
suffixInstructionsCondition = Param(registerNum)[suffixLength]
suffixInstructionsOut = Param(registerNum)[suffixLength]

programReturnReg = Param(registerNum)

#### Execution data description
## Stack
stackCarVal = Var(maxInt)[stackSize]
stackCdrVal = Var(stackSize)[stackSize]

## Program registers
regIntVal = Var(maxInt)[numTimesteps, registerNum]
regPtrVal = Var(stackSize)[numTimesteps, registerNum]
regBoolVal = Var(2)[numTimesteps, registerNum]

## Aggregator values, one after each loop iteration (+ an initial value)
aggregatorIntVal = Var(maxInt)[maxLoopsteps + 1]
aggregatorPtrVal = Var(stackSize)[maxLoopsteps + 1]
aggregatorBoolVal = Var(2)[maxLoopsteps + 1]
curCombinatorElementPtr1 = Var(stackSize)[maxLoopsteps + 1]
curCombinatorElementIntVal1 = Var(maxInt)[maxLoopsteps + 1]
curCombinatorElementPtr2 = Var(stackSize)[maxLoopsteps + 1]
curCombinatorElementIntVal2 = Var(maxInt)[maxLoopsteps + 1]
stackPtrAtLoopStart = stackPtrAtPrefixStart + prefixLength
stackSize = stackPtrAtLoopStart + maxLoopsteps * loopBodyLength + suffixLength

# Registers allow the inputs, the extras, and three additional ones in the loop:
registerNum = inputNum + extraRegisterNum
loopRegisterNum = registerNum + 2

inputRegIntVal = Input(maxInt)[inputNum]
inputRegPtrVal = Input(stackSize)[inputNum]
inputRegBoolVal = Input(2)[inputNum]
inputStackIntVal = Input(maxInt)[inputStackSize]
inputStackPtrVal = Input(stackSize)[inputStackSize]

#### Outputs
outputRegIntVal = Output(maxInt)
outputRegPtrVal = Var(stackSize) #Data structure output is special, see end of file
outputRegBoolVal = Output(2)
outputListVal = Output(maxInt)[stackSize]
outputListIsDone = Output(2)[stackSize]

#### Execution model description
## Loops: foreach in l, foreach in zip l1, l2
numLoops = 2

#### Instructions: cons, cdr, car, nil/zero/false, add, inc, eq, gt, and, ite, one/true, noop / copy, dec, or
numInstructions = 14
boolSize = 2
@Runtime([maxInt, maxInt], maxInt)
def Add(x, y): return (x + y) % maxInt
@Runtime([maxInt], maxInt)
def Inc(x): return (x + 1) % maxInt