Source file src/simd/archsimd/_gen/simdgen/sve/load.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package sve
     6  
     7  import (
     8  	"sort"
     9  
    10  	"simd/archsimd/_gen/unify"
    11  
    12  	"golang.org/x/arch/arm64/instgen/xmlspec"
    13  )
    14  
    15  // parseInstructions parses the ARM64 ISA XML files at path and returns the
    16  // SVE / SVE2 instructions.
    17  func parseInstructions(path string) ([]*Instruction, error) {
    18  	xmlInsts := xmlspec.ParseXMLFiles(path)
    19  
    20  	// One XML section can hold several iclasses with distinct mnemonics
    21  	// (e.g. SUNPKHI + SUNPKLO), so expand to one logical instruction per iclass.
    22  	var insts []*Instruction
    23  	for _, xmlInst := range xmlInsts {
    24  		if xmlInst == nil {
    25  			continue
    26  		}
    27  		for i := range xmlInst.Instruction.Classes.Iclass {
    28  			inst := &Instruction{
    29  				Instruction: xmlInst.Instruction,
    30  				iclass:      &xmlInst.Instruction.Classes.Iclass[i],
    31  			}
    32  			if inst.mnemonic() == "" || !inst.isSVE() {
    33  				// TODO: handle more extensions?
    34  				continue
    35  			}
    36  			insts = append(insts, inst)
    37  		}
    38  	}
    39  
    40  	sort.Slice(insts, func(i, j int) bool {
    41  		return insts[i].mnemonic() < insts[j].mnemonic()
    42  	})
    43  	return insts, nil
    44  }
    45  
    46  // Load parses the ARM64 ISA XML files at path and returns the SVE / SVE2
    47  // instruction definitions as simdgen unify values.
    48  func Load(path string) ([]*unify.Value, error) {
    49  	insts, err := parseInstructions(path)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  	var defs []*unify.Value
    54  	for _, inst := range insts {
    55  		defs = append(defs, inst.emitAll()...)
    56  	}
    57  	return defs, nil
    58  }
    59  

View as plain text