Help us shape the future of Go! Take the 2026 Go Developer Survey

Source file src/simd/internal/spec/basic.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  //specgen:category Basics
     6  
     7  package spec
     8  
     9  import (
    10  	"fmt"
    11  	"strings"
    12  )
    13  
    14  // Len returns the number of elements in x.
    15  func Len[E EltOrMask, W Width](x Vec[E, W]) int {
    16  	return x.len()
    17  }
    18  
    19  // String returns x in the form "{x[0],x[1],...}".
    20  func String[E Nums, W Width](x Vec[E, W]) string {
    21  	var buf strings.Builder
    22  	buf.WriteByte('{')
    23  	for i, val := range x {
    24  		if i > 0 {
    25  			buf.WriteByte(',')
    26  		}
    27  		fmt.Fprint(&buf, val)
    28  	}
    29  	buf.WriteByte('}')
    30  	return buf.String()
    31  }
    32  
    33  // StringMask returns x in the form "{x[0],x[1],...}", where 0 means false and 1
    34  // means true.
    35  //
    36  //specgen:name String
    37  func StringMask[E MaskElt, W Width](x Vec[E, W]) string {
    38  	var buf strings.Builder
    39  	buf.WriteByte('{')
    40  	for i, val := range x {
    41  		if i > 0 {
    42  			buf.WriteByte(',')
    43  		}
    44  		if val == 0 {
    45  			buf.WriteByte('0')
    46  		} else {
    47  			buf.WriteByte('1')
    48  		}
    49  	}
    50  	buf.WriteByte('}')
    51  	return buf.String()
    52  }
    53  

View as plain text