Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoGiachetta committed Oct 8, 2024
1 parent 2977807 commit 5ab0ed8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 21 deletions.
19 changes: 14 additions & 5 deletions src/libfuncs/sint128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use cairo_lang_sierra::{
};
use melior::{
dialect::{
ods::math,
arith::{self, CmpiPredicate},
cf, llvm,
ods::math,
},
ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike},
Context,
Expand Down Expand Up @@ -245,8 +245,7 @@ pub fn build_to_felt252<'ctx, 'this>(
metadata,
&info.branch_signatures()[0].vars[0].ty,
)?;
let prime =
entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;
let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;

let value: Value = entry.argument(0)?.into();
let value_type = value.r#type();
Expand All @@ -265,7 +264,12 @@ pub fn build_to_felt252<'ctx, 'this>(

let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?;

let final_result = entry.append_op_result(arith::select(is_negative, prime_minus_result, result, location))?;
let final_result = entry.append_op_result(arith::select(
is_negative,
prime_minus_result,
result,
location,
))?;

entry.append_operation(helper.br(0, &[final_result], location));

Expand Down Expand Up @@ -507,7 +511,12 @@ mod test {
-396372399979_i128.into()
}
);
run_program_assert_output(&program, "run_test", &[], Felt::from(-396372399979_i128).into());
run_program_assert_output(
&program,
"run_test",
&[],
Felt::from(-396372399979_i128).into(),
);
}

#[test]
Expand Down
12 changes: 8 additions & 4 deletions src/libfuncs/sint16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use cairo_lang_sierra::{
};
use melior::{
dialect::{
ods::math,
arith::{self, CmpiPredicate},
cf, llvm,
ods::math,
},
ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike},
Context,
Expand Down Expand Up @@ -275,8 +275,7 @@ pub fn build_to_felt252<'ctx, 'this>(
metadata,
&info.branch_signatures()[0].vars[0].ty,
)?;
let prime =
entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;
let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;

let value: Value = entry.argument(0)?.into();
let value_type = value.r#type();
Expand All @@ -295,7 +294,12 @@ pub fn build_to_felt252<'ctx, 'this>(

let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?;

let final_result = entry.append_op_result(arith::select(is_negative, prime_minus_result, result, location))?;
let final_result = entry.append_op_result(arith::select(
is_negative,
prime_minus_result,
result,
location,
))?;

entry.append_operation(helper.br(0, &[final_result], location));

Expand Down
12 changes: 8 additions & 4 deletions src/libfuncs/sint32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use cairo_lang_sierra::{
};
use melior::{
dialect::{
ods::math,
arith::{self, CmpiPredicate},
cf, llvm,
ods::math,
},
ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike},
Context,
Expand Down Expand Up @@ -274,8 +274,7 @@ pub fn build_to_felt252<'ctx, 'this>(
metadata,
&info.branch_signatures()[0].vars[0].ty,
)?;
let prime =
entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;
let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;

let value: Value = entry.argument(0)?.into();
let value_type = value.r#type();
Expand All @@ -294,7 +293,12 @@ pub fn build_to_felt252<'ctx, 'this>(

let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?;

let final_result = entry.append_op_result(arith::select(is_negative, prime_minus_result, result, location))?;
let final_result = entry.append_op_result(arith::select(
is_negative,
prime_minus_result,
result,
location,
))?;

entry.append_operation(helper.br(0, &[final_result], location));

Expand Down
12 changes: 8 additions & 4 deletions src/libfuncs/sint64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use cairo_lang_sierra::{
};
use melior::{
dialect::{
ods::math,
arith::{self, CmpiPredicate},
cf, llvm,
ods::math,
},
ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike},
Context,
Expand Down Expand Up @@ -275,8 +275,7 @@ pub fn build_to_felt252<'ctx, 'this>(
metadata,
&info.branch_signatures()[0].vars[0].ty,
)?;
let prime =
entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;
let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;

let value: Value = entry.argument(0)?.into();
let value_type = value.r#type();
Expand All @@ -295,7 +294,12 @@ pub fn build_to_felt252<'ctx, 'this>(

let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?;

let final_result = entry.append_op_result(arith::select(is_negative, prime_minus_result, result, location))?;
let final_result = entry.append_op_result(arith::select(
is_negative,
prime_minus_result,
result,
location,
))?;

entry.append_operation(helper.br(0, &[final_result], location));

Expand Down
12 changes: 8 additions & 4 deletions src/libfuncs/sint8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use cairo_lang_sierra::{
};
use melior::{
dialect::{
ods::math,
arith::{self, CmpiPredicate},
cf, llvm,
ods::math,
},
ir::{operation::OperationBuilder, r#type::IntegerType, Block, Location, Value, ValueLike},
Context,
Expand Down Expand Up @@ -276,8 +276,7 @@ pub fn build_to_felt252<'ctx, 'this>(
metadata,
&info.branch_signatures()[0].vars[0].ty,
)?;
let prime =
entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;
let prime = entry.const_int_from_type(context, location, PRIME.clone(), felt252_ty)?;

let value: Value = entry.argument(0)?.into();
let value_type = value.r#type();
Expand All @@ -296,7 +295,12 @@ pub fn build_to_felt252<'ctx, 'this>(

let prime_minus_result = entry.append_op_result(arith::subi(prime, result, location))?;

let final_result = entry.append_op_result(arith::select(is_negative, prime_minus_result, result, location))?;
let final_result = entry.append_op_result(arith::select(
is_negative,
prime_minus_result,
result,
location,
))?;

entry.append_operation(helper.br(0, &[final_result], location));

Expand Down

0 comments on commit 5ab0ed8

Please sign in to comment.