adda.s and the enum header cycles¶
Blocker 1: adda.s¶
Symptom¶
The list of blockers of the time had adda.s (the R5900 FPU accumulator add, ACC = fs + ft) as an instruction with no source form. The two UpdateAllEntryPos functions in ingamemenus.cpp (ob_003ad570, ob_003b1f28) were the smallest examples: the ZContainerMenu draft scored 134 and compiled to mula.s where the original has adda.s. The explanation given was that ee-gcc3.2-040921 has no adda.s template and ee-gcc3.2-030926 picks mula.s for the same source.
Diagnosis¶
Both compilers emit adda.s. A string search of the two cc1plus binaries finds the template adda.s %1,%2 only in 030926, but 040921 prints the same instruction through another output routine. Compiling y + 12.0f + i * 16.0f with either compiler gives:
GCC folds a + b + c * d into the accumulator: adda.s loads a + b, then madd.s adds the product. The newlib routines __ieee754_log10f and __kernel_tanf, which are plain GCC output, contain adda.s for the same reason.
The mula.s in the old draft came from the draft itself, which wrote m_fYPos * 12.0f where the original adds. With the sum written correctly the draft dropped to score 35. What remained was store order. The debug line table puts the three stores on zmath.h lines 529, 530 and 531 in x, y, z order, inside an inlined vset(float *v, float x, float y, float z) whose pointer argument lives in $t6. ingamemenus.cpp was calling the vset from engine/fysix/fysix_vector.h, which stores z, y, x. Changing that shared header to x, y, z order broke 61 matched functions in 32 units: their calls are zero vectors from a different inline on zmath.h line 628, so the fysix order is correct for them.
triggerline.cpp and knifethrower.cpp already kept identical local copies of the line-528 vset, each inside namespace zmath to avoid the name clash with fysix_vector.h.
Change¶
src/engine/zstdlib/zmath.hnow defineszmath::vset(x, y, z store order). The two local copies intriggerline.cppandknifethrower.cppare removed; both units already includezmath.h.ingamemenus.cppcallszmath::vseteverywhere. Its debug record places everyvsetin the unit onzmath.hline 528, and the fourDrawcalls match with either store order because they write a stack temporary.ZActionMenuBase::UpdateAllEntryPosandZContainerMenu::UpdateAllEntryPosare recovered:
void ZContainerMenu::UpdateAllEntryPos() {
int32 i = 0;
for (ZStackArrayInsert<42, sContainerEntry, float>::iterator it = m_ContainerEntrys.begin(); it != m_ContainerEntrys.end(); it++, i++) {
zmath::vset((*it).m_v3Position, m_fXPos, m_fYPos + 12.0f + i * 16.0f, 0.0f);
}
}
No compiler, flag or unit_compilers change was needed.
Functions now matching¶
| id | function | bytes |
|---|---|---|
ob_003ad570 |
ZActionMenuBase::UpdateAllEntryPos |
188 |
ob_003b1f28 |
ZContainerMenu::UpdateAllEntryPos |
156 |
Verification¶
python3 tools/check_unit.py on ingamemenus.cpp (96 exact, 9 asm), triggerline.cpp and knifethrower.cpp; python3 tools/build_sources.py --jobs 12 --fresh ends with C/C++: 16574/16574 exact and complete .text: EXACT; make test ends OK.
The other adda.s users¶
44 unrecovered functions contain adda.s. A scan of asm/nonmatchings (the word mask 0xffe007ff == 0x46000018) splits them into three groups.
- Plain GCC accumulator sums. Most of the list:
ZCloth::CollidePlanes,ZPoseModel::GetWeight,PF4::ZDynamicObstacle::*,rectBoxColi,fast_asin,ZUVProject::CalcUV,IWindowInterface::GetTopLeftPos,ZKnifeThrower::FrameUpdateand others. Nothing blocks the instruction itself; write the sum asa + b + c * d. - Original
.sunits and existing inline-asm entries:checklines,fastbgeom,zmathps2asm(vaddscalar),cloth_asmps2,zparticlebox_asmps2,zbonemodifybase_asmps2,rainsplash_asmps2,crt0,ExitVsExitChck.ZParticleController::DrawUpdatecontains IOI'svaddscalarblock (theadda.s x,$f0with$f0zero next to six preloaded operands), as recorded earlier. - One fixed-register matrix block, identical in seven functions, described below.
The $f31 matrix block¶
These seven functions contain the same 81-instruction sequence:
| id | function | bytes |
|---|---|---|
ob_001afa3c |
ZItem::GetMainMatPos |
800 |
ob_001bb698 |
ZLNKOBJ::ClassFrameUpdate |
804 |
ob_001ca1c4 |
ZMovementBase::GetAnimGroundMovement |
948 |
ob_002c00a0 |
ZAnimBufferControler::InterpolateBones |
1,592 |
ob_002c5a90 |
ZHFlow::UpdateBones |
544 |
ob_002c7264 |
ZHFlow::ZStateBase::UpdateBoneArrayInstance |
892 |
ob_00360e94 |
ZHM3MovementKillTargetAnimLineup::MoveAlignTargetToHitman |
660 |
The sequence is five nops, 24 lwc1 loads into fixed registers ($f21–$f23 for the parent position, $f12–$f20 for the parent rotation, $f9–$f11 and $f0–$f8 for the local matrix), mtc1 $zero,$f31, three adda.s pos,$f31; madda.s; madda.s; madd.s rows for the position, nine mula.s; madda.s; madd.s rows for the rotation, and 12 swc1 stores. Six pointer registers address the six operands (m0 and p0 of the result, the local matrix and the parent matrix). After masking the load offsets, the fingerprints of all seven copies are equal. Each function's prologue saves $f20–$f23 and $f31, which is what a clobber list produces. The line table attributes the block to the calling .cpp file, with no inlined scope, so IOI wrote it as a macro.
GCC never emits five nops, never zeroes $f31 to feed adda.s, and does not choose these fixed registers, so no C form exists. It computes
res.p0[j] = parent.p0[j] + local.p0[0] * parent.m0[2][j] + local.p0[1] * parent.m0[1][j] + local.p0[2] * parent.m0[0][j]
res.m0[i][j] = local.m0[i][0] * parent.m0[2][j] + local.m0[i][1] * parent.m0[1][j] + local.m0[i][2] * parent.m0[0][j]
The matching implementation uses the typed ZMatrixTransformMul overloads in src/engine/zstdlib/zmath.h. The output-pointer form accumulates the point row with adda.s. The in-place form writes the result back to the input matrix and position. See the readability standard for the approved instruction block.
Blocker 2: EDropBodyMode and EKillType header cycles¶
Symptom¶
ZHM3Actor::StartDrop (ob_00373a6c) is mangled _ZN9ZHM3Actor9StartDropEP8ZHitman3N17ZHM3ActionControl13EDropBodyModeEPfS4_, and ZHitman3::GetAnimKnifeKillHeaders (ob_00321764) takes ZHM3MovementKillTargetAnimLineup::EKillType *. Both enums are nested in classes, so a C++98 forward declaration cannot name them. Declaring either function needed a header that included the header declaring it: hm3actor.h would need zhitman3.h (which defines ZHM3ActionControl), and zhitman3.h would need zhitman3movement.h, which included zhitman3.h. ZHitmanActionChargeHitKnife::HandleSpecialAttack (ob_003389b0) calls GetAnimKnifeKillHeaders, so it waited on the same declaration. hm3actor.h also carried a second, global EDropBodyMode that nothing used.
Diagnosis¶
Neither cycle is real. ZHM3ActionControl belongs to zhitman3actioncontrol.cpp in the debug record, and its members need ZHitman3, ZHM3Actor, ZItem and ZItemContainer only as pointers. The tree already had zhitman3actioncontrol.h, which zhitman3.h includes, but the struct was defined in zhitman3.h. zhitman3movement.h included zhitman3.h only for three pointer types (ZHitman3, ZHM3Actor, ZLNKWHANDS).
Change¶
ZHM3ActionControlmoves unchanged fromzhitman3.hintozhitman3actioncontrol.h, with the includes it needs (zstackarray.h,zstlstring.h,action.h,ext_zmsg.h) and forward declarations for the pointer types.hm3actor.hincludeszhitman3actioncontrol.h, declaresStartDrop, and drops its unused globalEDropBodyMode, so each enum now has one definition.zhitman3movement.hforward-declaresZHitman3,ZHM3ActorandZLNKWHANDSin place of includingzhitman3.h.zhitman3.hincludeszhitman3movement.hand declaresGetAnimKnifeKillHeaders.ZHM3Actorgains the inlinebool IsSittingDown() const(named inanalysis/recovered-types.h;eSittingDownoreSittingDownBar, which compiles to the original(pos - 1) < 2test).ZHM3MovementKillTargetAnimLineupaddsZHitmanActionChargeHitKnifeto its friends, alongside the other close-combat actions, form_AnimationSoundEvents.
Every unit compiles unchanged after the moves, and the full build stayed exact before any function was recovered.
Functions now matching¶
| id | function | bytes |
|---|---|---|
ob_00373a6c |
ZHM3Actor::StartDrop |
456 |
ob_00321764 |
ZHitman3::GetAnimKnifeKillHeaders |
676 |
StartDrop is a switch over ZHM3ActionControl::EDropBodyMode. In GetAnimKnifeKillHeaders, the branch taken when CheckGeometryOnSide reports geometry beside Hitman calls GetAnimHeaderFromHandleName("/Die/Knife_03") and returns. The original makes that call separately from the shared one at the end, and the pTarget, fDistance and pKillType registers rotate until the branch is written this way.
HandleSpecialAttack and PerformDrop both match. The vreset(vSpurtDir) inline supplies the original z, y, x store order.