Source file src/simd/archsimd/_gen/cmd/specstats/output.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  	"bytes"
     9  	"fmt"
    10  	"strings"
    11  )
    12  
    13  // labelWidth leaves one space after the longest label. Increase this if labels
    14  // change and the tables get out of alignment.
    15  const labelWidth = 47
    16  
    17  // section writes a section heading and the tasks that move the figures in it.
    18  // A tag long enough to push the heading past the line budget goes on its own
    19  // line rather than trailing off the screen.
    20  func section(w *bytes.Buffer, title, tasks string) {
    21  	head := "## " + title
    22  	if tag := taskTag(tasks); tag != "" {
    23  		if len(head)+len(tag)+1 <= 88 {
    24  			head += " " + tag
    25  		} else {
    26  			head += "\n   " + strings.TrimSpace(tag)
    27  		}
    28  	}
    29  	fmt.Fprintf(w, "\n\n%s\n\n", head)
    30  }
    31  
    32  // note writes a block of explanatory prose, followed by a blank line.
    33  func note(w *bytes.Buffer, text string) {
    34  	fmt.Fprintf(w, "%s\n\n", text)
    35  }
    36  
    37  // frac writes a figure heading for 100%.
    38  func frac(w *bytes.Buffer, label string, r result, tasks string) {
    39  	pct := "  --"
    40  	if r.d > 0 {
    41  		pct = fmt.Sprintf("%3.0f%%", 100*float64(r.n)/float64(r.d))
    42  	}
    43  	line(w, fmt.Sprintf("%-*s %5d / %-5d %s%s", labelWidth, label, r.n, r.d, pct, taskTag(tasks)))
    44  }
    45  
    46  // count writes a figure heading for zero.
    47  func count(w *bytes.Buffer, label string, n int, tasks string) {
    48  	line(w, fmt.Sprintf("%-*s %5d %-9s%s", labelWidth, label, n, "-> 0", taskTag(tasks)))
    49  }
    50  
    51  // kv writes a bare number: context rather than a figure with a target.
    52  func kv(w *bytes.Buffer, label string, n int) {
    53  	line(w, fmt.Sprintf("%-*s %5d", labelWidth, label, n))
    54  }
    55  
    56  // sub writes a bare number indented under the figure it breaks down.
    57  func sub(w *bytes.Buffer, label string, n int) {
    58  	line(w, fmt.Sprintf("    %-*s %5d", labelWidth-4, label, n))
    59  }
    60  
    61  // countIndented writes a count heading for zero, indented under the figure it
    62  // breaks down. Used for per-field and per-file detail rows.
    63  func countIndented(w *bytes.Buffer, label string, n int, tasks string) {
    64  	line(w, fmt.Sprintf("    %-*s %5d %-9s%s", labelWidth-4, label, n, "-> 0", taskTag(tasks)))
    65  }
    66  
    67  // emptyList writes a placeholder when a list has no rows, so that a heading
    68  // with nothing under it reads as an empty list rather than a truncated one.
    69  func emptyList(w *bytes.Buffer, n int) {
    70  	if n == 0 {
    71  		line(w, "    (none)")
    72  	}
    73  }
    74  
    75  const lineWrap = 78
    76  
    77  // wrap writes lead followed by a list of words, breaking before the line
    78  // wrapping budget and aligning continuations under the first word. The lead
    79  // labels the list, so that an inventory nested under a table row says what it
    80  // is rather than leaving the reader to infer it from position.
    81  func wrap(w *bytes.Buffer, indent, lead string, words []string) {
    82  	first, rest := indent+lead, indent+strings.Repeat(" ", len(lead))
    83  	cur := first
    84  	for _, s := range words {
    85  		if len(cur) > len(rest) && len(cur)+1+len(s) > lineWrap {
    86  			line(w, cur)
    87  			cur = rest
    88  		}
    89  		if len(cur) > len(rest) {
    90  			cur += " "
    91  		}
    92  		cur += s
    93  	}
    94  	if len(cur) > len(rest) {
    95  		line(w, cur)
    96  	}
    97  }
    98  
    99  func line(w *bytes.Buffer, s string) {
   100  	fmt.Fprintf(w, "%s\n", strings.TrimRight(s, " "))
   101  }
   102  
   103  func taskTag(tasks string) string {
   104  	if tasks == "" || tasks == "-" {
   105  		return ""
   106  	}
   107  	return "  [" + tasks + "]"
   108  }
   109  

View as plain text