Hi,
I noticed that the C API exposes fast conditional negation for projective points via:
blst_p1_cneg
blst_p2_cneg
However, the Go bindings do not seem to expose equivalent public methods for P1 and P2.
At the moment, if one wants to compute the additive inverse of a point in Go, i.e. P -> -P, the closest public approach seems to be using subtraction, for example computing 0 - P through SubAssign.
This works mathematically, but it is significantly more expensive than direct group negation, because subtraction goes through point addition logic.
I tested a small local patch exposing direct negation in the Go bindings, using a small cgo wrapper around blst_p1_cneg.
Example API:
func (p1 *P1) NegAssign() *P1 {
C.go_p1_cneg(&p1.cgo)
return p1
}
With the corresponding C bridge:
static void go_p1_cneg(blst_p1 *p)
{
blst_p1_cneg(p, 1);
}
On my machine, using subtraction to compute -P gave approximately:
755 ns/op
0 B/op
0 allocs/op
while direct blst_p1_cneg through the local Go binding patch gave approximately:
65 ns/op
0 B/op
0 allocs/op
So this is roughly an 11x improvement for this operation in my benchmark.
Would you be open to adding direct group negation methods to the Go bindings?
Possible API names could be:
func (p1 *P1) NegAssign() *P1
func (p2 *P2) NegAssign() *P2
Thank you.
Hi,
I noticed that the C API exposes fast conditional negation for projective points via:
However, the Go bindings do not seem to expose equivalent public methods for
P1andP2.At the moment, if one wants to compute the additive inverse of a point in Go, i.e.
P -> -P, the closest public approach seems to be using subtraction, for example computing0 - PthroughSubAssign.This works mathematically, but it is significantly more expensive than direct group negation, because subtraction goes through point addition logic.
I tested a small local patch exposing direct negation in the Go bindings, using a small cgo wrapper around
blst_p1_cneg.Example API:
With the corresponding C bridge:
On my machine, using subtraction to compute
-Pgave approximately:while direct
blst_p1_cnegthrough the local Go binding patch gave approximately:So this is roughly an 11x improvement for this operation in my benchmark.
Would you be open to adding direct group negation methods to the Go bindings?
Possible API names could be:
Thank you.