-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathchecker.cpp
64 lines (60 loc) · 2.06 KB
/
checker.cpp
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
/**
* @file checker.cpp
*/
#include "checker.hpp"
#include "objection.hpp"
#include <cmath>
#include <string>
#include "fpsqrt.hpp"
#include "report.hpp"
using namespace sc_core;
namespace {
char const * const MSGID{ "/Doulos/Example/Modern/Checker_module" };
}
//..............................................................................
Checker_module::Checker_module( sc_module_name instance ) //< Constructor
: sc_module(instance)
{
SC_HAS_PROCESS( Checker_module );
SC_METHOD( received_method );
sensitive << result_port;
dont_initialize();
SC_THREAD( checker_thread );
}
//..............................................................................
void Checker_module::received_method( void ) {
result_fifo.put( result_port->read() );
}
//..............................................................................
void Checker_module::checker_thread( void ) {
const FixedPt_t allowable( 1.0/64.0 );
FixedPt_t expect_value, actual_value, difference;
REPORT( INFO, "Preparing checker" );
for(;;) {
// Is anything expected?
RawData_t v = rawin_port->read();
FixedPt_t expect_value = FP::fpsqrt( v.x()*v.x() + v.y()*v.y() + v.z()*v.z() );
{
Objection verifying{ name() };
// Wait for corresponding result
actual_value = result_fifo.get();
// Compare result to expected
difference = expect_value - actual_value;
if( difference < 0 ) difference = -difference;
if( difference > allowable ) {
REPORT( ERROR, "Expect:" << expect_value.to_string()
<< " Actual:" << actual_value.to_string()
<< " at " << sc_time_stamp() << " FAILURE"
);
++mismatches;
}
++verified_count;
}
}
}
//..............................................................................
void Checker_module::end_of_simulation( void ) {
INFO( ALWAYS, "Verified " << std::to_string( verified_count ) << " transactions\n"
<< "- Found " << std::to_string( mismatches ) << " mismatches\n"
<< "- Objected " << Objection::total() << " times" );
}