-
Notifications
You must be signed in to change notification settings - Fork 1
/
and_amd64.go
107 lines (100 loc) · 1.71 KB
/
and_amd64.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//go:build !purego
package and
func and(dst, a, b []byte) {
l := uint64(0)
if hasAVX2() {
l = uint64(len(a)) >> 8
if l != 0 {
andAVX2(&dst[0], &a[0], &b[0], l)
}
l <<= 8
} else if hasAVX() {
l = uint64(len(a)) >> 7
if l != 0 {
andAVX(&dst[0], &a[0], &b[0], l)
}
l <<= 7
}
andGeneric(dst[l:], a[l:], b[l:])
}
func or(dst, a, b []byte) {
l := uint64(0)
if hasAVX2() {
l = uint64(len(a)) >> 8
if l != 0 {
orAVX2(&dst[0], &a[0], &b[0], l)
}
l <<= 8
} else if hasAVX() {
l = uint64(len(a)) >> 7
if l != 0 {
orAVX(&dst[0], &a[0], &b[0], l)
}
l <<= 7
}
orGeneric(dst[l:], a[l:], b[l:])
}
func xor(dst, a, b []byte) {
l := uint64(0)
if hasAVX2() {
l = uint64(len(a)) >> 8
if l != 0 {
xorAVX2(&dst[0], &a[0], &b[0], l)
}
l <<= 8
} else if hasAVX() {
l = uint64(len(a)) >> 7
if l != 0 {
xorAVX(&dst[0], &a[0], &b[0], l)
}
l <<= 7
}
xorGeneric(dst[l:], a[l:], b[l:])
}
func andNot(dst, a, b []byte) {
l := uint64(0)
if hasAVX2() {
l = uint64(len(a)) >> 8
if l != 0 {
andNotAVX2(&dst[0], &a[0], &b[0], l)
}
l <<= 8
} else if hasAVX() {
l = uint64(len(a)) >> 7
if l != 0 {
andNotAVX(&dst[0], &a[0], &b[0], l)
}
l <<= 7
}
andNotGeneric(dst[l:], a[l:], b[l:])
}
func popcnt(a []byte) int {
l := uint64(0)
var ret int
if hasPopcnt() {
l = uint64(len(a)) >> 6
if l != 0 {
ret = popcntAsm(&a[0], l)
}
l <<= 6
}
ret += popcntGeneric(a[l:])
return ret
}
func memset(dst []byte, b byte) {
l := uint64(0)
if hasAVX2() {
l = uint64(len(dst)) >> 5
if l != 0 {
memsetAVX2(&dst[0], l, b)
}
l <<= 5
} else if hasAVX() {
l = uint64(len(dst)) >> 4
if l != 0 {
memsetAVX(&dst[0], l, b)
}
l <<= 4
}
memsetGeneric(dst[l:], b)
}