Source file test/codegen/simd_converts.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  // These tests check code generation of SIMD conversions on 128-bit vectors,
     8  // which every architecture has.
     9  
    10  //go:build goexperiment.simd
    11  
    12  package codegen
    13  
    14  import "simd/archsimd"
    15  
    16  // Widening the high half of a vector folds into a single instruction where the
    17  // architecture has one.
    18  
    19  func simdExtendHiInt8x16(x archsimd.Int8x16) archsimd.Int16x8 {
    20  	// arm64:`VSXTL2` -`VDUP`
    21  	// wasm:`I16x8ExtendHighI8x16S` -`ExtractLane` -`ReplaceLane`
    22  	return x.HiToLo().ExtendToInt16()
    23  }
    24  
    25  func simdExtendHiUint16x8(x archsimd.Uint16x8) archsimd.Uint32x4 {
    26  	// arm64:`VUXTL2` -`VDUP`
    27  	// wasm:`I32x4ExtendHighI16x8U` -`ExtractLane` -`ReplaceLane`
    28  	return x.HiToLo().ExtendToUint32()
    29  }
    30  
    31  func simdExtendHiInt32x4(x archsimd.Int32x4) archsimd.Int64x2 {
    32  	// arm64:`VSXTL2` -`VDUP`
    33  	// wasm:`I64x2ExtendHighI32x4S` -`ExtractLane` -`ReplaceLane`
    34  	return x.HiToLo().ExtendToInt64()
    35  }
    36  
    37  func simdConvertHiFloat32x4(x archsimd.Float32x4) archsimd.Float64x2 {
    38  	// arm64:`VFCVTL2` -`VDUP`
    39  	return x.HiToLo().ConvertToFloat64()
    40  }
    41  
    42  func simdExtendHiUint8x16(x archsimd.Uint8x16) archsimd.Uint16x8 {
    43  	// arm64:`VUXTL2` -`VDUP`
    44  	// wasm:`I16x8ExtendHighI8x16U` -`ExtractLane` -`ReplaceLane`
    45  	return x.HiToLo().ExtendToUint16()
    46  }
    47  
    48  func simdExtendHiUint32x4(x archsimd.Uint32x4) archsimd.Uint64x2 {
    49  	// arm64:`VUXTL2` -`VDUP`
    50  	// wasm:`I64x2ExtendHighI32x4U` -`ExtractLane` -`ReplaceLane`
    51  	return x.HiToLo().ExtendToUint64()
    52  }
    53  

View as plain text