QuISP
Loading...
Searching...
No Matches
def_instructions.h
Go to the documentation of this file.
1
10// X-macro pattern
11// https://quuxplusone.github.io/blog/2021/02/01/x-macros/
12#ifndef INSTR_LAST
13#define INSTR_LAST INSTR
14#endif
15
16// debugging
17INSTR(DEBUG_RUNTIME_STATE, None)
18INSTR(DEBUG, String)
19INSTR(DEBUG, RegId)
20INSTR(DEBUG, QubitId)
21
22// arithmetic
23INSTR(ADD, RegId, RegId, int)
24INSTR(ADD, RegId, RegId, RegId)
25INSTR(SUB, RegId, RegId, int)
26INSTR(SUB, RegId, RegId, RegId)
27INSTR(INC, RegId)
28INSTR(SET, RegId, int)
29INSTR(BITWISE_AND, RegId /* write */, RegId /* read */, RegId /* read */)
30INSTR(BITWISE_AND, RegId /* write */, RegId /* read */, int /* read */)
31INSTR(BITWISE_OR, RegId /* write */, RegId /* read */, RegId /* read */)
32INSTR(BITWISE_OR, RegId /* write */, RegId /* read */, int /* read */)
33INSTR(BITWISE_XOR, RegId /* write */, RegId /* read */, RegId /* read */)
34INSTR(BITWISE_XOR, RegId /* write */, RegId /* read */, int /* read */)
35// in place operation
36INSTR(BITWISE_AND, RegId /* write */, RegId /* read */) // in-place operation: first_reg = first_reg | second_reg (bitwise and)
37INSTR(BITWISE_AND, RegId /* write */, int /* read */) // in-place operation: first_reg = first_reg | int (bitwise and)
38INSTR(BITWISE_OR, RegId /* write */, RegId /* read */) // in-place operation: first_reg = first_reg | second_reg (bitwise or)
39INSTR(BITWISE_OR, RegId /* write */, int /* read */) // in-place operation: first_reg = first_reg | int (bitwise or)
40INSTR(BITWISE_XOR, RegId /* write */, RegId /* read */) // in-place operation: first_reg = first_reg | second_reg (bitwise xor)
41INSTR(BITWISE_XOR, RegId /* write */, int /* read */) // in-place operation: first_reg = first_reg | int (bitwise xor)
42
43// control flow
44INSTR(BEQ, Label, RegId, RegId) // branch if the reg values are same
45INSTR(BEQ, Label, RegId, int) // branch if the reg value is equal to the int value
46INSTR(BEZ, Label, RegId) // branch if the reg value is zero
47INSTR(BNZ, Label, RegId) // branch if the reg value is not zero
48INSTR(BLT, Label, RegId, int) // branch if the reg value is less than the int value
49INSTR(BRANCH_IF_LOCKED, Label, RegId)
50INSTR(BRANCH_IF_QUBIT_FOUND, Label)
51INSTR(BRANCH_IF_MESSAGE_FOUND, Label)
52INSTR(JMP, Label)
53INSTR(ERROR, String) // stop execution and show error
54INSTR(RET, ReturnCode) // stop execution with the ReturnCode
55
56// memory operations
57INSTR(LOAD, RegId, MemoryKey)
58INSTR(STORE, MemoryKey, RegId)
59INSTR(STORE, MemoryKey, int)
60
61INSTR(LOAD_LEFT_OP, RegId, MemoryKey)
62INSTR(LOAD_RIGHT_OP, RegId, MemoryKey)
63
64// qubit retrieval operations
65INSTR(GET_QUBIT, QubitId, QNodeAddr, int) // may throw "no qubit error"
66INSTR(GET_QUBIT, QubitId, QNodeAddr, RegId) // may throw "no qubit error"
67INSTR(GET_QUBIT, RegId /* qubit id */, QNodeAddr /* partner addr */, RegId /* given qubit index */)
68INSTR(GET_QUBIT_BY_SEQ_NO, RegId /* write: qubit */, QNodeAddr /* read */, RegId /* read: seq_no */)
69INSTR(GET_QUBIT_BY_SEQ_NO, QubitId /* write: qubit */, QNodeAddr /* read */, RegId /* read: seq_no */)
70
71// qubit quantum gate operations
72INSTR(MEASURE_RANDOM, MemoryKey, QubitId)
73INSTR(MEASURE, MemoryKey, QubitId, Basis)
74INSTR(MEASURE, RegId, QubitId, Basis)
75INSTR(MEASURE, RegId /* w: bitset */, int /* bit to set */, QubitId, Basis) // this will store the result at index (bitset) of the RegId specified by the int
76INSTR(GATE_X, QubitId)
77INSTR(GATE_Z, QubitId)
78INSTR(GATE_Y, QubitId)
79INSTR(GATE_CNOT, QubitId, QubitId)
80// circuit operations
81INSTR(PURIFY_X, RegId /* measurement_result */, int, QubitId /* keep_qubit */, QubitId /* trash_qubit */)
82INSTR(PURIFY_Z, RegId /* measurement_result */, int, QubitId /* keep_qubit */, QubitId /* trash_qubit */)
83INSTR(PURIFY_Y, RegId /* measurement_result */, int, QubitId /* keep_qubit */, QubitId /* trash_qubit */)
84
85// resource management operations
86// instructions we would want later: crucial for entanglement pumping, banding, and multipartite states
87// INSTR(SET_NAME, QubitId, {new_name: string | RegId }) // when using partner as name is not enough
88INSTR(FREE_QUBIT, QubitId)
89INSTR(PROMOTE, QubitId)
90INSTR(PROMOTE, QubitId, RegId /* new partner addr */) // promote with new partner/new name
91INSTR(LOCK_QUBIT, QubitId, RegId /* action index */)
92
93// message operations
94INSTR(GET_MESSAGE_SEQ, RegId /* write: sequence number */, RegId /* read: message index */)
95INSTR(COUNT_MESSAGE, RegId /* write: count */, RegId /* read: sequence number */)
96INSTR(GET_MESSAGE, RegId /* w: content[1] */, RegId /* r: sequence number */, int /* r: message index */) // for purification [result]
97INSTR(GET_MESSAGE, RegId /* w: content[1] */, RegId /* w: content[2] */, RegId /* r: sequence number */, int /* r: message index */) // for swapping [correction_op, new_partner]
98INSTR(DELETE_MESSAGE, RegId /* read: sequence number */) // delete all messages with this sequence number
99
100// send classical messages
101INSTR(SEND_LINK_TOMOGRAPHY_RESULT, QNodeAddr, RegId, MemoryKey, int, Time) // partner addr, current count reg_id, outcome key, max_count, start_time
102INSTR(SEND_PURIFICATION_RESULT, QNodeAddr, RegId /* measurement_result encoded in int */, RegId /* sequence_number */, PurType)
103INSTR(SEND_SWAPPING_RESULT, QNodeAddr /* receipient */, RegId /* pauli_op */, QNodeAddr /* new partner*/, RegId /* sequence_number */)
104
105INSTR_LAST(NOP, None)
106#undef INSTR
107#undef INSTR_LAST
#define INSTR(Opcode,...)
Definition InstructionVisitor.h:26
#define INSTR_LAST
def_instructions.h
Definition def_instructions.h:13