|
@@ -41,7 +41,13 @@ func fp503StrongReduce(x *FpElement) |
|
|
// Concrete implementation depends on capabilities of the CPU which |
|
|
// Concrete implementation depends on capabilities of the CPU which |
|
|
// are resolved at runtime. CPUs with ADCX, ADOX and MULX support |
|
|
// are resolved at runtime. CPUs with ADCX, ADOX and MULX support |
|
|
// run most optimized implementation |
|
|
// run most optimized implementation |
|
|
var fp503Mul func(z *FpElementX2, x, y *FpElement) |
|
|
|
|
|
|
|
|
func fp503Mul(z *FpElementX2, x, y *FpElement) { |
|
|
|
|
|
if cpu.HasBMI2 { |
|
|
|
|
|
mulWithMULXADX(z, x, y) |
|
|
|
|
|
} else { |
|
|
|
|
|
mul(z, x, y) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Mul implementattion for legacy CPUs |
|
|
// Mul implementattion for legacy CPUs |
|
|
//go:noescape |
|
|
//go:noescape |
|
@@ -58,7 +64,17 @@ func mulWithMULXADX(z *FpElementX2, x, y *FpElement) |
|
|
|
|
|
|
|
|
// Computes the Montgomery reduction z = x R^{-1} (mod 2*p). On return value |
|
|
// Computes the Montgomery reduction z = x R^{-1} (mod 2*p). On return value |
|
|
// of x may be changed. z=x not allowed. |
|
|
// of x may be changed. z=x not allowed. |
|
|
var fp503MontgomeryReduce func(z *FpElement, x *FpElementX2) |
|
|
|
|
|
|
|
|
func fp503MontgomeryReduce(z *FpElement, x *FpElementX2) { |
|
|
|
|
|
if cpu.HasBMI2 { |
|
|
|
|
|
if cpu.HasADX { |
|
|
|
|
|
redcWithMULXADX(z, x) |
|
|
|
|
|
} else { |
|
|
|
|
|
redcWithMULX(z, x) |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
redc(z, x) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func redc(z *FpElement, x *FpElementX2) |
|
|
func redc(z *FpElement, x *FpElementX2) |
|
|
|
|
|
|
|
@@ -76,14 +92,14 @@ func redcWithMULXADX(z *FpElement, x *FpElementX2) |
|
|
func init() { |
|
|
func init() { |
|
|
if cpu.HasBMI2 { |
|
|
if cpu.HasBMI2 { |
|
|
if cpu.HasADX { |
|
|
if cpu.HasADX { |
|
|
fp503Mul = mulWithMULXADX |
|
|
|
|
|
fp503MontgomeryReduce = redcWithMULXADX |
|
|
|
|
|
|
|
|
//fp503Mul = mulWithMULXADX |
|
|
|
|
|
//fp503MontgomeryReduce = redcWithMULXADX |
|
|
} else { |
|
|
} else { |
|
|
fp503Mul = mulWithMULX |
|
|
|
|
|
fp503MontgomeryReduce = redcWithMULX |
|
|
|
|
|
|
|
|
//fp503Mul = mulWithMULX |
|
|
|
|
|
//fp503MontgomeryReduce = redcWithMULX |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
fp503Mul = mul |
|
|
|
|
|
fp503MontgomeryReduce = redc |
|
|
|
|
|
|
|
|
//fp503Mul = mul |
|
|
|
|
|
//fp503MontgomeryReduce = redc |
|
|
} |
|
|
} |
|
|
} |
|
|
} |