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

crypto/sha256: add assembly implementation for ppc64 #50785

Closed
arsemaj opened this issue Jan 24, 2022 · 3 comments
Closed

crypto/sha256: add assembly implementation for ppc64 #50785

arsemaj opened this issue Jan 24, 2022 · 3 comments
Labels
arch-ppc64x FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Milestone

Comments

@arsemaj
Copy link

arsemaj commented Jan 24, 2022

What version of Go are you using (go version)?

Please note: Our "build machine" is Linux, from which we compile for Linux (linux/amd64) and cross-compile for our other platforms (windows/amd64, aix/ppc64, linux/ppc64le).

go version go1.17.5 linux/amd64

Does this issue reproduce with the latest release?

Yes, for all versions of Go used to compile programs for aix/ppc64.

What operating system and processor architecture are you using (go env)?

Please note: Our "build machine" is Linux, from which we compile for Linux (linux/amd64) and cross-compile for our other platforms (windows/amd64, aix/ppc64, linux/ppc64le).

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/builder/.cache/go-build"
GOENV="/home/builder/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="{{PRODUCT RELATED PATH OMITTED}}/pkg/mod"
GONOPROXY="github.ibm.com"
GONOSUMDB="github.ibm.com"
GOOS="linux"
GOPATH="{{PRODUCT RELATED PATH OMITTED}}/srv_git"
GOPRIVATE="github.ibm.com"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go1.17.5"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go1.17.5/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.5"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="{{PRODUCT RELATED PATH OMITTED}}/src/github.com/minio/minio/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1906808776=/tmp/go-build -gno-record-gcc-switches"

What did you do?

NOTE: This issue is related to issue #50784

Tagging @Helflym (Clement) for this issue as well.

Our company implements a cross-platform application (linux/amd64, windows/amd64, aix/ppc, linux/ppc64le) that makes extensive use of sha256 hashing. As a part of our development/test cycle, we CPU profile our application in different scenarios (using pprof). When doing so on AIX, we discovered that the sha256 hashing implementation was implemented in "generic" Go and not pseudo-assembler (as with ppc64le).

To work around these limitations, we've worked on customizing the Golang language by porting over the ppc64le implementation of sha256 hashing into a new src/crypto/sha256/sha256block_ppc64.s ppc64 file, then adding "ppc64" to the "build" annotation for src/crypto/sha256/sha256block_decl.go and "!ppc64" for src/crypto/sha256/sha256block_generic.go.

The purpose of this issue is to see whether we could get these changes added to Golang so that this customization is no longer needed for us or others making extensive use of sha256 hashing (especially with small block sizes) with Golang on aix/ppc64.

What did you expect to see?

Similar performance for sha256 hashing as with other platforms.

What did you see instead?

Performance was significantly worse on aix/ppc64 since this platform uses ("generic") Golang implementations and not optimized assembler functions.

@seankhliao seankhliao changed the title src/crypto/sha256: Performance optimizations for ppc64le should be ported to ppc64 crypto/sha256: add assembly implementation for ppc64 Jan 24, 2022
@mknyszek mknyszek added this to the Backlog milestone Jan 24, 2022
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 24, 2022
@laboger
Copy link
Contributor

laboger commented Jan 25, 2022

It's possible we could do this in the next release in the same way as is done now for md5 -- a single asm file for ppc64le & ppc64, with the instructions that affect endianness controlled by #ifdefs. for both sha256 and sha512.

@gopherbot
Copy link

Change https://golang.org/cl/380776 mentions this issue: crypto/sha256: clean PPC64 block function and enable for ppc64 too

@gopherbot
Copy link

Change https://go.dev/cl/388654 mentions this issue: crypto/sha512: add BE support to PPC64 asm implementation

gopherbot pushed a commit that referenced this issue Mar 2, 2022
This adds big endian support for the assembly implementation of
sha512. There was a recent request to do this for sha256 for
AIX users; for completeness, the same is being done for sha512.
The majority of the code is common between big and little
endian with a few differences controlled by ifdefs: with LE
the generation of a mask is needed along with VPERM instructions
to put bytes in the correct order; some VPERMs need the V
registers in a different order.

name        old time/op    new time/op     delta
Hash8Bytes    1.02µs ± 0%     0.38µs ± 0%   -62.68%
Hash1K        7.01µs ± 0%     2.43µs ± 0%   -65.42%
Hash8K        50.2µs ± 0%     14.6µs ± 0%   -70.89%

Updates #50785

Change-Id: I739b5e7c07b22b5748af11ca781e82ac67adb4f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/388654
Reviewed-by: Cherry Mui <cherryyz@google.com>
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@dmitshur dmitshur modified the milestones: Backlog, Go1.19 Mar 4, 2022
@golang golang locked and limited conversation to collaborators Mar 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-ppc64x FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance
Projects
None yet
Development

No branches or pull requests

6 participants