From fa2b9ca515b49c5504ecd499e918a3293b5b0800 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 26 Aug 2024 17:28:33 -0700 Subject: [PATCH] hide wide_traits behind a feature flag --- fixed_wide/Cargo.toml | 6 +++- fixed_wide/src/fixed.rs | 36 ++--------------------- fixed_wide/src/lib.rs | 3 ++ fixed_wide/src/wide_traits.rs | 44 ++++++++++++++++++++++++++++ fixed_wide_vectors/Cargo.toml | 6 +++- fixed_wide_vectors/src/macros/mod.rs | 3 +- 6 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 fixed_wide/src/wide_traits.rs diff --git a/fixed_wide/Cargo.toml b/fixed_wide/Cargo.toml index 86f99f6..dd50704 100644 --- a/fixed_wide/Cargo.toml +++ b/fixed_wide/Cargo.toml @@ -3,7 +3,11 @@ name = "fixed_wide" version = "0.1.0" edition = "2021" +[features] +default=["wide_traits"] +wide_traits=["dep:wide_traits"] + [dependencies] bnum = "0.11.0" typenum = "1.17.0" -wide_traits = { version = "0.1.0", path = "../wide_traits" } +wide_traits = { version = "0.1.0", path = "../wide_traits", optional = true } diff --git a/fixed_wide/src/fixed.rs b/fixed_wide/src/fixed.rs index 0a5140a..8b16620 100644 --- a/fixed_wide/src/fixed.rs +++ b/fixed_wide/src/fixed.rs @@ -1,13 +1,11 @@ -use bnum::cast::As; use bnum::BInt; -use wide_traits::wide::WideMul; -use typenum::{Sum,Unsigned}; +use typenum::Unsigned; use std::marker::PhantomData; #[derive(Clone,Copy,Debug,Hash)] pub struct Fixed{ - bits:BInt<{CHUNKS}>, - frac:PhantomData, + pub(crate)bits:BInt<{CHUNKS}>, + pub(crate)frac:PhantomData, } impl From for Fixed @@ -82,31 +80,3 @@ impl_assign_operator!( Fixed, BitOrAssign, bitor_assign ); impl_operator!( Fixed, BitOr, bitor, Self ); impl_assign_operator!( Fixed, BitXorAssign, bitxor_assign ); impl_operator!( Fixed, BitXor, bitxor, Self ); - -//going wider native -macro_rules! impl_wide_mul { - ($lhs: expr,$rhs: expr) => { - impl WideMul> for Fixed<$lhs,A> - where - A:std::ops::Add, - B:Unsigned, - { - type Output=Fixed<{$lhs+$rhs},Sum>; - fn wide_mul(self,rhs:Fixed<$rhs,B>)->Self::Output{ - Fixed{ - bits:self.bits.as_::>()*rhs.bits.as_::>(), - frac:PhantomData, - } - } - } - }; -} -//const generics sidestepped wahoo -impl_wide_mul!(1,1);impl_wide_mul!(2,1);impl_wide_mul!(3,1);impl_wide_mul!(4,1);impl_wide_mul!(5,1);impl_wide_mul!(6,1);impl_wide_mul!(7,1);impl_wide_mul!(8,1); -impl_wide_mul!(1,2);impl_wide_mul!(2,2);impl_wide_mul!(3,2);impl_wide_mul!(4,2);impl_wide_mul!(5,2);impl_wide_mul!(6,2);impl_wide_mul!(7,2);impl_wide_mul!(8,2); -impl_wide_mul!(1,3);impl_wide_mul!(2,3);impl_wide_mul!(3,3);impl_wide_mul!(4,3);impl_wide_mul!(5,3);impl_wide_mul!(6,3);impl_wide_mul!(7,3);impl_wide_mul!(8,3); -impl_wide_mul!(1,4);impl_wide_mul!(2,4);impl_wide_mul!(3,4);impl_wide_mul!(4,4);impl_wide_mul!(5,4);impl_wide_mul!(6,4);impl_wide_mul!(7,4);impl_wide_mul!(8,4); -impl_wide_mul!(1,5);impl_wide_mul!(2,5);impl_wide_mul!(3,5);impl_wide_mul!(4,5);impl_wide_mul!(5,5);impl_wide_mul!(6,5);impl_wide_mul!(7,5);impl_wide_mul!(8,5); -impl_wide_mul!(1,6);impl_wide_mul!(2,6);impl_wide_mul!(3,6);impl_wide_mul!(4,6);impl_wide_mul!(5,6);impl_wide_mul!(6,6);impl_wide_mul!(7,6);impl_wide_mul!(8,6); -impl_wide_mul!(1,7);impl_wide_mul!(2,7);impl_wide_mul!(3,7);impl_wide_mul!(4,7);impl_wide_mul!(5,7);impl_wide_mul!(6,7);impl_wide_mul!(7,7);impl_wide_mul!(8,7); -impl_wide_mul!(1,8);impl_wide_mul!(2,8);impl_wide_mul!(3,8);impl_wide_mul!(4,8);impl_wide_mul!(5,8);impl_wide_mul!(6,8);impl_wide_mul!(7,8);impl_wide_mul!(8,8); diff --git a/fixed_wide/src/lib.rs b/fixed_wide/src/lib.rs index 3f00234..02c82a7 100644 --- a/fixed_wide/src/lib.rs +++ b/fixed_wide/src/lib.rs @@ -1,2 +1,5 @@ pub mod fixed; pub mod types; + +#[cfg(feature="wide_traits")] +mod wide_traits; diff --git a/fixed_wide/src/wide_traits.rs b/fixed_wide/src/wide_traits.rs new file mode 100644 index 0000000..86bbae4 --- /dev/null +++ b/fixed_wide/src/wide_traits.rs @@ -0,0 +1,44 @@ +use bnum::BInt; +use bnum::cast::As; +use typenum::{Sum,Unsigned}; +use crate::fixed::Fixed; +use wide_traits::wide::WideMul; +use std::marker::PhantomData; + +macro_rules! impl_wide_mul { + ($lhs: expr,$rhs: expr) => { + impl WideMul> for Fixed<$lhs,A> + where + A:std::ops::Add, + B:Unsigned, + { + type Output=Fixed<{$lhs+$rhs},Sum>; + fn wide_mul(self,rhs:Fixed<$rhs,B>)->Self::Output{ + Fixed{ + bits:self.bits.as_::>()*rhs.bits.as_::>(), + frac:PhantomData, + } + } + } + }; +} + +macro_rules! impl_wide_mul_all { + ($(($x:expr, $y:expr)),*) => { + $( + impl_wide_mul!($x, $y); + )* + }; +} + +//const generics sidestepped wahoo +impl_wide_mul_all!( + (1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1), + (1,2),(2,2),(3,2),(4,2),(5,2),(6,2),(7,2),(8,2), + (1,3),(2,3),(3,3),(4,3),(5,3),(6,3),(7,3),(8,3), + (1,4),(2,4),(3,4),(4,4),(5,4),(6,4),(7,4),(8,4), + (1,5),(2,5),(3,5),(4,5),(5,5),(6,5),(7,5),(8,5), + (1,6),(2,6),(3,6),(4,6),(5,6),(6,6),(7,6),(8,6), + (1,7),(2,7),(3,7),(4,7),(5,7),(6,7),(7,7),(8,7), + (1,8),(2,8),(3,8),(4,8),(5,8),(6,8),(7,8),(8,8) +); diff --git a/fixed_wide_vectors/Cargo.toml b/fixed_wide_vectors/Cargo.toml index b96d9c1..0241f59 100644 --- a/fixed_wide_vectors/Cargo.toml +++ b/fixed_wide_vectors/Cargo.toml @@ -3,6 +3,10 @@ name = "fixed_wide_vectors" version = "0.1.0" edition = "2021" +[features] +default=["wide_traits"] +wide_traits=["dep:wide_traits"] + [dependencies] fixed_wide = { version = "0.1.0", path = "../fixed_wide" } -wide_traits = { version = "0.1.0", path = "../wide_traits" } +wide_traits = { version = "0.1.0", path = "../wide_traits", optional = true } diff --git a/fixed_wide_vectors/src/macros/mod.rs b/fixed_wide_vectors/src/macros/mod.rs index ffac9aa..314de3c 100644 --- a/fixed_wide_vectors/src/macros/mod.rs +++ b/fixed_wide_vectors/src/macros/mod.rs @@ -1,6 +1,7 @@ -// Stolen from https://github.com/c1m50c/fixed-vectors (MIT license) +#[cfg(feature="wide_traits")] pub mod wide; +// Stolen from https://github.com/c1m50c/fixed-vectors (MIT license) #[doc(hidden)] #[macro_export(local_inner_macros)] macro_rules! impl_vector {