在UVM中,我想约束一个数组,以便可以将一个数组中的个数固定为3,我使用了使用$ countones的约束编写了以下代码,但是如何在不使用$ countones的情况下实现呢? ?
import sys
from PyQt5 import QtWidgets, QtCore
from qtconsole.rich_jupyter_widget import RichJupyterWidget
from qtconsole.inprocess import QtInProcessKernelManager
from qtconsole.console_widget import ConsoleWidget
class ConsoleWidget_embed(RichJupyterWidget,ConsoleWidget):
global fit
def __init__(self, customBanner=None, *args, **kwargs):
super(ConsoleWidget_embed, self).__init__(*args, **kwargs)
if customBanner is not None:
self.banner = customBanner
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel(show_banner=True)
self.kernel_manager.kernel.gui = 'qt'
self.kernel = self.kernel_manager.kernel
self.kernel_client = self._kernel_manager.client()
self.kernel_client.start_channels()
def stop():
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
self.guisupport.get_app_qt().exit()
self.exit_requested.connect(stop)
def push_vars(self, variableDict):
"""
Given a dictionary containing name / value pairs, push those variables
to the Jupyter console widget
"""
self.kernel_manager.kernel.shell.push(variableDict)
def clear(self):
"""
Clears the terminal
"""
self._control.clear()
def print_text(self, text):
"""
Prints some plain text to the console
"""
self._append_plain_text(text, before_prompt=True)
def execute_command(self, command):
"""
Execute a command in the frame of the console widget
"""
self._execute(command, False)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
main = ConsoleWidget_embed()
main.show()
sys.exit(app.exec_())
答案 0 :(得分:0)
您写的等同于
constraint three_ones {
int'(array[0]) + int'(array[1]) + int'(array[2]) + ... + int'(array[31]) )
== 3;
}
endclass
要以编程方式执行此操作而没有任何功能,可以创建另一个数组,该数组包含应设置为一个的索引列表。数组的大小就是您要设置的数组的数量。
bit [0:255] array;
int countones = 5;
rand int unsigned bitset[];
constraint c_bits { bitset.size == countones;
foreach(bitset[i]) bitset[i] inside {[0;$bits(array)-1];
unique {bitset};
}
function void post_randomize();
array = 0;
foreach(bitset[i]) array[bitset[i]] = 1'b1;
endfunction
现在有一种方法可以在没有唯一约束且没有post_randomize的情况下进行此操作,但这对我来说是太多的工作。