Skip to content

Commit

Permalink
A few tweaks for performance.
Browse files Browse the repository at this point in the history
Some operations that can be done safely in 32 bits were being done in
64-bit mode after the recent changes. This change moves some of them
back to 32 bits when the benchmarks say that it's an improvement.
  • Loading branch information
agl committed Aug 26, 2015
1 parent 235aa49 commit 550d88d
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions edwards25519/edwards25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ func FeNeg(h, f *FieldElement) {
}

func FeCombine(h *FieldElement, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9 int64) {

var c0, c1, c2, c3, c4, c5, c6, c7, c8, c9 int64

/*
|h0| <= (1.1*1.1*2^52*(1+19+19+19+19)+1.1*1.1*2^50*(38+38+38+38+38))
i.e. |h0| <= 1.2*2^59; narrower ranges for h2, h4, h6, h8
Expand Down Expand Up @@ -386,11 +386,11 @@ func FeMul(h, f, g *FieldElement) {
f8 := int64(f[8])
f9 := int64(f[9])

f1_2 := 2 * f1
f3_2 := 2 * f3
f5_2 := 2 * f5
f7_2 := 2 * f7
f9_2 := 2 * f9
f1_2 := int64(2 * f[1])
f3_2 := int64(2 * f[3])
f5_2 := int64(2 * f[5])
f7_2 := int64(2 * f[7])
f9_2 := int64(2 * f[9])

g0 := int64(g[0])
g1 := int64(g[1])
Expand All @@ -403,15 +403,15 @@ func FeMul(h, f, g *FieldElement) {
g8 := int64(g[8])
g9 := int64(g[9])

g1_19 := 19 * g1 /* 1.4*2^29 */
g2_19 := 19 * g2 /* 1.4*2^30; still ok */
g3_19 := 19 * g3
g4_19 := 19 * g4
g5_19 := 19 * g5
g6_19 := 19 * g6
g7_19 := 19 * g7
g8_19 := 19 * g8
g9_19 := 19 * g9
g1_19 := int64(19 * g[1]) /* 1.4*2^29 */
g2_19 := int64(19 * g[2]) /* 1.4*2^30; still ok */
g3_19 := int64(19 * g[3])
g4_19 := int64(19 * g[4])
g5_19 := int64(19 * g[5])
g6_19 := int64(19 * g[6])
g7_19 := int64(19 * g[7])
g8_19 := int64(19 * g[8])
g9_19 := int64(19 * g[9])

h0 := f0*g0 + f1_2*g9_19 + f2*g8_19 + f3_2*g7_19 + f4*g6_19 + f5_2*g5_19 + f6*g4_19 + f7_2*g3_19 + f8*g2_19 + f9_2*g1_19
h1 := f0*g1 + f1*g0 + f2*g9_19 + f3*g8_19 + f4*g7_19 + f5*g6_19 + f6*g5_19 + f7*g4_19 + f8*g3_19 + f9*g2_19
Expand All @@ -438,14 +438,14 @@ func feSquare(f *FieldElement) (h0, h1, h2, h3, h4, h5, h6, h7, h8, h9 int64) {
f7 := int64(f[7])
f8 := int64(f[8])
f9 := int64(f[9])
f0_2 := 2 * f0
f1_2 := 2 * f1
f2_2 := 2 * f2
f3_2 := 2 * f3
f4_2 := 2 * f4
f5_2 := 2 * f5
f6_2 := 2 * f6
f7_2 := 2 * f7
f0_2 := int64(2 * f[0])
f1_2 := int64(2 * f[1])
f2_2 := int64(2 * f[2])
f3_2 := int64(2 * f[3])
f4_2 := int64(2 * f[4])
f5_2 := int64(2 * f[5])
f6_2 := int64(2 * f[6])
f7_2 := int64(2 * f[7])
f5_38 := 38 * f5 // 1.31*2^30
f6_19 := 19 * f6 // 1.31*2^30
f7_38 := 38 * f7 // 1.31*2^30
Expand Down

0 comments on commit 550d88d

Please sign in to comment.