如何定义求和结果的宽度? [英] How to define sum result's width?

查看:22
本文介绍了如何定义求和结果的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个无符号的 8 位宽数字需要加/减.下面的例子:

I have few unsigned, 8bits-wide number that i need to add/subtract together. Below the example:

 h_tmp <= signed(r4(calc_cnt - 2) + r4(calc_cnt - 1) + r4(calc_cnt) + 
                                        r4(calc_cnt + 1) + r4(calc_cnt + 2) - 
                                        r2(calc_cnt - 2) - r2(calc_cnt - 1) - r2(calc_cnt) -
                                        r2(calc_cnt + 1) - r2(calc_cnt + 2));

我知道 13 位宽的结果对于我拥有的数字是可以的,所以我将 h_tmp 定义为有符号(12 到 0).现在,合成后我有以下警告

I know that a 13 bit wide result is ok for the numbers that I have, so i defined h_tmp as a signed (12 downto 0). Now, after synthesis I have the following warning

Width mismatch. <h_tmp> has a width of 13 bits but assigned expression is 8-bit wide.

似乎合成器推断出一个 8bits-wide 的计算结果,我做错了什么?

It seems that the synthesiser inferred a 8bits-wide result of the calculation, what have I done incorrectly?

推荐答案

假设加法/减法 (+/-) 是基于 ieee.numeric_std包(或 ieee.std_logic_arithieee.std_logic_unsigned),结果加法/减法的长度是最长参数的长度.

Assuming the addition/subtraction (+/-) is based on the ieee.numeric_std package (or ieee.std_logic_arith and ieee.std_logic_unsigned), the result length of an addition/subtraction is that of the longest argument.

因此,如果加法/减法链中的所有参数都是 8 位长,然后所有的加法都是 8 位的加法/减法,即使通过您分配给 13 位结果.

So if all your arguments in the addition/subtraction chain are 8 bits long, then all the additions are made as 8-bit additions/subtractions, even through you assign to a 13-bit result.

因此,将第一个参数的大小调整为结果的长度,如下面的 ieee.numeric_std 包:

So start the addition/subtraction chain with resize of the first argument to the length of the result, like below for ieee.numeric_std package:

h_tmp <= signed(resize(r4(calc_cnt - 2), h_tmp'length) + r4(calc_cnt - 1) ...

对于 ieee.std_logic_arith 包使用 conv_unsigned.

这篇关于如何定义求和结果的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆