aboutsummaryrefslogtreecommitdiffstats
path: root/dot_product/dot_product/dot_product.v9/scverify/scverify_top.cpp
blob: 7d8ace3c82aefc09189e0afb06bb34412b90c02f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
// ----------------------------------------------------------------------------
// SystemC Top Module
//
//    HLS version: 2011a.126 Production Release
//       HLS date: Wed Aug  8 00:52:07 PDT 2012
//  Flow Packages: HDL_Tcl 2008a.1, SCVerify 2009a.1
//
//   Generated by: mg3115@EEWS104A-015
// Generated date: Tue Mar 01 14:54:47 +0000 2016
//
// ----------------------------------------------------------------------------
//---------------------------------------------------
// scverify_top.cpp
//---------------------------------------------------

#include <iostream>
#include "scverify_top.h"
#include <mc_simulator_extensions.h>
// 
// -------------------------------------
// scverify_top
// top module instantiating reference design,
// DUT and comparator
// -------------------------------------
// 
#include <mt19937ar.c>


// ============================================
// Function: setup_debug
// --------------------------------------------

void scverify_top::setup_debug()
{
   #ifdef MC_DEFAULT_TRANSACTOR_LOG
      static int input_a_flags = MC_DEFAULT_TRANSACTOR_LOG;
   #else
      static int input_a_flags = MC_TRANSACTOR_UNDERFLOW | MC_TRANSACTOR_WAIT;
   #endif
      static int input_a_count = -1;
   #ifdef MC_DEFAULT_TRANSACTOR_LOG
      static int input_b_flags = MC_DEFAULT_TRANSACTOR_LOG;
   #else
      static int input_b_flags = MC_TRANSACTOR_UNDERFLOW | MC_TRANSACTOR_WAIT;
   #endif
      static int input_b_count = -1;
   #ifdef MC_DEFAULT_TRANSACTOR_LOG
      static int output_flags = MC_DEFAULT_TRANSACTOR_LOG;
   #else
      static int output_flags = MC_TRANSACTOR_UNDERFLOW | MC_TRANSACTOR_WAIT;
   #endif
      static int output_count = -1;
   
      // At the breakpoint, modify the local variables
      // above to turn on/off different levels of transaction
      // logging for each variable. Available flags are:
      //   MC_TRANSACTOR_EMPTY       - log empty FIFOs (on by default)
      //   MC_TRANSACTOR_UNDERFLOW   - log FIFOs that run empty and then are loaded again (off)
      //   MC_TRANSACTOR_READ        - log all read events
      //   MC_TRANSACTOR_WRITE       - log all write events
      //   MC_TRANSACTOR_LOAD        - log all FIFO load events
      //   MC_TRANSACTOR_DUMP        - log all FIFO dump events
      //   MC_TRANSACTOR_STREAMCNT   - log all streamed port index counter events
      //   MC_TRANSACTOR_WAIT        - log user specified handshake waits
      //   MC_TRANSACTOR_SIZE        - log input FIFO size updates
   
      // In ModelSim, type ccs_extensions::ccs_opts to bring up a GUI to set these options
   
      debug("input_a:326:input_a",input_a_flags,input_a_count);
      debug("input_b:328:input_b",input_b_flags,input_b_count);
      debug("output:329:output",output_flags,output_count);
}
// ============================================
// Function: install_observe_foreign_signals
// --------------------------------------------

void scverify_top::install_observe_foreign_signals()
{
   #if !defined(CCS_DUT_SYSC) && defined(DEADLOCK_DETECTION)
   #if defined(CCS_DUT_CYCLE) || defined(CCS_DUT_RTL)
   #ifdef MTI_SYSTEMC
   #endif
   #ifdef VCS_SYSTEMC
   #if defined(CCS_DUT_VHDL)
   #include <hdl_connect_vhdl.h>
   #define HDL_CONNECT_FN hdl_connect_vhdl
   #else
   #if defined(CCS_DUT_VERILOG)
   #include <hdl_connect_v.h>
   #define HDL_CONNECT_FN hdl_connect_v
   #endif
   #endif
   #endif
   #ifdef NCSC
   #endif
   #endif
   #endif
}
// ============================================
// Function: debug
// --------------------------------------------

void scverify_top::debug(const char *varname, int flags, int count)
{
   sc_module *xlator_p = 0;
   sc_attr_base *debug_attr_p = 0;
   if (strcmp(varname,"input_a:326:input_a") == 0) {
      xlator_p = input_a_transactor;
   }
   if (strcmp(varname,"input_b:328:input_b") == 0) {
      xlator_p = input_b_transactor;
   }
   if (strcmp(varname,"output:329:output") == 0) {
      xlator_p = output_transactor;
   }
   if (xlator_p) {
      debug_attr_p = xlator_p->get_attribute("MC_TRANSACTOR_EVENT");
      if (!debug_attr_p) {
         debug_attr_p = new sc_attribute<int>("MC_TRANSACTOR_EVENT",flags);
         xlator_p->add_attribute(*debug_attr_p);
      }
      ((sc_attribute<int>*)debug_attr_p)->value = flags;
   }
   if (count>=0) {
      debug_attr_p = xlator_p->get_attribute("MC_TRANSACTOR_COUNT");
      if (!debug_attr_p) {
         debug_attr_p = new sc_attribute<int>("MC_TRANSACTOR_COUNT",count);
         xlator_p->add_attribute(*debug_attr_p);
      }
      ((sc_attribute<int>*)debug_attr_p)->value = count;
   }
}
// ---------------------------------------------------------------
// Process: SC_METHOD deadlock_notify
// Static sensitivity: sensitive << deadlock_event;

void scverify_top::deadlock_notify() {
   if (deadlocked.read() == SC_LOGIC_1) {
      testbench_INST->check_results();
      SC_REPORT_ERROR("System","Simulation deadlock detected");
      sc_stop();
   }
}
// ---------------------------------------------------------------
// Process: SC_METHOD deadlock_watch
// Static sensitivity: sensitive  << clk;

void scverify_top::deadlock_watch() {
   // DEADLOCK_WATCH
   #if !defined(CCS_DUT_SYSC) && defined(DEADLOCK_DETECTION)
   #if defined(CCS_DUT_CYCLE) || defined(CCS_DUT_RTL)
   #if defined(MTI_SYSTEMC) || defined(NCSC) || defined(VCS_SYTEMC)
   #endif
   #endif
   #endif
   // DEADLOCK_WATCH END
}
// ---------------------------------------------------------------
// Process: SC_METHOD generate_sync
// Static sensitivity: sensitive << clk << rst;

void scverify_top::generate_sync() {
   static int active_edge = 1;
   static CATMON_EX_TYPE latency = 6LL; // Total Cycles value
   static CATMON_EX_TYPE init_interval = 0LL;
   static CATMON_EX_TYPE csteps = 6LL;
   static CATMON_EX_TYPE duration = latency - csteps + init_interval;
   static CATMON_EX_TYPE latest_write = 5LL;
   static bool top_loop_pipelined = false;
   
   static CATMON_EX_TYPE max_state = init_interval ? duration : latency;
   
   static CATMON_EX_TYPE initial_in_state = ((init_interval>0)&&top_loop_pipelined&&(latency!=csteps)) ? 0 : 1;
   static CATMON_EX_TYPE initial_out_state = init_interval ? init_interval-latest_write+1 : 1;
   
   static int done_flag_used = 0;
   
   
   static CATMON_EX_TYPE in_state = initial_in_state;
   static CATMON_EX_TYPE out_state = initial_out_state;
   static sc_logic last_done = SC_LOGIC_0; // if DONE_FLAG used
   
   if (rst.read() == 1) {
      in_sync.write(SC_LOGIC_0);
      out_sync.write(SC_LOGIC_0);
      inout_sync.write(SC_LOGIC_0);
      catapult_start.write(SC_LOGIC_0);
      in_state = initial_in_state;
      last_done = SC_LOGIC_1;
      if (init_interval) {
         out_state = initial_out_state;
      } else {
         if (done_flag_used && (catapult_done.read() == 0)) wait_for_init = 0;
         out_state = initial_out_state;
      }
   } else {
     if (done_flag_used) {
         catapult_start.write(catapult_done.read()); // start follows done timing
         if (catapult_done.read() == SC_LOGIC_0) {
            // falling edge of done, deassert start
            wait_for_init.write(wait_for_init.read()+1);
            out_sync.write(SC_LOGIC_0);
            in_sync.write(SC_LOGIC_0);
            inout_sync.write(SC_LOGIC_0);
         } else {
            // rising edge of done, assert sync signals
            if (wait_for_init.read() > 1) {
               out_sync.write(SC_LOGIC_1);
               in_sync.write(SC_LOGIC_1);
               inout_sync.write(SC_LOGIC_1);
            }
         }
     } else {
      if ( clk.read() == active_edge ) {
         // wait for static array initialization loop to complete
         if (wait_for_init) {
            if (done_flag_used && (catapult_done.read() == 1)) wait_for_init = false;
         } else {
            if (((out_state >= max_state) && (init_interval || !done_flag_used)) || (done_flag_used && ((catapult_done.read() == 1) && (last_done == SC_LOGIC_0)))) {
               out_sync.write(SC_LOGIC_1);
               inout_sync.write(SC_LOGIC_1);
               out_state = 0;
               if (!init_interval) last_done = SC_LOGIC_1;
               if (init_interval == 0) in_state = max_state; // force in_sync to align with out_sync
            } else {
               if ( (init_interval == 0) && (catapult_done.read() == 0) && (last_done == SC_LOGIC_1) ) last_done = SC_LOGIC_0;
               out_sync.write(SC_LOGIC_0);
               inout_sync.write(SC_LOGIC_0);
            }
            out_state++;
         } // if (wait_for_init)
      } // if (clk.read() == active_edge)
   
      if ( clk.read() == active_edge ) {
         // wait for static array initialization loop to complete
         if (wait_for_init) {
            if (done_flag_used && (catapult_done.read() == 1)) wait_for_init = false;
         } else {
            if ( in_state >= max_state ) {
               in_sync.write(SC_LOGIC_1);
               inout_sync.write(SC_LOGIC_1);
               catapult_start.write(SC_LOGIC_1);
               in_state = 0;
            } else {
               if ( in_state == 1 ) {
                  catapult_start.write(SC_LOGIC_1);
               }
               in_sync.write(SC_LOGIC_0);
               inout_sync.write(SC_LOGIC_0);
               catapult_start.write(SC_LOGIC_0);
            }
            in_state++;
         }
      }
     } // if (done_flag_used)
   }
}
// ---------------------------------------------------------------
// Process: SC_METHOD generate_reset
// Static sensitivity: sensitive << reset_deactivation_event;

void scverify_top::generate_reset() {
      static bool first = true;
      if (first || sc_time_stamp() == SC_ZERO_TIME)
      {
         setup_debug();
         first = false;
         rst.write(SC_LOGIC_1);
         reset_deactivation_event.notify(40.0, SC_NS);
         TLS_en.write(SC_LOGIC_1);
      } else {
         input_a_transactor->reset_streams();
         input_b_transactor->reset_streams();
         output_transactor->reset_streams();
         rst.write(SC_LOGIC_0);
      }
   
}
#if defined(MC_SIMULATOR_OSCI) || defined(MC_SIMULATOR_VCS)
int sc_main(int argc, char *argv[])
{
   sc_report_handler::set_actions("/IEEE_Std_1666/deprecated", SC_DO_NOTHING);
   scverify_top scverify_top("scverify_top");
   sc_start();
   return scverify_top.testbench_INST->failed();
}
#else
MC_MODULE_EXPORT(scverify_top);
#endif