Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When comparing Field.t values, avoid the conversion to bigint #14597

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/lib/crypto/kimchi_backend/common/field.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ module type Input_intf = sig

val is_square : t -> bool

val compare : t -> t -> int

val equal : t -> t -> bool

val print : t -> unit
Expand Down Expand Up @@ -194,7 +196,7 @@ module Make (F : Input_intf) :

let hash = Hash.of_fold hash_fold_t

let compare t1 t2 = Bigint.compare (to_bigint t1) (to_bigint t2)
let compare = compare

let equal = equal

Expand Down
4 changes: 2 additions & 2 deletions src/lib/crypto/kimchi_backend/kimchi_backend.mli
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ module Kimchi_backend_common : sig

val sexp_of_t : t -> Sexplib0.Sexp.t

val compare : t -> t -> int

val bin_size_t : t Bin_prot.Size.sizer

val bin_write_t : t Bin_prot.Write.writer
Expand Down Expand Up @@ -56,6 +54,8 @@ module Kimchi_backend_common : sig

val is_square : t -> bool

val compare : t -> t -> int

val equal : t -> t -> bool

val print : t -> unit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl CamlFp {
unsafe extern "C" fn ocaml_compare(x: ocaml::Raw, y: ocaml::Raw) -> i32 {
let x = x.as_pointer::<Self>();
let y = y.as_pointer::<Self>();
match x.as_ref().0.cmp(&y.as_ref().0) {
match x.as_ref().0.into_repr().cmp(&y.as_ref().0.into_repr()) {
core::cmp::Ordering::Less => -1,
core::cmp::Ordering::Equal => 0,
core::cmp::Ordering::Greater => 1,
Expand Down Expand Up @@ -240,7 +240,7 @@ pub fn caml_pasta_fp_mut_square(mut x: ocaml::Pointer<CamlFp>) {
#[ocaml_gen::func]
#[ocaml::func]
pub fn caml_pasta_fp_compare(x: ocaml::Pointer<CamlFp>, y: ocaml::Pointer<CamlFp>) -> ocaml::Int {
match x.as_ref().0.cmp(&y.as_ref().0) {
match x.as_ref().0.into_repr().cmp(&y.as_ref().0.into_repr()) {
Less => -1,
Equal => 0,
Greater => 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl CamlFq {
unsafe extern "C" fn ocaml_compare(x: ocaml::Raw, y: ocaml::Raw) -> i32 {
let x = x.as_pointer::<Self>();
let y = y.as_pointer::<Self>();
match x.as_ref().0.cmp(&y.as_ref().0) {
match x.as_ref().0.into_repr().cmp(&y.as_ref().0.into_repr()) {
core::cmp::Ordering::Less => -1,
core::cmp::Ordering::Equal => 0,
core::cmp::Ordering::Greater => 1,
Expand Down Expand Up @@ -241,7 +241,7 @@ pub fn caml_pasta_fq_mut_square(mut x: ocaml::Pointer<CamlFq>) {
#[ocaml_gen::func]
#[ocaml::func]
pub fn caml_pasta_fq_compare(x: ocaml::Pointer<CamlFq>, y: ocaml::Pointer<CamlFq>) -> ocaml::Int {
match x.as_ref().0.cmp(&y.as_ref().0) {
match x.as_ref().0.into_repr().cmp(&y.as_ref().0.into_repr()) {
Less => -1,
Equal => 0,
Greater => 1,
Expand Down