gf127: remove branch in pure Go operations

```
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 <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2021-06-29 13:42:39 +03:00 committed by Alex Vanin
parent 33bf778066
commit 9b3f45993f

View file

@ -112,22 +112,22 @@ func Mul(a, b, c *GF127) {
// Mul10 sets b to a*x. // Mul10 sets b to a*x.
func Mul10(a, b *GF127) { func Mul10(a, b *GF127) {
c := (a[0] & msb64) >> 63 c := a[0] >> 63
b[0] = a[0] << 1 b[0] = a[0] << 1
b[1] = (a[1] << 1) ^ c b[1] = (a[1] << 1) ^ c
if b[1]&msb64 != 0 {
b[0] ^= x127x631[0] mask := b[1] & msb64
b[1] ^= x127x631[1] b[0] ^= mask | (mask >> 63)
} b[1] ^= mask
} }
// Mul11 sets b to a*(x+1). // Mul11 sets b to a*(x+1).
func Mul11(a, b *GF127) { func Mul11(a, b *GF127) {
c := (a[0] & msb64) >> 63 c := a[0] >> 63
b[0] = a[0] ^ (a[0] << 1) b[0] = a[0] ^ (a[0] << 1)
b[1] = a[1] ^ (a[1] << 1) ^ c b[1] = a[1] ^ (a[1] << 1) ^ c
if b[1]&msb64 != 0 {
b[0] ^= x127x631[0] mask := b[1] & msb64
b[1] ^= x127x631[1] b[0] ^= mask | (mask >> 63)
} b[1] ^= mask
} }