Source file src/simd/internal/spec/logical.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  //specgen:category Logical
     6  
     7  package spec
     8  
     9  // And returns the bitwise AND of x and y.
    10  //
    11  //	z[i] = x[i] & y[i]
    12  //
    13  //specgen:commutative
    14  func And[E Ints | Uints | MaskElt, W Width](x, y Vec[E, W]) (z Vec[E, W]) {
    15  	return map2[E, W, E, W](x, y, func(x, y E) E {
    16  		return x & y
    17  	})
    18  }
    19  
    20  // AndNot returns the bitwise AND NOT of x and y.
    21  //
    22  //	z[i] = x[i] &^ y[i]
    23  func AndNot[E Ints | Uints | MaskElt, W Width](x, y Vec[E, W]) (z Vec[E, W]) {
    24  	return map2[E, W, E, W](x, y, func(x, y E) E {
    25  		return x &^ y
    26  	})
    27  }
    28  
    29  // Or returns the bitwise OR of x and y.
    30  //
    31  //	z[i] = x[i] | y[i]
    32  //
    33  //specgen:commutative
    34  func Or[E Ints | Uints | MaskElt, W Width](x, y Vec[E, W]) (z Vec[E, W]) {
    35  	return map2[E, W, E, W](x, y, func(x, y E) E {
    36  		return x | y
    37  	})
    38  }
    39  
    40  // Xor returns the bitwise XOR of x and y.
    41  //
    42  //	z[i] = x[i] ^ y[i]
    43  //
    44  //specgen:commutative
    45  func Xor[E Ints | Uints | MaskElt, W Width](x, y Vec[E, W]) (z Vec[E, W]) {
    46  	return map2[E, W, E, W](x, y, func(x, y E) E {
    47  		return x ^ y
    48  	})
    49  }
    50  
    51  // Not returns the bitwise negation of x.
    52  //
    53  //	z[i] = ^x[i]
    54  func Not[E Ints | Uints | MaskElt, W Width](x Vec[E, W]) (z Vec[E, W]) {
    55  	return map1[E, W, E, W](x, func(x E) E {
    56  		return ^x
    57  	})
    58  }
    59  

View as plain text