From 93ca812846df349b0d4bee53ad9953553dddd54b Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Wed, 6 Aug 2025 09:33:39 -0300 Subject: [PATCH 1/7] Testing how to use melior --- src/libfuncs/circuit.rs | 32 ++++++++++++++++++++++++++++++-- src/types/circuit.rs | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/libfuncs/circuit.rs b/src/libfuncs/circuit.rs index c7bc1b4795..a47369273d 100644 --- a/src/libfuncs/circuit.rs +++ b/src/libfuncs/circuit.rs @@ -29,10 +29,14 @@ use cairo_lang_sierra::{ use melior::{ dialect::{ arith::{self, CmpiPredicate}, - cf, llvm, + cf, func, llvm, }, helpers::{ArithBlockExt, BuiltinBlockExt, GepIndex, LlvmBlockExt}, - ir::{r#type::IntegerType, Block, BlockLike, Location, Type, Value, ValueLike}, + ir::{ + attribute::{StringAttribute, TypeAttribute}, + r#type::IntegerType, + Block, BlockLike, Location, Region, Type, Value, ValueLike, + }, Context, }; use num_traits::Signed; @@ -998,6 +1002,30 @@ fn u384_struct_to_integer<'a>( Ok(value) } +fn u384_integer_to_struct_mlir<'a>( + context: &'a Context, + block: &'a Block<'a>, + location: Location<'a>, + integer: Value<'a, 'a>, +) { + let return_type = build_u384_struct_type(context); + let integer_type = IntegerType::new(context, 384); + let location = Location::unknown(&context); + let inner_block = Block::new(&[(integer_type.into(), location)]); // Receives the integer from where it will get the 4 limbs + + block.append_operation(func::func( + context, + StringAttribute::new(context, "u384_integer_to_struct"), + TypeAttribute::new(return_type), + region, + attributes, + location, + )); + + let region = Region::new(); + region.append_block(inner_block); +} + fn u384_integer_to_struct<'a>( context: &'a Context, block: &'a Block<'a>, diff --git a/src/types/circuit.rs b/src/types/circuit.rs index 18fa56cc4e..9b54701047 100644 --- a/src/types/circuit.rs +++ b/src/types/circuit.rs @@ -23,7 +23,11 @@ use cairo_lang_sierra::{ use melior::{ dialect::{func, llvm}, helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, - ir::{r#type::IntegerType, Block, BlockLike, Location, Module, Region, Type, Value}, + ir::{ + attribute::{StringAttribute, TypeAttribute}, + r#type::{FunctionType, IntegerType}, + Block, BlockLike, Location, Module, Region, Type, Value, + }, Context, }; @@ -517,6 +521,38 @@ pub fn layout( } pub fn build_u384_struct_type(context: &Context) -> Type<'_> { + let return_type = IntegerType::new(context, 96).into(); + let location = Location::unknown(&context); + let region = Region::new(); + let block = Block::new(&[]); + block.append_operation(func::r#return( + &[ + IntegerType::new(context, 96).into(), + IntegerType::new(context, 96).into(), + IntegerType::new(context, 96).into(), + IntegerType::new(context, 96).into(), + ], + location.clone(), + )); + region.append_block(block); + + let module = Module::new(location); + module.body().append_operation(func::func( + context, + StringAttribute::new(context, "create_u384"), + TypeAttribute::new( + FunctionType::new( + &context, + &[], + &[return_type, return_type, return_type, return_type], + ) + .into(), + ), + region, + &[], + location, + )); + llvm::r#type::r#struct( context, &[ From ac5fe2179f102c8f93dbb096599431d883be04db Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Thu, 7 Aug 2025 09:22:34 -0300 Subject: [PATCH 2/7] call and declared almost finished --- src/libfuncs/circuit.rs | 94 +++++++++++++++++++++++++++++++++++------ src/types/circuit.rs | 32 -------------- 2 files changed, 81 insertions(+), 45 deletions(-) diff --git a/src/libfuncs/circuit.rs b/src/libfuncs/circuit.rs index a47369273d..4f1caddd1b 100644 --- a/src/libfuncs/circuit.rs +++ b/src/libfuncs/circuit.rs @@ -29,11 +29,12 @@ use cairo_lang_sierra::{ use melior::{ dialect::{ arith::{self, CmpiPredicate}, - cf, func, llvm, + cf, func, llvm, ods, }, helpers::{ArithBlockExt, BuiltinBlockExt, GepIndex, LlvmBlockExt}, ir::{ - attribute::{StringAttribute, TypeAttribute}, + attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, + operation::OperationBuilder, r#type::IntegerType, Block, BlockLike, Location, Region, Type, Value, ValueLike, }, @@ -402,7 +403,11 @@ fn build_eval<'ctx, 'this>( ok_block.store(context, location, value_ptr, gate)?; } - let modulus_struct = u384_integer_to_struct(context, ok_block, location, circuit_modulus)?; + // let modulus_struct = u384_integer_to_struct(context, ok_block, location, circuit_modulus)?; + declare_u384_integer_to_struct_mlir_func(context, ok_block, location); + let modulus_struct = + call_u384_integer_to_struct_mlir_func(ok_block, location, context, circuit_modulus)?; + println!("Se llamo la funcion"); // Build output struct let outputs_type_id = &info.branch_signatures()[0].vars[2].ty; @@ -1002,28 +1007,91 @@ fn u384_struct_to_integer<'a>( Ok(value) } -fn u384_integer_to_struct_mlir<'a>( +fn declare_u384_integer_to_struct_mlir_func<'a>( context: &'a Context, block: &'a Block<'a>, location: Location<'a>, - integer: Value<'a, 'a>, ) { let return_type = build_u384_struct_type(context); - let integer_type = IntegerType::new(context, 384); - let location = Location::unknown(&context); - let inner_block = Block::new(&[(integer_type.into(), location)]); // Receives the integer from where it will get the 4 limbs + let integer_type = IntegerType::new(context, 384); // TODO: Does it make sense to have the 384 bits? + + // New block containing function. Receives the integer from where it will get the 4 limbs + let inner_block = Block::new(&[(integer_type.into(), location)]); + + /////// FUNCTION IMPLEMENTATION /////// + let argument: Value<'_, '_> = inner_block.argument(0).unwrap().into(); + let u96_type = IntegerType::new(context, 96).into(); + let limb1 = inner_block + .trunci(argument, IntegerType::new(context, 96).into(), location) + .unwrap(); + let limb2 = { + let k96 = inner_block.const_int(context, location, 96, 384).unwrap(); + let limb = inner_block.shrui(argument, k96, location).unwrap(); + inner_block.trunci(limb, u96_type, location).unwrap() + }; + let limb3 = { + let k192 = inner_block + .const_int(context, location, 96 * 2, 384) + .unwrap(); + let limb = inner_block.shrui(argument, k192, location).unwrap(); + inner_block.trunci(limb, u96_type, location).unwrap() + }; + let limb4 = { + let k288 = inner_block + .const_int(context, location, 96 * 3, 384) + .unwrap(); + let limb = inner_block.shrui(argument, k288, location).unwrap(); + inner_block.trunci(limb, u96_type, location).unwrap() + }; + let struct_type = build_u384_struct_type(context); + let struct_value = inner_block + .append_op_result(llvm::undef(struct_type, location)) + .unwrap(); + inner_block + .insert_values( + context, + location, + struct_value, + &[limb1, limb2, limb3, limb4], + ) + .unwrap(); + /////////////////////////////////////// + let region = Region::new(); + region.append_block(inner_block); + let func_name = StringAttribute::new(context, "cairo_native__u384_integer_to_struct"); + // Append the function with the region that has the implementation to the block block.append_operation(func::func( context, - StringAttribute::new(context, "u384_integer_to_struct"), - TypeAttribute::new(return_type), + func_name, + TypeAttribute::new(llvm::r#type::function( + llvm::r#type::r#struct(context, &[return_type], false), + &[integer_type.into()], + false, + )), region, - attributes, + &[], location, )); +} - let region = Region::new(); - region.append_block(inner_block); +fn call_u384_integer_to_struct_mlir_func<'a>( + block: &'a Block<'a>, + location: Location<'a>, + context: &'a Context, + integer: Value<'a, 'a>, +) -> Result> { + let return_type = build_u384_struct_type(context); + Ok(block + .append_operation( + OperationBuilder::new("llvm.call", location) + .add_operands(&[func_symbol.into()]) + .add_operands(&[integer]) + .add_results(&[return_type]) + .build()?, + ) + .result(0)? + .into()) } fn u384_integer_to_struct<'a>( diff --git a/src/types/circuit.rs b/src/types/circuit.rs index 9b54701047..c663b3e8de 100644 --- a/src/types/circuit.rs +++ b/src/types/circuit.rs @@ -521,38 +521,6 @@ pub fn layout( } pub fn build_u384_struct_type(context: &Context) -> Type<'_> { - let return_type = IntegerType::new(context, 96).into(); - let location = Location::unknown(&context); - let region = Region::new(); - let block = Block::new(&[]); - block.append_operation(func::r#return( - &[ - IntegerType::new(context, 96).into(), - IntegerType::new(context, 96).into(), - IntegerType::new(context, 96).into(), - IntegerType::new(context, 96).into(), - ], - location.clone(), - )); - region.append_block(block); - - let module = Module::new(location); - module.body().append_operation(func::func( - context, - StringAttribute::new(context, "create_u384"), - TypeAttribute::new( - FunctionType::new( - &context, - &[], - &[return_type, return_type, return_type, return_type], - ) - .into(), - ), - region, - &[], - location, - )); - llvm::r#type::r#struct( context, &[ From 4d1ef5d54286d23bbfda6e88c0d8fadec0982f89 Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Fri, 8 Aug 2025 09:17:25 -0300 Subject: [PATCH 3/7] Declare func one time --- src/compiler.rs | 72 ++++++++++++++++++++++++++++++++++++- src/libfuncs/circuit.rs | 78 ++++------------------------------------- 2 files changed, 78 insertions(+), 72 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 21a5d822da..68edadff1a 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -56,7 +56,7 @@ use crate::{ }, native_assert, native_panic, statistics::Statistics, - types::TypeBuilder, + types::{circuit::build_u384_struct_type, TypeBuilder}, utils::{generate_function_name, walk_ir::walk_mlir_block}, }; use bumpalo::Bump; @@ -141,6 +141,8 @@ pub fn compile( } } + declare_u384_integer_to_struct_mlir_func(context, module, Location::unknown(context)); + // Sierra programs have the following structure: // 1. Type declarations, one per line. // 2. Libfunc declarations, one per line. @@ -171,6 +173,74 @@ pub fn compile( Ok(()) } +fn declare_u384_integer_to_struct_mlir_func<'a>( + context: &'a Context, + module: &Module, + location: Location<'a>, +) { + let return_type = build_u384_struct_type(context); + let integer_type = IntegerType::new(context, 384); // TODO: Does it make sense to have the 384 bits? + + // New block containing function. Receives the integer from where it will get the 4 limbs + let inner_block = Block::new(&[(integer_type.into(), location)]); + + /////// FUNCTION IMPLEMENTATION /////// + let argument: Value<'_, '_> = inner_block.argument(0).unwrap().into(); + let u96_type = IntegerType::new(context, 96).into(); + let limb1 = inner_block + .trunci(argument, IntegerType::new(context, 96).into(), location) + .unwrap(); + let limb2 = { + let k96 = inner_block.const_int(context, location, 96, 384).unwrap(); + let limb = inner_block.shrui(argument, k96, location).unwrap(); + inner_block.trunci(limb, u96_type, location).unwrap() + }; + let limb3 = { + let k192 = inner_block + .const_int(context, location, 96 * 2, 384) + .unwrap(); + let limb = inner_block.shrui(argument, k192, location).unwrap(); + inner_block.trunci(limb, u96_type, location).unwrap() + }; + let limb4 = { + let k288 = inner_block + .const_int(context, location, 96 * 3, 384) + .unwrap(); + let limb = inner_block.shrui(argument, k288, location).unwrap(); + inner_block.trunci(limb, u96_type, location).unwrap() + }; + let struct_type = build_u384_struct_type(context); + let struct_value = inner_block + .append_op_result(llvm::undef(struct_type, location)) + .unwrap(); + inner_block + .insert_values( + context, + location, + struct_value, + &[limb1, limb2, limb3, limb4], + ) + .unwrap(); + /////////////////////////////////////// + + let region = Region::new(); + region.append_block(inner_block); + let func_name = StringAttribute::new(context, "cairo_native__u384_integer_to_struct"); + // Append the function with the region that has the implementation to the block + module.body().append_operation(func::func( + context, + func_name, + TypeAttribute::new(llvm::r#type::function( + llvm::r#type::r#struct(context, &[return_type], false), + &[integer_type.into()], + false, + )), + region, + &[], + location, + )); +} + /// Compile a single Sierra function. /// /// The function accepts a `Function` argument, which provides the function's entry point, signature diff --git a/src/libfuncs/circuit.rs b/src/libfuncs/circuit.rs index 4f1caddd1b..c5f78a1966 100644 --- a/src/libfuncs/circuit.rs +++ b/src/libfuncs/circuit.rs @@ -36,7 +36,7 @@ use melior::{ attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, operation::OperationBuilder, r#type::IntegerType, - Block, BlockLike, Location, Region, Type, Value, ValueLike, + Block, BlockLike, Identifier, Location, Region, Type, Value, ValueLike, }, Context, }; @@ -404,7 +404,7 @@ fn build_eval<'ctx, 'this>( } // let modulus_struct = u384_integer_to_struct(context, ok_block, location, circuit_modulus)?; - declare_u384_integer_to_struct_mlir_func(context, ok_block, location); + // declare_u384_integer_to_struct_mlir_func(context, ok_block, location); let modulus_struct = call_u384_integer_to_struct_mlir_func(ok_block, location, context, circuit_modulus)?; println!("Se llamo la funcion"); @@ -1007,74 +1007,6 @@ fn u384_struct_to_integer<'a>( Ok(value) } -fn declare_u384_integer_to_struct_mlir_func<'a>( - context: &'a Context, - block: &'a Block<'a>, - location: Location<'a>, -) { - let return_type = build_u384_struct_type(context); - let integer_type = IntegerType::new(context, 384); // TODO: Does it make sense to have the 384 bits? - - // New block containing function. Receives the integer from where it will get the 4 limbs - let inner_block = Block::new(&[(integer_type.into(), location)]); - - /////// FUNCTION IMPLEMENTATION /////// - let argument: Value<'_, '_> = inner_block.argument(0).unwrap().into(); - let u96_type = IntegerType::new(context, 96).into(); - let limb1 = inner_block - .trunci(argument, IntegerType::new(context, 96).into(), location) - .unwrap(); - let limb2 = { - let k96 = inner_block.const_int(context, location, 96, 384).unwrap(); - let limb = inner_block.shrui(argument, k96, location).unwrap(); - inner_block.trunci(limb, u96_type, location).unwrap() - }; - let limb3 = { - let k192 = inner_block - .const_int(context, location, 96 * 2, 384) - .unwrap(); - let limb = inner_block.shrui(argument, k192, location).unwrap(); - inner_block.trunci(limb, u96_type, location).unwrap() - }; - let limb4 = { - let k288 = inner_block - .const_int(context, location, 96 * 3, 384) - .unwrap(); - let limb = inner_block.shrui(argument, k288, location).unwrap(); - inner_block.trunci(limb, u96_type, location).unwrap() - }; - let struct_type = build_u384_struct_type(context); - let struct_value = inner_block - .append_op_result(llvm::undef(struct_type, location)) - .unwrap(); - inner_block - .insert_values( - context, - location, - struct_value, - &[limb1, limb2, limb3, limb4], - ) - .unwrap(); - /////////////////////////////////////// - - let region = Region::new(); - region.append_block(inner_block); - let func_name = StringAttribute::new(context, "cairo_native__u384_integer_to_struct"); - // Append the function with the region that has the implementation to the block - block.append_operation(func::func( - context, - func_name, - TypeAttribute::new(llvm::r#type::function( - llvm::r#type::r#struct(context, &[return_type], false), - &[integer_type.into()], - false, - )), - region, - &[], - location, - )); -} - fn call_u384_integer_to_struct_mlir_func<'a>( block: &'a Block<'a>, location: Location<'a>, @@ -1085,7 +1017,11 @@ fn call_u384_integer_to_struct_mlir_func<'a>( Ok(block .append_operation( OperationBuilder::new("llvm.call", location) - .add_operands(&[func_symbol.into()]) + .add_attributes(&[( + Identifier::new(context, "callee"), + FlatSymbolRefAttribute::new(context, &"cairo_native__u384_integer_to_struct") + .into(), + )]) .add_operands(&[integer]) .add_results(&[return_type]) .build()?, From bb9b704b7b6b6984298148df81593777cdf886fa Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Fri, 8 Aug 2025 14:48:34 -0300 Subject: [PATCH 4/7] First iteration of the MLIR function --- src/compiler.rs | 9 ++++++--- src/libfuncs/circuit.rs | 1 - 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 68edadff1a..0b10ca2ea7 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -179,7 +179,7 @@ fn declare_u384_integer_to_struct_mlir_func<'a>( location: Location<'a>, ) { let return_type = build_u384_struct_type(context); - let integer_type = IntegerType::new(context, 384); // TODO: Does it make sense to have the 384 bits? + let integer_type = IntegerType::new(context, 384); // New block containing function. Receives the integer from where it will get the 4 limbs let inner_block = Block::new(&[(integer_type.into(), location)]); @@ -221,17 +221,20 @@ fn declare_u384_integer_to_struct_mlir_func<'a>( &[limb1, limb2, limb3, limb4], ) .unwrap(); + + inner_block.append_operation(llvm::r#return(Some(struct_value), location)); /////////////////////////////////////// let region = Region::new(); region.append_block(inner_block); let func_name = StringAttribute::new(context, "cairo_native__u384_integer_to_struct"); + // Append the function with the region that has the implementation to the block - module.body().append_operation(func::func( + module.body().append_operation(llvm::func( context, func_name, TypeAttribute::new(llvm::r#type::function( - llvm::r#type::r#struct(context, &[return_type], false), + return_type, &[integer_type.into()], false, )), diff --git a/src/libfuncs/circuit.rs b/src/libfuncs/circuit.rs index c5f78a1966..04c99642da 100644 --- a/src/libfuncs/circuit.rs +++ b/src/libfuncs/circuit.rs @@ -407,7 +407,6 @@ fn build_eval<'ctx, 'this>( // declare_u384_integer_to_struct_mlir_func(context, ok_block, location); let modulus_struct = call_u384_integer_to_struct_mlir_func(ok_block, location, context, circuit_modulus)?; - println!("Se llamo la funcion"); // Build output struct let outputs_type_id = &info.branch_signatures()[0].vars[2].ty; From c7d691be7544f9ecb5593ffd77ba01731a2e88b3 Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Fri, 8 Aug 2025 15:11:15 -0300 Subject: [PATCH 5/7] Clippy --- src/libfuncs/circuit.rs | 10 ++++------ src/types/circuit.rs | 6 +----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/libfuncs/circuit.rs b/src/libfuncs/circuit.rs index 04c99642da..90698bbafb 100644 --- a/src/libfuncs/circuit.rs +++ b/src/libfuncs/circuit.rs @@ -29,14 +29,12 @@ use cairo_lang_sierra::{ use melior::{ dialect::{ arith::{self, CmpiPredicate}, - cf, func, llvm, ods, + cf, llvm, }, helpers::{ArithBlockExt, BuiltinBlockExt, GepIndex, LlvmBlockExt}, ir::{ - attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute}, - operation::OperationBuilder, - r#type::IntegerType, - Block, BlockLike, Identifier, Location, Region, Type, Value, ValueLike, + attribute::FlatSymbolRefAttribute, operation::OperationBuilder, r#type::IntegerType, Block, + BlockLike, Identifier, Location, Type, Value, ValueLike, }, Context, }; @@ -1018,7 +1016,7 @@ fn call_u384_integer_to_struct_mlir_func<'a>( OperationBuilder::new("llvm.call", location) .add_attributes(&[( Identifier::new(context, "callee"), - FlatSymbolRefAttribute::new(context, &"cairo_native__u384_integer_to_struct") + FlatSymbolRefAttribute::new(context, "cairo_native__u384_integer_to_struct") .into(), )]) .add_operands(&[integer]) diff --git a/src/types/circuit.rs b/src/types/circuit.rs index c663b3e8de..18fa56cc4e 100644 --- a/src/types/circuit.rs +++ b/src/types/circuit.rs @@ -23,11 +23,7 @@ use cairo_lang_sierra::{ use melior::{ dialect::{func, llvm}, helpers::{ArithBlockExt, BuiltinBlockExt, LlvmBlockExt}, - ir::{ - attribute::{StringAttribute, TypeAttribute}, - r#type::{FunctionType, IntegerType}, - Block, BlockLike, Location, Module, Region, Type, Value, - }, + ir::{r#type::IntegerType, Block, BlockLike, Location, Module, Region, Type, Value}, Context, }; From 1d0260c88c23484331ef048b6098da56d94a6b3d Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Tue, 26 Aug 2025 10:25:16 -0300 Subject: [PATCH 6/7] Fix error when returning mlir value --- src/compiler.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index 0b10ca2ea7..4f6bc3fa1b 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -213,7 +213,7 @@ fn declare_u384_integer_to_struct_mlir_func<'a>( let struct_value = inner_block .append_op_result(llvm::undef(struct_type, location)) .unwrap(); - inner_block + let result = inner_block .insert_values( context, location, @@ -222,7 +222,7 @@ fn declare_u384_integer_to_struct_mlir_func<'a>( ) .unwrap(); - inner_block.append_operation(llvm::r#return(Some(struct_value), location)); + inner_block.append_operation(llvm::r#return(Some(result), location)); /////////////////////////////////////// let region = Region::new(); From 57db025883354ed0ada6bb3216a0643b151a76ee Mon Sep 17 00:00:00 2001 From: Diego Civini Date: Tue, 26 Aug 2025 10:38:38 -0300 Subject: [PATCH 7/7] Stop using u384_integer_to_struct() --- src/libfuncs/circuit.rs | 75 +++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/src/libfuncs/circuit.rs b/src/libfuncs/circuit.rs index d385333e51..4b045e551a 100644 --- a/src/libfuncs/circuit.rs +++ b/src/libfuncs/circuit.rs @@ -395,7 +395,6 @@ fn build_eval<'ctx, 'this>( } // let modulus_struct = u384_integer_to_struct(context, ok_block, location, circuit_modulus)?; - // declare_u384_integer_to_struct_mlir_func(context, ok_block, location); let modulus_struct = call_u384_integer_to_struct_mlir_func(ok_block, location, context, circuit_modulus)?; @@ -922,7 +921,9 @@ fn build_get_output<'ctx, 'this>( u384_type, )?; let output_integer = entry.load(context, location, output_integer_ptr, u384_type)?; - let output_struct = u384_integer_to_struct(context, entry, location, output_integer)?; + // let output_struct = u384_integer_to_struct(context, entry, location, output_integer)?; + let output_struct = + call_u384_integer_to_struct_mlir_func(entry, location, context, output_integer)?; let guarantee_type_id = &info.branch_signatures()[0].vars[1].ty; let guarantee = build_struct_value( @@ -1030,41 +1031,41 @@ fn call_u384_integer_to_struct_mlir_func<'a>( .into()) } -fn u384_integer_to_struct<'a>( - context: &'a Context, - block: &'a Block<'a>, - location: Location<'a>, - integer: Value<'a, 'a>, -) -> Result> { - let u96_type = IntegerType::new(context, 96).into(); - - let limb1 = block.trunci(integer, IntegerType::new(context, 96).into(), location)?; - let limb2 = { - let k96 = block.const_int(context, location, 96, 384)?; - let limb = block.shrui(integer, k96, location)?; - block.trunci(limb, u96_type, location)? - }; - let limb3 = { - let k192 = block.const_int(context, location, 96 * 2, 384)?; - let limb = block.shrui(integer, k192, location)?; - block.trunci(limb, u96_type, location)? - }; - let limb4 = { - let k288 = block.const_int(context, location, 96 * 3, 384)?; - let limb = block.shrui(integer, k288, location)?; - block.trunci(limb, u96_type, location)? - }; - - let struct_type = build_u384_struct_type(context); - let struct_value = block.append_op_result(llvm::undef(struct_type, location))?; - - Ok(block.insert_values( - context, - location, - struct_value, - &[limb1, limb2, limb3, limb4], - )?) -} +// fn u384_integer_to_struct<'a>( +// context: &'a Context, +// block: &'a Block<'a>, +// location: Location<'a>, +// integer: Value<'a, 'a>, +// ) -> Result> { +// let u96_type = IntegerType::new(context, 96).into(); + +// let limb1 = block.trunci(integer, IntegerType::new(context, 96).into(), location)?; +// let limb2 = { +// let k96 = block.const_int(context, location, 96, 384)?; +// let limb = block.shrui(integer, k96, location)?; +// block.trunci(limb, u96_type, location)? +// }; +// let limb3 = { +// let k192 = block.const_int(context, location, 96 * 2, 384)?; +// let limb = block.shrui(integer, k192, location)?; +// block.trunci(limb, u96_type, location)? +// }; +// let limb4 = { +// let k288 = block.const_int(context, location, 96 * 3, 384)?; +// let limb = block.shrui(integer, k288, location)?; +// block.trunci(limb, u96_type, location)? +// }; + +// let struct_type = build_u384_struct_type(context); +// let struct_value = block.append_op_result(llvm::undef(struct_type, location))?; + +// Ok(block.insert_values( +// context, +// location, +// struct_value, +// &[limb1, limb2, limb3, limb4], +// )?) +// } /// The extended euclidean algorithm calculates the greatest common divisor (gcd) of two integers a and b, /// as well as the bezout coefficients x and y such that ax+by=gcd(a,b)