7

Vivado でユーザー定義の物理型の処理をデバッグしているときに (詳細を参照)、実数から整数への型変換の動作が異なることを発見しました。

これが私のコード例です:

library IEEE;
use     IEEE.STD_LOGIC_1164.ALL;
--use     IEEE.MATH_REAL.all;

entity Top_PhysicalTest_Simple is
  port (
    Clock : in STD_LOGIC;
    Input : in STD_LOGIC;
    Output : out STD_LOGIC
  );
end;

architecture top of Top_PhysicalTest_Simple is
  constant int_1     : INTEGER  := natural(0.5);
  constant int_2     : INTEGER  := integer(-0.5);
--  constant int_2     : INTEGER  := natural(-0.5);
begin
  assert FALSE report "16 - int_1 (natural(0.5)):  " & INTEGER'image(int_1) severity note;
  assert FALSE report "17 - int_2 (natural(-0.5)): " & INTEGER'image(int_2) severity note;

  Output <= Input when rising_edge(Clock);
end;

ダミー フリップフロップは、一部のツールが空のデザインについてエラーを出すのを防ぐために使用されます。

XST14.7:

Elaborating entity <Top_PhysicalTest_Simple> (architecture <top>) from library <work>.
Note: "16 - int_1 (natural(0.5)):  1"
Note: "17 - int_2 (natural(-0.5)): 0"

XST はモードの切り上げを使用しているようで、型変換を含む範囲チェックを処理します。したがって、integer(-0.5)代わりに を使用する必要がありますnatural(-0.5)

Vivado 2014.4:

[Synth 8-63] RTL assertion: "16 - int_1 (natural(0.5)):  1" ["D:/Temp/PhysicalTest_Vivado2014.4/vhdl/Top_PhysicalTest_Simple.vhdl":80]
[Synth 8-63] RTL assertion: "17 - int_2 (natural(-0.5)): -1" ["D:/Temp/PhysicalTest_Vivado2014.4/vhdl/Top_PhysicalTest_Simple.vhdl":81]

シンセは無限大に丸めるモードを使用しているようで、範囲チェックなしで型変換を処理します。だから多分natural(..)への単なるエイリアスinteger(..)です。
コメント行:constant int_2 : INTEGER := natural(-0.5);エラーをスローしません。

GHDL 0.29:

GHDL 0.29 は範囲チェックインを行いませんnatural(..)。時代遅れであることはわかっていますが、0.31 は私を嫌っているので、これが既に修正されているかどうかはわかりません。

GHDL 0.31:

後で結果を紹介します。Top_PhysicalTest_Simple.vhdl
:29:14: ファイル std_logic_1164.v93 が変更されたため、再解析する必要がある

私の質問:

  • VHDL は丸めモードを定義しますか? もしそうなら、どれですか?
  • モードが定義されていない場合、丸めをどのように処理すればよいですか?
4

2 に答える 2

8

IEEE Std 1076-2002 セクション 7.3.5「型変換」より

The conversion of a floating point value to an integer type rounds to
the nearest integer; if the value is halfway between two integers,
rounding may be up or down.

他の何かが必要な場合は、 の関数が役立つ可能性IEEE.MATH_REALがあります (特にCEILFLOORおよび/またはTRUNC)。

于 2015-01-07T16:30:03.483 に答える
0

(コメントをインラインで投稿できないため、これを回答として投稿します...)

ビルド済みの ghdl-0.31-mcode-win32 を使用した結果は次のとおりです。

  C:\brian\jobs\ghdl_test\paebbels>md work.ghd

  C:\brian\jobs\ghdl_test\paebbels>ghdl -a --workdir=work.ghd Top_PhysicalTest_Simple.vhd

  C:\brian\jobs\ghdl_test\paebbels>ghdl -r --workdir=work.ghd Top_PhysicalTest_Simple
  Top_PhysicalTest_Simple.vhd:18:3:@0ms:(assertion note): 16 - int_1 (natural(0.5)):  1
  Top_PhysicalTest_Simple.vhd:19:3:@0ms:(assertion note): 17 - int_2 (natural(-0.5)): -1

「0.31 は私の Windows マシン (mcode バージョン) です」 「GHDL は私のコードの解析を拒否します」

0.31 の Windows mcode ビルドでライブラリに問題がある場合は、そのマシンで GHDL の 0.29 以前の NSIS インストーラ バージョンをアンインストールしてみてください。また、0.31 Windows INSTALL、特に reanalyze_libraries.bat で説明されているように、セットアップ プロセス全体を実行したことを確認してください。

上記のテストに使用したバージョンは次のとおりです。

  C:\brian\jobs\ghdl_test\paebbels>ghdl -v
  GHDL 0.31 (20140108) [Dunoon edition] + ghdl-0.31-mcode-win32.patch
  Compiled with GNAT Version: GPL 2013 (20130314)
  mcode code generator
  Written by Tristan Gingold.

  Copyright (C) 2003 - 2014 Tristan Gingold.
  GHDL is free software, covered by the GNU General Public License.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

そしてライブラリパス情報:

  C:\brian\jobs\ghdl_test\paebbels>ghdl --dispconfig
  command line prefix (--PREFIX): (not set)
  environment prefix (GHDL_PREFIX): C:\Ghdl\ghdl-0.31-mcode-win32\lib
  default prefix: C:\Ghdl\ghdl-0.31-mcode-win32\lib
  actual prefix: C:\Ghdl\ghdl-0.31-mcode-win32\lib
  command_name: C:\Ghdl\ghdl-0.31-mcode-win32\bin\ghdl.exe
  default library pathes:
  C:\Ghdl\ghdl-0.31-mcode-win32\lib\v93\std\
  C:\Ghdl\ghdl-0.31-mcode-win32\lib\v93\ieee\
于 2015-01-10T03:05:53.513 に答える