Source file src/simd/archsimd/sve_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 && arm64
     6  
     7  package archsimd
     8  
     9  // vl reports the SVE hardware vector length in bytes. It is an intrinsic,
    10  // lowered to the RDVL instruction.
    11  func vl() int
    12  
    13  func init() {
    14  	if !ARM64.SVE() {
    15  		// No SVE so no need to check, unsafe accesses are not reachable.
    16  		return
    17  	}
    18  	// Go supports VL up to 32 bytes, that's because the stack allocation
    19  	// for scalable vectors have to be a fixed size, and 32 bytes is what
    20  	// we currently support, which we believe should cover most hardware.
    21  	// TODO: when the support for dynamic stack is ready, we can reconsider
    22  	// this design choice.
    23  	// TODO: another idea is to make SVE() return false if vl() > 32.
    24  	// But the user can still write code without checking SVE(), then
    25  	// it makes out-of-bound memory access possible.
    26  	if vl() > 32 {
    27  		panic("SVE vector length > 32 bytes not supported")
    28  	}
    29  }
    30  

View as plain text