...
1
2
3
4
5
6
7 package poly1305
8
9
10
11
12
13 func bitsAdd64(x, y, carry uint64) (sum, carryOut uint64) {
14 sum = x + y + carry
15 carryOut = ((x & y) | ((x | y) &^ sum)) >> 63
16 return
17 }
18
19 func bitsSub64(x, y, borrow uint64) (diff, borrowOut uint64) {
20 diff = x - y - borrow
21 borrowOut = ((^x & y) | (^(x ^ y) & diff)) >> 63
22 return
23 }
24
25 func bitsMul64(x, y uint64) (hi, lo uint64) {
26 const mask32 = 1<<32 - 1
27 x0 := x & mask32
28 x1 := x >> 32
29 y0 := y & mask32
30 y1 := y >> 32
31 w0 := x0 * y0
32 t := x1*y0 + w0>>32
33 w1 := t & mask32
34 w2 := t >> 32
35 w1 += x0 * y1
36 hi = x1*y1 + w2 + w1>>32
37 lo = x * y
38 return
39 }
40
View as plain text