github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/internal/xor/xor_amd64.go (about)

     1  // Copyright 2018 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  package xor
     6  
     7  // XorBytes xors the bytes in a and b. The destination should have enough
     8  // space, otherwise xorBytes will panic. Returns the number of bytes xor'd.
     9  func XorBytes(dst, a, b []byte) int {
    10  	n := len(a)
    11  	if len(b) < n {
    12  		n = len(b)
    13  	}
    14  	if n == 0 {
    15  		return 0
    16  	}
    17  	_ = dst[n-1]
    18  	xorBytesSSE2(&dst[0], &a[0], &b[0], n) // amd64 must have SSE2
    19  	return n
    20  }
    21  
    22  func XorWords(dst, a, b []byte) {
    23  	XorBytes(dst, a, b)
    24  }
    25  
    26  //go:noescape
    27  func xorBytesSSE2(dst, a, b *byte, n int)