addition.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  addition.cpp --
23
24  Original Author: Rocco Jonack, Synopsys, Inc., 1999-05-12
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38#include "addition.h"
39
40void addition::entry(){
41
42  int             tmp1;
43  sc_bigint<4>    tmp2;
44  sc_biguint<4>   tmp3;
45  sc_bigint<8>    tmp4;
46  sc_biguint<8>   tmp5;
47
48  // reset_loop
49  if (reset.read() == true) {
50    out_valid.write(false);
51    wait();
52  } else wait();
53
54  //
55  // main loop
56  //
57  //
58  while(1) {
59    while(in_valid.read()==false) wait();
60    wait();
61
62    //reading the inputs
63    tmp1 = in_value1.read();
64    tmp2 = in_value2.read();
65    tmp3 = in_value3.read();
66    tmp4 = in_value4.read();
67    tmp5 = in_value5.read();
68
69    //execute simple operations
70    tmp1 = tmp1 + 1;
71    tmp2 = tmp2 + 1;
72    tmp3 = tmp3 + 1;
73    tmp4 = tmp4 + 1;
74    tmp5 = tmp5 + 1;
75    wait();
76
77    // write outputs
78    out_value1.write(tmp1);
79    out_value2.write(tmp2);
80    out_value3.write(tmp3);
81    out_value4.write(tmp4);
82    out_value5.write(tmp5);
83    out_valid.write(true);
84    wait();
85    out_valid.write(false);
86    wait();
87    // execute increment post-operation and write outputs
88    out_value1.write(tmp1++);
89    out_value2.write(tmp2++);
90    out_value3.write(tmp3++);
91    out_value4.write(tmp4++);
92    out_value5.write(tmp5++);
93    out_valid.write(true);
94    wait();
95    out_valid.write(false);
96    wait();
97    // execute increment pre-operation and write outputs
98    out_value1.write(++tmp1);
99    out_value2.write(++tmp2);
100    out_value3.write(++tmp3);
101    out_value4.write(++tmp4);
102    out_value5.write(++tmp5);
103    out_valid.write(true);
104    wait();
105    out_valid.write(false);
106    wait();
107    //execute operations with overflow
108    tmp1 = tmp1 + 254;
109    tmp2 = tmp2 + 254;
110    tmp3 = tmp3 + 254;
111    tmp4 = tmp4 + 254;
112    tmp5 = tmp5 + 254;
113    wait();
114
115    // write outputs
116    out_value1.write(tmp1);
117    out_value2.write(tmp2);
118    out_value3.write(tmp3);
119    out_value4.write(tmp4);
120    out_value5.write(tmp5);
121    out_valid.write(true);
122    wait();
123    out_valid.write(false);
124    wait();
125    //execute operations with self assignment
126    tmp1 += 254;
127    tmp2 += 254;
128    tmp3 += 254;
129    tmp4 += 254;
130    tmp5 += 254;
131    wait();
132
133    // write outputs
134    out_value1.write(tmp1);
135    out_value2.write(tmp2);
136    out_value3.write(tmp3);
137    out_value4.write(tmp4);
138    out_value5.write(tmp5);
139    out_valid.write(true);
140    wait();
141    out_valid.write(false);
142    wait();
143    //execute operations with signed and unsigned mix and mixed bit width
144    tmp1 = (tmp3 + tmp2).to_int();
145    tmp2 = tmp2 + tmp4;
146    tmp3 = tmp3 + tmp5;
147    tmp4 = tmp4 + tmp5;
148    tmp5 = tmp4 + tmp5;
149    wait();
150
151    // write outputs
152    out_value1.write(tmp1);
153    out_value2.write(tmp2);
154    out_value3.write(tmp3);
155    out_value4.write(tmp4);
156    out_value5.write(tmp5);
157    out_valid.write(true);
158    wait();
159    out_valid.write(false);
160    wait();
161  }
162}
163
164// EOF
165
166