mirage / mirage-crypto

Cryptographic primitives for OCaml, in OCaml (also used in MirageOS)
ISC License
77 stars 43 forks source link

[optim - C binding] Use a contiguous array/flat representation for coordinates #241

Open dannywillems opened 4 months ago

dannywillems commented 4 months ago

At the moment, in the C bindings, the points are represented as a struct with 3 fields. It creates 3 indirections when calling the C code. When performing many operations on the same point, the same memory page, containing the 3 coordinates, can stay in the CPU cache, which may give a possible non-negligeable performance improvement.

hannesm commented 4 months ago

This is about the elliptic curves (mirage-crypto-ec). This is a good idea, would you mind to submit a PR and have some performance numbers before&after (see bench/speed.exe)?

dannywillems commented 4 months ago

This is about the elliptic curves (mirage-crypto-ec). This is a good idea, would you mind to submit a PR and have some performance numbers before&after (see bench/speed.exe)?

I can not commit to anything for the next two weeks. Maybe beginning of August I will have some spare time. More generally, I was curious about checking more the C related code to see if a flat representation in a single custom block can be used. A flat structure of a multiple of 64 bits can be used in general.