Chisel3 - 运算符和位宽推断

https://mp.weixin.qq.com/s/rI-CJM6GyI6EUHPZ3uYiFg

如同Verilog中的众多运算符,Chisel也针对自身的数据类型,提供了很多运算符。

Chisel语言内嵌于Scala。在Scala中,基本上所有的运算符都被当做一般的字符,可以作为命名符号(identifier)的一部分。并且Scala支持省略函数调用时,括在参数两边的括号。所以Scala中定义运算符重载很简单,可以很大的提高代码的可读性。

1. 运算符

参考链接:

https://github.com/freechipsproject/chisel3/wiki/Builtin-Operators

a. Bitwise operators

??

~ & | ^ 这些其实都是方法名,如:

??

b. Bitwise reductions

??

c. Equality comparison.

??

d. Shifts

??

e. Bitfield manipulation

??

f. Logical Operations

??

g. Arithmetic operations

??

h. Arithmetic comparisons

??

2. 位宽推断

两个相同类型但位宽不同的变量,也可以进行运算。运算参数以及运算结果的位宽会进行自动推断拓展。

参考链接:

https://github.com/freechipsproject/chisel3/wiki/Width-Inference

??

Chisel provides bit width inference to reduce design effort. Users are encouraged to manually specify widths of ports and registers to prevent any surprises, but otherwise unspecified widths will be inferred by the Firrtl compiler.

For all circuit components declared with unspecified widths, the FIRRTL compiler will infer the minimum possible width that maintains the legality of all its incoming connections. Implicit here is that inference is done in a right to left fashion in the sense of an assignment statement in chisel, i.e. from the left hand side from the right hand side. If a component has no incoming connections, and the width is unspecified, then an error is thrown to indicate that the width could not be inferred.

For module input ports with unspecified widths, the inferred width is the minimum possible width that maintains the legality of all incoming connections to all instantiations of the module. The width of a ground-typed multiplexor expression is the maximum of its two corresponding input widths. For multiplexing aggregate-typed expressions, the resulting widths of each leaf subelement is the maximum of its corresponding two input leaf subelement widths. The width of a conditionally valid expression is the width of its input expression. For the full formal description see the Firrtl Spec.

原文地址:https://www.cnblogs.com/wjcdx/p/10053075.html

时间: 2024-07-31 08:29:15

Chisel3 - 运算符和位宽推断的相关文章

FLASH位宽为8、16、32时,CPU与外设之间地址线的连接方法

转 http://blog.csdn.net/linweig/article/details/5556819 flash连接CPU时,根据不同的数据宽度,比如16位的NOR FLASH (A0-A19),处理器的地址线要(A1-A20)左移偏1位.为什么要偏1位? 从软件和CPU的角度而言,一个地址对应一个字节,就是8位数据.这是肯定的,不要怀疑这点. 对于具体器件而言,它的位宽是一定的,所谓位宽,指的是“读/写操作时,最小的数据单元”──别说最小单元是“位”,一般设备上没有单独的“位操作”,修

javascript学习笔记---ECMAScript运算符(位运算符)

位运算符是在数字底层(即表示数字的 32 个数位)进行操作的. 位运算 NOT 位运算 NOT 由否定号(~)表示,它是 ECMAScript 中为数不多的与二进制算术有关的运算符之一. 位运算 NOT 是三步的处理过程: 把运算数转换成 32 位数字 把二进制数转换成它的二进制反码 把二进制数转换成浮点数 例如: var iNum1 = 25; //25 等于 00000000000000000000000000011001 var iNum2 = ~iNum1; //转换为 11111111

MySQL----数据的显示位宽

问题:在MySQL表中的列可以定义它显示的位宽.那么定义了位宽会不会影响数据的取值范围呢? 测试: 1.定义一个用于测试的表 create table t(x int,y int(2),z int(2) zerofill); 2.插入数据以进行测试 insert into t(x,y,z) values(9,9,9); #插入一些在范围内的数据. insert into t(x,y,z) values(100,100,100); #插入超出范围的数据. 3.测试: select * from t

Flash的不同位宽与CPU地址线的接线问题?

一般Flash都有8.16.32等这些不同的位宽,当然说白了就是Flash的数据线位数. 在Flash与CPU的地址线的连接问题时:不同位宽的有不同的连接方法: 一般是:位宽为8时CPU的ADDR0与Flash的A0相连,其他的按顺序依次往下连接: 位宽为16时CPU的ADDR1与Flash的A0相连,其他的按顺序依次往下连接: 位宽为32时CPU的ADDR2与Flash的A0相连,其他的按顺序依次往下连接: 怎么对应起来的呢?    参考博客:http://blog.csdn.net/linw

FPGA位宽的转换和定义

数字表达式的定义<位宽><进制><数字>,这是一种全面的描述方式 例如:如果我要定义一个变量counter = 5000 0000 ,10进制数:那么他的位宽应该是多少了!那就需要知道把10进制数5000 0000 转换成二进制需要多少位可以表示,转换成二进制后为 1011_1110_1011_1100_0010_0000_00 ,一共26位 所以定义counter = 26'd5000_0000 ; 以上为我的一些粗浅认识,希望大家指正.

Verilog中变量位宽注意

Verilog中,变量定义方式可以为:reg[位宽-1:0] 数据名:reg[位宽:1] 数据名.其他变量也类似. 以reg变量cnt为例,当cnt位宽为4时,可定义为reg[3:0] cnt,或者定义为reg[4:1] cnt 当cnt赋值为3时,reg[3:0] cnt:cnt=3 等效为 cnt[3]=0,cnt[2]=0,cnt[1]=1,cnt[0]=1; reg[4:1] cnt:cnt=3 等效为 cnt[4]=0,cnt[3]=0,cnt[2]=1,cnt[1]=1; 当cnt被

poj 1019 Number Sequence 【组合数学+数字x的位宽函数】

题目地址:http://poj.org/problem?id=1019 Number Sequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35680   Accepted: 10287 Description A single positive integer i is given. Write a program to find the digit located in the position i in

运算符_位运算符,其他运算符,赋值运算符,三元运算符,运算符优先级

六. 位运算符PS:在一般的应用中,我们基本上用不到位运算符.虽然,它比较基于底层,性能和速度会非常好,而就是因为比较底层,使用的难度也很大.所以,我们作为选学来对待.位运算符有七种,分别是:位非 NOT(~).位与 AND(&).位或 OR(|).位异或 XOR(^).左移(<<).有符号右移(>>).无符号右移(>>>). var box = ~25; //-26 var box = 25 & 3; //1 var box = 25 | 3;

C++中输出 位宽和小数点后位数 的控制

要用到这个头文件: <iomanip> setw(x) : 表示控制输出x的位宽 setprecision(x) :表示 控制输出小数点后 x 位 cout.precision(x): 表示控制输出的 该数值的5个数字 例如:y=1.0456789 cout.precision(3); cout<<y<<endl; 输出为:1.04 (包含3个数字) #include <iostream> #include <iomanip> using nam