敏捷硬件开发语言Chisel与数字系统设计 课件 第2章 Chisel入门及数据类型_第1页
敏捷硬件开发语言Chisel与数字系统设计 课件 第2章 Chisel入门及数据类型_第2页
敏捷硬件开发语言Chisel与数字系统设计 课件 第2章 Chisel入门及数据类型_第3页
敏捷硬件开发语言Chisel与数字系统设计 课件 第2章 Chisel入门及数据类型_第4页
敏捷硬件开发语言Chisel与数字系统设计 课件 第2章 Chisel入门及数据类型_第5页
已阅读5页,还剩25页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

2.Chisel入门及数据类型西安交通大學XIAN

JIAOTONG

UNIVERSITY一、Chisel

开发环境安装二、Chisel的常见问题三、Chisel的变量与数据类型四

、总结目

录2一

、Chisel

开发环境安装西安交通大學XIANJIAOTONG,t!NIVFRSITY3xjtu-chisel@ubuntu:~$sbt

sbtVersion[info]welcome

to

sbt

1.4.6(Private

Build

Java

1.8.0_275)[info]loadingprojectdefinitionfrom/home/xjtu-chisel/project[info]set

current

project

to

xjtu-chisel

(in

build

file:/home/xjtu-chisel/)

[info]

1.4.61.1安装步骤

Scala的构建

工具安装SBT:安装Git:xjtu-chisel@ubuntu:~$sudo

apt-get

install

git

xjtu-chisel@ubuntu:~$git-versiongitversion

2.25.1Chisel

开发环境安装方便后续项目开发41.1安装步骤安装Verilator:xjtu-chisel@ubuntu:~$sudo

apt-get

install

verilatorxjtu-chisel@ubuntu:~$verilator-versionVerilator

4.0282020-02-06

revv4.026-92-g890cecc1开源高性能Verilog安装g++:

HDL仿真器xjtu-chisel@ubuntu:~$sudoapt-getinstallg++xjtu-chisel@ubuntu:~$g++-Vgcc

version

7.5.0

(Ubuntu

7.5.0-3

ubuntu1~18.04)

V

l用器ator会编译i+eCChisel

开发环境安装51.1安装步骤安装GTKWave:xjtu-chisel@ubuntu:~$sudoapt-get

installgtkwave波形查看器安装Chisel:xjtu-chisel@ubuntu:~$gitclonehttps://github.com/freechipsproject/chisel-template从github上克隆chisel-

template,其自带了Chisel3.4.3,后续项目都是基于

这个工程开发Chisel

开发环境安装6srCotest

-o-

o

scala测试文件和生

成电路的主函数1.2工程文件目录Chisel的设计部分文件Chisel

开发环境安装自定义工程文

件与Chisel互动

的外部文件resourceso

scala

·main

-o-1.2环境测试主工程文件:端口定义packagetestimport

chisel3.class

AND

extends

RawModule{val

io

=I0(

new

Bundle{val

a=Input(UInt(1.W))val

b=Input(UInt(

1.W))val

c=

Output(UInt(1,W))io.c

:=

io.a&

io.6二输入与门逻辑

8Chisel

开发环境安装1.2环境测试生成电路的主函数:I/ANDtest.scalapackage

testimport

chisel3.stage.ChiselGeneratorAnnotationobject

testMain

extends

App{(new

chisel3.stage.ChiselStage).execute(Array"-

-target-

dir","generated/and"

),Seq(ChiselGeneratorAnnotation()=>

new

AND)))Chisel

开发环境安装9module

AND(input

io_a,input

io_b,output

io_cassign

io_c=io_a&io_b;//@[and.scala

11:16]

endmodule对于大规模电路,用生成的Verilog文件在专业EDA工具里仿真。Chisel实现简单电路1.2环境测试生成Verilog文件:10二

、Chisel常见问题西安交通大學XIANJIAOTONG,t!NIVFRSITY112.1常见问题寄宿在Scala里面。转变成Verilog时不会采用不可综合语法。只支持0,1逻辑。自动检测未被驱动的输出型线网或端口。代码包不会被隐式导入。>Chisel

仍在更新中。Chisel

题12三

、Chisel

的变量与数据类型西安交通大學XIANJIAOTONG,t!NIVFRSITY13Chisel的变量与数据类型3.1数据类型长方形是trait,

三角形是object,

椭圆形是class。14构造UInt对

:1.U//字面值为“1”的UInt对象

Oxd.U//字面值为“14”的UInt对象构造SInt对

:-8.S//字面值为“-8”的SInt对象构造UInt,SInt

对象,其实调用了fromtIntToLiteral(1).U的方法,Bool则是fromBooleanToLiteral构造Bool对

:true.B//字面值为“true”的Bool

对象Chisel

的变量与数据类型3.2数据字面量153.3数据宽度默认情况,数据宽度按字面值取最小:1.U

字面值为“1”、宽度为1bit的UInt对象构造指定宽度的对象:1.U(32.W)

字面值为“1”、宽度为32bit的UInt对象

-8.S(32.W)

字面值为“-8”、宽度为32bit的SInt对象取数据的某一位:1.U(31)字面值为“0”、宽度为1bit的UInt对象1.U(0)字面值为“1”、宽度为1bit的UInt对象Chisel

的变量与数据类型16辅助完成子字赋值:class

TestModule

extends

Module{val

io=I0(

new

Bundle

{valin

=Input(UInt(10.W))val

bit=Output(Bool())val

out=Output(UInt(10.W))val

bools=Veclnit(

io.in.asBools)bools(0):=

io.bitio.out

:=

bools.asUInt

17类型转换包括asUInt、asSInt、asBool和asBools:"ha".asUInt(8.W)-1.S(3.W).asUInt、Chisel的变量与数据类型3.4类型转换参数:第一个参数:元素的个数第二个参数:元素的类型与位宽提取向量中某个元素:val

myReg_0=myVec(

0)val

myReg_1=myVec(

1.U)Chisel

的变量与数据类型val

myVec=Wire(Vec(

3,UInt(

32.W))3.5向量定义:183.5向量高级用法一import

chisel3.class

MyVecextends

Module{val

io

=I0(

new

Bundle{val

vecA

=Input(Vec(8,UInt(

8.W))val

uIntB

=Input(UInt(8.W))valoutC

=Output(UInt(16.W))})val

wireA=io.vecA.map(x=>x+

1.U)valwireB

=Wire(Vec(8,UInt(8.W))wireB.foreach(x=>x:=io.uIntB)io.outC:=wireA.reduce(_+&_)+&

wireB.reduce(_+&_)Chisel

的变量与数据类型19for(i=0;i<4;i=i+1)beginsumA[i]=wireA[i*

2]+wireA[i*

2+1];endfor(i=0;i<2;i=i+1)

beginsumA[i+4]=sumA[i*

2]+sumA[i*

2+1];endsumA[6]=sumA[

4]+sumA[5];sumB=ulntB<<

3;outC=sumA[

6]+sumB

;endendmodulemodule

MyVec(input

[63:0]vecA

,input

[7:0]ulntB,outputreg

[15:0

]outC);

reg

[7:0]vecA_t[7:0

];reg

[7:0]wireA

[7:0];reg

[15:0]sumA[

6:0];reg

[15:0]sumB

;integer

i;always@(*)beginfor(i=0;i<8;i=i+1)

beginvecA_t[i]=vecA[i*8+:8];endendalways@(*)beginfor(i=0;i<8;i=i+1)beginwireA[i]=vecA_t[i]+1

;Chisel

的变量与数据类型3.5向量end20高级用法二importchisel3.class

MyMatrixMulextendsModule{valio=IO(

new

Bundle{valmatrixA

=Input(Vec(

8,UInt(8.W))val

matrixB=Input(Vec(8,UInt(8.W))valmulAB

=Output(UInt(

23.W))valmulBA

=Output(Vec(8,Vec〔8,UInt(16.W)〕)})io.mulAB:=(io.matrixA

zip

io.matrixB).map(x=>x.1*

x._2).reduce(_+&_)io.mulBA.map(z=>io.matrixB.map(x=>Z:=io.matrixA.map(y=>

x*y))

21Chisel

的变量与数据类型3.5向量always@(*)beginfor(i=0;i<8;i=i+1)beginmulAB_t[i]=matrixA[i]*matrixB[i];endfor(i=0;i<4;i=i+1)beginmulAB_t1[i]=mulAB_t[i]+mulAB_t[i+4];endfor(i=0;i<2;i=i+1)beginmulAB_t2[i]=mulAB_t1[i]+mulAB_t1[i+2];endmulAB=mulAB_t2[0]+mulAB_t2[1];endalways@(*)beginfor(i=0;i<8;i=i+1)beginfor(j=0;j<8;j=j+1)

beginmulBA[i*128+j*16+:16]=matrixA[j]*matrixB[i];endendendendmodulemodule

MyMatrixMul(input

[63:0]matrixa,input

[63:0

]matrixb,output

reg

[22:0]mulAB

,

output

reg

[1023:0

]mulBAinteger

i,j;reg

[7:0

]matrixA[7:0];reg

[7:0]matrixB

[7:0];reg

[15:0]mulAB_t[7:0];reg

[16:0]mulAB_t1[3:0];reg

[17:0]mulAB_t2[1:0];always@(*)beginfor(i=0;i<8;i=i+1)beginmatrixA[i]=matrixa[i*8+:8];matrixB[i]=matrixb[i*8+:8];endendChisel

的变量与数据类型3.5向量22class

MyModule

extends

Module{val

io=1O(new

Bundle{valin

=Input(UInt(32.W))valout

=Output(UInt(32.W))可以包含向量class

MyBundle

extends

Bundle{

val

foo

=UInt(4.W)val

bar

=Vec(2

,

UInt(4.W))Chisel的变量与数据类型3.5包裹构建端口列表23字段拼接class

MyBundle

extends

Bundle{

val

foo

=UInt(4.W)//高位valbar

=UInt(4.W)/1

低位val

bundle=Wire(new

MyBundle)bundle.foo:=

0xc.Ubundle.bar:=0x3.Uval

uint=bundle.asUlnt

//12*16+3=195wire

[7:0]uint;reg

[3:0]foo

=4'hc;reg[3:0]bar=

4'h3;assignuint={foo,bar};//把foo和bar

拼接成uint。Chisel

的变量与数据类型3.5包裹24完成拼接变量的赋值class

MyBundle

extends

Bundle{

vala=Ulnt(2.W)val

b=Ulnt(

4.W)val

c=UInt(

3.W)val

z=Wire(UInt(

9.W))Z:=...val

unpacked=z.asTypeOf(newMyBundle)unpacked.aunpacked.bunpacked.cwire

[1:0]a

;wire

[3:0]b

;wire

[2:0]c

;wire

[8:0]z=[...]

;

assign

{a,b,c}=z;Chisel的变量与数据类型3.5包裹25Chisel的内建操作符操作符释义

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论