Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bounds check elimation in main loop of encryption #25

Merged
merged 2 commits into from
Oct 16, 2019
Merged

Conversation

xtaci
Copy link
Contributor

@xtaci xtaci commented Sep 18, 2018

Before

$ go build -gcflags="-d=ssa/check_bce/debug=1"  sm4.go
# command-line-arguments
./sm4.go:171:8: Found IsInBounds
./sm4.go:171:23: Found IsInBounds
./sm4.go:171:52: Found IsInBounds
./sm4.go:172:17: Found IsInBounds
./sm4.go:172:47: Found IsInBounds
./sm4.go:178:10: Found IsInBounds
./sm4.go:178:23: Found IsInBounds
./sm4.go:179:12: Found IsInBounds
./sm4.go:180:12: Found IsInBounds
./sm4.go:181:12: Found IsInBounds
./sm4.go:191:9: Found IsInBounds
./sm4.go:191:16: Found IsInBounds
./sm4.go:191:23: Found IsInBounds
./sm4.go:191:36: Found IsInBounds
./sm4.go:193:36: Found IsInBounds
./sm4.go:195:36: Found IsInBounds
./sm4.go:197:36: Found IsInBounds
./sm4.go:202:9: Found IsInBounds
./sm4.go:202:16: Found IsInBounds
./sm4.go:202:23: Found IsInBounds
./sm4.go:202:36: Found IsInBounds
./sm4.go:204:36: Found IsInBounds
./sm4.go:206:36: Found IsInBounds
./sm4.go:208:36: Found IsInBounds
./sm4.go:212:28: Found IsInBounds
./sm4.go:212:34: Found IsInBounds
./sm4.go:226:14: Found IsInBounds

After

$ go build -gcflags="-d=ssa/check_bce/debug=1"  sm4.go
# command-line-arguments
./sm4.go:171:8: Found IsInBounds
./sm4.go:171:23: Found IsInBounds
./sm4.go:171:52: Found IsInBounds
./sm4.go:172:17: Found IsInBounds
./sm4.go:172:47: Found IsInBounds
./sm4.go:178:10: Found IsInBounds
./sm4.go:178:23: Found IsInBounds
./sm4.go:179:12: Found IsInBounds
./sm4.go:180:12: Found IsInBounds
./sm4.go:181:12: Found IsInBounds
./sm4.go:192:7: Found IsInBounds
./sm4.go:195:16: Found IsSliceInBounds
./sm4.go:207:16: Found IsSliceInBounds
./sm4.go:232:14: Found IsInBounds

benchmark via kcp-go shows that we get 6~10% performance gain in this improvement
Before:

$ go test -cpuprofile=cpu.out -run=^$ -bench SM
beginning tests, encryption:salsa20, fec:10/3
goos: darwin
goarch: amd64
pkg: github.com/xtaci/kcp-go
BenchmarkSM4-4   	   50000	     33991 ns/op	  88.26 MB/s	       0 B/op	       0 allocs/op
PASS
ok  	github.com/xtaci/kcp-go	2.287s

After

$ go test -cpuprofile=cpu.out -run=^$ -bench SM
beginning tests, encryption:salsa20, fec:10/3
goos: darwin
goarch: amd64
pkg: github.com/xtaci/kcp-go
BenchmarkSM4-4   	   50000	     31625 ns/op	  94.86 MB/s	       0 B/op	       0 allocs/op
PASS
ok  	github.com/xtaci/kcp-go	2.222s

@czdsdo czdsdo merged commit 71e9164 into tjfoc:master Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants