@@ -868,6 +868,9 @@ pub fn setup_runtime(find_symbol_ptr: impl Fn(&str) -> Option<*mut c_void>) {
868868///
869869/// This function declares a MLIR function that given two numbers a and b, returns a MLIR struct with gcd(a, b)
870870/// and the bezout coefficient x. The declaration is done in the body of the module.
871+ ///
872+ /// The primary use of this function is to find the modular multiplicative inverse of a value. To so, it is expected
873+ /// the a represents the value to be inverted and b the modulus of the field field.
871874fn build_egcd_function < ' ctx > (
872875 module : & Module ,
873876 context : & ' ctx Context ,
@@ -892,13 +895,13 @@ fn build_egcd_function<'ctx>(
892895 ( integer_type, location) ,
893896 ] ) ) ;
894897
895- let a = entry_block. arg ( 0 ) ?;
896- let b = entry_block. arg ( 1 ) ?;
898+ let rhs = entry_block. arg ( 0 ) ?;
899+ let prime_modulus = entry_block. arg ( 1 ) ?;
897900 // The egcd algorithm works by calculating a series of remainders `rem`, being each `rem_i` the remainder of dividing `rem_{i-1}` with `rem_{i-2}`
898901 // For the initial setup, rem_0 = b, rem_1 = a.
899902 // This order is chosen because if we reverse them, then the first iteration will just swap them
900- let remainder = a ;
901- let prev_remainder = b ;
903+ let remainder = rhs ;
904+ let prev_remainder = prime_modulus ;
902905
903906 // Similarly we'll calculate another series which starts 0,1,... and from which we
904907 // will retrieve the modular inverse of a
@@ -964,7 +967,7 @@ fn build_egcd_function<'ctx>(
964967 ) )
965968 . result ( 0 ) ?
966969 . into ( ) ;
967- let wrapped_inverse = end_block. addi ( inverse, b , location) ?;
970+ let wrapped_inverse = end_block. addi ( inverse, prime_modulus , location) ?;
968971 let inverse = end_block. append_op_result ( arith:: select (
969972 is_negative,
970973 wrapped_inverse,
0 commit comments