-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(avm)!: variants for MOV opcode (#8440)
Yields an 11% to 21% reduction in bytecode size: ``` avm_simulation_bytecode_size_in_bytes (Token:constructor): 10,658 (-18%) avm_simulation_bytecode_size_in_bytes (FPC:constructor): 6,144 (-21%) avm_simulation_bytecode_size_in_bytes (FPC:prepare_fee): 3,089 (-21%) avm_simulation_bytecode_size_in_bytes (Token:transfer_public): 7,401 (-17%) avm_simulation_bytecode_size_in_bytes (FPC:pay_refund): 3,911 (-19%) avm_simulation_bytecode_size_in_bytes (Benchmarking:increment_balance): 2,620 (-16%) avm_simulation_bytecode_size_in_bytes (FPC:pay_refund_with_shielded_rebate): 3,911 (-19%) ``` There are some gas-related things to cleanup later.
- Loading branch information
Showing
21 changed files
with
283 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use acvm::{AcirField, FieldElement}; | ||
|
||
fn get_msb(n: u128) -> usize { | ||
let mut n = n; | ||
let mut msb = 0; | ||
while n > 0 { | ||
n >>= 1; | ||
msb += 1; | ||
} | ||
msb | ||
} | ||
|
||
pub trait BitsQueryable { | ||
fn num_bits(&self) -> usize; | ||
} | ||
|
||
impl BitsQueryable for FieldElement { | ||
fn num_bits(&self) -> usize { | ||
AcirField::num_bits(self) as usize | ||
} | ||
} | ||
|
||
impl BitsQueryable for u8 { | ||
fn num_bits(&self) -> usize { | ||
get_msb(*self as u128) | ||
} | ||
} | ||
|
||
impl BitsQueryable for u16 { | ||
fn num_bits(&self) -> usize { | ||
get_msb(*self as u128) | ||
} | ||
} | ||
|
||
impl BitsQueryable for u32 { | ||
fn num_bits(&self) -> usize { | ||
get_msb(*self as u128) | ||
} | ||
} | ||
|
||
impl BitsQueryable for u64 { | ||
fn num_bits(&self) -> usize { | ||
get_msb(*self as u128) | ||
} | ||
} | ||
|
||
impl BitsQueryable for u128 { | ||
fn num_bits(&self) -> usize { | ||
get_msb(*self) | ||
} | ||
} | ||
|
||
pub fn bits_needed_for<T: BitsQueryable>(val: &T) -> usize { | ||
let num_bits = val.num_bits(); | ||
if num_bits < 8 { | ||
8 | ||
} else if num_bits < 16 { | ||
16 | ||
} else if num_bits < 32 { | ||
32 | ||
} else if num_bits < 64 { | ||
64 | ||
} else if num_bits < 128 { | ||
128 | ||
} else { | ||
254 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.