@@ -155,114 +155,3 @@ impl<const N: u64> BitVec<N> {
155155 }
156156}
157157
158- pub mod int_vec_interp {
159- //! This module defines interpretation for bit vectors as vectors of machine integers of various size and signedness.
160- use super :: * ;
161-
162- /// An F* attribute that marks an item as being an interpretation lemma.
163- #[ allow( dead_code) ]
164- /// Derives interpretations functions, simplification lemmas and type
165- /// synonyms.
166- macro_rules! interpretations {
167- ( $n: literal; $( $name: ident [ $ty: ty; $m: literal] ) ,* ) => {
168- $(
169- #[ doc = concat!( stringify!( $ty) , " vectors of size " , stringify!( $m) ) ]
170- #[ allow( non_camel_case_types) ]
171- pub type $name = FunArray <$m, $ty>;
172- pastey:: paste! {
173- const _: ( ) = {
174- impl BitVec <$n> {
175- #[ doc = concat!( "Conversion from " , stringify!( $ty) , " vectors of size " , stringify!( $m) , "to bit vectors of size " , stringify!( $n) ) ]
176- pub fn [ < from_ $name >] ( iv: $name) -> BitVec <$n> {
177- let vec: Vec <$ty> = iv. as_vec( ) ;
178- Self :: from_slice( & vec[ ..] , <$ty>:: bits( ) as u64 )
179- }
180- #[ doc = concat!( "Conversion from bit vectors of size " , stringify!( $n) , " to " , stringify!( $ty) , " vectors of size " , stringify!( $m) ) ]
181- pub fn [ < to_ $name >] ( bv: BitVec <$n>) -> $name {
182- let vec: Vec <$ty> = bv. to_vec( ) ;
183- $name:: from_fn( |i| vec[ i as usize ] )
184- }
185-
186-
187- }
188-
189- #[ cfg( test) ]
190- impl From <BitVec <$n>> for $name {
191- fn from( bv: BitVec <$n>) -> Self {
192- BitVec :: [ < to_ $name >] ( bv)
193- }
194- }
195-
196- impl From <$name> for BitVec <$n> {
197- fn from( iv: $name) -> Self {
198- BitVec :: [ < from_ $name >] ( iv)
199- }
200- }
201-
202- impl $name {
203-
204- pub fn splat( value: $ty) -> Self {
205- FunArray :: from_fn( |_| value)
206- }
207- }
208- } ;
209- }
210- ) *
211- } ;
212- }
213-
214- interpretations ! ( 256 ; i32x8 [ i32 ; 8 ] , i64x4 [ i64 ; 4 ] , i16x16 [ i16 ; 16 ] , i128x2 [ i128 ; 2 ] , i8x32 [ i8 ; 32 ] ,
215- u32x8 [ u32 ; 8 ] , u64x4 [ u64 ; 4 ] , u16x16 [ u16 ; 16 ] , u8x32 [ u8 ; 32 ] ) ;
216- interpretations ! ( 128 ; i32x4 [ i32 ; 4 ] , i64x2 [ i64 ; 2 ] , i16x8 [ i16 ; 8 ] , i128x1 [ i128 ; 1 ] , i8x16 [ i8 ; 16 ] ,
217- u32x4 [ u32 ; 4 ] , u64x2 [ u64 ; 2 ] , u16x8 [ u16 ; 8 ] , u8x16 [ u8 ; 16 ] ) ;
218-
219- interpretations ! ( 512 ; u32x16 [ u32 ; 16 ] , u16x32 [ u16 ; 32 ] , i32x16 [ i32 ; 16 ] , i16x32 [ i16 ; 32 ] ) ;
220- interpretations ! ( 64 ; i64x1 [ i64 ; 1 ] , i32x2 [ i32 ; 2 ] , i16x4 [ i16 ; 4 ] , i8x8 [ i8 ; 8 ] , u64x1 [ u64 ; 1 ] , u32x2 [ u32 ; 2 ] , u16x4 [ u16 ; 4 ] , u8x8 [ u8 ; 8 ] ) ;
221- interpretations ! ( 32 ; i8x4 [ i8 ; 4 ] , u8x4 [ u8 ; 4 ] ) ;
222-
223- impl i64x4 {
224- pub fn into_i32x8 ( self ) -> i32x8 {
225- i32x8:: from_fn ( |i| {
226- let value = * self . get ( i / 2 ) ;
227- ( if i % 2 == 0 { value } else { value >> 32 } ) as i32
228- } )
229- }
230- }
231-
232- impl i32x8 {
233- pub fn into_i64x4 ( self ) -> i64x4 {
234- i64x4:: from_fn ( |i| {
235- let low = * self . get ( 2 * i) as u32 as u64 ;
236- let high = * self . get ( 2 * i + 1 ) as i32 as i64 ;
237- ( high << 32 ) | low as i64
238- } )
239- }
240- }
241-
242- impl From < i64x4 > for i32x8 {
243- fn from ( vec : i64x4 ) -> Self {
244- vec. into_i32x8 ( )
245- }
246- }
247-
248- #[ cfg( test) ]
249- mod direct_convertions_tests {
250- use super :: * ;
251- use crate :: helpers:: test:: HasRandom ;
252-
253- #[ test]
254- fn into_i32x8 ( ) {
255- for _ in 0 ..10000 {
256- let x: i64x4 = i64x4:: random ( ) ;
257- let y = x. into_i32x8 ( ) ;
258- assert_eq ! ( BitVec :: from_i64x4( x) , BitVec :: from_i32x8( y) ) ;
259- }
260- }
261- #[ test]
262- fn into_i64x4 ( ) {
263- let x: i32x8 = i32x8:: random ( ) ;
264- let y = x. into_i64x4 ( ) ;
265- assert_eq ! ( BitVec :: from_i32x8( x) , BitVec :: from_i64x4( y) ) ;
266- }
267- }
268- }
0 commit comments