用幂级数求和的方式进行乘法,带负项的乘法[英] Multiplication by power series summation with negative terms

本文是小编为大家收集整理的关于用幂级数求和的方式进行乘法,带负项的乘法的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

如何计算Verilog中的浮点乘数?到目前为止,我通常使用Shift <<1024,然后浮点数变为整数.然后我进行一些操作,然后>> 1024再次获得分数.

例如0.3545 = 2^-2 + 2^-4 + ...

我对另一种方式有疑问.我不知道负( - )来自何处:

0.46194 = 2^-1-2^-5-2^-7 + 2^-10.

我只是从某人那里看这个.但是,就像您一样,这是像这样的代表

0.46194 = 2^-2 + 2^-3 + 2^-4 + 2^-6 + 2^-7 + 2^-10 + ....

我不明白它是如何知道减去的?

我们怎么知道何时需要它?我还可以申请verilog rtl?

更新:我理解该概念在操作中使用减去.但是,还有其他方法来方程或方法论如何减少表达方式,什么用2?

乘以什么?

更新:我们如何在Verilog中使用此方法?例如,我倾斜了0.46194 = 2^-1-2^-5-2^-7 + 2^-10.然后,此代码是在Verilog中写的. 0.011101101 ='Hed ='D237.因此,问题的重点是我们如何将其应用于Verilog中的应用程序?


更新:先生,您能检查一下吗?有一点差异结果.

0.46194 = 0.011101101.我只是尝试了这样的

0.011101101

0.100T10T01

= 2^-1-2^-4 + 2^-5-2^-7 + 2^-9. = 0.462890625

不同的东西.我错了?

推荐答案

在4位碱基2中可以具有以下值:

Base 2: Unsigned 4 bit integer, 
2^3  2^2  2^1  2^0  
  8    4    2    1 

如果我们有0111代表7.如果我们要使用Shift Add Architecture乘以此数字,则需要3个时钟循环(3个shift and添加).

对此的优化称为 csd(经典签名digit .存在于"二进制数"中.我们将代表-1为一个条或 t ,因为看起来像是一个栏上的一个栏.

100T代表8 - 1,与0111相同.可以观察到,可以用1结束的0替换为1的长跑,而运行的第一个1,并且运行的第一个1变为-1,(t).

.

转换的示例:

00111101111
01000T1000T

,但是如果在两个部分中通过,我们会得到:

00111101111
0011111000T
010000T000T

我们采取了一个数字,该数字将需要8个时钟周期或8个逻辑块来计算并将其变成3.

x precision二进制固定点表示?和 verilog-floating-points-multiplication .

涵盖后续问题:

回答有关您有关CSD转换问题的后续部分.我将它们视为纯整数以简化数字,这与将值乘以2^9(9个分数位)相同.

.

256  128 64 32 16 8 4 2 1
  0    1  1  1  0 1 1 0 1

128 + 64 +32 + 8 +4 +1 => 237

现在使用您的CSD转换:

256  128 64 32 16 8 4 2 1
  1    0  0  T  1 0 T 0 1

256  -32 + 16 - 4 + 1 => 237

您可以看到您的转换是正确的.我得到237* 2^-9为0.462890625,它在转换回分数时与您的答案匹配.您开始使用的0.46194必须是圆形版本,或者量化为9个分数时被截断.此误差称为定量误差.不过,这里最重要的是您正确的CSD转换正确.

其他推荐答案

变量通过常数的乘法通常通过将变量添加到自身的移动版本中来实现.与接受两个变量的乘数电路相比,放在FPGA上要便宜得多.

当常数中有1位序列时,您也可以通过使用减法来获得进一步的节省. (扣除电路仅与加法一样昂贵.)

考虑数字30 = 11110.它等于16 + 8 + 4 + 2,但也等于32-2.

通常,可以通过在最显着的位后添加两个功率,并减去最小显着的位来形成一个乘数1位的序列,或两个连续的功率的总和.因此,而不是16x + ... + 2x,使用32x - 2x.

1位的序列是分数还是整数的一部分,这无关紧要.您只是在其他worsd ∑2^0 ... 2^a = 2^(a+1) - 1中应用身份2^a = 1 + ∑2^0 ... 2^(a-1).

本文地址:https://www.itbaoku.cn/post/2090961.html

问题描述

How can I calculate a floating point multiplicand in Verilog? So far, I usually use shift << 1024 , then floating point number become to integer. Then I do some operations, then >> 1024 to obtain a fraction again.

For example 0.3545 = 2^-2 + 2^-4 + ...

I have question about another way, like this. I don't know where does the minus (-) comes from:

0.46194 = 2^-1 - 2^-5 - 2^-7 + 2^-10.

I have just look this from someone. but as you way, that is represented like this

0.46194 = 2^-2 + 2^-3 + 2^-4 + 2^-6 + 2^-7 + 2^-10 + .... .

I don't understand how does it know the minus is used it?

How do we know when the minus needed to it? Also how can I apply to verilog RTL?

UPDATE : I understand the concept the using minus in operation. But Is there any other way to equation or methodologies what to make reduce expression what multiplying with power of 2?

UPDATE : how can we use this method in verilog? for example, I have leaned 0.46194 = 2^-1 - 2^-5 - 2^-7 + 2^-10. then this code was written like this in verilog. 0.011101101 ='hED = 'd237. So the point of the question is how can we apply it to application in verilog?


UPDATE : Sir Would you please check this one? there are a little difference result.

0.46194 = 0.011101101. I just tried like this

0.011101101

0.100T10T01

= 2^-1 - 2^-4 + 2^-5 - 2^-7 + 2^-9. = 0.462890625

Something different. What do I wrong?

推荐答案

In a 4 bit base 2 number can have these values:

Base 2: Unsigned 4 bit integer, 
2^3  2^2  2^1  2^0  
  8    4    2    1 

If we have a 0111 it represents 7. If we were to multiply by this number using a shift add architecture it would take 3 clockcycles (3 shift and adds).

An optimisation to this is called CSD (Canonical Signed Digit. It allows minus one to be present in the 'binary numbers'. We shall represent -1 as one bar, or T as that looks like a one with a bar over the top.

100T represents 8 - 1 which is the same as 0111. It can be observed that long runs of 1's can be replaced with a the 0 that ends the run becoming 1 and the first 1 of the run becoming a -1, (T).

An example of conversion:

00111101111
01000T1000T

But if passed in two section we would get :

00111101111
0011111000T
010000T000T

We have taken a number that would take 8 clock cycles or 8 blocks of logic to compute and turned it into 3.

Related questions to fixed point values in Verilog x precision binary fixed point representation? and verilog-floating-points-multiplication.

To cover the follow up question:

To answer the follow up section about your question on CSD conversion. I will look at them as pure integers to simplify the numbers, this is the same as multiplying the values by 2^9 (9 fractional bits).

256  128 64 32 16 8 4 2 1
  0    1  1  1  0 1 1 0 1

128 + 64 +32 + 8 +4 +1 => 237

Now with your CSD conversion:

256  128 64 32 16 8 4 2 1
  1    0  0  T  1 0 T 0 1

256  -32 + 16 - 4 + 1 => 237

You can see your conversion was correct. I get 237* 2^-9 as 0.462890625, which matches your answer when converted back to fractional. The 0.46194 that you started with must have been a rounded version, or when quantised to 9 fractional bits gets truncated. This error is known as quantisation error. The most important thing here though is that you got the CSD conversion correct.

其他推荐答案

Multiplication of a variable by a constant is often implemented by adding the variable to shifted versions of itself. This is much cheaper to put on an FPGA than a multiplier circuit accepting two variables.

You can get further savings when there's a sequence of 1-bits in the constant, by using subtraction as well. (A subtraction circuit is only equally expensive as addition.)

Consider the number 30 = 11110. It's equal to 16 + 8 + 4 + 2, but it's also equal to 32 - 2.

In general, a sequence of multiplicand 1-bits, or the sum of several successive powers of two, can be formed by adding the first power of two after the most significant bit, and subtracting the least significant bit. Hence, instead of 16x + ... + 2x, use 32x - 2x.

It doesn't matter if the sequence of 1-bits is part of a fraction or an integer. You're just applying the identity 2^a = 1 + ∑2^0 ... 2^(a-1), in other worsd ∑2^0 ... 2^a = 2^(a+1) - 1.