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

u256 implementation #4794

Closed
wants to merge 9 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
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ members = [
"swayfmt",
"test",
]
exclude = [
"examples/*",
"swayfmt/test_macros",
"forc-test/test_data"
]
exclude = ["examples/*", "swayfmt/test_macros", "forc-test/test_data"]

[workspace.dependencies]
fuel-asm = "0.34.1"
Expand Down
1 change: 1 addition & 0 deletions forc-plugins/forc-doc/src/render/item/type_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub(crate) fn render_type_anchor(
IntegerBits::Sixteen => "u16",
IntegerBits::ThirtyTwo => "u32",
IntegerBits::SixtyFour => "u64",
IntegerBits::V256 => "u256",
};
Ok(box_html! {
: uint;
Expand Down
1 change: 1 addition & 0 deletions sway-ast/src/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum LitIntType {
U16,
U32,
U64,
U256,
I8,
I16,
I32,
Expand Down
4 changes: 4 additions & 0 deletions sway-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ im = "15.0"
itertools = "0.10"
lazy_static = "1.4"
miden-core = "0.3.0"
num-bigint = { version = "0.4.3", features = ["serde"] }
num-traits = "0.2.16"
pest = "2.1.3"
pest_derive = "2.1"
petgraph = "0.6"
prettydiff = "0.6.4"
rustc-hash = "1.1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.91"
Expand All @@ -47,5 +50,6 @@ tracing = "0.1"
uint = "0.9"
vec1 = "1.8.0"


[target.'cfg(not(target_os = "macos"))'.dependencies]
sysinfo = "0.29.0"
2 changes: 2 additions & 0 deletions sway-core/src/abi_generation/evm_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub fn abi_str(type_info: &TypeInfo, type_engine: &TypeEngine, decl_engine: &Dec
IntegerBits::Sixteen => "uint16",
IntegerBits::ThirtyTwo => "uint32",
IntegerBits::SixtyFour => "uint64",
IntegerBits::V256 => todo!(),
}
.into(),
Boolean => "bool".into(),
Expand Down Expand Up @@ -149,6 +150,7 @@ pub fn abi_param_type(
IntegerBits::Sixteen => ethabi::ParamType::Uint(16),
IntegerBits::ThirtyTwo => ethabi::ParamType::Uint(32),
IntegerBits::SixtyFour => ethabi::ParamType::Uint(64),
IntegerBits::V256 => todo!(),
},
Boolean => ethabi::ParamType::Bool,
B256 => ethabi::ParamType::Uint(256),
Expand Down
1 change: 1 addition & 0 deletions sway-core/src/abi_generation/fuel_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ impl TypeInfo {
IntegerBits::Sixteen => "u16",
IntegerBits::ThirtyTwo => "u32",
IntegerBits::SixtyFour => "u64",
IntegerBits::V256 => "u256",
}
.into(),
Boolean => "bool".into(),
Expand Down
6 changes: 6 additions & 0 deletions sway-core/src/asm_generation/from_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,19 @@ fn compile_module_to_asm(
println!("{abstract_program}\n");
}

// let before = abstract_program.to_string();

let allocated_program = check!(
CompileResult::from(abstract_program.into_allocated_program()),
return err(warnings, errors),
warnings,
errors
);

// let after = allocated_program.to_string();
// println!("############################################# into_allocated_program");
// println!("{}", prettydiff::diff_lines(&before, &after));

if build_config
.map(|cfg| cfg.print_intermediate_asm)
.unwrap_or(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct AbstractInstructionSet {

impl AbstractInstructionSet {
pub(crate) fn optimize(self) -> AbstractInstructionSet {
// println!("AbstractInstructionSet:: Before:");
// println!("{}", self.to_string());
self.remove_sequential_jumps()
.remove_redundant_moves()
.remove_unused_ops()
Expand Down Expand Up @@ -57,6 +59,8 @@ impl AbstractInstructionSet {
}

fn remove_redundant_moves(mut self) -> AbstractInstructionSet {
// let before = self.to_string();

// This has a lot of room for improvement.
//
// For now it is just removing MOVEs to registers which are _never_ used. It doesn't
Expand Down Expand Up @@ -107,6 +111,9 @@ impl AbstractInstructionSet {
}
}

// let after = self.to_string();
// println!("######################################### remove_redundant_moves");
// println!("{}", prettydiff::diff_lines(&before, &after));
self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ impl AllocatedAbstractInstructionSet {
/// Typically there will be only one of each but the code here allows for nested sections or
/// even overlapping sections.
pub(crate) fn emit_pusha_popa(mut self) -> Self {
// let before = self.to_string();

// Gather the sets of used registers per section. Using a fold here because it's actually
// simpler to manage. We use a HashSet to keep track of the active section labels and then
// build a HashMap of Label to HashSet of registers.
Expand Down Expand Up @@ -171,6 +173,12 @@ impl AllocatedAbstractInstructionSet {
new_ops
});

// let after = self.to_string();
// println!(
// "################################################################# emit_pusha_popa"
// );
// println!("{}", prettydiff::diff_lines(&before, &after));

self
}

Expand Down
16 changes: 14 additions & 2 deletions sway-core/src/asm_generation/fuel/data_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,20 @@ impl Entry {
match &constant.value {
ConstantValue::Undef | ConstantValue::Unit => Entry::new_word(0, size, name),
ConstantValue::Bool(b) => Entry::new_word(u64::from(*b), size, name),
ConstantValue::Uint(u) => Entry::new_word(*u, size, name),

ConstantValue::Uint(u) => match constant.ty.get_uint_width(context) {
Some(width) if width <= 64 => {
let u = u64::try_from(u).unwrap();
Entry::new_word(u, size, name)
}
Some(256) => {
let number_bytes = u.to_bytes_be();
let mut bytes = vec![0u8; 32 - number_bytes.len()];
bytes.extend(number_bytes);
assert!(bytes.len() == size.unwrap());
Entry::new_byte_array(bytes, size, name)
}
_ => todo!(),
},
ConstantValue::B256(bs) => Entry::new_byte_array(bs.to_vec(), size, name),
ConstantValue::String(bs) => Entry::new_byte_array(bs.clone(), size, name),

Expand Down
Loading