Skip to content

Add ARM lowering coverage across stdlib asm corpus#10

Merged
cpunion merged 9 commits intoxgo-dev:mainfrom
cpunion:arm-support
Mar 14, 2026
Merged

Add ARM lowering coverage across stdlib asm corpus#10
cpunion merged 9 commits intoxgo-dev:mainfrom
cpunion:arm-support

Conversation

@cpunion
Copy link
Copy Markdown
Collaborator

@cpunion cpunion commented Mar 13, 2026

Summary

  • add ARM CFG-based lowering for branch-heavy stdlib asm paths
  • complete ARM lowering coverage for current stdlib arm corpora, including MOVM, SWI, MOVD, arithmetic/multiply families, and LDREX/STREX atomics
  • expand CI to cover ARM scan gates across multiple GOOS targets and test/build the CLI submodules with coverage upload

Verification

  • go test ./...
  • go test ./... in cmd/plan9asm
  • go test ./... in cmd/plan9asmll
  • go run ./cmd/plan9asmscan -goos linux -goarch arm ...
  • go run ./cmd/plan9asmscan -goos android -goarch arm ...
  • go run ./cmd/plan9asmscan -goos freebsd -goarch arm ...
  • go run ./cmd/plan9asmscan -goos netbsd -goarch arm ...
  • go run ./cmd/plan9asmscan -goos openbsd -goarch arm ...
  • go run ./cmd/plan9asmscan -goos plan9 -goarch arm ...
  • go run ./cmd/plan9asmscan -goos windows -goarch arm ...

Notes

  • current ARM scan coverage is clean for android/freebsd/linux/netbsd/openbsd/plan9/windows with Unsupported Ops = none
  • windows/arm parser tail was also fixed ($(16 + callbackArgs__size) style immediates)

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the plan9asm project by introducing robust Control Flow Graph (CFG)-based lowering for the ARM architecture. This enables more accurate and comprehensive translation of ARM assembly code, particularly for complex, branch-heavy standard library functions. The changes also expand test coverage and update related tooling to fully support ARM, ensuring broader compatibility and improved code generation capabilities.

Highlights

  • Expanded ARM Lowering: Introduced comprehensive Control Flow Graph (CFG)-based lowering for the ARM architecture, enabling more accurate translation of branch-heavy standard library assembly paths.
  • Full ARM Stdlib Coverage: Completed ARM lowering support for a wide range of instruction families, including MOVM (multiple register transfer), SWI (syscall), MOVD (floating-point data movement), various arithmetic and multiply operations, and LDREX/STREX atomics.
  • Enhanced CI for ARM: Extended continuous integration to include ARM scan gates across multiple GOOS targets (android, freebsd, linux, netbsd, openbsd, plan9, windows) and integrated coverage upload for CLI submodules.
  • Improved ARM Parsing: Fixed an issue with the windows/arm parser tail handling symbolic immediates, ensuring correct interpretation of complex immediate expressions.
  • New ARM-specific Infrastructure: Added numerous new Go files to implement the ARM lowering infrastructure, covering basic block splitting, context management, operand evaluation, flag handling, floating-point result management, and specific lowering logic for arithmetic, atomic, branch, data movement, MOVM, and syscall instructions.
  • Updated Tooling and Dependencies: Modified cmd/plan9asm, cmd/plan9asmll, and cmd/plan9asmscan to recognize and support the new arm architecture, and updated the github.com/goplus/llvm dependency to v0.8.6.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • arm64_eval.go
    • Updated shift operand evaluation to use a switch statement for ShiftOp and added a check for register-based shifts.
  • arm_atomic_test.go
    • Added a new test file to verify the translation of ARM LDREX and STREX atomic instructions.
  • arm_batch1_test.go
    • Added a new test file containing tests for ARM MOVM (push/pop), SWI (syscall), MOVD (float save/restore), and MULLU instructions.
  • arm_blocks.go
    • Added new file defining armBlock structure and functions for splitting ARM functions into basic blocks (armSplitBlocks), identifying branch targets (armBranchTarget), and decoding ARM operation details (armDecodeOp).
  • arm_ctx.go
    • Added new file defining armCtx for ARM translation context, including register/FPU slot management, flag handling, exclusive monitor state, and utility functions for temporary variables and symbol resolution.
  • arm_eval.go
    • Added new file with functions for evaluating ARM operands (imm, reg, mem, shifts, FP values/addresses) and handling memory loads/stores.
  • arm_flags.go
    • Added new file implementing ARM flag manipulation (N, Z, C, V) for arithmetic and logic operations, and a function to derive conditional values based on flags.
  • arm_fp.go
    • Added new file for managing ARM floating-point result slots, including marking them as written or address-taken, and loading/storing their values.
  • arm_lower_arith.go
    • Added new file containing lowering logic for various ARM arithmetic instructions (ADD, SUB, AND, ORR, EOR, RSB, BIC, MVN, ADC, SBC, MUL, MULLU, MULA, MULAL, MULAWT, DIVUHW, CLZ, MRC) and compare operations (CMP, CMN, TST, TEQ).
  • arm_lower_atomic.go
    • Added new file implementing lowering for ARM exclusive access instructions (LDREX, STREX, LDREXB, STREXB, LDREXD, STREXD), including handling of exclusive monitor state.
  • arm_lower_branch.go
    • Added new file with lowering logic for ARM branch instructions (B, BL, CALL, JMP) and conditional branches (BEQ, BNE, etc.), including tail call optimization.
  • arm_lower_data.go
    • Added new file providing lowering for ARM data movement instructions (MOVD, MOVW, MOVB, MOVBU), handling register and memory transfers, and conditional writes.
  • arm_lower_movm.go
    • Added new file for lowering ARM MOVM (multiple register transfer) instructions, supporting various addressing modes and writeback.
  • arm_lower_syscall.go
    • Added new file implementing lowering for the ARM SWI (software interrupt/syscall) instruction.
  • arm_needed.go
    • Added new file with funcNeedsARMCFG to determine if a function requires CFG-based ARM lowering.
  • arm_parser_immediate_test.go
    • Added a new test file to verify parsing of ARM symbolic immediate expressions.
  • arm_parser_test.go
    • Added a new test file to verify parsing of ARM register range lists and various shift operands.
  • arm_translate.go
    • Added new file with emitARMPrelude to declare ARM-specific intrinsics and armLLVMBlockName for consistent block naming.
  • arm_translate_cfg.go
    • Added new file containing the core CFG-based translation logic for ARM functions, iterating through basic blocks and lowering individual instructions.
  • arm_translate_test.go
    • Added a new test file to verify linear ARM translation for a simple ADD operation.
  • cmd/plan9asm/main.go
    • Updated goarch flag description to include arm.
    • Modified toPlan9Arch to support arm architecture.
  • cmd/plan9asmll/go.mod
    • Updated github.com/goplus/llvm dependency to v0.8.6.
  • cmd/plan9asmll/go.sum
    • Updated checksum for github.com/goplus/llvm v0.8.6.
  • cmd/plan9asmll/main.go
    • Updated goarch flag description to include arm.
    • Modified toPlan9Arch to support arm architecture.
  • cmd/plan9asmscan/main.go
    • Updated goarch flag description to include arm.
    • Modified architecture validation and toPlan9Arch to support arm.
  • cmd/plan9asmscan/main_test.go
    • Added a test case for toPlan9Arch("arm").
  • go_translate.go
    • Updated goArchFor to recognize arm.
    • Integrated translateFuncARM for CFG-based ARM lowering.
    • Extended linear translation to handle ARM-specific MOVW, MOVB, MOVBU, ADD, SUB, AND, ORR, EOR, RSB instructions and shift operands.
  • go_translate_helpers_test.go
    • Added a test case for goArchFor("arm").
  • stdlib_bytealg_arm_compile_test.go
    • Added a new comprehensive test file to compile ARM assembly files from internal/bytealg using llc, verifying the translation and compilation process.
  • translate.go
    • Integrated translateFuncARM for CFG-based ARM lowering.
    • Updated linear translation to handle ARM-specific MOVW, MOVB, MOVBU, ADD, SUB, AND, ORR, EOR, RSB instructions and shift operands.
  • translate_module_direct.go
    • Added a check to ensure direct module translation handles ARM CFG lowering requirements.
    • Updated translateFuncLinearModule to set argument registers for ARM.
  • translate_prelude.go
    • Added emitARMPrelude to include ARM-specific LLVM IR declarations.
  • types.go
    • Added ArchARM to the Arch type.
    • Introduced ShiftOp enum (ShiftLeft, ShiftRight, ShiftArith, ShiftRotate) and updated Operand structure to use it.
    • Modified Operand.String() to correctly format new shift operations.
    • Updated parseImm to be more permissive with symbolic immediate expressions.
    • Refactored parseRegShift to handle new ShiftOp types and register-based shifts.
    • Added expandRegRange, regRangeParts, and absInt for parsing register ranges.
Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/go-ci.yml
Activity
  • The author, cpunion, initiated this pull request to add ARM lowering coverage.
  • Extensive verification steps were performed by the author, including go test ./... for various submodules and go run ./cmd/plan9asmscan for multiple ARM GOOS targets.
  • The author notes that current ARM scan coverage is clean for android/freebsd/linux/netbsd/openbsd/plan9/windows with Unsupported Ops = none.
  • A specific fix for windows/arm parser tail handling ($(16 + callbackArgs__size) style immediates) was implemented.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Comment thread arm_lower_arith.go Outdated
Comment thread arm_flags.go
Comment thread .github/workflows/go-ci.yml
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 13, 2026

Codecov Report

❌ Patch coverage is 46.10607% with 1128 lines in your changes missing coverage. Please review.
✅ Project coverage is 31.42%. Comparing base (1e5e3f7) to head (02fcf2b).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
arm_lower_arith.go 14.64% 328 Missing and 16 partials ⚠️
arm_lower_branch.go 26.82% 104 Missing and 16 partials ⚠️
arm_lower_atomic.go 43.68% 96 Missing and 11 partials ⚠️
translate.go 30.06% 93 Missing and 14 partials ⚠️
arm_eval.go 49.47% 85 Missing and 11 partials ⚠️
arm_translate_cfg.go 55.55% 53 Missing and 7 partials ⚠️
arm_flags.go 61.42% 46 Missing and 8 partials ⚠️
arm_ctx.go 77.15% 38 Missing and 7 partials ⚠️
arm_lower_movm.go 60.00% 32 Missing and 8 partials ⚠️
arm_fp.go 46.15% 31 Missing and 4 partials ⚠️
... and 9 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #10      +/-   ##
==========================================
- Coverage   32.44%   31.42%   -1.03%     
==========================================
  Files          41       57      +16     
  Lines       12646    16380    +3734     
==========================================
+ Hits         4103     5147    +1044     
- Misses       7809    10365    +2556     
- Partials      734      868     +134     
Flag Coverage Δ
unittests 31.42% <46.10%> (-1.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread .github/workflows/go-ci.yml Outdated
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces comprehensive support for translating ARM assembly to LLVM IR. It adds a new CFG-based lowering path for complex functions, implements lowering for a wide range of ARM instructions, and enhances the parser for ARM-specific syntax. The changes are extensive, well-structured, and include thorough testing. I've identified one minor issue in the inline assembly for the MRC instruction.

Comment thread arm_lower_arith.go
Comment thread arm_lower_data.go Outdated
Comment thread arm_translate.go Outdated
Comment thread types.go Outdated
@fennoai
Copy link
Copy Markdown

fennoai Bot commented Mar 13, 2026

Solid ARM lowering coverage with good test breadth across stdlib corpora. A few items need attention before merge:

Correctness (high priority)

  • setFlags is silently dropped for ADD.S/SUB.S/AND.S etc. — flags are never written, breaking downstream conditionals (arm_lower_arith.go:11)
  • condValue is missing PL, VS, VC, AL — translation errors if any stdlib asm uses those conditions (arm_flags.go:134)

Code quality

  • parseImm returns silent 0 for unresolved symbolic immediates — consider a sentinel or distinct OpKind (types.go:283)
  • Dead if bits == 8 branch in storeARMValue — both paths call identical code (arm_lower_data.go:93)
  • @cliteErrno declared in every ARM prelude but never referenced — remove or document (arm_translate.go:7)

CI

  • go-version: '1.26.x' in arm-scan job does not exist; pin to a released version (go-ci.yml:191)
  • ${{ matrix.goos }} interpolated bare into shell — safe today but fragile; prefer env-var indirection (go-ci.yml:66)

@cpunion cpunion merged commit a28f694 into xgo-dev:main Mar 14, 2026
27 of 28 checks passed
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