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