Skip to contentSkip to conversation

crypto: arm/chacha20 - always use vrev for 16-bit rotates

PATCH New Eric Biggers 3 participants 3 messages Jul 25, 2018 – Aug 3, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: arm/chacha20 - always use vrev for 16-bit rotates

From: Eric Biggers <[email protected]>

The 4-way ChaCha20 NEON code implements 16-bit rotates with vrev32.16, but the one-way code (used on remainder blocks) implements it with vshl + vsri, which is slower. Switch the one-way code to vrev32.16 too.

---
 arch/arm/crypto/chacha20-neon-core.S | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
arch/arm/crypto/chacha20-neon-core.S +4 -6
index 3fecb2124c35..451a849ad518 100644
@@ -51,9 +51,8 @@ ENTRY(chacha20_block_xor_neon)
 .Ldoubleround:
 	// x0 += x1, x3 = rotl32(x3 ^ x0, 16)
 	vadd.i32	q0, q0, q1
-	veor		q4, q3, q0
-	vshl.u32	q3, q4, #16
-	vsri.u32	q3, q4, #16
+	veor		q3, q3, q0
+	vrev32.16	q3, q3
 
 	// x2 += x3, x1 = rotl32(x1 ^ x2, 12)
 	vadd.i32	q2, q2, q3
@@ -82,9 +81,8 @@ ENTRY(chacha20_block_xor_neon)
 
 	// x0 += x1, x3 = rotl32(x3 ^ x0, 16)
 	vadd.i32	q0, q0, q1
-	veor		q4, q3, q0
-	vshl.u32	q3, q4, #16
-	vsri.u32	q3, q4, #16
+	veor		q3, q3, q0
+	vrev32.16	q3, q3
 
 	// x2 += x3, x1 = rotl32(x1 ^ x2, 12)
 	vadd.i32	q2, q2, q3
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/1 crypto: arm/chacha20 - always use vrev for 16-bit rotates

Quoted 7 lines · Eric Biggers

From: Eric Biggers <[email protected]>

The 4-way ChaCha20 NEON code implements 16-bit rotates with vrev32.16, but the one-way code (used on remainder blocks) implements it with vshl + vsri, which is slower. Switch the one-way code to vrev32.16 too.

Quoted 35 lines
---
 arch/arm/crypto/chacha20-neon-core.S | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
arch/arm/crypto/chacha20-neon-core.S +4 -7
index 3fecb2124c35..451a849ad518 100644
@@ -51,9 +51,8 @@ ENTRY(chacha20_block_xor_neon)
 .Ldoubleround:
        // x0 += x1, x3 = rotl32(x3 ^ x0, 16)
        vadd.i32        q0, q0, q1
-       veor            q4, q3, q0
-       vshl.u32        q3, q4, #16
-       vsri.u32        q3, q4, #16
+       veor            q3, q3, q0
+       vrev32.16       q3, q3
 
        // x2 += x3, x1 = rotl32(x1 ^ x2, 12)
        vadd.i32        q2, q2, q3
@@ -82,9 +81,8 @@ ENTRY(chacha20_block_xor_neon)
 
        // x0 += x1, x3 = rotl32(x3 ^ x0, 16)
        vadd.i32        q0, q0, q1
-       veor            q4, q3, q0
-       vshl.u32        q3, q4, #16
-       vsri.u32        q3, q4, #16
+       veor            q3, q3, q0
+       vrev32.16       q3, q3
 
        // x2 += x3, x1 = rotl32(x1 ^ x2, 12)
        vadd.i32        q2, q2, q3
--

2.18.0

maintainer
#2 lore raw

PATCH 1/1 crypto: arm/chacha20 - always use vrev for 16-bit rotates

In reply to Eric Biggers
Quoted 7 lines · Eric Biggers

From: Eric Biggers <[email protected]>

The 4-way ChaCha20 NEON code implements 16-bit rotates with vrev32.16, but the one-way code (used on remainder blocks) implements it with vshl + vsri, which is slower. Switch the one-way code to vrev32.16 too.

Patch applied. Thanks.

Signature · 3 lines
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt