Source file src/simd/archsimd/_gen/simdgen/phase.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 main
     6  
     7  import (
     8  	"fmt"
     9  	"go/token"
    10  	"regexp"
    11  
    12  	"simd/archsimd/_gen/sgutil"
    13  	"simd/archsimd/_gen/specgen"
    14  )
    15  
    16  // apiPhase returns the phase of the current target's API files, other than
    17  // the files of experimental ops. SVE is entirely experimental.
    18  func apiPhase() sgutil.Phase {
    19  	if CurrentArch().isSVE() {
    20  		return sgutil.PhaseExperiment
    21  	}
    22  	return sgutil.PhaseStable
    23  }
    24  
    25  // opPhase returns the phase of op's Go declaration.
    26  //
    27  // Exported declarations are in [sgutil.PhaseStable] unless spec says
    28  // they're experimental. Unexported declarations are always in
    29  // [sgutil.PhaseStable], since they may implement generally available APIs.
    30  // Ops with no Go declaration are in [sgutil.PhaseExperiment], since no API
    31  // can depend on them.
    32  func opPhase(op Operation, specIdx *specgen.Index) sgutil.Phase {
    33  	recv, name, ok := opDecl(op)
    34  	if !ok {
    35  		return sgutil.PhaseExperiment
    36  	}
    37  	if token.IsExported(name) && specIdx.IsExperiment(recv, name) {
    38  		return sgutil.PhaseExperiment
    39  	}
    40  	return sgutil.PhaseStable
    41  }
    42  
    43  var stubDeclRE = regexp.MustCompile(`(?m)^func \(\w+ (\w+)\) (\w+)\(`)
    44  
    45  // opDecl returns the receiver type and method name of op's Go declaration, or
    46  // false if op has no Go declaration.
    47  func opDecl(op Operation) (recv, name string, ok bool) {
    48  	stub, ok := opStub(op)
    49  	if !ok {
    50  		return "", "", false
    51  	}
    52  	// The stub templates choose the receiver from among op's operands in ways
    53  	// that vary by template (see stubTemplates), so rather than duplicating
    54  	// that logic, find the receiver and name in the generated declaration.
    55  	m := stubDeclRE.FindSubmatch(stub)
    56  	if m == nil {
    57  		panic(fmt.Errorf("can't find method declaration in stub for op %v:\n%s", op.Go, stub))
    58  	}
    59  	return string(m[1]), string(m[2]), true
    60  }
    61  

View as plain text