Logic Synthesis和Minimization才是瓶颈吧?
有人在Verilog里用门写个复杂电路吗?Mostly RTL吧?用C/C++...写个simulator,当然不简单,可是像SystemC那样搞上一堆宏啥的,感觉和nginx这样的异步I/O比较类似。网络仿真好像是个学科。
在Verilog里写个 + , simulator还是用高级语言来做 + ,没大意思啊。如何把它变成很优的门电路才是瓶颈啊。
下了5本书,大量的数学公式,估计一本也看不懂。可能又想岔了: CPU又不是1~2000个变量的逻辑表达式,而是内部分成了许多块,每块单独合成。
Espresso里提到: pla - Format for physical description of Programmable Logic Arrays. This format is used by programs which manipulate plas to describe the physical implementation... What follows then is a description of the AND and OR planes of the pla with one line per product term. 有一种把真值表印在面包板上的感觉。
终极是查表法?:-) python里有程序(读PE文件的pe.py)这么玩:
@lru_cache(maxsize=2048) def cache_adjust_FileAlignment(val, file_alignment): if file_alignment < FILE_ALIGNMENT_HARDCODED_VALUE: return val return (int(val / 0x200)) * 0x200
你只管写函数,如adjust_FileAlignment. 然后用个装饰器lru_cache. 所谓装饰器,就是在被装饰的函数外面包了一层,本例它可以拿到adjust_FileAlignment的输入和输出,它还可以有自己的参数maxsize=2048,然后搞了个Last Recent Used, 表里查不到再去调你的函数。本例不是个好例子,因为被cache的计算很快很简单,但用@装饰好方便。pe.py还decorate了许多别的函数。
窃以为Verilog有痛点,但不算大。通用编程语言竞争激烈,Verilog你不用没得用,它也就懒得改。如果要做simulator,可以先设计个RTL语言,语法基本抄Verilog但简化下,the "compiler"可以把它转换为Verilog, C++或python. 能转换为Verilog,就能最终成为电路。比如:
circuit test { circuit foo (in a,b,c out x,y,z) { @(a) x = a; @(b,c) { x = b + 1; y = b + c; } always { z = 0; } // to be changed } f; circuit bar { ... } b;
wire { f[a:b] - b[e:f] // f的a连b的e... 线很多时方便
}
monitor(f, b[e:f]); // f是f的in和out,还可以f.in, f.out, f[a:c] initial {
with(f) { a = 0 # b = 0 #3 } // initial里用#而不是; #等于#1 f.c = 1 #
} };
土了,Verilog的assgin有这个功能: assign 红LED[5:3] = 开关[0:2]