Repository navigation
Description
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, #16Using 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
- Many cryptographic and SIMD‑heavy workloads (e.g., ML‑KEM, other post‑quantum schemes) need vector multiply–accumulate with narrowing (16→32→16) on arm64.
- The “refactor the arm64 assembler framework” issue (cmd/asm: refactor the framework of the arm64 assembler #44734) noted that there are many missing NEON/SVE instructions and that adding them via the old framework is costly; it proposed a new encoding path to make future additions easier.
- Similar gaps have been filled incrementally (e.g., FLDPQ/FSTPQ in cmd/asm: ARM64 instructions FLDPQ and FSTPQ not supported #40725; NEON FP in cmd/asm: ARM64 NEON floating point instructions (VFABD VFMAX, VFMAXNM, VFMINNM VFMIN VFADD, VFSUB VFMUL, VFDIV VFMLA, VFMLS VCVT*) #41092; VUMIN/VUMAX in cmd/asm: ARM64 NEON unsigned min and max instructions (VUMAX, VUMIN) #42326). This request fits the same pattern and directly supports real‑world arm64 SIMD use in Go.
- Adding even just a focused subset (MUL, UMULL/UMULL2, SHRN/SHRN2) would eliminate the need for error‑prone
WORDliterals in ML‑KEM arm64 assembly and make such code easier to maintain.
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
WORDconstants 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=arm64and, 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 (
VMULvsMUL,VUMULLvsUMULL, etc.). If Go already usesMUL/UMULLfor the scalar GPR forms and you’d preferVMUL/VUMULLfor 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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsIn Progress
Activity
gabyhelp commentedon Apr 2, 2026
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
randall77 commentedon Apr 8, 2026
@amusman
gopherbot commentedon Apr 9, 2026
Change https://go.dev/cl/764420 mentions this issue:
cmd/internal/obj/arm64: add ASIMD widening multiply-accumulate instructionscmd/internal/obj/arm64: add ASIMD widening multiply-accumulate instru…
emmansun commentedon Apr 16, 2026
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/UMULL2SHRN/SHRN22. Rounding/truncating doubling multiply-high and accumulate:
SQRDMULH/SQDMULHSQRDMLAH/SQRDMLSHSRSHR/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 replacingABSto avoid extra latency), conditional masking, and coefficient clamping.UMAXV/SMAXV/UMINV/SMINV: Essential for horizontal reductions. Specifically,UMAXVis the workhorse for computing theEvidence from the ecosystem
SQRDMULHandSQRDMLAHfor Kyber/Dilithium NTTs on Cortex‑A72 and Apple M1.max(|v_i|) < β. In hand-written ARM64 assembly, this translates directly to taking the absolute value (via bitwise logic orCMGTmasks) followed by aUMAXVreduction to a scalar register. Right now, we have to use rawWORDencodings for these elegant vectorized paths.Why assembler mnemonics matter (even with SIMD intrinsics on the horizon)
WORDconstants for encodings is error-prone and hard to review; having mnemonics matches the existing style of incremental assembler improvements (like the recent additions forVUMIN/VUMAXand NEON FP instructions).amusman commentedon Apr 16, 2026
@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=simdexperimentation. Here's a summary of what has already landed: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,SQRDMLSHare not yet covered.@randall77, could you please reopen this issue so we can track the remaining work here?