Skip to content

cmd/asm,arch/arm64: add NEON VMUL, VUMULL/VUMULL2, VSHRN/VSHRN2 (vector integer multiply with narrow) #78498

Open

Description

@emmansun

What version of Go are you using (go version)?

v1.25

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

ALL

What did you do?

I am implementing ML‑KEM (Kyber) in Go assembly for arm64. To implement NEON vector integer multiplications with narrowing, I had to encode the instructions by hand as raw 32‑bit words:

	WORD $0x4E619C14  // MUL   V20.8H, V0.8H, V1.8H
	WORD $0x2E61C015  // UMULL V21.4S, V0.4H, V1.4H
	WORD $0x6E61C016  // UMULL2 V22.4S, V0.8H, V1.8H
	WORD $0x0F1086B5  // SHRN  V21.4H, V21.4S, #16
	WORD $0x4F1086D5  // SHRN2 V21.8H, V22.4S, #16
	WORD $0x4E7E9E96  // MUL   V22.8H, V20.8H, V30.8H
	WORD $0x2E7FC2D7  // UMULL V23.4S, V22.4H, V31.4H
	WORD $0x6E7FC2D8  // UMULL2 V24.4S, V22.8H, V31.8H
	WORD $0x0F1086F7  // SHRN  V23.4H, V23.4S, #16
	WORD $0x4F108717  // SHRN2 V23.8H, V24.4S, #16

Using raw WORD is fragile, hard to review, and error‑prone. I’d like to use proper Go assembly mnemonics instead.

What did you expect to see?

I expected the assembler to accept NEON vector integer multiply/narrow instructions similar to how other NEON instructions are accepted (for example, unsigned min/max in #42326 and floating‑point NEON ops in #41092), for example:

  • MUL (vector, integer, .8H):
    VMUL V20.8H, V0.8H, V1.8H
  • UMULL / UMULL2 (H → S):
    VUMULL V21.4S, V0.4H, V1.4H
    VUMULL2 V22.4S, V0.8H, V1.8H
  • SHRN / SHRN2 (S → H, immediate shift amount):
    VSHRN V21.4H, V21.4S, #16
    VSHRN2 V21.8H, V22.4S, #16
    I’m focusing on these because they’re the key building blocks for efficient NEON 16‑bit multiply–accumulate and narrowing in cryptographic kernels like ML‑KEM, but a more general set of NEON vector integer multiply/shift‑narrow ops would also be very welcome.

What did you see instead?

go tool asm only accepts raw WORD literals for these encodings; there are no mnemonic aliases for them in the assembler.

Motivation


Proposal

Add support for the following NEON vector integer operations to cmd/asm on arm64 (and the corresponding assembler tables), so they can be written using Go assembly syntax instead of raw WORD constants:

  • VMUL (vector, integer), e.g., element‑wise multiply with 8‑bit/16‑bit/32‑bit element types.
  • VUMULL / VUMULL2 (wider, unsigned multiply): widen elements and multiply, low/high halves; common use case is 16‑bit to 32‑bit.
  • VSHRN / VSHRN2 (shift‑right narrow): take wider elements and narrow them back down with a right‑shift; common use case is 32‑bit to 16‑bit narrowing after UMULL.
    These encodings are standard A64 NEON SIMD&FP instructions defined in the ARM Architecture Reference Manual; I’ve listed concrete encodings above to unambiguously identify the variants I’m using (H/S lanes).
    If the team prefers a broader change (e.g., “add support for all NEON integer multiply–accumulate/narrow variants in one batch”), I’m happy to adjust scope and help test.

Rationale / Use cases

  • ML‑KEM (Kyber) arm64 assembly currently uses hand‑encoded WORD constants for these ops; having mnemonics would significantly improve readability and reduce risk of encoding mistakes.
  • Other DSP and crypto workloads also use UMULL+SHRN style patterns; this is a small but high‑impact subset for those domains.

Proposed syntax (for discussion)

These follow the style used by other NEON instructions in Go assembly (e.g., VFADD, VUMIN, VUMAX), with explicit element types on the operands:

  • Multiply (same width):
    VMUL Vd.<T>, Vn.<T>, Vm.<T>
    Example: VMUL V20.8H, V0.8H, V1.8H
  • Unsigned widen‑multiply (low/high):
    VUMULL Vd.4S, Vn.4H, Vm.4H
    VUMULL2 Vd.4S, Vn.8H, Vm.8H
  • Shift‑right narrow (to lower/higher half):
    VSHRN Vd.4H, Vn.4S, #imm
    VSHRN2 Vd.8H, Vn.4S, #imm

Risks and compatibility

  • This only adds new instruction aliases; it does not change semantics of existing instructions.
  • The new ops can be gated by GOARCH=arm64 and, if desired, behind a build tag, though the current practice for NEON asm additions has been to make them available when assembling for arm64.

Note to maintainers

  • I’m not attached to a particular naming scheme (VMUL vs MUL, VUMULL vs UMULL, etc.). If Go already uses MUL/UMULL for the scalar GPR forms and you’d prefer VMUL/VUMULL for the vector forms (to avoid ambiguity), I’m happy to adopt whatever convention you prefer.
  • I can provide small test cases that exercise these encodings and validate the generated code against an external disassembler (e.g., GNU objdump/llvm‑objdump).

Optional section if you want to be more explicit that this is a feature request, not a language proposal:
This is a cmd/asm feature request, not a language change.

Activity

  1. added
    ToolProposalIssues describing a requested change to a Go tool or command-line program.
    on Apr 2, 2026
  2. randall77 commented on Apr 8, 2026

    @randall77
    Contributor
  3. added this to the Unplanned milestone on Apr 8, 2026
  4. gopherbot commented on Apr 9, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/764420 mentions this issue: cmd/internal/obj/arm64: add ASIMD widening multiply-accumulate instructions

  5. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Apr 9, 2026
  6. added a commit that references this issue on Apr 15, 2026
    e73621e
  7. emmansun commented on Apr 16, 2026

    @emmansun
    Author

    I would strongly support expanding the scope here to include additional NEON integer operations. In our experience, beyond basic widening multiplies, several comparison, reduction, and doubling-multiply instructions show up repeatedly in NTTs, butterfly steps, and rejection sampling.
    What we actually need (beyond the initial MUL/UMULL/SHRN set)
    In our kernels, the most useful missing mnemonics fall into three categories:

    1. Widening + narrowing integer multiplies:

    • MUL (vector, integer)
    • UMULL / UMULL2
    • SHRN / SHRN2

    2. Rounding/truncating doubling multiply-high and accumulate:

    • SQRDMULH / SQDMULH
    • SQRDMLAH / SQRDMLSH
    • SRSHR / SSHR (for rounding right-shifts in Barrett-style reductions)

    3. Comparisons and Horizontal Reductions (Crucial for ML-DSA):

    • CMGT / CMGE / CMHI / CMHS: Heavily used for computing absolute values (often replacing ABS to avoid extra latency), conditional masking, and coefficient clamping.
    • UMAXV / SMAXV / UMINV / SMINV: Essential for horizontal reductions. Specifically, UMAXV is the workhorse for computing the $\ell_\infty$ norm (finding the maximum absolute value of a polynomial) during ML-DSA's rejection sampling step.
      Evidence from the ecosystem
    • The NeonNTT paper (Becker et al., TCHES 2022) relies heavily on SQRDMULH and SQRDMLAH for Kyber/Dilithium NTTs on Cortex‑A72 and Apple M1.
    • For ML-DSA specifically, the inner loops of signature generation require efficiently checking if max(|v_i|) < β. In hand-written ARM64 assembly, this translates directly to taking the absolute value (via bitwise logic or CMGT masks) followed by a UMAXV reduction to a scalar register. Right now, we have to use raw WORD encodings for these elegant vectorized paths.
      Why assembler mnemonics matter (even with SIMD intrinsics on the horizon)
    • Using WORD constants for encodings is error-prone and hard to review; having mnemonics matches the existing style of incremental assembler improvements (like the recent additions for VUMIN/VUMAX and NEON FP instructions).
  8. amusman commented on Apr 16, 2026

    @amusman
    Contributor

    @emmansun , thank you for the request. Sorry for not mentioning this here earlier, I originally implemented a superset of this request as part of GOEXPERIMENT=simd experimentation. Here's a summary of what has already landed:

    CL Instructions Category
    https://go-review.googlesource.com/c/go/+/721640 CMGT, CMGE, CMHI, CMHS Vector comparisons
    https://go-review.googlesource.com/c/go/+/762180 VSHRN, VSHRN2, VSSHR, VSRSHR Shift-right narrow + arithmetic shifts
    https://go-review.googlesource.com/c/go/+/762200 VMUL Vector integer multiply
    https://go-review.googlesource.com/c/go/+/762202 VUMAXV, VSMAXV, VUMINV, VSMINV Horizontal reductions
    https://go-review.googlesource.com/c/go/+/764420 VUMULL, VUMULL2 Widening unsigned multiply

    This covers instructions from the original request. CL 764420 carried a Fixes reference to this issue, which caused it to auto-close. The instructions from the last comment, SQRDMULH, SQDMULH, SQRDMLAH,SQRDMLSH are not yet covered.
    @randall77, could you please reopen this issue so we can track the remaining work here?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.ToolProposalIssues describing a requested change to a Go tool or command-line program.arch-arm64compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions