关于Verilog中begin-end & fork-join
转载:http://blog.sina.com.cn/s/blog_6c7b6f030101cpgt.html
begin-end and fork-join are used to combine a group of statements in a single block. General syntax with begin-end is as follows:
type_of_block @(sensitivity_list)
begin: group_name
local_variable_declarations;
statements;
end
type_of_block may be initial or always. sensitivity_list is optional and possible only in always block. You are knowing about initial and always block in the previous chapter.
Sensitivity list is used to model sequential or combinational logic. To make it more clear, observe these examples:
module comb(a, b, c);
input c;
input b;
output a;
reg a;
always @( c or b)
begin
a = c & b;
end
endmodule
module seq(a, b, c);
output a;
input b;
input c;
reg a;
always @( posedge c)
begin
a <= b;
end
endmodule
In the left hand side example, whenever c or b changes, a will become c & b. So it is combinational logic, represents and gate. Note that actual hardware register won't be implemented while synthesizing in the left-hand side example, even though it is declared as the type reg. Right hand side example will be synthesized as D-type Flip-flop since b will be assigned to a when ever c goes high. Difference between "=" and "<=" is explained in the next chapter. These codes can be represented in the form of circuits as shown below.
Output of module comb
Output of the module seq
Inside an initial or always block, we can group statements using begin--end or fork--join. begin--endgroups two or more statements together sequentially, so that statements are evaluated in the order they are listed. Each timing control is relative to the previous statement. fork--join groups two or more statements together in parallel, so that all statements are evaluated concurrently. Each timing control is absolute to when the group started.
These are some examples to understand how begin--end and fork--join executes.
module forkjoin(clk, a, b);
input clk;
output a;
output b;
reg a, b;
initial
begin
a = 0;
b = 0;
end
always @(posedge clk)
fork
#2 a = 1;
#1 b = 1;
join
endmodule
module forkjoin1(clk, a, b);
input clk;
output a;
output b;
reg a, b;
initial
begin
a = 0;
b = 0;
end
always @(posedge clk)
fork
#2 a = 1;
#1 b = a;
join
endmodule
Output of forkjoin ^
Output of forkjoin1 ^
module beginend(clk, a, b);
input clk;
output a;
output b;
reg a, b;
initial
begin
a = 0;
b = 0;
end
always @(posedge clk)
begin
#2 a = 1;
#1 b = a;
end
endmodule
Output of beginend ^
From these examples, you can understand the execution.
We can nest begin--end and fork--join. That is, inside a begin--end we can have fork--join and inside fork--join we can have begin--end. Consider these codes to find out how nested begin--end and fork--join works.
module nesting1(clk, a, b, c, d, e, f);
input clk;
output a, b, c, d, e, f;
reg a, b, c, d, e, f;
initial
begin
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
end
always @(posedge clk)
fork
#2 a = 1;
#2 b = 1;
begin
#2 c = 1;
#2 d = 1;
#2 e = 1;
end
#2 f = 1;
join
endmodule
and here is the output: You can notice that a, b, c and f became high 2 ns after the clock, d 2ns after c and e 2ns after d.
module nesting2(clk, a, b, c, d, e, f);
input clk;
output a, b, c, d, e, f;
reg a, b, c, d, e, f;
initial
begin
a = 0;
b = 0;
c = 0;
d = 0;
e = 0;
f = 0;
end
always @(posedge clk)
begin
#2 a = 1;
#2 b = 1;
fork
#2 c = 1;
#2 d = 1;
#2 e = 1;
join
#2 f = 1;
end
endmodule
Output wave of the above code is here. Notice that a, b and c became 1 with 2ns delay in-between, d and e became 1 together with c, after that f with 2 ns delay.
Program control will come out of the fork--join block when all the statements finishes executing. in the case of code bellow, control will come out of block after 30ns.
fork
#20 c = 1;
#30 d = 1;
#10 e = 1;
join
关于Verilog中begin-end & fork-join的更多相关文章
- java并发编程(10)Fork/Join
Fork/Join JAVA7中出现的Fork/Join,类似于分布式文件系统hadoop的mapreduce思想,就是将任务分割,再分割,直到分割到满足条件 为了便于理解:编程逻辑可以借用 递归的思 ...
- Fork/Join框架与Java8 Stream API 之并行流的速度比较
Fork/Join 框架有特定的ExecutorService和线程池构成.ExecutorService可以运行任务,并且这个任务会被分解成较小的任务,它们从线程池中被fork(被不同的线程执行)出 ...
- 013-多线程-基础-Fork/Join框架、parallelStream讲解
一.概述 Fork/Join框架是Java7提供了的一个用于并行执行任务的框架, 是一个把大任务分割成若干个小任务,最终汇总每个小任务结果后得到大任务结果的框架. 它同ThreadPoolExecut ...
- JAVA中的Fork/Join框架
看了下Java Tutorials中的fork/join章节,整理下. 什么是fork/join框架 fork/join框架是ExecutorService接口的一个实现,可以帮助开发人员充分利用多核 ...
- java 中的fork join框架
文章目录 ForkJoinPool ForkJoinWorkerThread ForkJoinTask 在ForkJoinPool中提交Task java 中的fork join框架 fork joi ...
- 关于verilog中语句可不可综合
1)所有综合工具都支持的结构:always,assign,begin,end,case,wire,tri,aupply0,supply1,reg,integer,default,for,functio ...
- Fork/Join 型线程池与 Work-Stealing 算法
JDK 1.7 时,标准类库添加了 ForkJoinPool,作为对 Fork/Join 型线程池的实现.Fork 在英文中有 分叉 的意思,而 Join 有 合并 的意思.ForkJoinPool ...
- 并发编程之Fork/Join
并发与并行 并发:多个进程交替执行. 并行:多个进程同时进行,不存在线程的上下文切换. 并发与并行的目的都是使CPU的利用率达到最大.Fork/Join就是为了尽可能提高硬件的使用率而应运而生的. 计 ...
- fork/join并发编程
Fork & Join 的具体含义 Fork 一词的原始含义是吃饭用的叉子,也有分叉的意思.在Linux 平台中,函数 fork()用来创建子进程,使得系统进程可以多一个执行分支.在 Java ...
- 多线程高并发编程(8) -- Fork/Join源码分析
一.概念 Fork/Join就是将一个大任务分解(fork)成许多个独立的小任务,然后多线程并行去处理这些小任务,每个小任务处理完得到结果再进行合并(join)得到最终的结果. 流程:任务继承Recu ...
随机推荐
- 2019清明期间qbxt培训qwq
4.4上午:数学基础 (qwq整成word和cpp了,它居然不能直接把文档附上来) part 1:高精度运算 高精加和高精减就不说了,之前写过博客了qwq,讲一讲高精乘和高精除吧. 1.高精度乘法(不 ...
- activiti 快速入门--组任务(candidate users)分配(6)
http://blog.csdn.net/u011320740/article/details/53018040
- python 利用selectors实现异步I/O
它的功能与linux的epoll,还是select模块,poll等类似:实现高效的I/O multiplexing, 常用于非阻塞的socket的编程中: 简单介绍一下这个模块,更多内容查看 pyt ...
- Eclipse+Spring boot开发教程
一.安装 其实spring boot官方已经提供了用于开发spring boot的定制版eclipse(STS,Spring Tool Suite)直接下载使用即可,但考虑到可能有些小伙伴不想又多装个 ...
- 拒绝服务(DoS)理解、防御与实现
一.说明 我一直不明白为什么拒绝服务,初学着喜欢拿来装逼.媒体喜欢吹得神乎其神.公司招聘也喜欢拿来做标准,因为我觉得拒绝服务和社会工程学就是最名不副实的两样东西.当然由于自己不明确拒绝服务在代码上是怎 ...
- Win10系列:C#应用控件基础21
ListView控件 ListView控件的常用方式是与后台数据进行绑定,并将所绑定的数据内容与前端界面布局相结合,按照特定的顺序将数据集合以列表形式展示在界面当中,如电子邮件列表或搜索结果列表等. ...
- 防止asp马后门
好多朋友都拿的有webshell吧,基本上都加了密的... 可是,没见到源码,很难测试它到底有没有后门, 指不定给别人打工了... 下面贴种很简单的方法,大家别扔蛋哈 (asp的哦) 在代码的最 ...
- python全栈开发笔记----基本数据类型---列表List
#list 是 类 ,列表 序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第一个索引是0,第二个索引是1,依此类推. Python有6个序列的内置类型,但 ...
- oracle监控资源管理器
资源管理器的配置在一组dba视图显示,主要是如下视图: dba_rsrc_plans 显示计划和状态. dba_rsrc_plan_directives 显示计划指令 dba_rsrc_consume ...
- mac搭配Nginx服务器常见问题
推流服务器主要是使用了开源的nginx和rtmp模块,网上也有很多资料,不过对有些可能出现的问题没有很好的总结. 安装brew 使用Mac进行开发很久的老司机应该对这个工具很熟悉了.brew是一个第三 ...