From 9b3f45993f742683b55e75225d99248b956c6c1a Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 29 Jun 2021 13:42:39 +0300 Subject: [PATCH] gf127: remove branch in pure Go operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` name old time/op new time/op delta Sum/PureGo_digest-8 16.1ms ± 3% 10.4ms ± 3% -35.53% (p=0.000 n=10+10) name old speed new speed delta Sum/PureGo_digest-8 6.22MB/s ± 3% 9.65MB/s ± 3% +55.12% (p=0.000 n=10+10) ``` Signed-off-by: Evgenii Stratonikov --- gf127/arith.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gf127/arith.go b/gf127/arith.go index 7977440..1a5243f 100644 --- a/gf127/arith.go +++ b/gf127/arith.go @@ -112,22 +112,22 @@ func Mul(a, b, c *GF127) { // Mul10 sets b to a*x. func Mul10(a, b *GF127) { - c := (a[0] & msb64) >> 63 + c := a[0] >> 63 b[0] = a[0] << 1 b[1] = (a[1] << 1) ^ c - if b[1]&msb64 != 0 { - b[0] ^= x127x631[0] - b[1] ^= x127x631[1] - } + + mask := b[1] & msb64 + b[0] ^= mask | (mask >> 63) + b[1] ^= mask } // Mul11 sets b to a*(x+1). func Mul11(a, b *GF127) { - c := (a[0] & msb64) >> 63 + c := a[0] >> 63 b[0] = a[0] ^ (a[0] << 1) b[1] = a[1] ^ (a[1] << 1) ^ c - if b[1]&msb64 != 0 { - b[0] ^= x127x631[0] - b[1] ^= x127x631[1] - } + + mask := b[1] & msb64 + b[0] ^= mask | (mask >> 63) + b[1] ^= mask }