Created
October 23, 2025 19:16
-
-
Save LeeMetaX/b5cee8f18e62d0fa2acfa9de16199941 to your computer and use it in GitHub Desktop.
Boolean 4 state logic wrapped inside package SIMD vectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[derive(Clone, Copy, Debug, PartialEq, Eq)] | |
| pub enum State { Z, X, Zero, One } | |
| impl State { | |
| #[inline(always)] | |
| pub fn from_bool(b: Option<bool>) -> Self { | |
| match b { | |
| None => State::X, // undefined / faulted | |
| Some(true) => State::One, | |
| Some(false) => State::Zero, | |
| } | |
| } | |
| #[inline(always)] | |
| pub fn and(self, rhs: Self) -> Self { | |
| use State::*; | |
| match (self, rhs) { | |
| (Z, _) | (_, Z) => Z, | |
| (X, _) | (_, X) => X, | |
| (One, One) => One, | |
| (Zero, _) | (_, Zero) => Zero, | |
| } | |
| } | |
| #[inline(always)] | |
| pub fn or(self, rhs: Self) -> Self { | |
| use State::*; | |
| match (self, rhs) { | |
| (Z, s) | (s, Z) => s, | |
| (X, _) | (_, X) => X, | |
| (One, _) | (_, One) => One, | |
| (Zero, Zero) => Zero, | |
| } | |
| } | |
| #[inline(always)] | |
| pub fn not(self) -> Self { | |
| use State::*; | |
| match self { | |
| Z => Z, | |
| X => X, | |
| One => Zero, | |
| Zero => One, | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment