Part B · Lesson 1

Posted writes and the pulse table

A control core has no instruction for "play a pulse". It has stores. This lesson shows the addresses those stores go to, the registers of a channel, how a frequency, a phase and an amplitude become 16-bit codes, and how one store to one address fires a row of a table.

You should have followed one pulse in A3. The background chapter on the RISC-Q architecture places these registers in the whole controller. Hexadecimal numbers are written 0x….

1A store that does not wait

How does a 32-bit store on a RISC-V core end up as a pulse parameter next to a DAC?

Each control core of RISC-Q is an RV32I processor with its own RAM at 0x80000000. Some addresses outside the RAM are not memory. A store into the put window, from 0x10000 upward, leaves the core as a posted write: the address and the 32-bit word travel over the link to a channel or to the board hub. "Posted" means that the core sends it and goes on. It does not wait for the channel to answer, and it cannot read the value back.

That is the whole interface between software and pulses. Programming a channel is a series of stores; starting a pulse is one more store. The model charges each load or store one extra batch in the core, an assumed bound from RISC-Q's LsuPlugin.md, and delivers the write 1 + link depth batches later (lesson A3).

2The address map of a core

In this section: where everything a core can reach sits, and how the put window is divided into nodes.

AddressWhat is thereRISC-Q source
0x80000000The core's own RAM: program, tables, classical bitslinker layout
0x4000, 0x4008, 0x4010timeCmp, waitTimeCmp (a read stalls until the time is reached), doneControlMemMaps.scala
0xBFF8time: the core's copy of the batch counterControlMemMaps.scala
0x4200 + 0x20·kSinks: readout results, input events (lesson B3)EventLink.scala
0x4300, 0x4320, 0x4340Hub board words, barrier release, mailboxes (lesson B4)PutHub.scala
0x10000 + node · 0x10000The put window: one 64 KiB window per nodemap.py
0x40000000Host window: results for the host computer, write onlyHostWindow.md

The put window is divided into nodes. Nodes 0 to 15 are the core's own channels, in the order the build lists them. Nodes 16 to 19 are the hub's four shared bit groups, nodes 20 to 35 its sixteen barriers, and the nodes from 36 reach other cores' mailboxes (MAP in riscq/soc.mjs, after RISC-Q's map.py). So channel n starts at

channel base = 0x10000 + n · 0x10000

Core q0 of the transmon ring has five channels: gate (node 0), cz0 (1), cz1 (2), ro (3) and demod (4). Its drive channel starts at 0x10000, its readout tone channel at 0x40000.

3Inside a channel

A channel that drives a DAC or reads an ADC holds a small register file, which RISC-Q calls the pulse parameter buffer (PulseParamBuffer.scala). Offsets are from the channel base:

OffsetRegisterData
+0x0fireThe number of the table entry to play
+0x4freq: the carrier frequency16-bit code
+0x8dcOffset16-bit code
+0xCphaseOffset, added to every entry's phase16-bit code
(i + 1) · 16 + 0, 4, 8, 12Entry i of the pulse table: phase, amp, env, dur16-bit codes
+0x4100startTime: the batch at which the next fired entry starts32-bit batch number

The pulse table is the heart of it. Each entry is one prepared pulse: its phase, its amplitude, the address of its envelope in envelope memory, and its duration in batches. On the ring, every drive channel has two entries: entry 0 is the x90, entry 1 the x. A CZ channel, the readout channel and the demodulation channel have one entry each.

Writing i to fire hands entry i to the timed queues, to start at the current startTime, and then advances startTime by the entry's duration. Two fires in a row therefore play back to back without any time arithmetic in the program. The fields of a 16-bit register sit in bits 31:16 of the stored word; the lower half is ignored. pack16 in riscq/soc.mjs builds such a word: (code & 0xFFFF) << 16.

Proved in Lean, about the model (QControl/RiscQ/Timing.lean): fire_captures_start, a fire schedules its entry at the current start time; fire_fire_contiguous, a second fire is scheduled exactly one duration after the first; explicit_start_wins, writing startTime after a fire discards the advance; fire_preserves_table, a fire changes no table entry, so an entry can be fired again and again; decode_layout, the addresses the firmware writes decode to the intended fields. These are statements about the model's decoder, which follows RISC-Q's Scala source. The RTL itself is not proved here.

The store that fires the x90 of qubit 0 is sw x0, 0(x5) with x5 = 0x10000. What does the stored word, 0, mean?

  1. Play entry 0 of q0.gate's pulse table, the x90.
  2. Stop the channel.
  3. Start at batch 0.
  4. Nothing: register x0 is a dummy and the word is ignored.
The fire register takes an entry number. Register x0 always reads 0 in RISC-V, so sw x0 is the cheapest way to store 0. The start time was written separately, three batches earlier.

Core q0 writes the start time of its readout tone channel ro before firing it. At which CPU address? You may answer in hexadecimal.

ro is node 3: base 0x10000 + 3 · 0x10000 = 0x40000, plus 0x4100 for startTime, gives 0x44100. In the firmware it is lui x5, 0x44 followed by sw x6, 256(x5).

4From physical values to codes

In this section: the three conversions the compiler performs before any store, with qubit 0 as the example.

The calibration states frequencies in hertz, phases in radians and amplitudes as fractions of full scale. The registers take 16-bit integers. Three functions of riscq/soc.mjs convert, each a copy of the corresponding function in RISC-Q's units.py.

Frequency. The NCO of a channel advances the carrier phase by a fixed step for each DAC sample. The code is that step as a fraction of a full turn, times 65,536:

freqCode = round( f · 65536 / (16 · dspClk) )

16 · dspClk is the DAC sample rate, 8 GS/s on the ring. Qubit 0's drive frequency in the calibration is 5,498,857,081.67 Hz, which gives a code just below 45,047. The code is kept to 16 bits: freqCode returns it in signed form, −20,489, and the register holds the same 16 bits, which the trace prints as 45,047.

Phase. An angle is wrapped to −π…π and expressed in units of π/32,768:

phaseCode = round( φ / π · 32768 ), kept to 16 bits

Amplitude. A fraction a between −1 and 1 is scaled by 19,896, the largest code that keeps RISC-Q's unsaturated datapath in range (AMP_SCALE, from RISC-Q's pulses/golden.py):

ampCode = round( a · 19896 )

Qubit 0's x90 has amplitude 0.10560383, so its entry holds 2,101. The durations are already batches (lesson A2): 18 for the x90, 35 for the x.

Qubit 0's x pulse has amplitude 0.10674013 in the calibration. Which code does entry 1 of q0.gate hold? Check your answer in the Machine state of the workspace, or in the init stores of q0's firmware.

0.10674013 × 19,896 = 2,123.7, rounded to 2,124. The run stores it with sw to 0x10024: entry 1 is at (1 + 1) · 16 = 0x20, amplitude at +4.

Compute the frequency code of qubit 0's drive channel from its frequency, 5,498,857,081.67 Hz, as the trace prints it (unsigned, 0 to 65,535).

5,498,857,081.67 × 65,536 / 8 × 10⁹ = 45,046.97, rounded to 45,047. This is above 32,767, so the signed form is 45,047 − 65,536 = −20,489. The register bits are the same.

5Programming the tables

Before any pulse, each core programs its channels. The firmware generator (riscq/firmware.mjs, initChannel, after init_pulse_params in RISC-Q's riscq.h) writes, for every channel: the current time as startTime, a zero phaseOffset and dcOffset, the carrier freq, and then the four fields of every table entry. In the trace these are the put frames of core q0 whose source is init, each followed three batches later by a write frame at the channel.

Open the workspace at any early step and choose core q0 in the firmware layer. The init region is a long run of pairs: lui or addi to load an address and a value, then sw. Hover a word to see its address and machine word.

How many posted writes does core q0 make while programming its five channels (source init)?

The drive channel: 4 registers and 2 entries × 4 fields = 12. Each of the two CZ channels, the readout channel and the demodulation channel: 4 + 4 = 8. In all 12 + 4 · 8 = 44.

6Firing one pulse

With the tables in place, a pulse costs three stores in this firmware. For the first x90 of qubit 0 (hardware instruction h2):

0x800001fc  addi x7, x8, -96       # issue time = time base − 96
0x80000200  sw   x7, 0(x9)         # timeCmp
0x80000204  lw   x7, 8(x9)         # waitTimeCmp: stall until then (lesson B2)
0x80000208  lui  x6, 0xbfc60       # phase code 0xBFC6 in bits 31:16
0x8000020c  lui  x5, 0x10          # channel q0.gate
0x80000210  sw   x6, 12(x5)        # phaseOffset  ← the virtual Z so far (0x1000C)
0x80000214  addi x6, x8, 7         # start = time base + 7
0x80000218  lui  x5, 0x14
0x8000021c  sw   x6, 256(x5)       # startTime    ← 320 (0x14100)
0x80000220  lui  x5, 0x10
0x80000224  sw   x0, 0(x5)         # fire         ← entry 0 (0x10000)

This is region h2 of q0's firmware, exactly as the workspace disassembles it; the comments are added. Register x8 holds the time base of the segment and x9 the control block at 0x4000. The first three words wait for the right moment to issue, which is the subject of lesson B2. The other eight are the three stores and the instructions that load their addresses and data.

The first store carries the virtual Z. Lesson A1 showed that a Hadamard begins with frame updates; the lowering adds them up for each qubit and writes their negative as the phase offset before the pulse (lower in riscq/platforms/superconducting.mjs). Every later parameter of the entry stays as it was programmed. This is why Z rotations cost no pulse: they are one register write before the next pulse of the same qubit.

Step 333: core q0 executes sw x0, 0(x5). The firmware layer highlights the word; the Step inspector shows the address 0x10000 and the channel 0 it targets.

Before the x90 of h2, qubit 0 has two frame updates: π/2 and 0.0055315388 rad. The phase offset is minus their sum. Which 16-bit code does q0 write to phaseOffset, as the trace prints it (unsigned)?

−(1.5707963 + 0.0055315) = −1.5763279 rad. Divided by π and multiplied by 32,768 that is −16,441.6, rounded to −16,442. As an unsigned 16-bit number: 65,536 − 16,442 = 49,094. The store is sw x6, 12(x5) with the code in bits 31:16 of x6.
What a store cannot do. A posted write is fire and forget. If the timed queue of the channel is full when it arrives, the write is dropped and the model reports a drop frame and a fault. The compiler therefore refuses a schedule that would overflow the queues; lesson B2 shows the limit.

What to remember

  1. A store into the put window is a posted write: it travels to a channel or the hub, and the core does not wait.
  2. Channel n of a core starts at 0x10000 + n · 0x10000; fire +0, freq +4, dcOffset +8, phaseOffset +0xC, entry i at (i+1)·16, startTime +0x4100.
  3. 16-bit fields go in bits 31:16 of the word.
  4. Frequencies, phases and amplitudes become codes by freqCode, phaseCode and ampCode.
  5. Firing writes an entry number; the start time advances by the entry's duration.