mech_logic/
xor.rs

1use crate::*;
2use mech_core::*;
3
4// Xor ------------------------------------------------------------------------
5macro_rules! xor_op {
6    ($lhs:expr, $rhs:expr, $out:expr) => {
7      unsafe {*$out = *$lhs ^ *$rhs;}
8      };}
9  
10macro_rules! xor_vec_op {
11  ($lhs:expr, $rhs:expr, $out:expr) => {
12    unsafe {
13      for i in 0..(*$lhs).len() {
14        (*$out)[i] = (*$lhs)[i] ^ (*$rhs)[i];
15      }}};}
16    
17macro_rules! xor_scalar_rhs_op {
18  ($lhs:expr, $rhs:expr, $out:expr) => {
19    unsafe {
20      for i in 0..(*$rhs).len() {
21        (*$out)[i] = (*$lhs) ^ (*$rhs)[i];
22      }}};}
23      
24
25macro_rules! xor_scalar_lhs_op {
26  ($lhs:expr, $rhs:expr, $out:expr) => {
27    unsafe {
28      for i in 0..(*$lhs).len() {
29        (*$out)[i] = (*$lhs)[i] ^ (*$rhs);
30      }}};} 
31
32macro_rules! xor_mat_vec_op {
33  ($lhs:expr, $rhs:expr, $out:expr) => {
34    unsafe {
35      let mut out_deref = &mut (*$out);
36      let lhs_deref = &(*$lhs);
37      let rhs_deref = &(*$rhs);
38      for (mut col, lhs_col) in out_deref.column_iter_mut().zip(lhs_deref.column_iter()) {
39        for i in 0..col.len() {
40          col[i] = lhs_col[i] ^ rhs_deref[i];
41        }
42      }
43    }
44  };}   
45      
46macro_rules! xor_vec_mat_op {
47  ($lhs:expr, $rhs:expr, $out:expr) => {
48      unsafe {
49        let mut out_deref = &mut (*$out);
50        let lhs_deref = &(*$lhs);
51        let rhs_deref = &(*$rhs);
52        for (mut col, rhs_col) in out_deref.column_iter_mut().zip(rhs_deref.column_iter()) {
53          for i in 0..col.len() {
54            col[i] = lhs_deref[i] ^ rhs_col[i];
55          }
56        }
57      }
58  };}
59  
60macro_rules! xor_mat_row_op {
61  ($lhs:expr, $rhs:expr, $out:expr) => {
62      unsafe {
63      let mut out_deref = &mut (*$out);
64      let lhs_deref = &(*$lhs);
65      let rhs_deref = &(*$rhs);
66      for (mut row, lhs_row) in out_deref.row_iter_mut().zip(lhs_deref.row_iter()) {
67          for i in 0..row.len() {
68          row[i] = lhs_row[i] ^ rhs_deref[i];
69          }
70      }
71      }
72  };}
73
74macro_rules! xor_row_mat_op {
75  ($lhs:expr, $rhs:expr, $out:expr) => {
76      unsafe {
77      let mut out_deref = &mut (*$out);
78      let lhs_deref = &(*$lhs);
79      let rhs_deref = &(*$rhs);
80      for (mut row, rhs_row) in out_deref.row_iter_mut().zip(rhs_deref.row_iter()) {
81          for i in 0..row.len() {
82          row[i] = lhs_deref[i] ^ rhs_row[i];
83          }
84      }
85      }
86  };}      
87
88
89impl_logic_fxns!(Xor);
90
91fn impl_xor_fxn(lhs_value: Value, rhs_value: Value) -> Result<Box<dyn MechFunction>, MechError> {
92  impl_binop_match_arms!(
93    Xor,
94    (lhs_value, rhs_value),
95    Bool, Bool => MatrixBool, bool, false, "Bool";
96  )
97}
98
99impl_mech_binop_fxn!(LogicXor,impl_xor_fxn);