-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
3,419 additions
and
3,413 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
use num_bigint::BigUint; | ||
use num_bigint::ToBigUint; | ||
use num_traits::One; | ||
use static_assertions::const_assert; | ||
|
||
use crate::encode::COMMON_RANGE_OFFSET; | ||
use crate::itable::InstructionTableEntry; | ||
use crate::itable::Opcode; | ||
use crate::itable::OPCODE_SHIFT; | ||
|
||
use super::FromBn; | ||
|
||
pub(crate) const INSTRUCTION_ENCODE_BOUNDARY: u32 = 224; | ||
pub const INSTRUCTION_ENCODE_BOUNDARY: u32 = 250; | ||
pub(crate) const IID_BITS: u32 = 16; | ||
pub(crate) const FID_BITS: u32 = 16; | ||
const_assert!(OPCODE_SHIFT + IID_BITS + FID_BITS <= INSTRUCTION_ENCODE_BOUNDARY); | ||
|
||
pub fn encode_instruction_table_entry<T: FromBn>(fid: T, iid: T, opcode: T) -> T { | ||
const FID_SHIFT: u32 = IID_SHIFT + COMMON_RANGE_OFFSET; | ||
const FID_SHIFT: u32 = IID_SHIFT + IID_BITS; | ||
const IID_SHIFT: u32 = OPCODE_SHIFT; | ||
|
||
assert!(FID_SHIFT + COMMON_RANGE_OFFSET <= INSTRUCTION_ENCODE_BOUNDARY); | ||
|
||
fid * T::from_bn(&(1u64.to_biguint().unwrap() << FID_SHIFT)) | ||
+ iid * T::from_bn(&(1u64.to_biguint().unwrap() << IID_SHIFT)) | ||
fid * T::from_bn(&(BigUint::one() << FID_SHIFT)) | ||
+ iid * T::from_bn(&(BigUint::one() << IID_SHIFT)) | ||
+ opcode | ||
} | ||
|
||
impl InstructionTableEntry { | ||
pub(crate) fn encode(fid: u32, iid: u32, opcode: &Opcode) -> BigUint { | ||
assert!(fid < 1 << FID_BITS); | ||
assert!(iid < 1 << IID_BITS); | ||
|
||
encode_instruction_table_entry(BigUint::from(fid), BigUint::from(iid), opcode.into()) | ||
} | ||
} |
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.