Skip to content

lb: implement lb_80019628; improve four lbbgflash functions - #2508

Merged
ribbanya merged 4 commits into
doldecomp:masterfrom
itsgrimetime:pr/lb-0192-impl
May 16, 2026
Merged

lb: implement lb_80019628; improve four lbbgflash functions#2508
ribbanya merged 4 commits into
doldecomp:masterfrom
itsgrimetime:pr/lb-0192-impl

Conversation

@itsgrimetime

@itsgrimetime itsgrimetime commented May 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • lb_0192.c (lb_80019628): adds a C body for the pad-sampling-rate maintenance function called from lb_80019894. Snapshots lb_804329F0.x38, picks the minimum of x0[0].x0 / x0[1].x0 / OS_TIMER_CLOCK / OS_TIMER_CLOCK * 1/60 as the new period, divides by OS_TIMER_CLOCK/1000 for the ms cap (≤ 11), then updates PADSetSamplingRate and reschedules the periodic alarm with fn_800195FC.
  • lbbgflash.c (fn_8001FC08): restructures each per-channel saturation block to use branch-local u8 target / f32* cur locals so MWCC keeps the byte target and the x10[i] pointer in r5/r4 across the rising/falling logic.
  • lbbgflash.c (lbBgFlash_80020E38): reorders the squared-component locals (dx2/dy2/dz2 instead of dz2/dx2/dy2) and the sum to match how the original schedules the lfs/fmuls/fadds pipeline.
  • lbbgflash.c (fn_8002113C): routes &rot through a Quaternion* volatile local so MWCC keeps the inline-substituted asserts at jobj.h:699/700 in the Fake_HSD_JObjGetRotation expansion (previously the compiler proved &rot non-null and elided the assert call entirely).
  • lbbgflash.c (fn_80020AEC): expands parent = jobj ? jobj->parent : NULL; to an explicit if/else so MWCC schedules the non-null case first, matching the bne / b / li sequence the original emits for parent.

Functions matched

No 100% matches. Five improvements toward the original:

  • lb_80019628: 0% (no source body — was relying on the asm-only fallback) → 82.58% fuzzy
  • fn_8001FC08: 89.55% → 91.77% fuzzy
  • fn_8002113C: 93.17% → 94.72% fuzzy
  • fn_80020AEC: 88.27% → 88.77% fuzzy
  • lbBgFlash_80020E38: 98.46% → 98.52% fuzzy

Files

  • src/melee/lb/lb_0192.c
  • src/melee/lb/lbbgflash.c

Verification

  • python configure.py && ninja → green (build/GALE01/main.dol: OK)
  • All sibling functions in both TUs unchanged.

@decomp-dev

decomp-dev Bot commented May 16, 2026

Copy link
Copy Markdown

Report for GALE01 (d489106 - 321cbf9)

📈 5 improvements in unmatched items
Unit Item Bytes Before After
main/melee/lb/lb_0192 lb_80019628 +495 0.00% 82.58%
main/melee/lb/lbbgflash fn_8001FC08 +15 89.68% 91.77%
main/melee/lb/lbbgflash fn_8002113C +11 93.17% 94.72%
main/melee/lb/lbbgflash .sdata +6 50.00% 65.71%
main/melee/lb/lbbgflash lbBgFlash_80020E38 0 98.46% 98.52%

Adds a C body for lb_80019628 — the pad-sampling-rate maintenance
function called from lb_80019894 to keep PADSetSamplingRate and the
periodic poll alarm in sync with whatever current period was set
via lb_80019880.

Reads the publication slot at lb_804329F0.x38, picks the minimum
of x0[0].x0 / x0[1].x0 / OS_TIMER_CLOCK / OS_TIMER_CLOCK*1/60 as
the new period, then if it changed, divides it by OS_TIMER_CLOCK/1000
to get milliseconds (cap 11), updates PADSetSamplingRate, and
reschedules the periodic alarm with fn_800195FC as the handler.

Brings lb_80019628 from 0% (no source body — was relying on the
asm-only fallback) to 82.58% fuzzy match. The TU's data section
(static lb_804329F0 vs global in the original) and the inner
abs-comparison register choices still differ from the original.
Splits each per-channel block into branch-local `u8 target` /
`f32* cur` locals so MWCC keeps the byte target and the pointer
into x10[i] in r5/r4 across the rising/falling alpha-style
saturation logic, matching the order the original emits.

fn_8001FC08: 89.55% -> 91.77% fuzzy.

The remaining 8% is anonymous .sdata2 constants the function uses
for 0.0f / 2^52 (compiler-pooled in the original to lbl_804D7CE8
and lbl_804D7CF0 but anonymous in our build).
@itsgrimetime itsgrimetime changed the title lb: implement lb_80019628 (pad sampling-rate sync) lb: implement lb_80019628, improve fn_8001FC08 May 16, 2026
Reorder the squared-component locals (dx2 / dy2 / dz2 instead of
dz2 / dx2 / dy2) and the sum to match how the original schedules
the lfs/fmuls/fadds pipeline (dx-first load, dz-last). MWCC now
emits the same sum order as the original.

lbBgFlash_80020E38: 98.46% -> 98.52% fuzzy. Remaining mismatch is
f4 / f0 register swap on the dx / dy loads.
@itsgrimetime itsgrimetime changed the title lb: implement lb_80019628, improve fn_8001FC08 lb: implement lb_80019628, improve fn_8001FC08 and lbBgFlash_80020E38 May 16, 2026
Routes &rot through a `Quaternion* volatile` local so MWCC keeps
the inline-substituted asserts at jobj.h:699/700 in the
Fake_HSD_JObjGetRotation expansion (previously the compiler
proved &rot non-null and elided the assert call entirely).

fn_8002113C: 93.17% -> 94.72% fuzzy. The volatile pointer adds an
extra 8-byte stack slot, so current is +6 instructions vs target —
but the missing assert chain (jobj/rotate at line 700) is now
emitted in the right place.
@itsgrimetime itsgrimetime changed the title lb: implement lb_80019628, improve fn_8001FC08 and lbBgFlash_80020E38 lb: implement lb_80019628, improve fn_8001FC08 / fn_8002113C / lbBgFlash_80020E38 May 16, 2026
@ribbanya
ribbanya merged commit 9f6156e into doldecomp:master May 16, 2026
7 checks passed
@itsgrimetime itsgrimetime changed the title lb: implement lb_80019628, improve fn_8001FC08 / fn_8002113C / lbBgFlash_80020E38 lb: implement lb_80019628; improve four lbbgflash functions May 16, 2026
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.

2 participants