Source file src/simd/archsimd/_gen/cmd/specstats/main.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  // Specstats reports progress on the internal/spec transition described in
     6  // SPEC-TRANSITION.md. The checked-in output is archsimd/_gen/SPEC-STATS.txt:
     7  //
     8  //	go run ./cmd/specstats -w
     9  //
    10  // Every figure it prints is a fraction heading for 100% or a defect count
    11  // heading for zero, tied to the tasks that move it. Anything that is merely
    12  // interesting, rather than a measure of how far along we are, does not belong
    13  // here.
    14  //
    15  // # How it is put together
    16  //
    17  // Almost every figure in the report is the same operation: count the distinct
    18  // things at some granularity, and count how many of them are done. So the
    19  // program builds one fact table -- [fact], a declaration as seen in one build
    20  // configuration -- and everything downstream is a pivot over it: pick a grain
    21  // ([fact.declKey], [fact.triple], [fact.pair], name), pick a predicate, and
    22  // optionally group by a dimension. [tally] does the counting and [pivot] does
    23  // the grouping, so a new figure is a few lines rather than a new loop.
    24  //
    25  // Like Fill, this parses rather than type-checks, so it sees every target's
    26  // declarations regardless of build tags (SPEC-TRANSITION.md ยง2.4). It is a
    27  // measurement tool and not a checker: it reports divergence and does not judge
    28  // it. fill builds the checker, and should absorb the comparison half of this
    29  // program rather than leave two implementations to drift.
    30  package main
    31  
    32  import (
    33  	"flag"
    34  	"log"
    35  	"path/filepath"
    36  
    37  	"simd/archsimd/_gen/gentools"
    38  	"simd/archsimd/_gen/specgen"
    39  )
    40  
    41  func main() {
    42  	log.SetFlags(0)
    43  	log.SetPrefix("specstats: ")
    44  	genOpts := gentools.RegisterFlags(nil)
    45  	flag.Parse()
    46  
    47  	specDir := specgen.MustFindSpecDir(genOpts.GOROOT)
    48  	simdDir := filepath.Clean(filepath.Join(specDir, "..", ".."))
    49  	genDir := filepath.Join(simdDir, "archsimd", "_gen")
    50  
    51  	spec, err := specgen.Load(specDir, nil)
    52  	if err != nil {
    53  		log.Fatalf("loading spec: %s", err)
    54  	}
    55  
    56  	var files gentools.Files
    57  	defer files.FlushOrExit()
    58  
    59  	buf := files.NewRawFile("simd/archsimd/_gen/SPEC-STATS.txt")
    60  	measure(loadAPI(genOpts, simdDir), spec, genDir).report(buf)
    61  }
    62  

View as plain text