前にブログで紹介したのですが、SystemVerilog 2012より
soft constraintが追加されます。
SystemVerilog 2012 : soft constraint
しかし、試そうにも Modelsim-ASEはランダム生成は無理だったので、
soft constraintがどういったものかイマイチ分かっていませんでしたが、
「それ、SCVなら出来るよ!」
っていうことです。
1|#include <scv.h>
2|
3|//Valid values for a are 10 or 30
4|class slower : public scv_constraint_base {
5|public:
6| scv_smart_ptr <int> a;
7| SCV_CONSTRAINT_CTOR(slower) {
8| SCV_SOFT_CONSTRAINT(
9| (a() == 10 || a() == 30)
10| );
11| }
12|};
13|
14|//Valid values for a are 20 or 50
15|class new_slower : public slower {
16| SCV_CONSTRAINT_CTOR(new_slower) {
17| SCV_BASE_CONSTRAINT(slower);
18| SCV_CONSTRAINT(
19| (a() == 20 || a() == 50)
20| );
21| }
22|};
23|
24|int sc_main( int argc, char* argv[] ) {
25|
26| slower s_hoge("slower");
27| new_slower n_hoge("new_slower");
28|
29| for (int i=0; i<5; i++) {
30| s_hoge.next();
31| printf( "[SCV] slower data = %d\n", s_hoge.a->read() );
32| }
33| printf("\n");
34| for (int i=0; i<5; i++) {
35| n_hoge.next();
36| printf( "[SCV] new slower data = %d\n", n_hoge.a->read() );
37| }
38|
39| return 0;
40|}
41|
$> ./main
SystemC 2.2.0 --- Jan 15 2012 14:19:56
Copyright (c) 1996-2006 by all Contributors
ALL RIGHTS RESERVED
*** SCV_WARNING: CONSTRAINT_WARNING_IGNORE_SOFT_CONSTRAINT at time 0 s in process
Soft constraints for over-constrained object 'new_slower' will be ignored.
[SCV] slower data = 30
[SCV] slower data = 10
[SCV] slower data = 30
[SCV] slower data = 30
[SCV] slower data = 10
[SCV] new slower data = 20
[SCV] new slower data = 20
[SCV] new slower data = 20
[SCV] new slower data = 50
[SCV] new slower data = 20
確かに、制約が上書きされていることが分かります。
でも、SCVの場合 SCV_BASE_CONSTRAINT書かなければ。。。(ry
ちなみに、相反する制約かけると暴走?します。
ぜひお試しください。