【问题标题】:VHDL : Library requiredVHDL:需要库
【发布时间】:2012-10-05 08:02:14
【问题描述】:

我生成了随机浮点数(十进制格式)并将它们保存在一个文本文件中。我编写了一个代码来用 VHDL 读取该文件。现在我想将这些浮点数转换为 IEEE 格式(32 bir 或 64 位)。是否有任何可用的图书馆可以用于我的工作。 还是有VHDL代码?

谢谢

【问题讨论】:

    标签: floating-point vhdl ieee-754


    【解决方案1】:

    您可以通过纯软件脚本将浮点数转换为 IEEE 754(例如 1.0 -> 0x3F800000):

    1. matlab 脚本:

      将实数转换为 IEEE 754 浮点格式的数字的 Matlab 程序 http://users.eecs.northwestern.edu/~ismail/courses/c92/fpu/

    2. lisp 脚本:http://common-lisp.net/project/ieee-floats/

      使用 ieee-floats 中定义的 encode-float32,可以快速转换。

      (defun fix2float (fp)
           (format t "~%~x~T~x" fp (ieee-floats:encode-float32 fp)))
       (fix2float 1.1)
      

    至于硬件库,Vfloat(王晓军,2010)值得一试。

    【讨论】:

      【解决方案2】:

      有一个VHDL浮点包:

      http://vhdl.org/fphdl/index.html

      【讨论】:

        【解决方案3】:

        如果您想在 VHDL 中使用随机数,为什么不使用 *math_real* 库中的 UNIFORM 函数? Uniform 是你的函数,用法在定义中解释

        procedure UNIFORM (variable Seed1,Seed2:inout integer; variable X:out real);
            -- returns a pseudo-random number with uniform distribution in the 
            -- interval (0.0, 1.0).
            -- Before the first call to UNIFORM, the seed values (Seed1, Seed2) must
            -- be initialized to values in the range [1, 2147483562] and 
            -- [1, 2147483398] respectively.  The seed values are modified after 
            -- each call to UNIFORM.
            -- This random number generator is portable for 32-bit computers, and
            -- it has period ~2.30584*(10**18) for each set of seed values.
            --
            -- For VHDL-1992, the seeds will be global variables, functions to 
            -- initialize their values (INIT_SEED) will be provided, and the UNIFORM
            -- procedure call will be modified accordingly.  
        

        如果这不是您需要的,请使用 *std_textio* 包读取数据:

        procedure READ(L:inout LINE; VALUE: out real; GOOD : out BOOLEAN);
        procedure READ(L:inout LINE; VALUE: out real);
        

        【讨论】:

        • 感谢 BennyBarns。问题不在于读取文件。我已经这样做了。现在我想将这些浮点数转换为 IEEE 格式。我应该使用图书馆吗?
        • 那么你应该更精确而不是投票否决答案。所以你的意思是IEEE 754?我以为你在谈论 ieee.std_logic_1164!在这种情况下,您将为 754 操作使用某种块集,它应该提供转换......我记得 Synplicity 确实可以
        • 假设我生成了一个文本文件,其中浮点数就像这样 1.9832, 0.211, -1.12 我用 VHDL 编写了可以读取的代码。现在我想将这些数字转换为 IEEE-754(32 位格式)。为此,我需要哪个库。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-03
        相关资源
        最近更新 更多