当前位置:网站首页>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
边栏推荐
- 使用默认路由作为指向Internet的路由
- Variable promotion and function promotion in JS
- Programmer anxiety
- Unittest框架中引入TestFixture
- Openharmony application development how to create dayu200 previewer
- Ws2811 m is a special circuit for three channel LED drive and control, and the development of color light strip scheme
- 近日小结(非技术文)
- 2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
- MySQL5免安装修改
- 吃透Chisel语言.08.Chisel基础(五)——Wire、Reg和IO,以及如何理解Chisel生成硬件
猜你喜欢
Understanding and difference between viewbinding and databinding
Unittest框架中引入TestFixture
Go 语言入门很简单:Go 实现凯撒密码
2022 Shandong Province safety officer C certificate examination question bank and online simulation examination
1200. Minimum absolute difference
嵌入式编程中五个必探的“潜在错误”
硬件基础知识-二极管基础
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
MySQL version 8 installation Free Tutorial
OpenHarmony应用开发之如何创建DAYU200预览器
随机推荐
易周金融 | Q1保险行业活跃人数8688.67万人 19家支付机构牌照被注销
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
Read excel table data
Unittest框架之断言
动画与过渡效果
基于PaddleX的智能零售柜商品识别
BLOB,TEXT GEOMETRY or JSON column 'xxx' can't have a default value query 问题
华昊中天冲刺科创板:年亏2.8亿拟募资15亿 贝达药业是股东
2022年起重机械指挥考试模拟100题模拟考试平台操作
Fs4056 800mA charging IC domestic fast charging power IC
Basic mode of service mesh
2022G3锅炉水处理考试题模拟考试题库及模拟考试
Whether the loyalty agreement has legal effect
The Secretary of Homeland Security warned immigrants "not to embark on a dangerous journey"
go vendor 项目迁移到 mod 项目
Interview disassembly: how to check the soaring usage of CPU after the system goes online?
吃透Chisel语言.12.Chisel项目构建、运行和测试(四)——Chisel测试之ChiselTest
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
舔狗舔到最后一无所有(状态机)
Worried about "cutting off gas", Germany is revising the energy security law