Skip to content

ProgressHandler

ProgressHandler (ob_003bc914, src/hitman3/gui/mcprogressps2.cpp, 1,168 bytes) is the one game function still built from its assembly fallback. This note records the state on 18 November 2026.

The draft emits all 292 instructions in the original order. It keeps the advance speed in $f5 and the bar width in $f4; the original has them the other way round. Every other register, immediate and relocation matches.

What the debug record settled

research-tools/debug_blocks.py compares the original's $LBB block numbers and the registers of the variables in each block with a -g build of the draft. It found three differences that earlier rounds missed. All three are now in the source:

  • The last three value and register pairs of the second packet are AddReg calls. Their stores sit four scope levels deep in the original, and the statements then fit lines 98 to 124 with one line to spare.
  • uNloop keeps the value 5. It is declared after the first packet, the first GIF tag is passed to Add64 as an expression, and the later Add64(GS_CLAMP_CLAMP_UV) reuses its register.
  • EndPacket has the locals lByteSize and lqSize, and EndDirectPacket has lByteSize.

Three more facts are left out of the source because they do not change the code:

  • The function is static and its parameter is named a.
  • sync and ei are one statement on line 140 with no inline scope, which fits Sony's ExitHandler() macro. The draft uses ZSyncMemory() and ZEnableInterrupts().
  • The unit compiled static int GetNeededBones(uint8 *pNeededBones, const ZBoneConstraint *pBoneConstraint) from engine/drawing/zprimcontrolbase.h before ProgressHandler (blocks 2 to 9, 0x60 bytes, dropped at link). The tree has no such function. A function compiled ahead of ProgressHandler did not change its code.

Apart from those three, block numbers, per-block variable registers and the source line of every instruction equal the original's.

The remaining difference

Local register allocation gives $f4 to whichever of the two values has the higher priority (references times frequency over live span). The width has 3,200,000. The advance speed has 3,076,923 with a span of 26, and a span of 24 would give it 3,333,333.

The span is set by the first scheduling pass. In the block that starts after the if (g_bType) arms, cycle 9 has one slot left for an ALU instruction and two candidates with priority 103 and register weight 1:

insn dependents luid
pGifTag = lo_sum(high, g_GifTagRegsAD) 4: block end, sync, the call, the second ld 85
high(g_startx) 3: block end, sync, the lw 44

The first wins on dependents and lands between the advance-speed load and its multiply. The original must have picked something else there.

Forced orders that match

research-tools/probe.py runs the compiler with a preload library that can force one insn above another in the ready list (PH_ABOVE=a:b, insn UIDs). research-tools/flip.py tries such pairs across the block. The function scores 0 when one of these takes the slot instead of the lo_sum:

  • high(g_startx), picked anywhere from cycle 7 to cycle 9;
  • high(g_readme);
  • the constant of Add32(VIF_FLUSH) or of Add32(VIFCODE_DIRECT).

All four are single-use values that local-alloc later moves next to their use, so they do not count in the span. The lw of g_startx has to stay after the loads of g_starty and g_height; moving it earlier gives 135 or more.

Three changes to the pass's inputs also give 0: marking the pseudo that holds high(g_GifTagRegsAD) as crossing a call, one more reference frequency (1000) on the advance-speed pseudo, or one fewer on the width product.

No source form that produces any of these has been found.

The scheduler in this compiler

Measured with the preload library. sched-deps.c in build/gccsrc (3.2.3) differs in places.

  • Every dependence costs the latency of the earlier insn whatever its kind: ALU 1, load or store 2, FP arithmetic 4. Links to the final use and to an asm insn cost nothing. The first call has priority 98, an ALU insn before it 99, a store 100.
  • Anti and output dependences between memory references check alias sets. int loads are tied to later uint32 packet stores, uint64 loads to earlier uint64 stores, and stores to pointer members to each other.
  • An asm insn is a barrier that every earlier insn precedes. The link from the last setter of a register is an output dependence.
  • A use of a pseudo that crosses no call makes the next call depend on the insn. A set does not.
  • Forward dependence lists are never returned to the free list, so the cost flags cached on them are never stale.

Ruled out

  • About 130 compiler flags and the ee-gcc3.2-030926 compiler.
  • lRight *= 16: the call then waits for the shift, the float registers come out right, and the integer schedule of the whole block changes.
  • Other load types in BeginGifPacket: the two ld have to share an alias set with the Add64 stores.
  • the historical mutation script (available with git show ee3346987^:tools/mutate.py) (650 candidates), ZASSERT and ZTRACE placements, clamp forms on lines 76 to 81, uNloop declared before the first packet.
  • The pending-memory-list flush: the block has 28 references before the first call and the limit is 32.

Research tools

All in research-tools/, specific to this function.

  • debug_blocks.py <copy.cpp>: $LBB numbers and per-block variable registers, original against a -g build.
  • line_tags.py <copy.cpp> and line_labels.py <copy.cpp>: the source line of every instruction, and the full $LM label sequence including labels with no code.
  • shim/build.sh: builds the preload library into build/ph/shim.
  • probe.py <copy.cpp> [--sched]: priority and span of the two float quantities, the score, and the tie. Environment: PH_ABOVE=a:b[,c:d] forces an order, PH_DEPS=1 lists dependents with their cost flags, PH_PRIO=lo:hi prints priority, weight and dependents for a UID range, PH_CROSS=regno marks a pseudo as crossing a call, PH_FREQ=regno with PH_FREQ_DELTA=n changes a reference frequency.
  • flip.py <copy.cpp> <uid,uid,...>: forces each later insn of the list above each of the twelve before it and reports the pairs that lower the score.

<copy.cpp> is a path inside the repository, for example src/hitman3/gui/mcprogressps2.cpp.