微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 关于除法电路

关于除法电路

时间:11-17 来源:互联网 点击:

除法,这个小学4年纪就开始学习和使用的方法却一直是我这个ASIC工程师心中的痛。我一直在思考如何能找到一个简单(硬件资源少)而快捷(时钟排数少)的通用除法电路。

其实简单的说除法可以用迭代的减法来实现,但是对于硬件,这恐怕要花很多时间。我也一直没有找到实现任意除法的好方法。但是对于某些除数固定的除法还是有一些办法的。

1)最容易想到的就是ROM查找表,但是ROM毕竟不是我们的目标,虽然ROM有时是不错的方法。

2)我开始仔细考虑这个问题是在做264解码时必须要处理QP的问题。这是一个除以6的计算,由于被除数不会大于52(6bit),所以我简化了一个组合逻辑来实现。代码如下:

always@(idata)

begin

case(idata[5:3])

3'b000: begin

oquotient[3:1] = 3'b000;

if (idata[2:1]==2'b11)

begin

oquotient[0] = 1'b1;

end

else

begin

oquotient[0] = 1'b0;

end

end

3'b001: begin

oquotient[3:2] = 2'b00;

if (idata[2]==1'b1)

begin

oquotient[1:0] = 2'b10;

end

else

begin

oquotient[1:0] = 2'b01;

end

end

3'b010: begin

oquotient[3:1] = 3'b001;

if (idata[2:1]!=2'b00)

begin

oquotient[0] = 1'b1;

end

else

begin

oquotient[0] = 1'b0;

end

end

3'b011: begin

oquotient[3:1] = 3'b010;

if (idata[2:1]==2'b11)

begin

oquotient[0] = 1'b1;

end

else

begin

oquotient[0] = 1'b0;

end

end

3'b100: begin

oquotient[3:2] = 2'b01;

if (idata[2]==1'b1)

begin

oquotient[1:0] = 2'b10;

end

else

begin

oquotient[1:0] = 2'b01;

end

end

3'b101: begin

oquotient[3:1] = 3'b011;

if (idata[2:1]!=2'b00)

begin

oquotient[0] = 1'b1;

end

else

begin

oquotient[0] = 1'b0;

end

end

3'b110: begin

oquotient[3:1] = 3'b100;

if (idata[2:1]==2'b11)

begin

oquotient[0] = 1'b1;

end

else

begin

oquotient[0] = 1'b0;

end

end

3'b111: begin

oquotient[3:2] = 2'b10;

if (idata[2]==1'b1)

begin

oquotient[1:0] = 2'b10;

end

else

begin

oquotient[1:0] = 2'b01;

end

end

default: oquotient[3:0] = 4'd0;

endcase

end

//always@(idata)

//begin

// case(idata[3:1])

// 3'b000: rem_temp[1:0] = 2'b00;

// 3'b001: rem_temp[1:0] = 2'b01;

// 3'b010: rem_temp[1:0] = 2'b10;

// 3'b011: rem_temp[1:0] = 2'b00;

// 3'b100: rem_temp[1:0] = 2'b01;

// 3'b101: rem_temp[1:0] = 2'b10;

// 3'b110: rem_temp[1:0] = 2'b00;

// 3'b111: rem_temp[1:0] = 2'b01;

// default:rem_temp[1:0] = 2'b00;

// endcase

//end

//

//always@(idataor rem_temp)

//begin

// oremainder[0] = idata[0];

// case(idata[5:4])

// 2'b00,2'b11: oremainder[2:1] = rem_temp[1:0];

// 2'b01: oremainder[2:1] = {(~(rem_temp[1] | rem_temp[0])),rem_temp[1]};

// 2'b10: oremainder[2:1] = {rem_temp[0],(~(rem_temp[1] | rem_temp[0]))};

// default: oremainder[2:1] = rem_temp[1:0];

// endcase

//end

可见这个逻辑并不是很大,求商的逻辑不过是一个3bit的case里面套一级选择(if),FPGA里不过就是一个ALU。时序也很好,百兆的钟都没有问题。我由此想到了,对于除数固定,被除数有一定范围限制的除法,还是可以用一定简化了逻辑实现的。

3)以下我们讨论的除法就由此先做一个前提的约束:被除数是8bit,除数我们将分别讨论3、5、7、11等质数的情况,其它的和数的除法可以分解成质数。

4) 除数为3(二进制2‘b11)

我最早的想法其实很简单,除

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top