我們?cè)谟胾vm_sequence_library的時(shí)候,會(huì)遇到三種方式往uvm_sequence_library添加sequence,分別是:
- function void add_sequence(uvm_object_wrapper seq_type);
- function void add_typewide_sequence(uvm_object_wrapper seq_type);
- function void add_typewide_sequences(uvm_object_wrapper seq_types[$]);
第2和第3種方式類似,第3種是一下子添加多個(gè)sequence,它內(nèi)部原理就是調(diào)用第2種的函數(shù),因此在本質(zhì)上,只有第1和第2種這兩類區(qū)別。第1種方式是往sequences隊(duì)列里push sequences。第2種方式是往m_typewide_sequences隊(duì)列里push sequences。sequences和m_typewide_sequences的定義如下,它們都是uvm_object_wrapper類型,因此sequence在push的時(shí)候,要采用sequence_name::get_type()的方式加入。
protected uvm_object_wrapper sequences[$];
static protected uvm_object_wrapper m_typewide_sequences[$];
下面分別說(shuō)下兩種push有何不同。
1. add_sequence(uvm_object_wrapper seq_type)
它的代碼如下:
function void add_sequence(uvm_object_wrapper seq_type);
if (m_dyn_check(seq_type))
sequences.push_back(seq_type);
endfunction
可以看出add_sequence(xxx)函數(shù)很簡(jiǎn)單,就是往sequences隊(duì)列里push sequence的uvm_object_wrapper類型。
在m_dyn_check(xxx)函數(shù)里會(huì)檢查push進(jìn)來(lái)的sequence不能是非uvm_sequence_base類型的,且不能重復(fù)。只有都不滿足以上兩者條件,才能被push進(jìn)sequences隊(duì)列里。而且我們根據(jù)sequences隊(duì)列的定義可以看出,它沒(méi)有帶static修飾,也就是說(shuō),uvm_sequence_library例化多份instance的話,它也會(huì)跟著被例化多份,多個(gè)instance里的sequences隊(duì)列互不共享。這一點(diǎn)是和m_typewide_sequences隊(duì)列有著本質(zhì)區(qū)別的。
function bit m_dyn_check(uvm_object_wrapper seq_type);
if (!m_check(seq_type,this))
return 0;
foreach (sequences[i])
if (sequences[i] == seq_type)
return 0;
return 1;
endfunction
m_check(xxx)函數(shù)定義如下,它就是單純的判斷seq_type,如果seq_type是uvm_sequence_base類型的,就返回1,否則返回0。
function bit m_check(uvm_object_wrapper seq_type, this_type lib);
uvm_object obj;
uvm_sequence_base seq;
uvm_root top;
string name;
string typ;
obj = seq_type.create_object();
name = (lib == null) ? type_name : lib.get_full_name();
typ = (lib == null) ? type_name : lib.get_type_name();
top = uvm_root::get();
if (!$cast(seq, obj)) begin
`uvm_error_context("SEQLIB/BAD_SEQ_TYPE",
{"Object '",obj.get_type_name(),
"' is not a sequence. Cannot add to sequence library '",name,
"'"},top)
return 0;
end
return 1;
endfunction
2. add_typewide_sequence(uvm_object_wrapper seq_type)
它的代碼如下:
static function void add_typewide_sequence(uvm_object_wrapper seq_type);
if (m_static_check(seq_type))
m_typewide_sequences.push_back(seq_type);
endfunction
可以看出add_typewide_sequence(xxx)函數(shù)也很簡(jiǎn)單,就是往m_typewide_sequences隊(duì)列里push sequence的uvm_object_wrapper類型。
m_static_check(xxx)函數(shù)和m_dyn_check(xxx)函數(shù)類似,這里面會(huì)檢查push進(jìn)來(lái)的sequence不能是非uvm_sequence_base類型的,且不能重復(fù)。只有都不滿足以上兩者條件,才能被push進(jìn)m_typewide_sequences隊(duì)列里。
function bit m_static_check(uvm_object_wrapper seq_type);
if (!m_check(seq_type,null))
return 0;
foreach (m_typewide_sequences[i])
if (m_typewide_sequences[i] == seq_type)
return 0;
return 1;
endfunction
從m_typewide_sequences隊(duì)列和add_typewide_sequence(xxx)函數(shù)的定義我們可以看出,它們都是static類型的,也就是就算uvm_sequence_library有多份不同的instances,m_typewide_sequences在它們之間是共享的。因此,放在m_typewide_sequences隊(duì)列里的sequences是打算被多個(gè)uvm_sequence_library(包含從它擴(kuò)展出的子類libraries)共享的話,就可以用add_typewide_sequence(xxx)函數(shù)把它們加入到m_typewide_sequences隊(duì)列里。如果要被某個(gè)uvm_sequence_library私自獨(dú)享的話,就需要用add_sequence(xxx)函數(shù)把它們加入到sequences隊(duì)列中。
3. 注意事項(xiàng)
在uvm_sequence_library調(diào)用new(xxx)函數(shù)例化的時(shí)候,會(huì)自動(dòng)調(diào)用init_sequence_library()函數(shù),這個(gè)函數(shù)的定義如下:
function void init_sequence_library();
foreach (this_type::m_typewide_sequences[i])
sequences.push_back(this_type::m_typewide_sequences[i]);
endfunction
init_sequence_library()函數(shù)會(huì)自動(dòng)把m_typewide_sequences隊(duì)列里的內(nèi)容復(fù)制到sequences隊(duì)列里,因?yàn)閡vm_sequence_library隨機(jī)選擇sequence時(shí)看的是sequences隊(duì)列里的sequence。
因此大家要注意的是,如果在uvm_sequence_library例化之前,通過(guò)uvm_sequence_library::add_typewide_sequence(xxx)方式放到m_typewide_sequences隊(duì)列里的sequences會(huì)自動(dòng)也復(fù)制到sequences隊(duì)列里。但如果是在uvm_sequence_library例化之后,才調(diào)用add_typewide_sequence(xxx)方式放到m_typewide_sequences隊(duì)列里的sequences,需要自己再調(diào)用下init_sequence_library()函數(shù)。
下面是一段UVM的例子,selection_mode為UVM_SEQ_LIB_RAND,它會(huì)按平均權(quán)重隨機(jī)在sequences隊(duì)列挑出sequence。
UVM_SEQ_LIB_RAND: begin
valid_rand_selection.constraint_mode(1);
valid_sequence_count.constraint_mode(0);
for (int i=1; i<=sequence_count; i++) begin
if (!randomize(select_rand)) begin
`uvm_error("SEQLIB/RAND_FAIL", "Random sequence selection failed")
break;
end
else begin
wrap = sequences[select_rand];
end
execute(wrap);
end
valid_rand_selection.constraint_mode(0);
valid_sequence_count.constraint_mode(1);
end
下面是另一段UVM的例子,selection_mode為UVM_SEQ_LIB_USER,也是用戶可以自動(dòng)的方式。因此用戶需要select_sequence(xxx)函數(shù)來(lái)完成自己挑選算法。
UVM_SEQ_LIB_USER: begin
for (int i=1; i<=sequence_count; i++) begin
int user_selection;
user_selection = select_sequence(sequences.size()-1);
if (user_selection >= sequences.size()) begin
`uvm_error("SEQLIB/USER_FAIL", "User sequence selection out of range")
wrap = REQ::get_type();
end
else begin
wrap = sequences[user_selection];
end
execute(wrap);
end
end
select_sequence(xxx)函數(shù)定義如下,用戶用systemverilog語(yǔ)法的virtual override就可以實(shí)現(xiàn)自定義挑選sequence的算法了。
function int unsigned select_sequence(int unsigned max);
static int unsigned counter;
select_sequence = counter;
counter++;
if (counter >= max)
counter = 0;
endfunction
-
Verilog
+關(guān)注
關(guān)注
28文章
1343瀏覽量
109925 -
UVM
+關(guān)注
關(guān)注
0文章
181瀏覽量
19121 -
sequence
+關(guān)注
關(guān)注
0文章
23瀏覽量
2828
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論