Skip to content

[AUTOMATED] fix(sleigh): set the reservation in PowerPC lwarx - #1259

Merged
mahaloz merged 5 commits into
Noelo-Lab:mainfrom
phix33:fix/powerpc-lwarx-reservation
Oct 29, 2026
Merged

mahaloz merged 5 commits into
Noelo-Lab:mainfrom
phix33:fix/powerpc-lwarx-reservation

Conversation

@phix33

@phix33 phix33 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

On every PowerPC language, a lwarx/stwcx. retry loop decompiles as a loop
instead of as one atomic update. In the output below, v1 is never assigned,
so the store and the loop exit both depend on an uninitialized value.

printf '\tlwarx 9,0,3\n\taddi 9,9,1\n\tstwcx. 9,0,3\n\tbne- .-12\n\tblr\n' > atomic.s
powerpc-linux-gnu-as atomic.s -o atomic.o
powerpc-linux-gnu-ld -Ttext=0x10000 -e 0x10000 atomic.o -o atomic.elf
kuna decompile atomic.elf 0x10000 --addr
void sub_10000(int *a0)
{
  char v1; // reserve
  unsigned char v2; // cr0
  
  do {
    if (v1) {
      *a0 = storeWordConditionalIndexed(*a0 + 1,0,a0);
      v2 = 2;
    }
  } while (!(bool)(v2 >> 1 & 1));
}

With the fix this is *a0 = storeWordConditionalIndexed(*a0 + 1,0,a0);.
Compiled __atomic_fetch_add, compare-exchange, exchange and spinlock code
shows the same pattern.

Fix

  • stwcx. and stdcx. skip their store while RESERVE is 0, but lwarx in
    ppc_instructions.sinc had its reservation setup commented out, with a
    misspelled register name. It now sets RESERVE, RESERVE_LENGTH and
    RESERVE_ADDRESS, as the ISA lwarx does.
  • That constructor fixes the hint bit at 0, so for ordinary encodings it is
    chosen over the ISA one in the ISA languages too. All 23 PowerPC languages
    were affected, and all now produce the single conditional store.

Tests

  • tests/stages/kuna-ppc-lwarx-reservation.xml: the loop above on
    PowerPC:BE:32:default. It passes 0/2 without the fix and 2/2 with it.
  • kuna-sleigh ppc_lwarx_reservation: lwarx writes all three reservation
    registers on generic 32- and 64-bit, e500 and ISA languages. It fails on the
    unpatched specs.
  • The datatest corpus is unchanged (675/675). No other stage expectation moved.

@phix33
phix33 force-pushed the fix/powerpc-lwarx-reservation branch 2 times, most recently from 24d7cf1 to d65607f Compare October 26, 2026 07:52
stwcx. and stdcx. store only while RESERVE is set, but lwarx had its
reservation setup commented out (with a misspelled register name). Every
lwarx/stwcx. retry loop therefore decompiled as a loop gated on an
uninitialized reserve flag. The generic constructor wins over the ISA one
for ordinary encodings, so this affected all 23 PowerPC languages,
including the ISA languages that already set the reservation in their own
lwarx. Set RESERVE, RESERVE_LENGTH and RESERVE_ADDRESS as the ISA
constructor does; the loop now decompiles to its single conditional store.

Adds a stage case for the generic 32-bit loop (0/2 without the fix, 2/2
with it) and a kuna-sleigh test that lwarx writes all three reservation
registers on generic, e500 and ISA languages. Correctness repair without
an option; stages baseline re-recorded for the two new assertions only.
@phix33
phix33 force-pushed the fix/powerpc-lwarx-reservation branch from d65607f to 437c0a6 Compare October 26, 2026 09:41
mahaloz and others added 4 commits October 26, 2026 05:46
…nly subset) (Noelo-Lab#1286)

A ported name-only Swift demangler subset (parse-or-passthrough: context chains, functions with argument labels, accessors, init/deinit, six global markers; punycode/witnesses/thunks/specializations pass through byte-identical; the one ambiguous production refused). Wired beside the Rust/Itanium/MSVC demanglers behind the Swift name-shape test; swiftdemangle on|off default on, loadtime env bridge. Crate alternatives rejected on evidence (cmake C++ build + rustc floor; unvetted 0.x). Corpus hand-derived from the Swift ABI mangling spec with per-case citations. E2e synthesizes an ELF with genuine mangled names (no Swift toolchain exists here or on CI - the vendored-fixture follow-up is named in the spec prose).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WoTv7T2Ep5hmbZcyYSMk1g
… export (Noelo-Lab#1290)

* Add --stream-layout address: streamed progress over a reproducible export

`decompile-project --stream --stream-layout address` runs the non-stream
export unchanged (same serial or pooled decompile, plan, structure naming,
merge and artifacts) and reports on it while it runs: `.streaming` on its
clock, a running README, and `index.jsonl` as a per-function feed in
completion order with null `.c` spans. At the end the four artifacts are the
non-stream export's byte for byte, `index.jsonl` is replaced by the
address-ordered index of that `.c`, and `.streaming` is removed, so the
folder does not depend on --jobs N wherever the non-stream export does not.

The default layout (`decompile`) is unchanged. Hooks: jobs::PoolWatch on the
pool's planned first pass, a `landed` callback on the serial and
callee-first loops, and decompile_project::ExportWatch around the export.

Measured on /usr/bin/ssh (1,090 functions): address-layout runs at --jobs 2
and 4 and a non-stream --jobs 4 run leave identical folders apart from
index.jsonl; CPU time of the two --jobs 4 arms is within noise.

[AUTOMATED] Authored by an agent.

* Rename --stream-layout address to --progress

Progress reporting and incremental artifacts are two separate things;
`--stream` bundles both, and only the incremental `.c` costs
reproducibility. `--progress` is now its own flag: the status file and the
index.jsonl feed over an ordinary export written at the end. With both
flags the export is the streamed one. `--progress` accepts `--assert`
under the non-stream export's rules. `--stream-layout` is removed.

[AUTOMATED] Authored by an agent.
@mahaloz
mahaloz merged commit e034fef into Noelo-Lab:main Oct 29, 2026
2 checks passed
mahaloz added a commit to thotypous/kuna that referenced this pull request Oct 29, 2026
…ports Noelo-Lab#1291)

Resolve the stage-corpus count (591 = 83 datatests + 508 stages) and
keep both lift-and-flow spec paragraphs. Re-record the stages baseline
on the merged tree (3229/3229).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013BBaWTixHX2E5cBwneY5aW
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.

3 participants