Source file test/codegen/simd_portable_inline.go

     1  // asmcheck
     2  
     3  // Copyright 2026 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  // Verify that portable simd operations inline completely in a package that
     8  // imports only simd. The bridge between simd and simd/archsimd inlines bodies
     9  // from simd/archsimd (and, in its emulated fallbacks, from math and
    10  // math/bits), and simd's export data must carry those bodies, too.
    11  //
    12  // Do not import simd/archsimd, math, or math/bits here: that would mask
    13  // missing bodies.
    14  
    15  //go:build goexperiment.simd && (amd64 || arm64 || wasm)
    16  
    17  package codegen
    18  
    19  import "simd"
    20  
    21  func portableLoadStore(s []uint32) {
    22  	// amd64:-`CALL simd/archsimd` arm64:-`CALL simd/archsimd` wasm:-`CALL simd/archsimd`
    23  	x := simd.LoadUint32s(s)
    24  	// amd64:-`CALL simd/archsimd` arm64:-`CALL simd/archsimd` wasm:-`CALL simd/archsimd`
    25  	x.Add(x).Store(s)
    26  }
    27  
    28  func portableLoadStorePart(s []uint32) int {
    29  	// amd64:-`CALL simd/archsimd` arm64:-`CALL simd/archsimd` wasm:-`CALL simd/archsimd`
    30  	x, n := simd.LoadUint32sPart(s)
    31  	// amd64:-`CALL simd/archsimd` arm64:-`CALL simd/archsimd` wasm:-`CALL simd/archsimd`
    32  	return x.StorePart(s) + n
    33  }
    34  
    35  func portableLenReduceSum(s []int16) int16 {
    36  	// amd64:-`CALL simd/archsimd` arm64:-`CALL simd/archsimd` wasm:-`CALL simd/archsimd`
    37  	return simd.LoadInt16s(s[:simd.Int16s{}.Len()]).ReduceSum()
    38  }
    39  
    40  // Like any function that uses portable simd types, these are multicompiled
    41  // for each vector width. That includes an emulated (no SIMD) variant, which
    42  // uses the bridge's pure-Go fallbacks. Those call math.Float32bits and
    43  // bits.OnesCount8.
    44  
    45  func portableToBits(s []float32, d []uint32) {
    46  	// amd64:-`CALL math` arm64:-`CALL math` wasm:-`CALL math`
    47  	simd.LoadFloat32s(s).ToBits().Store(d)
    48  }
    49  
    50  func portableOnesCount(s []int8) {
    51  	// amd64:-`CALL math` arm64:-`CALL math` wasm:-`CALL math`
    52  	simd.LoadInt8s(s).OnesCount().Store(s)
    53  }
    54  

View as plain text