A trap of SystemVerilog inline constraint

In Constraint Random Verification(CRV), we may write the inline constraint with below format:

 

In most cases,  this works. After be randomized, the value of item.var1 is _something_. But have you ever thought about the result of below codes:

 

You will find that the  both item.var1 is not set to 10, but a random value. Why? This is because the ‘scope’. For inline constraint, it first looks up the var1 in item scope, thus it finds var1. The inline constraint equals to:

 

That means assign the value to itself. So the result is a random value.

To achieve our goal, there are two ways.

First is rename the local variable name from var1 to _var1.

The second is add “local::” contributor before the local variable var1. Shown as below.

 

 

Then the item.var1 will be set to 10 after randomization.

A summary: The priority of the scope in inline constraint is

 

SV DPI Scope

SV的DPI(Directed Program Interface)提供了SV与其他语言(C/C++)通信的桥梁。本文不会讲解DPI的基础知识,只针对Scope这一概念进行解释,因为这是在DPI编程中常遇到的,也是比较难debug的问题。

对于SV呼叫C,不会存在Scope不对找不到对应的C function的问题。但是C呼叫SV,则会碰到这种问题。VCS仿真器会给出如下Log

Error-[DPI-DXFNF] DPI export function not found

The DPI export function/task ‘sv_task’ called from a user/external  C/C++/DPI-C code originated from import DPI function ‘c_main’ at file ‘test.sv'(line 3) is not defined or visible.

Please check the called DPI export function/task is defined in the mentioned which invokes that DPI export function/task is made with ‘context’. Another work-around is using svGetScopeFromName/svSetScope to explicitly set the scope to the module which contains the definition of the DPI export function/task.

Continue reading “SV DPI Scope”

Open Verdi with existed simv

Verdi is a very useful tool in ASIC/SoC verification. We use it to check waveform and debug issues. Usually we use

to open the Verdi GUI. In this way, Verdi will compile the Design and Testbench with the files specified in dut.f and tb.f which may spend much time.

Verdi provides another way to avoid this. First you needs to add “-kdb” option when analyze your design&testbench files, re-compile and build the design&testbench, then you get the “./simv” which is an executable binary file. Now you can use below command to open verdi without re-compiling DUT/TB: Continue reading “Open Verdi with existed simv”

2016,乐乐成长汇报(2)

五月份,是我最焦虑的一个月,我甚至都快要分离出来第二人格了。那段时间,乐乐也一直在忍受着我飘忽不定的坏脾气,加上不能满足她的学习欲望,乐乐变得有些忧郁。

十月份每天带着乐乐去鱼乐贝贝游泳,给了我很好的喘息的机会,也让乐乐满身的力气和探索世界的欲望得到了发泄。乐乐从害怕陌生人,甚至不敢和同龄的小孩子一起玩到后来敢在超市里买自己喜欢的零食,带她出去办事,看到办事窗口有为小朋友准备的糖果,她也敢和窗口的营业员要糖果,整个人都变得阳光、大方、爱笑。虽然现在不能玩游泳,乐乐也并没有变得忧郁阴沉,但是玩鱼乐贝贝给我很好的提示,多让孩子参加体育锻炼,有助于孩子的成长。 Continue reading “2016,乐乐成长汇报(2)”

2016,乐乐成长汇报(1)

很久很久不写博客了,一方面为了更好地陪伴乐乐,一方面,这个网络状况实在很让人担忧。先后使用了移动、电信和联通的宽带,本以为联通的宽带会厚道点,谁知道刚才发现,访问博客的速度已经变得很慢很慢了,估计没多久又要被墙了,感觉非常绝望。

2016,对乐乐来说是非常不平凡的一年。虽说小孩子长得快,每一年都不平凡。不过乐乐在一岁以前是非常省心的,因为太小了,根本不需要太多操心,每天只要喂饱了奶,带着睡好了觉,她就可以自己长大了。一岁以前的孩子和孩子之间基本上看不出来太多差别,不过一岁以后,孩子的个性差异便表现出来了。有的孩子喜闹,有的孩子喜静;有的孩子好动,有的孩子文静…… Continue reading “2016,乐乐成长汇报(1)”

Dynamic constraint using decorator design pattern

During the process of functional verification, we may encounter the problems of narrowing down the constraint to verify some corner cases times again. Usually we will need a children class and write down the constraint in it. If there are lots of corner cases, then we have to maintain lots of children classes. It’s painful and boring work.

And in another case,  we have a class tree with 1 parent class and 4 children classes. If we want to add new constraint to the parent class in some test cases, in traditional way, that means another 4 grandchildren classes with the same constraint block. Continue reading “Dynamic constraint using decorator design pattern”

母女冤家情

都说无仇不成父子,但又何尝不是无怨不成母女?

这是一个很久很久以前的故事,多少百年了吧,我记不清了。那时,我是个大家闺秀,在父母的张罗下,带着贴身小婢女嫁到夫家。夫家自然也是高门大户,只可惜夫君是个纨绔子弟,不事家业,每天寻花问柳。我也不与他闹红脸,毕竟我多年无出,公公婆婆也冷言冷语,我只能勤劳家事,让他们无所挑剔。

然而我千算万算,独独没算到身边还有个小贱人;我日防夜防,缺偏偏家贼难防。我的夫君竟随着这个小贱人进了我的房门上了我的床。在夫家本就活得艰难,平日里就靠着和这个小婢女聊聊心事,缅怀故乡,聊以安慰。谁知事情竟是如此发展,当初千选万选,选了这个看着老实勤恳的小丫鬟,谁知她竟是如此有心机,勾引我的夫君! Continue reading “母女冤家情”

第四章:你还好吗?

看完烟花往回走的时候已经九点多了。山里人睡得早,到处一片漆黑,他们两对情侣,四个人就这样在村里迷了路。别说只有手电那点微弱的光,就算是白天,这样七拐八绕的山里,要轻松找到回去的路也不容易,毕竟那旅馆,他们也才第一天入住。

“看,是那颗星!”荟儿叫了起来,同时手指向南边,“原来到了这里,这颗星的位置也会高一点,在学校看到的时候,这颗星几户就在地平线上。”

“哪颗星?”廷信顺着荟儿指的方向望去,之见满天星斗,因为是在山里,没有城市里灯光的干扰,天上的星星也变多了。 Continue reading “第四章:你还好吗?”

第三章:青坪之旅

“信,你看,这里也能看到那颗星星。”廷信被荟儿轻轻地摇醒。不知道荟儿什么时候醒的,她手指南方,声音中略带几分兴奋,然后她很快又换了消沉的语气接着说,“你说,我们是不是也会像那颗星星那样,摇摇欲坠?大概那颗星星掉落下去的时候,我们也就结束了吧。”

“别瞎想,我们会一直在一起的,就算我家里再怎么反对,我也要娶你。”廷信坚定地说,声音依然那么温柔。他依然没找到荟儿说的那颗星星,一颗摇摇欲坠的星星,应该很容易发现才对,但是不管廷信再怎么找也找不到。 Continue reading “第三章:青坪之旅”