Compare commits
	
		
			2 commits
		
	
	
		
			259bee39c2
			...
			e504cfebfe
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| e504cfebfe | |||
| 9f42cab471 | 
					 4 changed files with 28 additions and 25 deletions
				
			
		
							
								
								
									
										8
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -301,7 +301,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
 | 
			
		|||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "fayalite"
 | 
			
		||||
version = "0.2.1"
 | 
			
		||||
version = "0.3.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "bitvec",
 | 
			
		||||
 "blake3",
 | 
			
		||||
| 
						 | 
				
			
			@ -326,14 +326,14 @@ dependencies = [
 | 
			
		|||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "fayalite-proc-macros"
 | 
			
		||||
version = "0.2.1"
 | 
			
		||||
version = "0.3.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "fayalite-proc-macros-impl",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "fayalite-proc-macros-impl"
 | 
			
		||||
version = "0.2.1"
 | 
			
		||||
version = "0.3.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "base16ct",
 | 
			
		||||
 "num-bigint",
 | 
			
		||||
| 
						 | 
				
			
			@ -347,7 +347,7 @@ dependencies = [
 | 
			
		|||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "fayalite-visit-gen"
 | 
			
		||||
version = "0.2.1"
 | 
			
		||||
version = "0.3.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "indexmap",
 | 
			
		||||
 "prettyplease",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@ resolver = "2"
 | 
			
		|||
members = ["crates/*"]
 | 
			
		||||
 | 
			
		||||
[workspace.package]
 | 
			
		||||
version = "0.2.1"
 | 
			
		||||
version = "0.3.0"
 | 
			
		||||
license = "LGPL-3.0-or-later"
 | 
			
		||||
edition = "2021"
 | 
			
		||||
repository = "https://git.libre-chip.org/libre-chip/fayalite"
 | 
			
		||||
| 
						 | 
				
			
			@ -14,9 +14,9 @@ categories = ["simulation", "development-tools", "compilers"]
 | 
			
		|||
rust-version = "1.82.0"
 | 
			
		||||
 | 
			
		||||
[workspace.dependencies]
 | 
			
		||||
fayalite-proc-macros = { version = "=0.2.1", path = "crates/fayalite-proc-macros" }
 | 
			
		||||
fayalite-proc-macros-impl = { version = "=0.2.1", path = "crates/fayalite-proc-macros-impl" }
 | 
			
		||||
fayalite-visit-gen = { version = "=0.2.1", path = "crates/fayalite-visit-gen" }
 | 
			
		||||
fayalite-proc-macros = { version = "=0.3.0", path = "crates/fayalite-proc-macros" }
 | 
			
		||||
fayalite-proc-macros-impl = { version = "=0.3.0", path = "crates/fayalite-proc-macros-impl" }
 | 
			
		||||
fayalite-visit-gen = { version = "=0.3.0", path = "crates/fayalite-visit-gen" }
 | 
			
		||||
base16ct = "0.2.0"
 | 
			
		||||
bitvec = { version = "1.0.1", features = ["serde"] }
 | 
			
		||||
blake3 = { version = "1.5.4", features = ["serde"] }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -265,7 +265,7 @@ impl Neg {
 | 
			
		|||
        };
 | 
			
		||||
        let result_ty = retval.ty();
 | 
			
		||||
        retval.literal_bits = arg.to_literal_bits().map(|bits| {
 | 
			
		||||
            Intern::intern_owned(result_ty.bits_from_bigint_wrapping(-SInt::bits_to_bigint(&bits)))
 | 
			
		||||
            Intern::intern_owned(result_ty.bits_from_bigint_wrapping(&-SInt::bits_to_bigint(&bits)))
 | 
			
		||||
        });
 | 
			
		||||
        retval
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -372,7 +372,7 @@ fn binary_op_literal_bits<ResultTy: BoolOrIntType, Lhs: BoolOrIntType, Rhs: Bool
 | 
			
		|||
    let rhs = Rhs::bits_to_bigint(&rhs);
 | 
			
		||||
    let result = f(lhs, rhs)?;
 | 
			
		||||
    Ok(Intern::intern_owned(
 | 
			
		||||
        result_ty.bits_from_bigint_wrapping(result),
 | 
			
		||||
        result_ty.bits_from_bigint_wrapping(&result),
 | 
			
		||||
    ))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1347,7 +1347,7 @@ macro_rules! binary_op_fixed_shift {
 | 
			
		|||
                    literal_bits: Err(NotALiteralExpr),
 | 
			
		||||
                };
 | 
			
		||||
                retval.literal_bits = lhs.to_literal_bits().map(|bits| {
 | 
			
		||||
                    Intern::intern_owned(retval.ty().bits_from_bigint_wrapping($Trait::$method(
 | 
			
		||||
                    Intern::intern_owned(retval.ty().bits_from_bigint_wrapping(&$Trait::$method(
 | 
			
		||||
                        $ty::bits_to_bigint(&bits),
 | 
			
		||||
                        rhs,
 | 
			
		||||
                    )))
 | 
			
		||||
| 
						 | 
				
			
			@ -1624,7 +1624,7 @@ macro_rules! impl_cast_int_op {
 | 
			
		|||
                    ty,
 | 
			
		||||
                    literal_bits: arg.to_literal_bits().map(|bits| {
 | 
			
		||||
                        Intern::intern_owned(
 | 
			
		||||
                            ty.bits_from_bigint_wrapping($from::bits_to_bigint(&bits)),
 | 
			
		||||
                            ty.bits_from_bigint_wrapping(&$from::bits_to_bigint(&bits)),
 | 
			
		||||
                        )
 | 
			
		||||
                    }),
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -202,17 +202,17 @@ macro_rules! impl_int {
 | 
			
		|||
                    bit_width: self.width(),
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            pub fn bits_from_bigint_wrapping(self, v: BigInt) -> BitVec {
 | 
			
		||||
            pub fn bits_from_bigint_wrapping(self, v: &BigInt) -> BitVec {
 | 
			
		||||
                BoolOrIntType::bits_from_bigint_wrapping(self, v)
 | 
			
		||||
            }
 | 
			
		||||
            pub fn from_bigint_wrapping(self, v: BigInt) -> $value<Width> {
 | 
			
		||||
            pub fn from_bigint_wrapping(self, v: &BigInt) -> $value<Width> {
 | 
			
		||||
                $value {
 | 
			
		||||
                    bits: Arc::new(self.bits_from_bigint_wrapping(v)),
 | 
			
		||||
                    _phantom: PhantomData,
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            pub fn from_int_wrapping(self, v: impl Into<BigInt>) -> $value<Width> {
 | 
			
		||||
                self.from_bigint_wrapping(v.into())
 | 
			
		||||
                self.from_bigint_wrapping(&v.into())
 | 
			
		||||
            }
 | 
			
		||||
            pub fn zero(self) -> $value<Width> {
 | 
			
		||||
                self.from_int_wrapping(0u8)
 | 
			
		||||
| 
						 | 
				
			
			@ -234,7 +234,7 @@ macro_rules! impl_int {
 | 
			
		|||
            fn new(width: Width::SizeType) -> Self {
 | 
			
		||||
                $name { width }
 | 
			
		||||
            }
 | 
			
		||||
            fn value_from_bigint_wrapping(self, v: BigInt) -> Self::Value {
 | 
			
		||||
            fn value_from_bigint_wrapping(self, v: &BigInt) -> Self::Value {
 | 
			
		||||
                $value::<Width>::from_bigint_wrapping(self, v)
 | 
			
		||||
            }
 | 
			
		||||
            fn bits_to_value(bits: Cow<'_, BitSlice>) -> Self::Value {
 | 
			
		||||
| 
						 | 
				
			
			@ -378,7 +378,7 @@ macro_rules! impl_int {
 | 
			
		|||
                    self.bits.len()
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            pub fn from_bigint_wrapping(ty: $name<Width>, v: BigInt) -> $value<Width> {
 | 
			
		||||
            pub fn from_bigint_wrapping(ty: $name<Width>, v: &BigInt) -> $value<Width> {
 | 
			
		||||
                ty.from_bigint_wrapping(v)
 | 
			
		||||
            }
 | 
			
		||||
            pub fn to_bigint(&self) -> BigInt {
 | 
			
		||||
| 
						 | 
				
			
			@ -603,20 +603,23 @@ pub trait BoolOrIntType: Type + sealed::BoolOrIntTypeSealed {
 | 
			
		|||
        UIntType::new(Self::Width::from_usize(self.width()))
 | 
			
		||||
    }
 | 
			
		||||
    fn value_from_int_wrapping(self, v: impl Into<BigInt>) -> Self::Value {
 | 
			
		||||
        self.value_from_bigint_wrapping(v.into())
 | 
			
		||||
        self.value_from_bigint_wrapping(&v.into())
 | 
			
		||||
    }
 | 
			
		||||
    fn value_from_bigint_wrapping(self, v: BigInt) -> Self::Value;
 | 
			
		||||
    fn bits_from_bigint_wrapping(self, v: BigInt) -> BitVec {
 | 
			
		||||
        let width = self.width();
 | 
			
		||||
    fn value_from_bigint_wrapping(self, v: &BigInt) -> Self::Value;
 | 
			
		||||
    fn bits_from_bigint_wrapping(self, v: &BigInt) -> BitVec {
 | 
			
		||||
        let mut bits = BitVec::repeat(false, self.width());
 | 
			
		||||
        Self::copy_bits_from_bigint_wrapping(v, &mut bits);
 | 
			
		||||
        bits
 | 
			
		||||
    }
 | 
			
		||||
    fn copy_bits_from_bigint_wrapping(v: &BigInt, bits: &mut BitSlice) {
 | 
			
		||||
        let width = bits.len();
 | 
			
		||||
        let mut bytes = v.to_signed_bytes_le();
 | 
			
		||||
        bytes.resize(
 | 
			
		||||
            width.div_ceil(u8::BITS as usize),
 | 
			
		||||
            if v.is_negative() { 0xFF } else { 0 },
 | 
			
		||||
        );
 | 
			
		||||
        let bitslice = &BitSlice::<u8, Lsb0>::from_slice(&bytes)[..width];
 | 
			
		||||
        let mut bits = BitVec::new();
 | 
			
		||||
        bits.extend_from_bitslice(bitslice);
 | 
			
		||||
        bits
 | 
			
		||||
        bits.clone_from_bitslice(bitslice);
 | 
			
		||||
    }
 | 
			
		||||
    fn bits_to_bigint(bits: &BitSlice) -> BigInt {
 | 
			
		||||
        let sign_byte = if Self::Signed::VALUE && bits.last().as_deref().copied().unwrap_or(false) {
 | 
			
		||||
| 
						 | 
				
			
			@ -712,7 +715,7 @@ impl BoolOrIntType for Bool {
 | 
			
		|||
        Bool
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn value_from_bigint_wrapping(self, v: BigInt) -> Self::Value {
 | 
			
		||||
    fn value_from_bigint_wrapping(self, v: &BigInt) -> Self::Value {
 | 
			
		||||
        v.bit(0)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue