Skip to content

Commit 0091315

Browse files
committed
poly1305: 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: Ia99c51c7409fe4fabcd88fdf5ff19772c1ca2257 Reviewed-on: https://go-review.googlesource.com/c/164382 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e37aea1 commit 0091315

File tree

3 files changed

+5
-56
lines changed

3 files changed

+5
-56
lines changed

Diff for: poly1305/sum_s390x.go

+5-12
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@
66

77
package poly1305
88

9-
// hasVectorFacility reports whether the machine supports
10-
// the vector facility (vx).
11-
func hasVectorFacility() bool
12-
13-
// hasVMSLFacility reports whether the machine supports
14-
// Vector Multiply Sum Logical (VMSL).
15-
func hasVMSLFacility() bool
16-
17-
var hasVX = hasVectorFacility()
18-
var hasVMSL = hasVMSLFacility()
9+
import (
10+
"golang.org/x/sys/cpu"
11+
)
1912

2013
// poly1305vx is an assembly implementation of Poly1305 that uses vector
2114
// instructions. It must only be called if the vector facility (vx) is
@@ -33,12 +26,12 @@ func poly1305vmsl(out *[16]byte, m *byte, mlen uint64, key *[32]byte)
3326
// 16-byte result into out. Authenticating two different messages with the same
3427
// key allows an attacker to forge messages at will.
3528
func Sum(out *[16]byte, m []byte, key *[32]byte) {
36-
if hasVX {
29+
if cpu.S390X.HasVX {
3730
var mPtr *byte
3831
if len(m) > 0 {
3932
mPtr = &m[0]
4033
}
41-
if hasVMSL && len(m) > 256 {
34+
if cpu.S390X.HasVXE && len(m) > 256 {
4235
poly1305vmsl(out, mPtr, uint64(len(m)), key)
4336
} else {
4437
poly1305vx(out, mPtr, uint64(len(m)), key)

Diff for: poly1305/sum_s390x.s

-22
Original file line numberDiff line numberDiff line change
@@ -376,25 +376,3 @@ b1:
376376

377377
MOVD $0, R3
378378
BR multiply
379-
380-
TEXT ·hasVectorFacility(SB), NOSPLIT, $24-1
381-
MOVD $x-24(SP), R1
382-
XC $24, 0(R1), 0(R1) // clear the storage
383-
MOVD $2, R0 // R0 is the number of double words stored -1
384-
WORD $0xB2B01000 // STFLE 0(R1)
385-
XOR R0, R0 // reset the value of R0
386-
MOVBZ z-8(SP), R1
387-
AND $0x40, R1
388-
BEQ novector
389-
390-
vectorinstalled:
391-
// check if the vector instruction has been enabled
392-
VLEIB $0, $0xF, V16
393-
VLGVB $0, V16, R1
394-
CMPBNE R1, $0xF, novector
395-
MOVB $1, ret+0(FP) // have vx
396-
RET
397-
398-
novector:
399-
MOVB $0, ret+0(FP) // no vx
400-
RET

Diff for: poly1305/sum_vmsl_s390x.s

-22
Original file line numberDiff line numberDiff line change
@@ -907,25 +907,3 @@ square:
907907
MULTIPLY(H0_0, H1_0, H2_0, H0_1, H1_1, H2_1, R_0, R_1, R_2, R5_1, R5_2, M0, M1, M2, M3, M4, M5, T_0, T_1, T_2, T_3, T_4, T_5, T_6, T_7, T_8, T_9)
908908
REDUCE2(H0_0, H1_0, H2_0, M0, M1, M2, M3, M4, T_9, T_10, H0_1, M5)
909909
BR next
910-
911-
TEXT ·hasVMSLFacility(SB), NOSPLIT, $24-1
912-
MOVD $x-24(SP), R1
913-
XC $24, 0(R1), 0(R1) // clear the storage
914-
MOVD $2, R0 // R0 is the number of double words stored -1
915-
WORD $0xB2B01000 // STFLE 0(R1)
916-
XOR R0, R0 // reset the value of R0
917-
MOVBZ z-8(SP), R1
918-
AND $0x01, R1
919-
BEQ novmsl
920-
921-
vectorinstalled:
922-
// check if the vector instruction has been enabled
923-
VLEIB $0, $0xF, V16
924-
VLGVB $0, V16, R1
925-
CMPBNE R1, $0xF, novmsl
926-
MOVB $1, ret+0(FP) // have vx
927-
RET
928-
929-
novmsl:
930-
MOVB $0, ret+0(FP) // no vx
931-
RET

0 commit comments

Comments
 (0)