1 /*
2     Copyright (c) 2005-2021 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 TBB_examples_logic_sim_fba_H
18 #define TBB_examples_logic_sim_fba_H
19 
20 #include "one_bit_adder.hpp"
21 
22 typedef oneapi::tbb::flow::composite_node<
23     std::tuple<signal_t,
24                signal_t,
25                signal_t,
26                signal_t,
27                signal_t,
28                signal_t,
29                signal_t,
30                signal_t,
31                signal_t>,
32     std::tuple<signal_t, signal_t, signal_t, signal_t, signal_t>>
33     fba_base_type;
34 
35 class four_bit_adder : public fba_base_type {
36     oneapi::tbb::flow::graph& my_graph;
37     std::vector<one_bit_adder> four_adders;
38 
39 public:
four_bit_adder(oneapi::tbb::flow::graph & g)40     four_bit_adder(oneapi::tbb::flow::graph& g)
41             : fba_base_type(g),
42               my_graph(g),
43               four_adders(4, one_bit_adder(g)) {
44         make_connections();
45         set_up_composite();
46     }
four_bit_adder(const four_bit_adder & src)47     four_bit_adder(const four_bit_adder& src)
48             : fba_base_type(src.my_graph),
49               my_graph(src.my_graph),
50               four_adders(4, one_bit_adder(src.my_graph)) {
51         make_connections();
52         set_up_composite();
53     }
~four_bit_adder()54     ~four_bit_adder() {}
55 
56 private:
make_connections()57     void make_connections() {
58         make_edge(output_port<1>(four_adders[0]), input_port<0>(four_adders[1]));
59         make_edge(output_port<1>(four_adders[1]), input_port<0>(four_adders[2]));
60         make_edge(output_port<1>(four_adders[2]), input_port<0>(four_adders[3]));
61     }
set_up_composite()62     void set_up_composite() {
63         fba_base_type::input_ports_type input_tuple(input_port<0>(four_adders[0] /*CI*/),
64                                                     input_port<1>(four_adders[0]),
65                                                     input_port<2>(four_adders[0]),
66                                                     input_port<1>(four_adders[1]),
67                                                     input_port<2>(four_adders[1]),
68                                                     input_port<1>(four_adders[2]),
69                                                     input_port<2>(four_adders[2]),
70                                                     input_port<1>(four_adders[3]),
71                                                     input_port<2>(four_adders[3]));
72 
73         fba_base_type::output_ports_type output_tuple(output_port<0>(four_adders[0]),
74                                                       output_port<0>(four_adders[1]),
75                                                       output_port<0>(four_adders[2]),
76                                                       output_port<0>(four_adders[3]),
77                                                       output_port<1>(four_adders[3] /*CO*/));
78 
79         fba_base_type::set_external_ports(input_tuple, output_tuple);
80     }
81 };
82 
83 #endif /* TBB_examples_logic_sim_fba_H */
84