sdiehl / galois-field

Finite field and algebraic extension field arithmetic
MIT License
50 stars 13 forks source link

Add mod dependencies for minor optimisations of prime fields #24

Closed Multramate closed 5 years ago

Multramate commented 5 years ago

Pull Request Checklist

sdiehl commented 5 years ago

I think this is fine. What is the delta in performance with and without unsafeCoerce?

Multramate commented 5 years ago

I think this is fine. What is the delta in performance with and without unsafeCoerce?

Without unsafeCoerce, we would have to use fromInteger, which does unnecessary slow modular reductions. Using the current benchmarks on my machine,

I did not measure the other operations but their deltas are relatively negligible (e.g. division already takes ~1us, so nanosecond boosts are unnoticeable). Essentially, there is a minor boost in performance in all fronts, but with higher robustness due to abstracting low-level optimisations completely to mod.

Alternatively, we could request for Mod to be exposed in Data.Mod.Unsafe, for instance.

sdiehl commented 5 years ago

Ok sounds good to me.