当前位置:网站首页>Understand chisel language thoroughly 04. Chisel Foundation (I) - signal type and constant
Understand chisel language thoroughly 04. Chisel Foundation (I) - signal type and constant
2022-07-04 14:08:00 【github-3rr0r】
Chisel Basics ( One )—— Signal types and constants
At first, it must be an introduction Chisel The basic content of ,《Chisel Basics 》 This part mainly introduces two basic components in digital design : Combinational circuits and triggers . Neither of these basic components is complicated , But together, you can get a large scale 、 It is also a powerful digital circuit .
In the digital logic circuit system , Generally, binary signals are used , That is to say, only two possible values are allowed for a single bit or a single signal , That's what we all know 0 and 1. But in digital design , Some other terms may be used , such as : low (low)/ high (high), false (false)/ really (true), Or set invalid (de-asserted)/ Set valid (asserted). These groups of terms correspond to 0 and 1, But pay attention to the last group de-asserted and asserted, I translate it here as set invalid and set valid , The reason is that in some scenarios, the low level is effective , In some scenarios, high level is effective , So they and 0/1 The corresponding relationship of depends on the specific scenario .
In the first part, let's take a brief look Chisel Signal types and constants in , In the last article, there is also a related introduction , It also includes and Verilog Contrast between .
Three basic signal types
Chisel There are three basic data types to describe signals 、 Combinational logic and registers :Bits
、UInt
and SInt
. among UInt
and SInt
from Bits
Expanded .
These three types are signals / Vector of bits .UInt
Used to represent the bit vector corresponding to an unsigned integer , and SInt
Represents the bit vector corresponding to a signed integer , and Chisel The signed integer encoding method used is Binary complement , I learned this in computer general courses .
Below Chisel The code defines a 8 position Bits
、 One 8 Bit unsigned integer and a 10 Bit signed integer :
Bits(8.W)
UInt(8.W)
SInt(10.W)
The width of these bit vectors is through Chisel Width type Width
To define the , expression n.W
You can put a Scala The integer is converted to a Width
, Then it is used for the definition of bit vector :
n.W
Bits(n.W)
Be careful : Current version Chisel Medium Bits
There is no corresponding operation , So it's of little use to us , Just know there's such a thing .
Chisel Constant
Constants can be used like Width
Define methods to define , Direct use Scala The integer of is converted to Chisel Type is OK :
0.U // Defined a UInt Constant of type 0
-3.S // Defined a SInt Constant of type -3
When defining constants, you can also take the width , Use or Chisel Of Width
type :
3.U(4.W) // A bit width is defined as 4 Of UInt Type constant 3
Maybe you think 3.U
and 4.W
This kind of notation is very strange , Then you can think of it as an integer constant followed by a type . This notation is similar to C、Java and Scala Medium 3L
, Indicates a value of 3 Long integer .
A common problem when defining a specified width constant
We may define a constant with a specified width , Forget the width behind .W
identifier , such as 1.U(32)
. This representation Can't Define a 32 Constant of bit width 1, contrary , expression (32)
Will be interpreted as 1.U
This number is in position 32 Bit extraction on , That is, you will get a single bit constant 0, Obviously, it's not what we expected , Therefore, we must not omit .W
!
Chisel Use other base numbers to represent constants
Chisel It's from Scala Extended ,Scala Type inference in Chisel Benefit a lot , Therefore, the type information in many places can be omitted . This type of inference on bit width also applies ,Chisel It will automatically infer the correct bit width , So from this point of view Chisel Describing hardware circuits is also better than Verilog and VHDL More concise 、 More readable .
For constants in base numbers other than decimal , Constants are defined by strings , Determine the base according to the character at the beginning of the string . among h
It's hexadecimal ,o
It's octal ,b
For binary , The following code uses these three bases to represent constants 255:
"hff".U
"o377".U
"b1111_1111".U
It can be noted that , The above definitions are useless (n.W)
To specify the width , Because this can be omitted ,Chisel The minimum width will be automatically inferred to represent this constant , Here is all 8 position (255 The binary representation of 8 Bit binary number ).
You can also notice ,"b1111_1111"
Underline in , Here is for grouping numbers , Make the code more readable , In the compiler's view, underscores are omitted , such as b_1_1_11_1111
and b11111111
Is equivalent .
Chisel of use ASCII Characters represent constants
ASCII code ( Content of computer general course ) The character of can also be used for Chisel Constant definition of :
val aChar = 'A'.U
The result is UInt<7>(65)
, namely 7 Bit unsigned number 65. Note that strings cannot be used in this way , such as :
val aChar = "AA".U // Incorrect usage
Report error as chisel3.internal.ChiselException: Invalid base A
, That is, for strings ,Chisel The first character will be regarded as the base of a hexadecimal string .
Chisel Logical value in
To represent logical values ,Chisel Types are defined in Bool
.Bool
The value of type can represent a true
perhaps false
Value , Define a Bool
Variables of type can be like this :
Bool()
And constant Bool
Value can be passed Scala The logical value is converted to , Method is xx.B
:
true.B
false.B
边栏推荐
- 2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
- 华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
- 吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
- DGraph: 大规模动态图数据集
- Golang 使用 JSON unmarshal 数字到 interface{} 数字变成 float64 类型(转)
- How to choose a technology stack for web applications in 2022
- 源码编译安装MySQL
- .Net之延迟队列
- Getting started with microservices
- 德明利深交所上市:市值31亿 为李虎与田华夫妻档
猜你喜欢
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
How to choose a technology stack for web applications in 2022
小程序直播 + 电商,想做新零售电商就用它吧!
2022年起重机械指挥考试模拟100题模拟考试平台操作
吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
JVM series - stack and heap, method area day1-2
2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance
Automatic filling of database public fields
源码编译安装MySQL
逆向调试入门-PE结构-资源表07/07
随机推荐
【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
Haproxy high availability solution
软件测试之测试评估
安装Mysql
Deming Lee listed on Shenzhen Stock Exchange: the market value is 3.1 billion, which is the husband and wife of Li Hu and Tian Hua
数据库公共字段自动填充
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
1200. 最小绝对差
Use the default route as the route to the Internet
面试拆解:系统上线后Cpu使用率飙升如何排查?
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
近日小结(非技术文)
JVM series - stack and heap, method area day1-2
Variable promotion and function promotion in JS
Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
MySQL version 8 installation Free Tutorial
Service Mesh的基本模式
自主工业软件的创新与发展
以房抵债能否排除强制执行