This commit is contained in:
Sahil-4555 2025-10-12 13:33:02 +05:30
parent 55fdee27cd
commit 49cae59c6a

View file

@ -27,32 +27,32 @@ func XORBytes(dst, a, b []byte) int {
// fastXORBytes xors in bulk. It only works on architectures that support
// unaligned read/writes.
func fastXORBytes(dst, a, b []byte) int {
n := min(len(a), len(b), len(dst))
if n == 0 {
return 0
}
wordSize := int(unsafe.Sizeof(uintptr(0)))
i := 0
for ; i < n && uintptr(unsafe.Pointer(&a[i]))%uintptr(wordSize) != 0; i++ {
dst[i] = a[i] ^ b[i]
}
w := (n - i) / wordSize
if w > 0 {
ad := unsafe.Slice((*uintptr)(unsafe.Pointer(&a[i])), w)
bd := unsafe.Slice((*uintptr)(unsafe.Pointer(&b[i])), w)
dd := unsafe.Slice((*uintptr)(unsafe.Pointer(&dst[i])), w)
for j := 0; j < w; j++ {
dd[j] = ad[j] ^ bd[j]
}
i += w * wordSize
}
for ; i < n; i++ {
dst[i] = a[i] ^ b[i]
}
return n
n := min(len(a), len(b), len(dst))
if n == 0 {
return 0
}
wordSize := int(unsafe.Sizeof(uintptr(0)))
i := 0
for ; i < n && uintptr(unsafe.Pointer(&a[i]))%uintptr(wordSize) != 0; i++ {
dst[i] = a[i] ^ b[i]
}
w := (n - i) / wordSize
if w > 0 {
ad := unsafe.Slice((*uintptr)(unsafe.Pointer(&a[i])), w)
bd := unsafe.Slice((*uintptr)(unsafe.Pointer(&b[i])), w)
dd := unsafe.Slice((*uintptr)(unsafe.Pointer(&dst[i])), w)
for j := 0; j < w; j++ {
dd[j] = ad[j] ^ bd[j]
}
i += w * wordSize
}
for ; i < n; i++ {
dst[i] = a[i] ^ b[i]
}
return n
}
// safeXORBytes xors one by one. It works on all architectures, independent if
@ -77,32 +77,32 @@ func ANDBytes(dst, a, b []byte) int {
// fastANDBytes ands in bulk. It only works on architectures that support
// unaligned read/writes.
func fastANDBytes(dst, a, b []byte) int {
n := min(len(a), len(b), len(dst))
if n == 0 {
return 0
}
wordSize := int(unsafe.Sizeof(uintptr(0)))
i := 0
for ; i < n && uintptr(unsafe.Pointer(&a[i]))%uintptr(wordSize) != 0; i++ {
dst[i] = a[i] & b[i]
}
w := (n - i) / wordSize
if w > 0 {
ad := unsafe.Slice((*uintptr)(unsafe.Pointer(&a[i])), w)
bd := unsafe.Slice((*uintptr)(unsafe.Pointer(&b[i])), w)
dd := unsafe.Slice((*uintptr)(unsafe.Pointer(&dst[i])), w)
for j := 0; j < w; j++ {
dd[j] = ad[j] & bd[j]
}
i += w * wordSize
}
for ; i < n; i++ {
dst[i] = a[i] & b[i]
}
return n
n := min(len(a), len(b), len(dst))
if n == 0 {
return 0
}
wordSize := int(unsafe.Sizeof(uintptr(0)))
i := 0
for ; i < n && uintptr(unsafe.Pointer(&a[i]))%uintptr(wordSize) != 0; i++ {
dst[i] = a[i] & b[i]
}
w := (n - i) / wordSize
if w > 0 {
ad := unsafe.Slice((*uintptr)(unsafe.Pointer(&a[i])), w)
bd := unsafe.Slice((*uintptr)(unsafe.Pointer(&b[i])), w)
dd := unsafe.Slice((*uintptr)(unsafe.Pointer(&dst[i])), w)
for j := 0; j < w; j++ {
dd[j] = ad[j] & bd[j]
}
i += w * wordSize
}
for ; i < n; i++ {
dst[i] = a[i] & b[i]
}
return n
}
// safeANDBytes ands one by one. It works on all architectures, independent if
@ -127,32 +127,32 @@ func ORBytes(dst, a, b []byte) int {
// fastORBytes ors in bulk. It only works on architectures that support
// unaligned read/writes.
func fastORBytes(dst, a, b []byte) int {
n := min(len(a), len(b), len(dst))
if n == 0 {
return 0
}
wordSize := int(unsafe.Sizeof(uintptr(0)))
i := 0
for ; i < n && uintptr(unsafe.Pointer(&a[i]))%uintptr(wordSize) != 0; i++ {
dst[i] = a[i] | b[i]
}
w := (n - i) / wordSize
if w > 0 {
ad := unsafe.Slice((*uintptr)(unsafe.Pointer(&a[i])), w)
bd := unsafe.Slice((*uintptr)(unsafe.Pointer(&b[i])), w)
dd := unsafe.Slice((*uintptr)(unsafe.Pointer(&dst[i])), w)
for j := 0; j < w; j++ {
dd[j] = ad[j] | bd[j]
}
i += w * wordSize
}
for ; i < n; i++ {
dst[i] = a[i] | b[i]
}
return n
n := min(len(a), len(b), len(dst))
if n == 0 {
return 0
}
wordSize := int(unsafe.Sizeof(uintptr(0)))
i := 0
for ; i < n && uintptr(unsafe.Pointer(&a[i]))%uintptr(wordSize) != 0; i++ {
dst[i] = a[i] | b[i]
}
w := (n - i) / wordSize
if w > 0 {
ad := unsafe.Slice((*uintptr)(unsafe.Pointer(&a[i])), w)
bd := unsafe.Slice((*uintptr)(unsafe.Pointer(&b[i])), w)
dd := unsafe.Slice((*uintptr)(unsafe.Pointer(&dst[i])), w)
for j := 0; j < w; j++ {
dd[j] = ad[j] | bd[j]
}
i += w * wordSize
}
for ; i < n; i++ {
dst[i] = a[i] | b[i]
}
return n
}
// safeORBytes ors one by one. It works on all architectures, independent if