Skip to content

Commit 7cccbc8

Browse files
committed
use immediate values for pulse/trig times when possible, to save instructions
1 parent bda0f33 commit 7cccbc8

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

qick_lib/qick/asm_v2.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,18 @@ def expand(self, prog):
941941
insts = []
942942
pulse = prog.pulses[self.name]
943943
tproc_ch = prog.soccfg['gens'][self.ch]['tproc_ch']
944-
insts.append(self.set_timereg(prog, "t"))
944+
t_reg = self.t_regs['t']
945+
# if the time is in a register, we need to copy it to the time register
946+
# otherwise, we can save an instruction by using a immediate value
947+
# TODO: clean this up a bit, maybe fold this into set_timereg somehow?
948+
imm_time = isinstance(t_reg, Integral)
949+
if not imm_time:
950+
insts.append(self.set_timereg(prog, "t"))
945951
for wave in pulse.get_wavenames():
946952
idx = prog.wave2idx[wave]
947953
insts.append(AsmInst(inst={'CMD':'WPORT_WR', 'DST':str(tproc_ch) ,'SRC':'wmem', 'ADDR':'&'+str(idx)}, addr_inc=1))
954+
# add the immediate value
955+
if imm_time: insts[-1].inst['TIME'] = '@'+str(t_reg)
948956
return insts
949957

950958
class ConfigReadout(TimedMacro):
@@ -957,10 +965,19 @@ def expand(self, prog):
957965
insts = []
958966
pulse = prog.pulses[self.name]
959967
tproc_ch = prog.soccfg['readouts'][self.ch]['tproc_ctrl']
960-
insts.append(self.set_timereg(prog, "t"))
968+
t_reg = self.t_regs['t']
969+
# if the time is in a register, we need to copy it to the time register
970+
# otherwise, we can save an instruction by using a immediate value
971+
# TODO: clean this up a bit, maybe fold this into set_timereg somehow?
972+
imm_time = isinstance(t_reg, Integral)
973+
if not imm_time:
974+
insts.append(self.set_timereg(prog, "t"))
961975
for wave in pulse.get_wavenames():
962976
idx = prog.wave2idx[wave]
963-
insts.append(AsmInst(inst={'CMD':'WPORT_WR', 'DST':str(tproc_ch) ,'SRC':'wmem', 'ADDR':'&'+str(idx)}, addr_inc=1))
977+
if imm_time:
978+
insts.append(AsmInst(inst={'CMD':'WPORT_WR', 'DST':str(tproc_ch) ,'SRC':'wmem', 'ADDR':'&'+str(idx), 'TIME':'@'+str(t_reg)}, addr_inc=1))
979+
else:
980+
insts.append(AsmInst(inst={'CMD':'WPORT_WR', 'DST':str(tproc_ch) ,'SRC':'wmem', 'ADDR':'&'+str(idx)}, addr_inc=1))
964981
return insts
965982

966983
class Trigger(TimedMacro):
@@ -1010,21 +1027,32 @@ def preprocess(self, prog):
10101027

10111028
def expand(self, prog):
10121029
insts = []
1013-
if self.t is not None:
1030+
t_reg = self.t_regs['t']
1031+
width_reg = self.t_regs['width']
1032+
# if the time or width is in a register, we need to use the time register
1033+
# otherwise, we can save an instruction by using immediate values
1034+
# TODO: clean this up a bit, maybe fold this into set_timereg somehow?
1035+
imm_time = t_reg is not None and isinstance(t_reg, Integral) and isinstance(width_reg, Integral)
1036+
if self.t is not None and not imm_time:
10141037
insts.append(self.set_timereg(prog, "t"))
10151038
if self.outdict:
10161039
for outport, out in self.outdict.items():
10171040
insts.append(AsmInst(inst={'CMD':'DPORT_WR', 'DST':str(outport), 'SRC':'imm', 'DATA':str(out)}, addr_inc=1))
1041+
if imm_time: insts[-1].inst['TIME'] = '@'+str(t_reg)
10181042
if self.trigset:
10191043
for outport in self.trigset:
10201044
insts.append(AsmInst(inst={'CMD':'TRIG', 'SRC':'set', 'DST':str(outport)}, addr_inc=1))
1021-
insts.append(self.inc_timereg(prog, "width"))
1045+
if imm_time: insts[-1].inst['TIME'] = '@'+str(t_reg)
1046+
if not imm_time:
1047+
insts.append(self.inc_timereg(prog, "width"))
10221048
if self.outdict:
10231049
for outport, out in self.outdict.items():
10241050
insts.append(AsmInst(inst={'CMD':'DPORT_WR', 'DST':str(outport), 'SRC':'imm', 'DATA':'0'}, addr_inc=1))
1051+
if imm_time: insts[-1].inst['TIME'] = '@'+str(t_reg+width_reg)
10251052
if self.trigset:
10261053
for outport in self.trigset:
10271054
insts.append(AsmInst(inst={'CMD':'TRIG', 'SRC':'clr', 'DST':str(outport)}, addr_inc=1))
1055+
if imm_time: insts[-1].inst['TIME'] = '@'+str(t_reg+width_reg)
10281056
return insts
10291057

10301058
class AsmV2:

0 commit comments

Comments
 (0)