source: trunk/IPs/systemC/processor/Morpheo/Behavioural/Generic/Multiplier/SelfTest/src/test.cpp @ 116

Last change on this file since 116 was 116, checked in by moulu, 15 years ago

1) added a generic multiplier (systemC isn't working with 8bits)
2) added a partial functionnal unit vhdl.

  • Property svn:keywords set to Id
File size: 8.6 KB
Line 
1/*
2 * $Id: test.cpp 116 2009-04-30 13:51:41Z moulu $
3 *
4 * [ Description ]
5 *
6 * Test
7 */
8
9#include "Behavioural/Generic/Multiplier/SelfTest/include/test.h"
10#include "Behavioural/include/Allocation.h"
11#include "Common/include/BitManipulation.h"
12
13void test (string name,
14           morpheo::behavioural::generic::multiplier::Parameters * _param)
15{
16  msg(_("<%s> : Simulation SystemC.\n"),name.c_str());
17
18  if (setlocale (LC_ALL, "") == NULL)
19    msg(_("setlocale ko.\n"));
20
21#ifdef STATISTICS
22  morpheo::behavioural::Parameters_Statistics * _parameters_statistics = new morpheo::behavioural::Parameters_Statistics (5,CYCLE_MAX);
23#endif
24
25  Tusage_t _usage = USE_ALL;
26
27//   _usage = usage_unset(_usage,USE_SYSTEMC              );
28//   _usage = usage_unset(_usage,USE_VHDL                 );
29//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH       );
30//   _usage = usage_unset(_usage,USE_VHDL_TESTBENCH_ASSERT);
31//   _usage = usage_unset(_usage,USE_POSITION             );
32//   _usage = usage_unset(_usage,USE_STATISTICS           );
33//   _usage = usage_unset(_usage,USE_INFORMATION          );
34
35  Multiplier * _Multiplier = new Multiplier
36    (name.c_str(),
37#ifdef STATISTICS
38     _parameters_statistics,
39#endif
40     _param,
41     _usage);
42 
43#ifdef SYSTEMC
44  if (usage_is_set(_usage,USE_SYSTEMC))
45    {
46  /*********************************************************************
47   * Déclarations des signaux
48   *********************************************************************/
49  string rename;
50
51  sc_clock              *  in_CLOCK  = new sc_clock ("clock", 1.0, 0.5);         
52  sc_signal<Tcontrol_t> *  in_NRESET = new sc_signal<Tcontrol_t> ("NRESET");
53
54  sc_signal<Tdata_t   > *  in_MULTIPLIER_DATA_IN_0;
55  sc_signal<Tdata_t   > *  in_MULTIPLIER_DATA_IN_1;
56  sc_signal<Tcontrol_t> *  in_MULTIPLIER_NSTALL   ;
57
58  sc_signal<Tdata_t   > * out_MULTIPLIER_DATA_LSB_OUT;
59  sc_signal<Tdata_t   > * out_MULTIPLIER_DATA_MSB_OUT;
60
61
62  ALLOC0_SC_SIGNAL( in_MULTIPLIER_DATA_IN_0,"in_MULTIPLIER_DATA_IN_0",Tdata_t   );
63  ALLOC0_SC_SIGNAL( in_MULTIPLIER_DATA_IN_1,"in_MULTIPLIER_DATA_IN_1",Tdata_t   );
64  ALLOC0_SC_SIGNAL( in_MULTIPLIER_NSTALL   ,"in_MULTIPLIER_NSTALL   ",Tcontrol_t);
65
66  ALLOC0_SC_SIGNAL(out_MULTIPLIER_DATA_LSB_OUT,"out_MULTIPLIER_DATA_LSB_OUT",Tdata_t   );
67  ALLOC0_SC_SIGNAL(out_MULTIPLIER_DATA_MSB_OUT,"out_MULTIPLIER_DATA_MSB_OUT",Tdata_t   );
68
69  /********************************************************
70   * Instanciation
71   ********************************************************/
72 
73  msg(_("<%s> : Instanciation of _Multiplier.\n"),name.c_str());
74
75  (*(_Multiplier->in_CLOCK))        (*(in_CLOCK));
76  (*(_Multiplier->in_NRESET))       (*(in_NRESET));
77
78  INSTANCE0_SC_SIGNAL(_Multiplier, in_MULTIPLIER_DATA_IN_0);
79  INSTANCE0_SC_SIGNAL(_Multiplier, in_MULTIPLIER_DATA_IN_1);
80  INSTANCE0_SC_SIGNAL(_Multiplier, in_MULTIPLIER_NSTALL);
81
82  INSTANCE0_SC_SIGNAL(_Multiplier,out_MULTIPLIER_DATA_LSB_OUT);
83  INSTANCE0_SC_SIGNAL(_Multiplier,out_MULTIPLIER_DATA_MSB_OUT);
84
85  msg(_("<%s> : Start Simulation ............\n"),name.c_str());
86   
87  Time * _time = new Time();
88
89  /********************************************************
90   * Simulation - Begin
91   ********************************************************/
92
93  // Initialisation
94
95  const uint32_t seed = 0;
96//const uint32_t seed = static_cast<uint32_t>(time(NULL));
97
98  srand(seed);
99
100  SC_START(0);
101  LABEL("Initialisation");
102
103  LABEL("Reset");
104  in_NRESET->write(0);
105  SC_START(5);
106  in_NRESET->write(1); 
107
108  LABEL("Loop of Test");
109
110  for (uint32_t iteration=0; iteration<NB_ITERATION; iteration ++)
111    {
112      LABEL("Iteration %d",iteration);
113     
114      uint64_t data0 = range<uint64_t>(rand(),_param->_size_data);
115      uint64_t data1 = range<uint64_t>(rand(),_param->_size_data);
116     
117      in_MULTIPLIER_DATA_IN_0->write(static_cast<Tdata_t>(data0));
118      in_MULTIPLIER_DATA_IN_1->write(static_cast<Tdata_t>(data1));
119      in_MULTIPLIER_NSTALL->write(static_cast<Tcontrol_t>(1));
120     
121      sc_uint<32> res_lsb = 0;
122      sc_uint<32> res_msb = 0;
123     
124      switch (_param->_size_data)
125        {
126        case 8 :
127          {
128            if (_param->_sign){ // 0 = signed, 1 = unsigned
129              sc_uint<16> mask = 0xff;
130              sc_uint<16> tmp = (static_cast<sc_uint<16> >(data0)) * (static_cast<sc_uint<16> >(data1));
131              res_lsb = tmp.range(7,0);
132              res_msb = tmp.range(15,8);
133            }
134            else{
135              sc_int<8> data_0 = static_cast<sc_int<8> >(data0);
136              sc_int<8> data_1 = static_cast<sc_int<8> >(data1);
137              sc_int<16> tmp   = (static_cast<sc_int<16> >(data_0) * 
138                                  static_cast<sc_int<16> >(data_1));
139              res_lsb = static_cast<Tdata_t>(_param->_mask &  tmp);
140              res_msb = static_cast<Tdata_t>(_param->_mask &  (tmp>>8));
141            }
142            break;
143          }
144        case 16 :
145          {
146            if (_param->_sign){ // 0 = signed, 1 = unsigned
147              sc_uint<32> mask = 0xffff;
148              sc_uint<32> tmp = (static_cast<sc_uint<32> >(data0)) * (static_cast<sc_uint<32> >(data1));
149              res_lsb = tmp.range(15,0);
150              res_msb = tmp.range(31,16);
151            }
152            else{
153              sc_int<16> data_0 = static_cast<sc_int<16> >(data0);
154              sc_int<16> data_1 = static_cast<sc_int<16> >(data1);
155              sc_int<32> tmp    = (static_cast<sc_int<32> >(data_0) * 
156                                   static_cast<sc_int<32> >(data_1));
157              res_lsb = static_cast<Tdata_t>(_param->_mask &  tmp);
158              res_msb = static_cast<Tdata_t>(_param->_mask &  (tmp>>16));
159             
160              cout << "data_0  : " << std::hex << data_0 << std::dec << " - dec : " << data_0<< endl;
161              cout << "data_1  : " << std::hex << data_1 << std::dec << " - dec : " << data_1<< endl;
162              cout << "tmp     : " << std::hex << tmp    << std::dec << " - dec : " << tmp   << endl;
163              cout << "res_lsb : " << std::hex << res_lsb << std::dec << endl;
164              cout << "res_msb : " << std::hex << res_msb << std::dec << endl;
165            }
166            break;
167          }
168        case 32 :
169          {
170            if (_param->_sign){ // 0 = signed, 1 = unsigned
171              sc_uint<32> data_0 = static_cast<sc_uint<32> >(data0);
172              sc_uint<32> data_1 = static_cast<sc_uint<32> >(data1);
173              sc_uint<64> tmp = (data0) * (data1);
174              res_lsb = static_cast<Tdata_t>(_param->_mask &  tmp);
175              res_msb = static_cast<Tdata_t>(_param->_mask &  (tmp>>32));
176
177              cout << "tmp : " << std::hex << tmp << std::dec << endl;
178            }
179            else{
180              sc_int<32> data_0 = static_cast<sc_int<32> >(data0);
181              sc_int<32> data_1 = static_cast<sc_int<32> >(data1);
182              sc_int<64> tmp = (data0) * (data1);
183              res_lsb = static_cast<Tdata_t>(_param->_mask &  tmp);
184              res_msb = static_cast<Tdata_t>(_param->_mask &  (tmp>>32));
185
186              cout << "data_0  : " << std::hex << data_0 << std::dec << endl;
187              cout << "data_1  : " << std::hex << data_1 << std::dec << endl;
188              cout << "tmp     : " << std::hex << tmp << std::dec << endl;
189              cout << "res_lsb : " << std::hex << res_lsb << std::dec << endl;
190              cout << "res_msb : " << std::hex << res_msb << std::dec << endl;
191
192
193            }
194            break;
195          }
196//         case 64 :
197//           {
198//             if (_param->_sign){ 0 = signed, 1 = unsigned
199//               uint64_t tmp = static_cast<uint64_t>(data0) * static_cast<uint64_t>(data1);
200//               res_lsb = tmp;
201//             }
202//             else{
203//               int64_t tmp = static_cast< int64_t>(data0) * static_cast< int64_t>(data1);
204//               res_lsb = 0xffffffffffffffff&tmp;
205//             }
206//             break;
207//           }
208        default :
209          {
210            TEST_KO("Invalid size for the test.");
211          }
212        }
213      SC_START(_param->_latency);
214      TEST(Tdata_t,out_MULTIPLIER_DATA_LSB_OUT->read(),res_lsb);
215      TEST(Tdata_t,out_MULTIPLIER_DATA_MSB_OUT->read(),res_msb);
216
217      SC_START(1);
218    }
219
220  /********************************************************
221   * Simulation - End
222   ********************************************************/
223
224  TEST_OK ("End of Simulation");
225  delete _time;
226
227  msg(_("<%s> : ............ Stop Simulation\n"),name.c_str());
228
229  delete in_CLOCK;
230  delete in_NRESET;
231
232  DELETE0_SC_SIGNAL( in_MULTIPLIER_DATA_IN_0);
233  DELETE0_SC_SIGNAL( in_MULTIPLIER_DATA_IN_1);
234  DELETE0_SC_SIGNAL( in_MULTIPLIER_NSTALL);
235  DELETE0_SC_SIGNAL(out_MULTIPLIER_DATA_LSB_OUT);
236  DELETE0_SC_SIGNAL(out_MULTIPLIER_DATA_MSB_OUT);
237
238    }
239#endif
240
241  delete _Multiplier;
242#ifdef STATISTICS
243  delete _parameters_statistics;
244#endif
245}
Note: See TracBrowser for help on using the repository browser.