2929#define INPUT_SIZE 96 ;; the size of (source ++ target)
3030#define RECORD_SIZE 116 ;; the size of (address ++ source ++ target)
3131
32+ #define REQUEST_TYPE 0x02
33+
3234;; -----------------------------------------------------------------------------
3335;; PROGRAM START ---------------------------------------------------------------
3436;; -----------------------------------------------------------------------------
@@ -213,7 +215,13 @@ read_requests:
213215 push MAX_PER_BLOCK ;; [count, head_idx, tail_idx]
214216
215217begin_loop:
216- push0 ;; [i, count, head_idx, tail_idx]
218+ ;; Store request type prefix into the output buffer.
219+ push1 REQUEST_TYPE ;; [type, count, head_idx, tail_idx]
220+ push 0 ;; [offset, type, count, head_idx, tail_idx]
221+ mstore8 ;; [count, head_idx, tail_idx]
222+
223+ ;; Push initial loop index.
224+ push 0 ;; [i, count, head_idx, tail_idx]
217225
218226accum_loop:
219227 ;; This loop will read each request and byte bang it into a RECORD_SIZE byte chunk.
@@ -227,7 +235,9 @@ accum_loop:
227235 ;; Precompute record_offset = i*RECORD_SIZE.
228236 dup1 ;; [i, i, count, head_idx, tail_idx]
229237 push RECORD_SIZE ;; [size, i, i, count, head_idx, tail_idx]
230- mul ;; [record_offset, i, count, head_idx, tail_idx]
238+ mul ;; [offset, i, count, head_idx, tail_idx]
239+ push 1 ;; [1, offset, i, count, head_idx, tail_idx]
240+ add ;; [record_offset, i, count, head_idx, tail_idx]
231241
232242 ;; Determine the storage slot of the address for this iteration. This value is
233243 ;; also the base for the other storage slots containing the source and the target
@@ -389,7 +399,9 @@ store_excess:
389399
390400 ;; Return the requests.
391401 push RECORD_SIZE ;; [record_size, count]
392- mul ;; [size]
402+ mul ;; [size, count]
403+ push 1 ;; [1, size, count]
404+ add ;; [size+1, count]
393405 push0 ;; [0, size]
394406 return ;; []
395407
0 commit comments