Repository navigation
One more Map::Units function at 100%: UpdateBallista - #451
Open
kotijekriv wants to merge 1 commit into
Open
kotijekriv wants to merge 1 commit into
kotijekriv wants to merge 1 commit into
Conversation
Units::UpdateBallista, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (e44a5a0 at 32.08%), through versions on our dev branch from 85.9% to 94.5%. The forms that matter: - the siege engine shapes: the crew search's tick test is ((fixedRng ^ ticks ^ 8) & 15) != 0, the target building's half size a signed division of an int ((int)widthOrHeight / 2: cdq; sub; sar), the projectile's height offset a local that starts at 26 and becomes 0 for a negative shootTargetedUnit, and the failed target search of the resting state written behind its success path; - when both of the AI's engineers are back, the two are set out in a loop of two passes over manningEngineerRef, which the compiler unrolls. The original reads the slot again in front of it and computes the unit's offset anew (`mov ecx, [slot]; imul ecx, ecx, 1168` at 0x0056F045), and keeps 0x6d and 5 in ebp and ebx for the second pass; written as two blocks the function is 16 bytes short. The six stores are in the order of the second pass; - in the search for a new crew the distance to an engineer is taken with the engineer's coordinate first (`cmp di, ax; jle` at 0x0056F1A2), and in the two loops that remove the crew the engineer's slot is read once into a local. Main's style-lint flags every ternary on one line, so the six of the two crew loops are if / else, and the unit is read through the slot global everywhere, with no local copy of the unit ID; the code is the same. compiler-flags-gl.txt gets UpdateBallista.cpp and UnitsState/deselectUnit.cpp, which is at 100% on main and was on no /GL list. The crew loop calls deselectUnit, and the compiler has to see its body: the original keeps edx across the call at 0x0056F291 (used at 0x0056F296) and does not reload ecx before 0x0056F2A1; quick_diff with the /GL callees in the unit reads 0.9836 with it and 0.9063 without it. hasUnitReachedDestination, the other callee it has to see, is on main's list already (0.5999 without it, 0.5601 with no callee at all); sourcehold#398's manifest has both edges. reccmp in a build of main's whole /GL list (the 133 files that exist) and the two files, with every resolver of those files on: 145 functions, average 99.57. UpdateBallista 100.0% raw and normalised, no differing line; deselectUnit 100.0%. In the same narrow build of main (3458fea) without the two lines (143 functions), UpdateFireBallistaBuilding reads 99.6% (normalised 95.5), and 100.0% with them; main's own full build reads it at 100.0% already, so that is a reading of the narrow build. Each of the other 142 functions reads the same. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 21, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One more function at 100%, with no header changes.
Units::UpdateBallistais from gynt's units branchreimpl/map-units-updatefunctions(his draft #204), and the commit credits him as co-author.Units::UpdateBallista/GLMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie.field_0x58 = 0forFALSEand adds one comment, and the instruction list is the same line for line), with its two/GLlines and with 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) left out and its resolver off, as in main's baseline: 0 failed of 2,424 compile steps, 99.58 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files undertools/).UpdateBallistareads 100.0 raw and normalised there too, with no diff entry, anddeselectUnitstays at 100.0 under/GL.UpdateFireBallistaBuilding(0x0041E240) reads 100.0 raw and normalised, as it does in main's own build. Every main function reads exactly what it read before (unrounded 99.5761 against 99.5759)./GLlist that exist on main,UpdateBallista.cppandUnitsState/deselectUnit.cpp: 145 functions, average 99.57.UpdateBallistareads 100.0% raw and normalised, with no diff entries, anddeselectUnit100.0%. The same build without the two files has 143 functions. One of them,UpdateFireBallistaBuilding(on main's list), reads 99.6% / 95.5% in that narrow build and 100.0% / 100.0% with the two lines; in main's own full build it reads 100.0% already, so the 99.6% is a reading of our narrow build, not something these lines fix. Each of the other 142 reads the same.openshc-pr-fixfinds nothing to change, andopenshc-pr-checkgives 0 ERROR and 33 CHECK (explained below).What got it to 100%
Every number here is with the file on the
/GLlist (below). On our dev branch (not public) it went from 85.9% to 94.5% with the siege engine shapes ofUpdateCatapult, read against the original one block at a time:((fixedRng ^ ticks ^ 8) & 15) != 0, the original'sxor -8; test al, 15;(int)widthOrHeight / 2:cdq; sub; sar);shootTargetedUnit;Three things were left, all around the engineers that man the ballista.
mov ecx, [slot]; imul ecx, ecx, 1168at 0x0056F045), then sets out the first engineer and the second in two runs of the same stores, keeping 0x6d and 5 inebpandebxfor the second run. That is aforloop of two passes overmanningEngineerRef[i], which the compiler unrolls and which reads the array through the slot global in each pass. Written as two blocks withfirstandsecond, as the draft had it, the compiler uses the offset it already holds, and the function is 16 bytes short. The six stores inside the loop are in the order of the second run; in the five other orders we tried, two or three stores are out of place.if (units[i].x > own.x) { dx = units[i].x - own.x; } else { … }, as in the first loop. The original comparescmp di, ax; jle(0x0056F1A2). With our coordinate first, the compiler writescmp ax, di; jge.int const engineer, and the uid is compared through it. With the array read in each access, the compiler keeps the two pointers into the arrays in each other's registers.quick_diff, with its
/GLcallees in the unit, reads 0.9836: 821 instructions against 824. The rest are spellings of one mask (and eax, 0x80000007, twelve times) and three alignmentjmps that quick_diff does not lay out.Lines added to
cmake/compiler-flags-gl.txtUpdateBallista.cppandUnitsState/deselectUnit.cpp.deselectUnitis at 100% on main and was on no/GLlist.deselectUnit, and the compiler has to see its body: the original keepsedxacross the call at 0x0056F291 (used at 0x0056F296) and does not reloadecxbefore 0x0056F2A1. quick_diff reads 0.9836 with the body and 0.9063 without it.hasUnitReachedDestination, the other callee it has to see, is on main's list already (cmake: function-visibility.txt, which callers must see which callees' bodies #398's manifest has both edges): 0.5999 without it, and 0.5601 with no callee bodies at all.Kept as they are
int dx;andint dy;without a value, twice (fourdeclared without a valueCHECKs): each is assigned in both arms of the if / else that replaces the ternary. Main's style-lint flags every line with a?and a:, so the six ternaries of the two crew loops are if / else now; the instruction list is the same line for line.(int)widthOrHeight / 2:widthOrHeightis auint, and the original divides signed (cdq; sub; sar).(char)casts: four reads of frame tables (two intoanimationFrame, two in the sums forimageIDUnk) and one test ofdisappearFadeAlphaCountdown. The headers have these asbyte, and the original reads them signed.field_0x58 = 0, 4 times (theSG 5CHECKs): the checker takes the name for aBOOLEnumof another struct; inUnit.hppit is ashort, and the original stores a word.What some placeholders hold
Unit::field_0x3bc: a countdown before the ballista looks for a target again. When there is no target or the target is out of range it is set to -40, -80 or -200, and while it is negative each update counts it up by one and does nothing else.Unit::field_0x58: ashortthat four of the ballista's states set to 0 (waiting for a crew, resting, aiming and loading).Frames_Shared_UnitClimbingUp:.field_0x1b14and.field_0x1b50are loading, for the ballista (gfxNumber) and its second picture (imageIDUnk)..field_0x1b8cand.field_0x1bc8are firing. The bolt leaves at frame 12 of.field_0x1b8c.Proposed, not changed here
charfor byte fields read as signed: the AnimationFrameData frame tables andUnit::disappearFadeAlphaCountdown, as on Five more functions at 100%: InGameMenu MainButtons, Roundtable handler, BuySell, UpdateGhost and UpdateHopsFarmer #416 and Three more Map::Units functions at 100%: UpdateOx, ConsiderHavingABreakNowUnk and UpdateMinerIronFetcher #421. Ascharthe five casts above could go.Other PRs
UpdateBallista.cpptoo: an add/add conflict on that file, and the status line at 0x0056ECD0 differs (100.0% here against his 32.1%). Once this lands, his branch can take main's version of it.cmake/compiler-flags-gl.txt. The conflict is line-level only: whichever lands second needs a trivial merge that keeps the lines of both. Reimpl/TileMapState 100% batch 2 #396 already conflicts with main on its own. One more Map::Units function at 100%: UpdateMangonel #445 adds the samedeselectUnit.cppline; with both in, the list names it twice, which does no harm. Map::Units::UpdateLion at 100% #425 merges cleanly, and cmake: optional wrapper units built from function-visibility.txt #399 doesn't touch the list./GLlist. We have not measured it with Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 in the tree.🤖 Generated with Claude Code