golang/go · error

Loong64 extension: invalid LSX/LASX register: {reg}

Error message

Loong64 extension: invalid LSX/LASX register: {reg}

What it means

The Go assembler's Loong64 arch helper Loong64RegisterExtension returns this error when the register is neither an LSX vector register (V0-V31) nor an LASX vector register (X0-X31) (loong64.go:82-91). LSX/LASX SIMD extensions require the operand to be a 128-bit (V) or 256-bit (X) SIMD register; any general-purpose, floating-point, or out-of-range register is rejected before any arrangement/extension encoding is attempted.

Source

Thrown at src/cmd/asm/internal/arch/loong64.go:90

	"Q2":  loong64.ARNG_2Q,
}

// Loong64RegisterExtension constructs an Loong64 register with extension or arrangement.
func Loong64RegisterExtension(a *obj.Addr, ext string, reg, num int16, isAmount, isIndex bool) error {
	var ok bool
	var arngType int16
	var simdType int16
	var simdReg int16

	switch {
	case reg >= loong64.REG_V0 && reg <= loong64.REG_V31:
		simdType = loong64.LSX
		simdReg = reg - loong64.REG_V0
	case reg >= loong64.REG_X0 && reg <= loong64.REG_X31:
		simdType = loong64.LASX
		simdReg = reg - loong64.REG_X0
	default:
		return errors.New("Loong64 extension: invalid LSX/LASX register: " + fmt.Sprintf("%d", reg))
	}

	if isIndex {
		arngType, ok = loong64ElemExtMap[ext]
		if !ok {
			return errors.New("Loong64 extension: invalid LSX/LASX arrangement type: " + ext)
		}

		a.Reg = loong64.REG_ELEM
		a.Reg += ((simdReg & loong64.EXT_REG_MASK) << loong64.EXT_REG_SHIFT)
		a.Reg += ((arngType & loong64.EXT_TYPE_MASK) << loong64.EXT_TYPE_SHIFT)
		a.Reg += ((simdType & loong64.EXT_SIMDTYPE_MASK) << loong64.EXT_SIMDTYPE_SHIFT)
		a.Index = num
	} else {
		switch simdType {
		case loong64.LSX:
			arngType, ok = loong64LsxArngExtMap[ext]
			if !ok {

View on GitHub (pinned to b6b368adc5)

Solutions

  1. Use V0-V31 for LSX instructions or X0-X31 for LASX instructions as the SIMD operand.
  2. If the operation is scalar, remove the SIMD arrangement/extension suffix and use the scalar instruction form.
  3. Verify the register prefix against the LoongArch ISA: V = LSX 128-bit, X = LASX 256-bit.
  4. Check the .s file line cited by the assembler error and correct the register name.

Example fix

; before — GPR used with SIMD arrangement
VADD.B R0, R1, R2

; after — use LSX vector registers
VADD.B V0, V1, V2
Defensive patterns

Strategy: validation

Validate before calling

// Validate the register is an LSX (V) or LASX (X) SIMD register.
func validLoong64SimdReg(reg int16) bool {
    return (reg >= loong64.REG_V0 && reg <= loong64.REG_V31) ||
        (reg >= loong64.REG_X0 && reg <= loong64.REG_X31)
}

Prevention

When it happens

Trigger: Triggered when a LoongArch assembly instruction applies an LSX/LASX extension/arrangement to a non-SIMD register, e.g., `VADDI R0.B16, ...` (R is GPR) or `XVADD F0.B32, ...` (F is FPR). The switch at loong64.go:82-90 only matches REG_V0..V31 and REG_X0..X31; everything else hits the default branch.

Common situations: Hand-written LoongArch assembly (.s files) targeting LSX (V registers) or LASX (X registers) but using R (GPR) or F (FPR) operands with a SIMD arrangement suffix. Porting LoongArch assembly from GNU as syntax where register naming differs. Typos in the register prefix (e.g., 'W' instead of 'X').

Related errors


AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12). Data as JSON: /api/errors/e226cd41261898b3. Report an issue: GitHub.