...

Source file src/simd/archsimd/slicepart_amd64.go

Documentation: simd/archsimd

     1  // Copyright 2025 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 && amd64
     6  
     7  package archsimd
     8  
     9  // Implementation of all the {Int,Uint}{8,16} load and store slice part
    10  // functions and methods for 256-bit vectors.
    11  
    12  /* These two masks are used by generated code */
    13  
    14  var vecMask64 = [16]int64{
    15  	-1, -1, -1, -1,
    16  	-1, -1, -1, -1,
    17  	0, 0, 0, 0,
    18  	0, 0, 0, 0,
    19  }
    20  
    21  var vecMask32 = [32]int32{
    22  	-1, -1, -1, -1,
    23  	-1, -1, -1, -1,
    24  	-1, -1, -1, -1,
    25  	-1, -1, -1, -1,
    26  	0, 0, 0, 0,
    27  	0, 0, 0, 0,
    28  	0, 0, 0, 0,
    29  	0, 0, 0, 0,
    30  }
    31  
    32  /* 256-bit int vector loads and stores made from 128-bit parts */
    33  
    34  // LoadInt8x32Part loads a Int8x32 from the slice s.
    35  // If s has fewer than 32 elements, the remaining elements of the vector are filled with zeroes.
    36  // If s has 32 or more elements, the function is equivalent to LoadInt8x32Slice.
    37  func LoadInt8x32Part(s []int8) (Int8x32, int) {
    38  	l := len(s)
    39  	if l >= 32 {
    40  		return LoadInt8x32(s), 32
    41  	}
    42  	var x Int8x32
    43  	if l == 0 {
    44  		return x, 0
    45  	}
    46  	if l > 16 {
    47  		v, _ := LoadInt8x16Part(s[16:])
    48  		return x.SetLo(LoadInt8x16(s)).SetHi(v), l
    49  	} else {
    50  		v, _ := LoadInt8x16Part(s)
    51  		return x.SetLo(v), l
    52  	}
    53  }
    54  
    55  // LoadInt16x16Part loads a Int16x16 from the slice s.
    56  // If s has fewer than 16 elements, the remaining elements of the vector are filled with zeroes.
    57  // If s has 16 or more elements, the function is equivalent to LoadInt16x16Slice.
    58  func LoadInt16x16Part(s []int16) (Int16x16, int) {
    59  	l := len(s)
    60  	if l >= 16 {
    61  		return LoadInt16x16(s), 16
    62  	}
    63  	var x Int16x16
    64  	if l == 0 {
    65  		return x, 0
    66  	}
    67  	if l > 8 {
    68  		v, _ := LoadInt16x8Part(s[8:])
    69  		return x.SetLo(LoadInt16x8(s)).SetHi(v), l
    70  	} else {
    71  		v, _ := LoadInt16x8Part(s)
    72  		return x.SetLo(v), l
    73  	}
    74  }
    75  
    76  // StorePart stores the elements of x into the slice s.
    77  // It stores as many elements as will fit in s.
    78  // If s has 32 or more elements, the method is equivalent to x.StoreSlice.
    79  func (x Int8x32) StorePart(s []int8) int {
    80  	l := len(s)
    81  	if l >= 32 {
    82  		x.Store(s)
    83  		return 32
    84  	}
    85  	if l == 0 {
    86  		return 0
    87  	}
    88  	if l > 16 {
    89  		x.GetLo().Store(s)
    90  		x.GetHi().StorePart(s[16:])
    91  	} else { // fits in one
    92  		x.GetLo().StorePart(s)
    93  	}
    94  	return l
    95  }
    96  
    97  // StorePart stores the elements of x into the slice s.
    98  // It stores as many elements as will fit in s.
    99  // If s has 16 or more elements, the method is equivalent to x.StoreSlice.
   100  func (x Int16x16) StorePart(s []int16) int {
   101  	l := len(s)
   102  	if l >= 16 {
   103  		x.Store(s)
   104  		return 16
   105  	}
   106  	if l == 0 {
   107  		return 0
   108  	}
   109  	if l > 8 {
   110  		x.GetLo().Store(s)
   111  		x.GetHi().StorePart(s[8:])
   112  	} else { // fits in one
   113  		x.GetLo().StorePart(s)
   114  	}
   115  	return l
   116  }
   117  

View as plain text