Skip to content

aarch64: fix the operand order of the data processing (1 source) instructions - #1546

Merged
Redhpm merged 1 commit into
cea-sec:masterfrom
bacescuandrei:fix/aarch64-dataproc-1src-operands
Oct 30, 2026
Merged

Redhpm merged 1 commit into
cea-sec:masterfrom
bacescuandrei:fix/aarch64-dataproc-1src-operands

Conversation

@bacescuandrei

Copy link
Copy Markdown
Contributor

The aarch64 data processing (1 source) instructions (RBIT, REV16, REV, REV32, CLZ, CLS) are defined without an explicit argument list, so their operands are taken in field order, rn, rd. Miasm therefore shows and lifts them with the source and destination swapped:

e310c05a   clz w3, w7    (llvm-mc)
           CLZ W7, W3    (miasm)

and the IR writes the result to the source register. The two definitions now list the arguments as [rd, rn], like the other instructions; the semantics already treat the first argument as the destination.

Added CLZ, CLS, RBIT, REV16, REV (W and X), and REV32 vectors to test/arch/aarch64/arch.py, with encodings checked against llvm-mc. On master the test fails at the first one (CLZ W3, W7 is disassembled as CLZ W7, W3); with this change it passes.

Also compared the python jitter with Unicorn 2.1.4 on these instructions: CLZ, RBIT, REV16 and 32-bit REV now give the same results. The aarch64 unit scripts pass with the python and gcc jitters.

@bacescuandrei

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #1527, which makes the same change to miasm/arch/aarch64/arch.py and was opened earlier. I missed it when checking for existing pull requests, sorry for the noise.

The only addition here was a set of regression vectors in test/arch/aarch64/arch.py (CLZ, CLS, RBIT, REV16, REV W/X, REV32; encodings checked with llvm-mc). They fail on master and pass with the change from #1527, and are in e685303 if they are useful there.

@Redhpm

Redhpm commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

I prefer adding tests, so I'll merge yours

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