1 /* 2 Copyright (c) 2005-2020 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_fba_H 18 #define __TBBexample_graph_logicsim_fba_H 1 19 20 #include "one_bit_adder.h" 21 22 typedef composite_node< tuple< signal_t, signal_t, signal_t, signal_t, signal_t, signal_t, signal_t, signal_t, signal_t >, 23 tuple< signal_t, signal_t, signal_t, signal_t, signal_t > > fba_base_type; 24 25 class four_bit_adder : public fba_base_type { 26 graph& my_graph; 27 std::vector<one_bit_adder> four_adders; 28 29 public: four_bit_adder(graph & g)30 four_bit_adder(graph& g) : fba_base_type(g), my_graph(g), four_adders(4, one_bit_adder(g)) { 31 make_connections(); 32 set_up_composite(); 33 } four_bit_adder(const four_bit_adder & src)34 four_bit_adder(const four_bit_adder& src) : 35 fba_base_type(src.my_graph), my_graph(src.my_graph), four_adders(4, one_bit_adder(src.my_graph)) 36 { 37 make_connections(); 38 set_up_composite(); 39 } ~four_bit_adder()40 ~four_bit_adder() {} 41 42 private: make_connections()43 void make_connections() { 44 make_edge(output_port<1>(four_adders[0]), input_port<0>(four_adders[1])); 45 make_edge(output_port<1>(four_adders[1]), input_port<0>(four_adders[2])); 46 make_edge(output_port<1>(four_adders[2]), input_port<0>(four_adders[3])); 47 } set_up_composite()48 void set_up_composite() { 49 50 fba_base_type::input_ports_type input_tuple(input_port<0>(four_adders[0]/*CI*/), input_port<1>(four_adders[0]), input_port<2>(four_adders[0]), input_port<1>(four_adders[1]), input_port<2>(four_adders[1]), input_port<1>(four_adders[2]), input_port<2>(four_adders[2]), input_port<1>(four_adders[3]), input_port<2>(four_adders[3])); 51 52 fba_base_type::output_ports_type output_tuple(output_port<0>(four_adders[0]), output_port<0>(four_adders[1]), output_port<0>(four_adders[2]), output_port<0>(four_adders[3]),output_port<1>(four_adders[3]/*CO*/)); 53 54 fba_base_type::set_external_ports(input_tuple, output_tuple); 55 } 56 }; 57 58 #endif /* __TBBexample_graph_logicsim_fba_H */ 59