Rule90

这篇博客探讨了一种简化版的top_module设计,通过使用向量操作将511位数据的异或逻辑合并为单个操作,提高了时钟周期内的效率。作者对比了自己复杂的实现和官方推荐的简洁方法,并解释了如何利用部分选择和串联操作来减少组合逻辑复杂度。
摘要由CSDN通过智能技术生成

在这里插入图片描述

module top_module(
    input clk,
    input load,
    input [511:0] data,
    output [511:0] q ); 
    
    reg [511:0] q_last;
  
    always @(posedge clk)
        begin
            if(load)
                q <= data;
            else
                q <= q_last;
         end
    //组合逻辑构建下一个q
    genvar i;
    generate
        for(i=0; i<=511; i++)
            begin: my_block_name
                if(i==0)
                    assign q_last[i] = q[1]^0;
                else
                    if(i == 511)
                        assign q_last[511] = q[510]^0;
                	else
                        assign q_last[i] = q[i+1]^q[i-1];
            end
    endgenerate
                
endmodule

看了下参考答案,自己做的比较复杂,没有运用vecto思想;在此贴上官方的参考答案

module top_module(
	input clk,
	input load,
	input [511:0] data,
	output reg [511:0] q);
	
	always @(posedge clk) begin
		if (load)
			q <= data;	// Load the DFFs with a value.
		else begin
			// At each clock, the DFF storing each bit position becomes the XOR of its left neighbour
			// and its right neighbour. Since the operation is the same for every
			// bit position, it can be written as a single operation on vectors.
			// The shifts are accomplished using part select and concatenation operators.
			
			//     left           right
			//  neighbour       neighbour
			q <= q[511:1] ^ {q[510:0], 1'b0} ;
		end
	end
endmodule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值