fake_simd/
lib.rs

1#![no_std]
2use core::ops::{Add, BitAnd, BitOr, BitXor, Shl, Shr, Sub};
3
4#[derive(Clone, Copy, PartialEq, Eq)]
5#[allow(non_camel_case_types)]
6pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
7
8impl Add for u32x4 {
9    type Output = u32x4;
10
11    #[inline(always)]
12    fn add(self, rhs: u32x4) -> u32x4 {
13        u32x4(
14            self.0.wrapping_add(rhs.0),
15            self.1.wrapping_add(rhs.1),
16            self.2.wrapping_add(rhs.2),
17            self.3.wrapping_add(rhs.3))
18    }
19}
20
21impl Sub for u32x4 {
22    type Output = u32x4;
23
24    #[inline(always)]
25    fn sub(self, rhs: u32x4) -> u32x4 {
26        u32x4(
27            self.0.wrapping_sub(rhs.0),
28            self.1.wrapping_sub(rhs.1),
29            self.2.wrapping_sub(rhs.2),
30            self.3.wrapping_sub(rhs.3))
31    }
32}
33
34impl BitAnd for u32x4 {
35    type Output = u32x4;
36
37    #[inline(always)]
38    fn bitand(self, rhs: u32x4) -> u32x4 {
39        u32x4(self.0 & rhs.0, self.1 & rhs.1, self.2 & rhs.2, self.3 & rhs.3)
40    }
41}
42
43impl BitOr for u32x4 {
44    type Output = u32x4;
45
46    #[inline(always)]
47    fn bitor(self, rhs: u32x4) -> u32x4 {
48        u32x4(self.0 | rhs.0, self.1 | rhs.1, self.2 | rhs.2, self.3 | rhs.3)
49    }
50}
51
52impl BitXor for u32x4 {
53    type Output = u32x4;
54
55    #[inline(always)]
56    fn bitxor(self, rhs: u32x4) -> u32x4 {
57        u32x4(self.0 ^ rhs.0, self.1 ^ rhs.1, self.2 ^ rhs.2, self.3 ^ rhs.3)
58    }
59}
60
61impl Shl<usize> for u32x4 {
62    type Output = u32x4;
63
64    #[inline(always)]
65    fn shl(self, amt: usize) -> u32x4 {
66        u32x4(self.0 << amt, self.1 << amt, self.2 << amt, self.3 << amt)
67    }
68}
69
70impl Shl<u32x4> for u32x4 {
71    type Output = u32x4;
72
73    #[inline(always)]
74    fn shl(self, rhs: u32x4) -> u32x4 {
75        u32x4(self.0 << rhs.0, self.1 << rhs.1, self.2 << rhs.2, self.3 << rhs.3)
76    }
77}
78
79impl Shr<usize> for u32x4 {
80    type Output = u32x4;
81
82    #[inline(always)]
83    fn shr(self, amt: usize) -> u32x4 {
84        u32x4(self.0 >> amt, self.1 >> amt, self.2 >> amt, self.3 >> amt)
85    }
86}
87
88impl Shr<u32x4> for u32x4 {
89    type Output = u32x4;
90
91    #[inline(always)]
92    fn shr(self, rhs: u32x4) -> u32x4 {
93        u32x4(self.0 >> rhs.0, self.1 >> rhs.1, self.2 >> rhs.2, self.3 >> rhs.3)
94    }
95}
96
97#[derive(Clone, Copy)]
98#[allow(non_camel_case_types)]
99pub struct u64x2(pub u64, pub u64);
100
101impl Add for u64x2 {
102    type Output = u64x2;
103
104    #[inline(always)]
105    fn add(self, rhs: u64x2) -> u64x2 {
106        u64x2(self.0.wrapping_add(rhs.0), self.1.wrapping_add(rhs.1))
107    }
108}