Source file src/simd/archsimd/maskrange_amd64.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
     6  
     7  package archsimd
     8  
     9  import "math/bits"
    10  
    11  // 128-bit masks
    12  
    13  // All returns true when all positions in mask x are true.
    14  //
    15  // Emulated, CPU Feature AVX
    16  func (x Mask8x16) All() bool {
    17  	return x.ToBits() == 0xffff
    18  }
    19  
    20  // Any returns true when any position in mask x is true.
    21  //
    22  // Emulated, CPU Feature AVX
    23  func (x Mask8x16) Any() bool {
    24  	return x.ToBits() != 0
    25  }
    26  
    27  // None returns true when no positions in mask x are set.
    28  //
    29  // Emulated, CPU Feature AVX
    30  func (x Mask8x16) None() bool {
    31  	return x.ToBits() == 0
    32  }
    33  
    34  // All returns true when all positions in mask x are true.
    35  //
    36  // Emulated, CPU Feature AVX
    37  func (x Mask16x8) All() bool {
    38  	return x.ToInt16x8().AsInt8x16().asMask().ToBits()&0x5555 == 0x5555
    39  }
    40  
    41  // Any returns true when any position in mask x is true.
    42  //
    43  // Emulated, CPU Feature AVX
    44  func (x Mask16x8) Any() bool {
    45  	return x.ToInt16x8().AsInt8x16().asMask().ToBits()&0x5555 != 0
    46  }
    47  
    48  // None returns true when no positions in mask x are set.
    49  //
    50  // Emulated, CPU Feature AVX
    51  func (x Mask16x8) None() bool {
    52  	return x.ToInt16x8().AsInt8x16().asMask().ToBits()&0x5555 == 0
    53  }
    54  
    55  // All returns true when all positions in mask x are true.
    56  //
    57  // Emulated, CPU Feature AVX
    58  func (x Mask32x4) All() bool {
    59  	return x.ToBits()&0x0f == 0x0f
    60  }
    61  
    62  // Any returns true when any position in mask x is true.
    63  //
    64  // Emulated, CPU Feature AVX
    65  func (x Mask32x4) Any() bool {
    66  	return x.ToBits()&0x0f != 0
    67  }
    68  
    69  // None returns true when no positions in mask x are set.
    70  //
    71  // Emulated, CPU Feature AVX
    72  func (x Mask32x4) None() bool {
    73  	return x.ToBits()&0x0f == 0
    74  }
    75  
    76  // All returns true when all positions in mask x are true.
    77  //
    78  // Emulated, CPU Feature AVX
    79  func (x Mask64x2) All() bool {
    80  	return x.ToBits()&0x03 == 0x03
    81  }
    82  
    83  // Any returns true when any position in mask x is true.
    84  //
    85  // Emulated, CPU Feature AVX
    86  func (x Mask64x2) Any() bool {
    87  	return x.ToBits()&0x03 != 0
    88  }
    89  
    90  // None returns true when no positions in mask x are set.
    91  //
    92  // Emulated, CPU Feature AVX
    93  func (x Mask64x2) None() bool {
    94  	return x.ToBits()&0x03 == 0
    95  }
    96  
    97  // 256-bit masks
    98  
    99  // All returns true when all positions in mask x are true.
   100  //
   101  // Emulated, CPU Feature AVX2
   102  func (x Mask8x32) All() bool {
   103  	return x.ToBits() == 0xffffffff
   104  }
   105  
   106  // Any returns true when any position in mask x is true.
   107  //
   108  // Emulated, CPU Feature AVX2
   109  func (x Mask8x32) Any() bool {
   110  	return x.ToBits() != 0
   111  }
   112  
   113  // None returns true when no positions in mask x are set.
   114  //
   115  // Emulated, CPU Feature AVX2
   116  func (x Mask8x32) None() bool {
   117  	return x.ToBits() == 0
   118  }
   119  
   120  // All returns true when all positions in mask x are true.
   121  //
   122  // Emulated, CPU Feature AVX2
   123  func (x Mask16x16) All() bool {
   124  	return x.ToInt16x16().AsInt8x32().asMask().ToBits()&0x55555555 == 0x55555555
   125  }
   126  
   127  // Any returns true when any position in mask x is true.
   128  //
   129  // Emulated, CPU Feature AVX2
   130  func (x Mask16x16) Any() bool {
   131  	return x.ToInt16x16().AsInt8x32().asMask().ToBits()&0x55555555 != 0
   132  }
   133  
   134  // None returns true when no positions in mask x are set.
   135  //
   136  // Emulated, CPU Feature AVX2
   137  func (x Mask16x16) None() bool {
   138  	return x.ToInt16x16().AsInt8x32().asMask().ToBits()&0x55555555 == 0
   139  }
   140  
   141  // All returns true when all positions in mask x are true.
   142  //
   143  // Emulated, CPU Feature AVX2
   144  func (x Mask32x8) All() bool {
   145  	return x.ToBits() == 0xff
   146  }
   147  
   148  // Any returns true when any position in mask x is true.
   149  //
   150  // Emulated, CPU Feature AVX2
   151  func (x Mask32x8) Any() bool {
   152  	return x.ToBits() != 0
   153  }
   154  
   155  // None returns true when no positions in mask x are set.
   156  //
   157  // Emulated, CPU Feature AVX2
   158  func (x Mask32x8) None() bool {
   159  	return x.ToBits() == 0
   160  }
   161  
   162  // All returns true when all positions in mask x are true.
   163  //
   164  // Emulated, CPU Feature AVX2
   165  func (x Mask64x4) All() bool {
   166  	return x.ToBits()&0x0f == 0x0f
   167  }
   168  
   169  // Any returns true when any position in mask x is true.
   170  //
   171  // Emulated, CPU Feature AVX2
   172  func (x Mask64x4) Any() bool {
   173  	return x.ToBits()&0x0f != 0
   174  }
   175  
   176  // None returns true when no positions in mask x are set.
   177  //
   178  // Emulated, CPU Feature AVX2
   179  func (x Mask64x4) None() bool {
   180  	return x.ToBits()&0x0f == 0
   181  }
   182  
   183  // 512-bit masks
   184  
   185  // All returns true when all positions in mask x are true.
   186  //
   187  // Emulated, CPU Feature AVX512
   188  func (x Mask8x64) All() bool {
   189  	return ^x.ToBits() == 0
   190  }
   191  
   192  // Any returns true when any position in mask x is true.
   193  //
   194  // Emulated, CPU Feature AVX512
   195  func (x Mask8x64) Any() bool {
   196  	return x.ToBits() != 0
   197  }
   198  
   199  // None returns true when no positions in mask x are set.
   200  //
   201  // Emulated, CPU Feature AVX512
   202  func (x Mask8x64) None() bool {
   203  	return x.ToBits() == 0
   204  }
   205  
   206  // All returns true when all positions in mask x are true.
   207  //
   208  // Emulated, CPU Feature AVX512
   209  func (x Mask16x32) All() bool {
   210  	return ^x.ToBits() == 0
   211  }
   212  
   213  // Any returns true when any position in mask x is true.
   214  //
   215  // Emulated, CPU Feature AVX512
   216  func (x Mask16x32) Any() bool {
   217  	return x.ToBits() != 0
   218  }
   219  
   220  // None returns true when no positions in mask x are set.
   221  //
   222  // Emulated, CPU Feature AVX512
   223  func (x Mask16x32) None() bool {
   224  	return x.ToBits() == 0
   225  }
   226  
   227  // All returns true when all positions in mask x are true.
   228  //
   229  // Emulated, CPU Feature AVX512
   230  func (x Mask32x16) All() bool {
   231  	return ^x.ToBits() == 0
   232  }
   233  
   234  // Any returns true when any position in mask x is true.
   235  //
   236  // Emulated, CPU Feature AVX512
   237  func (x Mask32x16) Any() bool {
   238  	return x.ToBits() != 0
   239  }
   240  
   241  // None returns true when no positions in mask x are set.
   242  //
   243  // Emulated, CPU Feature AVX512
   244  func (x Mask32x16) None() bool {
   245  	return x.ToBits() == 0
   246  }
   247  
   248  // All returns true when all positions in mask x are true.
   249  //
   250  // Emulated, CPU Feature AVX512
   251  func (x Mask64x8) All() bool {
   252  	return ^x.ToBits() == 0
   253  }
   254  
   255  // Any returns true when any position in mask x is true.
   256  //
   257  // Emulated, CPU Feature AVX512
   258  func (x Mask64x8) Any() bool {
   259  	return x.ToBits() != 0
   260  }
   261  
   262  // None returns true when no positions in mask x are set.
   263  //
   264  // Emulated, CPU Feature AVX512
   265  func (x Mask64x8) None() bool {
   266  	return x.ToBits() == 0
   267  }
   268  
   269  // TrailingZeros returns the number of low-order false (zero) elements in mask x.
   270  //
   271  // Emulated, CPU Feature AVX
   272  func (x Mask8x16) TrailingZeros() int {
   273  	word := uint64(x.ToBits())
   274  	lane := bits.TrailingZeros64(word)
   275  	if lane >= 16 {
   276  		return 16
   277  	}
   278  	return lane
   279  }
   280  
   281  // TrailingZeros returns the number of low-order false (zero) elements in mask x.
   282  //
   283  // Emulated, CPU Feature AVX
   284  func (x Mask8x32) TrailingZeros() int {
   285  	word := uint64(x.ToBits())
   286  	lane := bits.TrailingZeros64(word)
   287  	if lane >= 32 {
   288  		return 32
   289  	}
   290  	return lane
   291  }
   292  
   293  // TrailingZeros returns the number of low-order false (zero) elements in mask x.
   294  //
   295  // Emulated, CPU Feature AVX
   296  func (x Mask8x64) TrailingZeros() int {
   297  	word := uint64(x.ToBits())
   298  	lane := bits.TrailingZeros64(word)
   299  	if lane >= 64 {
   300  		return 64
   301  	}
   302  	return lane
   303  }
   304  
   305  // TrailingZeros returns the number of low-order false (zero) elements in mask m.
   306  //
   307  // Emulated, CPU Feature AVX
   308  func (x Mask16x8) TrailingZeros() int {
   309  	word := uint64(x.ToInt16x8().AsInt8x16().asMask().ToBits() & 0x5555)
   310  	lane := bits.TrailingZeros64(word) >> 1
   311  	if lane >= 8 {
   312  		return 8
   313  	}
   314  	return lane
   315  }
   316  
   317  // TrailingZeros returns the number of low-order false (zero) elements in mask m.
   318  //
   319  // Emulated, CPU Feature AVX2
   320  func (x Mask16x16) TrailingZeros() int {
   321  	word := uint64(x.ToInt16x16().AsInt8x32().asMask().ToBits() & 0x55555555)
   322  	lane := bits.TrailingZeros64(word) >> 1
   323  	if lane >= 16 {
   324  		return 16
   325  	}
   326  	return lane
   327  }
   328  
   329  // TrailingZeros returns the number of low-order false (zero) elements in mask m.
   330  //
   331  // Emulated, CPU Feature AVX512
   332  func (x Mask16x32) TrailingZeros() int {
   333  	word := uint64(x.ToBits())
   334  	lane := bits.TrailingZeros64(word)
   335  	if lane >= 32 {
   336  		return 32
   337  	}
   338  	return lane
   339  }
   340  
   341  // TrailingZeros returns the number of low-order false (zero) elements in mask m.
   342  //
   343  // Emulated, CPU Feature AVX
   344  func (x Mask32x4) TrailingZeros() int {
   345  	word := uint64(x.ToBits())
   346  	lane := bits.TrailingZeros64(word)
   347  	if lane >= 4 {
   348  		return 4
   349  	}
   350  	return lane
   351  }
   352  
   353  // TrailingZeros returns the number of low-order false (zero) elements in mask m.
   354  //
   355  // Emulated, CPU Feature AVX2
   356  func (x Mask32x8) TrailingZeros() int {
   357  	word := uint64(x.ToBits())
   358  	lane := bits.TrailingZeros64(word)
   359  	if lane >= 8 {
   360  		return 8
   361  	}
   362  	return lane
   363  }
   364  
   365  // TrailingZeros returns the number of low-order false (zero) elements in mask m.
   366  //
   367  // Emulated, CPU Feature AVX512
   368  func (x Mask32x16) TrailingZeros() int {
   369  	word := uint64(x.ToBits())
   370  	lane := bits.TrailingZeros64(word)
   371  	if lane >= 16 {
   372  		return 16
   373  	}
   374  	return lane
   375  }
   376  
   377  // TrailingZeros returns the number of low-order false (zero) elements in mask m.
   378  //
   379  // Emulated, CPU Feature AVX
   380  func (x Mask64x2) TrailingZeros() int {
   381  	word := uint64(x.ToBits())
   382  	lane := bits.TrailingZeros64(word)
   383  	if lane >= 2 {
   384  		return 2
   385  	}
   386  	return lane
   387  }
   388  
   389  // TrailingZeros returns the number of low-order false (zero) elements in mask m.
   390  //
   391  // Emulated, CPU Feature AVX2
   392  func (x Mask64x4) TrailingZeros() int {
   393  	word := uint64(x.ToBits())
   394  	lane := bits.TrailingZeros64(word)
   395  	if lane >= 4 {
   396  		return 4
   397  	}
   398  	return lane
   399  }
   400  
   401  // TrailingZeros returns the number of low-order false (zero) elements in mask m.
   402  //
   403  // Emulated, CPU Feature AVX512
   404  func (x Mask64x8) TrailingZeros() int {
   405  	word := uint64(x.ToBits())
   406  	lane := bits.TrailingZeros64(word)
   407  	if lane >= 8 {
   408  		return 8
   409  	}
   410  	return lane
   411  }
   412  

View as plain text