github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/simd/bitwise_generic.go.tpl (about)

     1  // Copyright 2018 GRAIL, Inc.  All rights reserved.
     2  // Use of this source code is governed by the Apache-2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build !amd64 appengine
     6  
     7  package PACKAGE
     8  
     9  // ZZUnsafeInplace sets main[pos] := main[pos] OPCHAR arg[pos] for every position
    10  // in main[].
    11  //
    12  // WARNING: This is a function designed to be used in inner loops, which makes
    13  // assumptions about length and capacity which aren't checked at runtime.  Use
    14  // the safe version of this function when that's a problem.
    15  // Assumptions #2-3 are always satisfied when the last
    16  // potentially-size-increasing operation on arg[] is {Re}makeUnsafe(),
    17  // ResizeUnsafe(), or XcapUnsafe(), and the same is true for main[].
    18  //
    19  // 1. len(arg) and len(main) must be equal.
    20  //
    21  // 2. Capacities are at least RoundUpPow2(len(main) + 1, bytesPerVec).
    22  //
    23  // 3. The caller does not care if a few bytes past the end of main[] are
    24  // changed.
    25  func ZZUnsafeInplace(main, arg []byte) {
    26  	for i, x := range main {
    27  		main[i] = x OPCHAR arg[i]
    28  	}
    29  }
    30  
    31  // ZZInplace sets main[pos] := main[pos] OPCHAR arg[pos] for every position in
    32  // main[].  It panics if slice lengths don't match.
    33  func ZZInplace(main, arg []byte) {
    34  	if len(arg) != len(main) {
    35  		panic("ZZInplace() requires len(arg) == len(main).")
    36  	}
    37  	for i, x := range main {
    38  		main[i] = x OPCHAR arg[i]
    39  	}
    40  }
    41  
    42  // ZZUnsafe sets dst[pos] := src1[pos] OPCHAR src2[pos] for every position in dst.
    43  //
    44  // WARNING: This is a function designed to be used in inner loops, which makes
    45  // assumptions about length and capacity which aren't checked at runtime.  Use
    46  // the safe version of this function when that's a problem.
    47  // Assumptions #2-3 are always satisfied when the last
    48  // potentially-size-increasing operation on src1[] is {Re}makeUnsafe(),
    49  // ResizeUnsafe(), or XcapUnsafe(), and the same is true for src2[] and dst[].
    50  //
    51  // 1. len(src1), len(src2), and len(dst) must be equal.
    52  //
    53  // 2. Capacities are at least RoundUpPow2(len(dst) + 1, bytesPerVec).
    54  //
    55  // 3. The caller does not care if a few bytes past the end of dst[] are
    56  // changed.
    57  func ZZUnsafe(dst, src1, src2 []byte) {
    58  	for i, x := range src1 {
    59  		dst[i] = x OPCHAR src2[i]
    60  	}
    61  }
    62  
    63  // ZZ sets dst[pos] := src1[pos] OPCHAR src2[pos] for every position in dst.  It
    64  // panics if slice lengths don't match.
    65  func ZZ(dst, src1, src2 []byte) {
    66  	dstLen := len(dst)
    67  	if (len(src1) != dstLen) || (len(src2) != dstLen) {
    68  		panic("ZZ() requires len(src1) == len(src2) == len(dst).")
    69  	}
    70  	for i, x := range src1 {
    71  		dst[i] = x OPCHAR src2[i]
    72  	}
    73  }
    74  
    75  // ZZConst8UnsafeInplace sets main[pos] := main[pos] OPCHAR val for every position
    76  // in main[].
    77  //
    78  // WARNING: This is a function designed to be used in inner loops, which makes
    79  // assumptions about length and capacity which aren't checked at runtime.  Use
    80  // the safe version of this function when that's a problem.
    81  // These assumptions are always satisfied when the last
    82  // potentially-size-increasing operation on main[] is {Re}makeUnsafe(),
    83  // ResizeUnsafe(), or XcapUnsafe().
    84  //
    85  // 1. cap(main) is at least RoundUpPow2(len(main) + 1, bytesPerVec).
    86  //
    87  // 2. The caller does not care if a few bytes past the end of main[] are
    88  // changed.
    89  func ZZConst8UnsafeInplace(main []byte, val byte) {
    90  	for i, x := range main {
    91  		main[i] = x OPCHAR val
    92  	}
    93  }
    94  
    95  // ZZConst8Inplace sets main[pos] := main[pos] OPCHAR val for every position in
    96  // main[].
    97  func ZZConst8Inplace(main []byte, val byte) {
    98  	for i, x := range main {
    99  		main[i] = x OPCHAR val
   100  	}
   101  }
   102  
   103  // ZZConst8Unsafe sets dst[pos] := src[pos] OPCHAR val for every position in dst.
   104  //
   105  // WARNING: This is a function designed to be used in inner loops, which makes
   106  // assumptions about length and capacity which aren't checked at runtime.  Use
   107  // the safe version of this function when that's a problem.
   108  // Assumptions #2-3 are always satisfied when the last
   109  // potentially-size-increasing operation on src[] is {Re}makeUnsafe(),
   110  // ResizeUnsafe(), or XcapUnsafe(), and the same is true for dst[].
   111  //
   112  // 1. len(src) and len(dst) must be equal.
   113  //
   114  // 2. Capacities are at least RoundUpPow2(len(dst) + 1, bytesPerVec).
   115  //
   116  // 3. The caller does not care if a few bytes past the end of dst[] are
   117  // changed.
   118  func ZZConst8Unsafe(dst, src []byte, val byte) {
   119  	for i, x := range src {
   120  		dst[i] = x OPCHAR val
   121  	}
   122  }
   123  
   124  // ZZConst8 sets dst[pos] := src[pos] OPCHAR val for every position in dst.  It
   125  // panics if slice lengths don't match.
   126  func ZZConst8(dst, src []byte, val byte) {
   127  	if len(src) != len(dst) {
   128  		panic("ZZConst8() requires len(src) == len(dst).")
   129  	}
   130  	for i, x := range src {
   131  		dst[i] = x OPCHAR val
   132  	}
   133  }