Skip to content

UI: the population report's graph at 100% - #436

Open
kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round25-100
Open

kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round25-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

StatusMenus::RenderStatusMenu_Population at 100%, moved out of our open draft #313, from gynt's draft. No header changes.

Function Address Before reccmp raw Normalised
StatusMenus::RenderStatusMenu_Population 0x0043F6A0 93.8% in the draft PR (6a2b835; 82.4% in our earlier 4faa418 on our fork kotijekriv's reimpl/UI-StatusMenus-development); gynt's own 73.2% (the status line of 67318e1 on his fork's reimpl/UI-StatusMenus-development; his scored commits are a92aa37 at 59.18% and 142ef0b at 64.1%, the second on sourcehold's reimpl/UI-StatusMenus; the newest commit on the file, e30b3f0, is on his reimpl/UI-MenuItems-development) 100.0 100.0

Measured.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie. The struct resolvers and the function resolvers are enabled locally (not committed); in the full build 0x004314E0 (MapEditorLandscaping_GeneralButtons handler) is left out and its resolver stays off, as in main's baseline.
  • Narrow build: the function alone reads 100.0 raw and normalised.
  • Full build: an all-on build of this head's tree on main 3458fea: 0 failed of 2,424 compile steps, 99.57 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files under tools/). The function reads 100.0 raw and normalised, with no diff entry.
    • Two functions on main read lower, and it is how reccmp prints a constant, not their code: Menu::handleMenuItems (0x004F6280) reads 97.9 (91.4 normalised) and Menu::Constructor_Menu (0x004F4100) reads 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all. In this build's layout a symbol of our DLL lies at exactly the address 0x11000000, so reccmp prints the constant as that symbol's name on our side. The instructions are the same on both sides. UI: three more functions at 100%: the building menu's DoInitial, the credits' prepare and activateModalDialog2 #435's text describes the same thing for its build.
    • The average: these two are the whole difference. Unrounded it is 99.5746 here against 99.5759 for main, and it would be 99.5761 with the two at 100.
    • Every other main function reads exactly what it read before.
  • Checks: openshc-pr-check gives 0 ERROR and 2 CHECK (below). openshc-pr-fix finds nothing to change.
  • Not run in game.

What got it to 100%

Two differences were left, in two different loops, with one cause.

  • The loop that draws the year labels took a label's years as label * 5. The compiler turns that into a counter of its own either way (add ebp, 5 at 0x0043F999). But with the multiplication in the source, the sum of the first year and the label's years was an lea into a third register, where the original adds in place (add ecx, ebp at 0x0043F985).
  • In the next loop, the one that draws the bars, three scratch registers came out rotated: the screen width in ecx where the original has eax (0x0043F9F0), and so on.
  • With the years as a second counter of the for loop (years += 5), both are gone.

That the next loop followed suggests the compiler hands out scratch registers in turn, so one temporary more shifts the choices behind it. This may help with other functions whose only gap is a rotation of eax, ecx and edx.

The checker's 2 CHECKs

What Why it stays
int scale; declared without a value both arms of the test assign it, and one arm chooses among five values, so there is no single first assignment to declare it at
the frame's left side: three drawLine calls that differ only in a number stepping by one as for loops the compiler keeps loops where the original has the calls written out (measured with both sides as loops: 289 instructions against the original's 318). The comment above the calls says so

🤖 Generated with Claude Code

StatusMenus::RenderStatusMenu_Population, from gynt's drafts: a92aa37 at 59.18% and 142ef0b at 64.1%, the
second on sourcehold's reimpl/UI-StatusMenus; 73.2% in the status line of 67318e1 on his fork's
reimpl/UI-StatusMenus-development; the newest commit on the file, e30b3f0, is on his
reimpl/UI-MenuItems-development. Through our drafts 4faa418 (82.4%, on our fork kotijekriv's
reimpl/UI-StatusMenus-development) and 6a2b835 (93.8%, in the draft PR sourcehold#313).

Two differences were left, in two different loops, with one cause: the year labels' loop took the label's years as
label * 5.
The compiler turns that into a counter of its own either way (add ebp, 5 at 0x0043F999), but with the
multiplication in the source
- the sum of the first year and the label's years was an lea into a third register, where the original adds in
  place (add ecx, ebp at 0x0043F985), and
- in the next loop, the bars' loop, the three scratch registers came out rotated (the screen width in ecx where
  the original has eax, at 0x0043F9F0).
With the years as a second counter of the for loop (years += 5) both are gone. That the next loop followed
suggests the compiler hands out scratch registers in turn, so one temporary more shifts the choices behind it.

Measured: quick_diff 0.9984 with 318 instructions against 317; the one line is the jmp over the padding in front
of the labels' loop (0x0043F926), which our listing shows as padding. reccmp 100.0% (normalized 100.0%) alone, data
resolvers and its own resolver on. Not run in game.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant