如何在 verilog 中获得小数(比如 0.78)的平方和立方?

How to get the square and cube of a fractional number (say 0.78) in verilog?

我是 Verilog/System Verilog 的新手,我想实现小数的平方和立方。考虑以下示例

module test(
  input wire [31:0] input, 
  output reg [63:0] output
);
reg [63:0] temp;
always @ (*) begin
          temp = input*input;
          output <= temp*input;
end
endmodule

所以,当我的 input32'h0_C7AE147hexadecimal 数字系统中的 0.78 使用 32 位表示并假设_ 相当于 Verilog 中的 .)我希望 32'h0_797C3D6output([=16= 中的 0.4745 ]数制)

但我得到 64'hD546_4A9C_ED94_2917

output

另外,如何处理乘法中增加的位大小?

当我们将两个 N位宽的操作数相乘时,我们得到宽度为2N[=37的输出=]-位。当我们将这个 2N 位宽的数字乘以一个 k 位宽的数字时,我们得到宽度为 2N+k 的数字 位宽,此过程继续进行。

你的意思是你想用4位整数部分+28位小数部分来表示32位定点数的小数?为什么输出需要 64 位?

无论如何,我认为每次乘法都需要将乘积向右移动 28 位。

尝试:

temp = input * input >> 28;
output <= temp * input >> 28;

如果您需要适当的舍入,请在每次换档前进行。