File: xor_amd64.go

package info (click to toggle)
golang-github-templexxx-xor 0.1.2-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports-sloppy
  • size: 100 kB
  • sloc: asm: 834; makefile: 2
file content (120 lines) | stat: -rw-r--r-- 2,243 bytes parent folder | download | duplicates (3)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
package xor

import "github.com/templexxx/cpufeat"

func init() {
	getEXT()
}

func getEXT() {
	if cpufeat.X86.HasAVX2 {
		extension = avx2
	} else {
		extension = sse2
	}
	return
}

func xorBytes(dst, src0, src1 []byte, size int) {
	switch extension {
	case avx2:
		bytesAVX2(dst, src0, src1, size)
	default:
		bytesSSE2(dst, src0, src1, size)
	}
}

// non-temporal hint store
const nontmp = 8 * 1024
const avx2loopsize = 128

func bytesAVX2(dst, src0, src1 []byte, size int) {
	if size < avx2loopsize {
		bytesAVX2mini(dst, src0, src1, size)
	} else if size >= avx2loopsize && size <= nontmp {
		bytesAVX2small(dst, src0, src1, size)
	} else {
		bytesAVX2big(dst, src0, src1, size)
	}
}

const sse2loopsize = 64

func bytesSSE2(dst, src0, src1 []byte, size int) {
	if size < sse2loopsize {
		bytesSSE2mini(dst, src0, src1, size)
	} else if size >= sse2loopsize && size <= nontmp {
		bytesSSE2small(dst, src0, src1, size)
	} else {
		bytesSSE2big(dst, src0, src1, size)
	}
}

func xorMatrix(dst []byte, src [][]byte) {
	switch extension {
	case avx2:
		matrixAVX2(dst, src)
	default:
		matrixSSE2(dst, src)
	}
}

func matrixAVX2(dst []byte, src [][]byte) {
	size := len(dst)
	if size > nontmp {
		matrixAVX2big(dst, src)
	} else {
		matrixAVX2small(dst, src)
	}
}

func matrixSSE2(dst []byte, src [][]byte) {
	size := len(dst)
	if size > nontmp {
		matrixSSE2big(dst, src)
	} else {
		matrixSSE2small(dst, src)
	}
}

//go:noescape
func xorSrc0(dst, src0, src1 []byte)

//go:noescape
func xorSrc1(dst, src0, src1 []byte)

//go:noescape
func bytesAVX2mini(dst, src0, src1 []byte, size int)

//go:noescape
func bytesAVX2big(dst, src0, src1 []byte, size int)

//go:noescape
func bytesAVX2small(dst, src0, src1 []byte, size int)

//go:noescape
func bytesSSE2mini(dst, src0, src1 []byte, size int)

//go:noescape
func bytesSSE2small(dst, src0, src1 []byte, size int)

//go:noescape
func bytesSSE2big(dst, src0, src1 []byte, size int)

//go:noescape
func matrixAVX2small(dst []byte, src [][]byte)

//go:noescape
func matrixAVX2big(dst []byte, src [][]byte)

//go:noescape
func matrixSSE2small(dst []byte, src [][]byte)

//go:noescape
func matrixSSE2big(dst []byte, src [][]byte)

//go:noescape
func hasAVX2() bool

//go:noescape
func hasSSE2() bool