Source file src/simd/archsimd/types_other_arm64.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  //go:build goexperiment.simd
     6  
     7  package archsimd
     8  
     9  // vsve is a tag type for SVE vectors.
    10  type vsve struct {
    11  	_sve [0]func() // uncomparable
    12  }
    13  
    14  // psve is a tag type for SVE predicates.
    15  type psve struct {
    16  	_sve [0]func() // uncomparable
    17  }
    18  
    19  // Int8s is an SVE vector of int8s.
    20  type Int8s struct {
    21  	int8s vsve
    22  	vals  [32]int8
    23  }
    24  
    25  // Mask8s is an SVE predicate for 8-bit elements.
    26  type Mask8s struct {
    27  	mask8s psve
    28  	vals   uint32
    29  }
    30  
    31  func (v *Int8s) Len() int {
    32  	return vl()
    33  }
    34  
    35  func (m *Mask8s) Len() int {
    36  	return vl()
    37  }
    38  
    39  func vl() int
    40  
    41  func init() {
    42  	if !ARM64.SVE() {
    43  		// No SVE so no need to check, unsafe accesses are not reachable.
    44  		return
    45  	}
    46  	// Go supports VL up to 32 bytes, that's because the stack allocation
    47  	// for scalable vectors have to be a fixed size, and 32 bytes is what
    48  	// we currently support, which we believe should cover most hardware.
    49  	// TODO: when the support for dynamic stack is ready, we can reconsider
    50  	// this design choice.
    51  	// TODO: another idea is to make SVE() return false if vl() > 32.
    52  	// But the user can still write code without checking SVE(), then
    53  	// it makes out-of-bound memory access possible.
    54  	if vl() > 32 {
    55  		panic("SVE vector length > 32 bytes not supported")
    56  	}
    57  }
    58  

View as plain text