Hi
阅读NEMU源码时,发现了没见过的结构体成员声明方式,就是这个":",问了gpt并STFW了解这个叫做位域指定(Bitfield)。Bitfiled设计的目的应该是用于节省内存空间,比如对于一个开关类型,只需要考虑0和1两种可能,需要的内存只有1b,但是如果你用int存,就会占用16/32位(具体基于平台),如下,gate, b, c三个变量都会存在一个字节里,提升了内存利用率。(虽然在目前的32位机下,整体结构体还是会占4B(可以考虑用printf+sizeof或者gdb调试)struct oneByte { int gate:1; int b:2; int c:6; }; 当然,考虑到内存访问效率,BItField的使用是基于字节对齐的。struct twoBytes { int gate:1; int b:3; int c:6; }; 结构体中第一个字节前四位(@这里说法可能有BUG,考虑到小端法,这个前四位会是低四位还是高四位呢?)被gate和b占用,后面四位为空,c占用第二个字节的六位。Ref:关于位结构体及
Definition树的结构如下: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */前序遍历 preordervoid printTree(TreeNode* root) { if(root == nullptr) return; ans.push_back(root->val); printTree(
tl; dr先上图卡了一天的bug,一直报错如下:%Warning-LATCH: /home/ghhu/Desktop/study/lab3_nv/vsrc/top.v:35:1: Latch inferred for signal 'top.local_cin' (not all control paths of combinational always assign a value) : ... Suggest use of always_latch for intentional latches 35 | always @(*) begin | ^~~~~~ ... For warning description see https://verilator.org/warn/LATCH?v=5.008 ... Use "/* verilator
在刚接触NVBoard时感到非常棘手,因为不知道怎么配置引脚,也不知道怎么在cpp文件中接入nvboard,后来想到了阅读example项目的makefile,尝试模仿example的项目结构搭建,最后算是顺利完成了~Step 0配置环境,具体见READMEhttps://github.com/NJU-ProjectN/nvboardStep 1创建项目框架. ├── constr │ └── top.nxdc ├── csrc │ └── nvb.cpp ├── makefile └── vsrc ├── MuxKeyInternal.v ├── MuxKey.v ├── MuxKeyWithDefault.v └── top.v 共3个目录(constr, csrc, vsrc),1个makefile文件makefile文件我是直接复制的官方仓库/example/MakefileStep 2编写好.cpp文件,其实就是根据手册上说的:在进入verilator仿真的循环前,先对引脚进行绑定,然后对NVBoard进行初始化在verilator仿真
What Verilator DoesVerilator is invoked with parameters similar to GCC or Synopsys's VCS. It "Verilates" the specified Verilog or SystemVerilog code by reading it, performing lint checks, and optionally inserting assertion checks and coverage-analysis points. It outputs single- or multithreaded .cpp and .h files, the "Verilated" code.These Verilated C++/SystemC files are then compiled by a C++ compiler (gcc/clang/MSVC++), optionally along with a user's own C++/SystemC wrapper file, to instantiat
Genghong Hu