mech_logic/
xor.rs

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