Skip to content

Commit 8dd112b

Browse files
committed
internal/chacha20: use x/sys/cpu for s390x feature detection
Use the recently added CPU feature detection API rather than custom assembly. This will need to be updated to use 'internal/cpu' when the package is revendored into std. Change-Id: Icf0f28236ca0c351c88035f36e5b9c29d4bc2ba7 Reviewed-on: https://go-review.googlesource.com/c/164383 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 0091315 commit 8dd112b

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

Diff for: internal/chacha20/chacha_s390x.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
package chacha20
88

9-
var haveAsm = hasVectorFacility()
9+
import (
10+
"golang.org/x/sys/cpu"
11+
)
1012

11-
const bufSize = 256
13+
var haveAsm = cpu.S390X.HasVX
1214

13-
// hasVectorFacility reports whether the machine supports the vector
14-
// facility (vx).
15-
// Implementation in asm_s390x.s.
16-
func hasVectorFacility() bool
15+
const bufSize = 256
1716

1817
// xorKeyStreamVX is an assembly implementation of XORKeyStream. It must only
1918
// be called when the vector facility is available.

Diff for: internal/chacha20/chacha_s390x.s

-23
Original file line numberDiff line numberDiff line change
@@ -258,26 +258,3 @@ tail:
258258
MOVD R8, R3
259259
MOVD $0, R4
260260
JMP continue
261-
262-
// func hasVectorFacility() bool
263-
TEXT ·hasVectorFacility(SB), NOSPLIT, $24-1
264-
MOVD $x-24(SP), R1
265-
XC $24, 0(R1), 0(R1) // clear the storage
266-
MOVD $2, R0 // R0 is the number of double words stored -1
267-
WORD $0xB2B01000 // STFLE 0(R1)
268-
XOR R0, R0 // reset the value of R0
269-
MOVBZ z-8(SP), R1
270-
AND $0x40, R1
271-
BEQ novector
272-
273-
vectorinstalled:
274-
// check if the vector instruction has been enabled
275-
VLEIB $0, $0xF, V16
276-
VLGVB $0, V16, R1
277-
CMPBNE R1, $0xF, novector
278-
MOVB $1, ret+0(FP) // have vx
279-
RET
280-
281-
novector:
282-
MOVB $0, ret+0(FP) // no vx
283-
RET

0 commit comments

Comments
 (0)