| 1 | /* | 
|---|
| 2 | Copyright (c) 2005-2019 Intel Corporation | 
|---|
| 3 |  | 
|---|
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); | 
|---|
| 5 | you may not use this file except in compliance with the License. | 
|---|
| 6 | You may obtain a copy of the License at | 
|---|
| 7 |  | 
|---|
| 8 | http://www.apache.org/licenses/LICENSE-2.0 | 
|---|
| 9 |  | 
|---|
| 10 | Unless required by applicable law or agreed to in writing, software | 
|---|
| 11 | distributed under the License is distributed on an "AS IS" BASIS, | 
|---|
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|---|
| 13 | See the License for the specific language governing permissions and | 
|---|
| 14 | limitations under the License. | 
|---|
| 15 | */ | 
|---|
| 16 |  | 
|---|
| 17 | #ifndef __TBBexample_graph_logicsim_oba_H | 
|---|
| 18 | #define __TBBexample_graph_logicsim_oba_H 1 | 
|---|
| 19 |  | 
|---|
| 20 | namespace P { | 
|---|
| 21 | //input ports | 
|---|
| 22 | const int CI = 0; | 
|---|
| 23 | const int A0 = 1; | 
|---|
| 24 | const int B0 = 2; | 
|---|
| 25 | const int A1 = 3; | 
|---|
| 26 | const int B1 = 4; | 
|---|
| 27 | const int A2 = 5; | 
|---|
| 28 | const int B2 = 6; | 
|---|
| 29 | const int A3 = 7; | 
|---|
| 30 | const int B3 = 8; | 
|---|
| 31 |  | 
|---|
| 32 | //output_ports | 
|---|
| 33 | const int S0 = 0; | 
|---|
| 34 | const int S1 = 1; | 
|---|
| 35 | const int S2 = 2; | 
|---|
| 36 | const int S3 = 3; | 
|---|
| 37 |  | 
|---|
| 38 | #if USE_TWO_BIT_FULL_ADDER | 
|---|
| 39 | const int CO = 2; | 
|---|
| 40 | #else | 
|---|
| 41 | const int CO = 4; | 
|---|
| 42 | #endif | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | #include "basics.h" | 
|---|
| 46 |  | 
|---|
| 47 | class one_bit_adder : public composite_node< tuple< signal_t, signal_t, signal_t >, tuple< signal_t, signal_t > > { | 
|---|
| 48 | broadcast_node<signal_t> A_port; | 
|---|
| 49 | broadcast_node<signal_t> B_port; | 
|---|
| 50 | broadcast_node<signal_t> CI_port; | 
|---|
| 51 | xor_gate<2> FirstXOR; | 
|---|
| 52 | xor_gate<2> SecondXOR; | 
|---|
| 53 | and_gate<2> FirstAND; | 
|---|
| 54 | and_gate<2> SecondAND; | 
|---|
| 55 | or_gate<2> FirstOR; | 
|---|
| 56 | graph& my_graph; | 
|---|
| 57 | typedef composite_node< tuple< signal_t, signal_t, signal_t >, tuple< signal_t, signal_t > > base_type; | 
|---|
| 58 |  | 
|---|
| 59 | public: | 
|---|
| 60 | one_bit_adder(graph& g) : base_type(g), my_graph(g), A_port(g), B_port(g), CI_port(g), FirstXOR(g), | 
|---|
| 61 | SecondXOR(g), FirstAND(g), SecondAND(g), FirstOR(g) { | 
|---|
| 62 | make_connections(); | 
|---|
| 63 | set_up_composite(); | 
|---|
| 64 | } | 
|---|
| 65 | one_bit_adder(const one_bit_adder& src) : | 
|---|
| 66 | base_type(src.my_graph), my_graph(src.my_graph), A_port(src.my_graph), B_port(src.my_graph), | 
|---|
| 67 | CI_port(src.my_graph), FirstXOR(src.my_graph), SecondXOR(src.my_graph), | 
|---|
| 68 | FirstAND(src.my_graph), SecondAND(src.my_graph), FirstOR(src.my_graph) | 
|---|
| 69 | { | 
|---|
| 70 | make_connections(); | 
|---|
| 71 | set_up_composite(); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | ~one_bit_adder() {} | 
|---|
| 75 |  | 
|---|
| 76 | private: | 
|---|
| 77 | void make_connections() { | 
|---|
| 78 |  | 
|---|
| 79 | make_edge(A_port, input_port<0>(FirstXOR)); | 
|---|
| 80 | make_edge(A_port, input_port<0>(FirstAND)); | 
|---|
| 81 | make_edge(B_port, input_port<1>(FirstXOR)); | 
|---|
| 82 | make_edge(B_port, input_port<1>(FirstAND)); | 
|---|
| 83 | make_edge(CI_port, input_port<1>(SecondXOR)); | 
|---|
| 84 | make_edge(CI_port, input_port<1>(SecondAND)); | 
|---|
| 85 | make_edge(FirstXOR, input_port<0>(SecondXOR)); | 
|---|
| 86 | make_edge(FirstXOR, input_port<0>(SecondAND)); | 
|---|
| 87 | make_edge(SecondAND, input_port<0>(FirstOR)); | 
|---|
| 88 | make_edge(FirstAND, input_port<1>(FirstOR)); | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | void set_up_composite() { | 
|---|
| 92 | base_type::input_ports_type input_tuple(CI_port, A_port, B_port); | 
|---|
| 93 | base_type::output_ports_type output_tuple(output_port<0>(SecondXOR), output_port<0>(FirstOR)); | 
|---|
| 94 | base_type::set_external_ports( input_tuple, output_tuple); | 
|---|
| 95 | base_type::add_visible_nodes(A_port, B_port, CI_port, FirstXOR, SecondXOR, FirstAND, SecondAND, FirstOR ); | 
|---|
| 96 | } | 
|---|
| 97 | }; | 
|---|
| 98 |  | 
|---|
| 99 | #endif /* __TBBexample_graph_logicsim_oba_H */ | 
|---|
| 100 |  | 
|---|