Skip to content

Commit 370303f

Browse files
edited avx2
1 parent d418b8a commit 370303f

File tree

6 files changed

+325
-238
lines changed

6 files changed

+325
-238
lines changed

library/Cargo.lock

Lines changed: 90 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

testable-simd-models/src/abstractions/bitvec.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ use std::fmt::Formatter;
1717
#[derive(Copy, Clone, Eq, PartialEq)]
1818
pub struct BitVec<const N: u32>(FunArray<N, Bit>);
1919

20+
impl<const N: u32> BitVec<N> {
21+
#[allow(non_snake_case)]
22+
pub fn ZERO() -> Self {
23+
Self::from_fn(|_| Bit::Zero)
24+
}
25+
}
26+
2027
/// Pretty prints a bit slice by group of 8
2128
fn bit_slice_to_string(bits: &[Bit]) -> String {
2229
bits.iter()

testable-simd-models/src/abstractions/funarr.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! This module implements a fixed-size array wrapper with functional semantics
22
//! which are used in formulating abstractions.
33
4+
use crate::abstractions::bit::MachineInteger;
5+
46
/// `FunArray<N, T>` represents an array of `T` values of length `N`, where `N` is a compile-time constant.
57
/// Internally, it uses a fixed-length array of `Option<T>` with a maximum capacity of 512 elements.
68
/// Unused elements beyond `N` are filled with `None`.
@@ -53,6 +55,13 @@ impl<const N: u32, T> FunArray<N, T> {
5355
}
5456
}
5557

58+
impl<const N: u32, T:MachineInteger> FunArray<N, T> {
59+
#[allow(non_snake_case)]
60+
pub fn ZERO() -> Self {
61+
Self::from_fn(|_| T::ZEROS)
62+
}
63+
}
64+
5665
impl<const N: u32, T: Clone> TryFrom<Vec<T>> for FunArray<N, T> {
5766
type Error = ();
5867
fn try_from(v: Vec<T>) -> Result<Self, ()> {

testable-simd-models/src/abstractions/simd.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ macro_rules! interpretations {
2525
#[doc = concat!("Conversion from bit vectors of size ", stringify!($n), " to ", stringify!($ty), " vectors of size ", stringify!($m))]
2626
pub fn [< to_ $name >](bv: BitVec<$n>) -> $name {
2727
let vec: Vec<$ty> = bv.to_vec();
28+
$name::from_fn(|i| vec[i as usize])
29+
}
30+
#[doc = concat!("Conversion from bit vectors of size ", stringify!($n), " to ", stringify!($ty), " vectors of size ", stringify!($m))]
31+
pub fn [< as_ $name >](self) -> $name {
32+
let vec: Vec<$ty> = self.to_vec();
2833
$name::from_fn(|i| vec[i as usize])
2934
}
3035

@@ -71,7 +76,6 @@ interpretations!(32; i8x4 [i8; 4], u8x4 [u8; 4]);
7176
/// # Safety
7277
///
7378
/// `idx` must be in-bounds of the vector, ie. idx < N
74-
7579
pub fn simd_insert<const N: u32, T: Copy>(x: FunArray<N, T>, idx: u32, val: T) -> FunArray<N, T> {
7680
FunArray::from_fn(|i| if i == idx { val } else { x[i] })
7781
}
@@ -936,3 +940,8 @@ pub fn simd_select<const N: u32, T1: Eq + MachineInteger, T2: Copy + MachineInte
936940
}
937941
})
938942
}
943+
944+
/// Converts one type to another
945+
pub fn transmute<T, U:From<T>>(a:T) -> U {
946+
a.into()
947+
}

0 commit comments

Comments
 (0)