Source file src/simd/archsimd/maskrange_128.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 || wasm)
     6  
     7  package archsimd
     8  
     9  import "math/bits"
    10  
    11  // All returns true when all positions in mask x are true.
    12  //
    13  // Emulated
    14  func (x Mask8x16) All() bool {
    15  	word := x.ToInt8x16().ToBits().ReshapeToUint64s()
    16  	a0 := word.GetElem(0)
    17  	b0 := word.GetElem(1)
    18  	return (a0&b0)&0x0101010101010101 == 0x0101010101010101
    19  }
    20  
    21  // Any returns true when any position in mask x is true.
    22  //
    23  // Emulated
    24  func (x Mask8x16) Any() bool {
    25  	word := x.ToInt8x16().ToBits().ReshapeToUint64s()
    26  	a0 := word.GetElem(0)
    27  	b0 := word.GetElem(1)
    28  	return (a0|b0)&0x0101010101010101 != 0
    29  }
    30  
    31  // None returns true when no positions in mask x are set.
    32  //
    33  // Emulated
    34  func (x Mask8x16) None() bool {
    35  	word := x.ToInt8x16().ToBits().ReshapeToUint64s()
    36  	a0 := word.GetElem(0)
    37  	b0 := word.GetElem(1)
    38  	return (a0|b0)&0x0101010101010101 == 0
    39  }
    40  
    41  // All returns true when all positions in mask x are true.
    42  //
    43  // Emulated
    44  func (x Mask16x8) All() bool {
    45  	word := x.ToInt16x8().ToBits().ReshapeToUint64s()
    46  	a0 := word.GetElem(0)
    47  	b0 := word.GetElem(1)
    48  	return (a0&b0)&0x0001000100010001 == 0x0001000100010001
    49  }
    50  
    51  // Any returns true when any position in mask x is true.
    52  //
    53  // Emulated
    54  func (x Mask16x8) Any() bool {
    55  	word := x.ToInt16x8().ToBits().ReshapeToUint64s()
    56  	a0 := word.GetElem(0)
    57  	b0 := word.GetElem(1)
    58  	return (a0|b0)&0x0001000100010001 != 0
    59  }
    60  
    61  // None returns true when no positions in mask x are set.
    62  //
    63  // Emulated
    64  func (x Mask16x8) None() bool {
    65  	word := x.ToInt16x8().ToBits().ReshapeToUint64s()
    66  	a0 := word.GetElem(0)
    67  	b0 := word.GetElem(1)
    68  	return (a0|b0)&0x0001000100010001 == 0
    69  }
    70  
    71  // All returns true when all positions in mask x are true.
    72  //
    73  // Emulated
    74  func (x Mask32x4) All() bool {
    75  	word := x.ToInt32x4().ToBits().ReshapeToUint64s()
    76  	a0 := word.GetElem(0)
    77  	b0 := word.GetElem(1)
    78  	return (a0&b0)&0x0000000100000001 == 0x0000000100000001
    79  }
    80  
    81  // Any returns true when any position in mask x is true.
    82  //
    83  // Emulated
    84  func (x Mask32x4) Any() bool {
    85  	word := x.ToInt32x4().ToBits().ReshapeToUint64s()
    86  	a0 := word.GetElem(0)
    87  	b0 := word.GetElem(1)
    88  	return (a0|b0)&0x0000000100000001 != 0
    89  }
    90  
    91  // None returns true when no positions in mask x are set.
    92  //
    93  // Emulated
    94  func (x Mask32x4) None() bool {
    95  	word := x.ToInt32x4().ToBits().ReshapeToUint64s()
    96  	a0 := word.GetElem(0)
    97  	b0 := word.GetElem(1)
    98  	return (a0|b0)&0x0000000100000001 == 0
    99  }
   100  
   101  // All returns true when all positions in mask x are true.
   102  //
   103  // Emulated
   104  func (x Mask64x2) All() bool {
   105  	word := x.ToInt64x2().ToBits()
   106  	a0 := word.GetElem(0)
   107  	b0 := word.GetElem(1)
   108  	return a0 != 0 && b0 != 0
   109  }
   110  
   111  // Any returns true when any position in mask x is true.
   112  //
   113  // Emulated
   114  func (x Mask64x2) Any() bool {
   115  	word := x.ToInt64x2().ToBits()
   116  	a0 := word.GetElem(0)
   117  	b0 := word.GetElem(1)
   118  	return a0 != 0 || b0 != 0
   119  }
   120  
   121  // None returns true when no positions in mask x are set.
   122  //
   123  // Emulated
   124  func (x Mask64x2) None() bool {
   125  	word := x.ToInt64x2().ToBits()
   126  	a0 := word.GetElem(0)
   127  	b0 := word.GetElem(1)
   128  	return a0 == 0 && b0 == 0
   129  }
   130  
   131  // TrailingZeros returns the number of low-order false (zero) elements in mask x
   132  //
   133  // Emulated
   134  func (x Mask8x16) TrailingZeros() int {
   135  	word := x.ToInt8x16().ToBits().ReshapeToUint64s()
   136  	a0 := word.GetElem(0)
   137  	a := a0 & 0x0101010101010101
   138  	lane := bits.TrailingZeros64(a)
   139  	if lane < 64 {
   140  		return lane >> 3
   141  	}
   142  	a0 = word.GetElem(1)
   143  	a = a0 & 0x0101010101010101
   144  	lane = bits.TrailingZeros64(a)
   145  	return lane>>3 + 8
   146  }
   147  
   148  // TrailingZeros returns the number of trailing (low-order) zeroes in mask x
   149  //
   150  // Emulated
   151  func (x Mask16x8) TrailingZeros() int {
   152  	word := x.ToInt16x8().ToBits().ReshapeToUint64s()
   153  	a0 := word.GetElem(0)
   154  	a := a0 & 0x0001000100010001
   155  	lane := bits.TrailingZeros64(a)
   156  	if lane < 64 {
   157  		return lane >> 4
   158  	}
   159  	a0 = word.GetElem(1)
   160  	a = a0 & 0x0001000100010001
   161  	lane = bits.TrailingZeros64(a)
   162  	return lane>>4 + 4
   163  }
   164  
   165  // TrailingZeros returns the number of trailing (low-order) zeroes in mask x
   166  //
   167  // Emulated
   168  func (x Mask32x4) TrailingZeros() int {
   169  	word := x.ToInt32x4().ToBits().ReshapeToUint64s()
   170  	a0 := word.GetElem(0)
   171  	a := a0 & 0x0000000100000001
   172  	lane := bits.TrailingZeros64(a)
   173  	if lane < 64 {
   174  		return lane >> 5
   175  	}
   176  	a0 = word.GetElem(1)
   177  	a = a0 & 0x0000000100000001
   178  	lane = bits.TrailingZeros64(a)
   179  	return lane>>5 + 2
   180  }
   181  
   182  // TrailingZeros returns the number of trailing (low-order) zeroes in mask x
   183  //
   184  // Emulated
   185  func (x Mask64x2) TrailingZeros() int {
   186  	word := x.ToInt64x2().ToBits()
   187  	if word.GetElem(0) != 0 {
   188  		return 0
   189  	}
   190  	if word.GetElem(1) != 0 {
   191  		return 1
   192  	}
   193  	return 2
   194  }
   195  

View as plain text