LRM読解(Chap.5 Scheduling semantics)

2008/09/16Verilog::文法import

LRM 5. スケジューリング意味論?(Scheduling semantics)

5.1 モデルの実行(Execution of a model)

本章では,エレメント間の振る舞いを示す.特にイベントスケジューリングと実行について.
Verilog-HDLの処理構造は,ブロックやプロセスの並列実行にあります.
そのため,処理順序の決定方法等をユーザに明確に示す必要があります.が,simulator依存です,といっているみたい...?(勝手な意訳)




5.2 イベントシミュレーション(Event simulation)

1つのデザインは,接続された実行またはプロセスのスレッドから成る.

プロセスは,以下の特徴を持つobjectである.

  • 評価されることができる
  • ステート(状態)を持てる
  • 入力の変化に対して出力を出すことができる

また,プロセスは以下を含む:

  • primitives
  • modules
  • initial procedural blocks
  • always procedural blocks
  • continuous assignments
  • asynchronous tasks
  • procedural assignment statements

命名されたイベントと同様にシミュレートされる回路の NETや変数の値の変化がアップデートイベントであると考えられます。
(自力:シミュレーション対象の回路内の,全てのnetや変数の値の変化は,update eventを考慮している.(excite翻訳のほうが正しそうだな..)プロセスは、イベントをアップデートするために敏感(sensitive)です。
アップデートイベントが実行されるとき、そのイベントに敏感なすべてのプロセスが任意のオーダーで評価されます。
また、プロセスの評価は,evaluation eventとして知られているイベントです。

イベントに加えて、シミュレータの別のキーは時間です。
"simulation time"は、それがシミュレートされる回路にかかる実際の時間をモデル化するためにシミュレータによって保持された時間の値を参照するために使用されます。

この章では,"time"は,シミュレーション時間と共に互換性を持って使用されます。(おなじっちゅうこっちゃ?)


イベントは,異なる時間に起こりえます.
イベントの動向(track)をおさえて、それらが正しいオーダーで処理されるのを確実にするために、イベントは,要求された"simulation time"まで,イベント待ち行列に保たれます。(意訳)
イベントを待ち行列(queue)に置くのは,"scheduling an event"と呼ばれます。

In order to keep track of the events and to make sure they are processed in the correct order,
the events are kept on an event queue, ordered by simulation time.



5.3 階層状のイベント待ち行列(The stratified event queue)

表形式で順序,トリガを引くやつ,負荷情報を記載すると良い.Verilogイベントキューは,論理的に5つの異なる領域に分割されています.イベントは5つのどの領域にも追加できますが,削除はアクティブな領域からのみ可能です.

event name remark
active現在の"simulation time"で起きた,順不同に処理ができる*1イベント
inactive現在の"simulation time"で起きたが,activeイベントのあとに処理ができるイベント
non blocking assign update以前の"simulation time"で評価されたが,現在の"simulation time"でassignedされるイベント.active/inactive処理は先.
monitor上の3つのイベントが終わってから処理されるイベント
future未来の"simulation time"で起こるイベント."future inactive events"と"future non blocking assignment update events"に分けられる.

※処理優先度は上位から.

すべてのアクティブなイベント処理は,"simulation cycle"と呼ばれます.
即時処理のためのあらゆるアクティブなイベントを選ぶ自由度は,Verilog HDLの「非-決定論」の不可欠の源です。
明白なゼロ遅延(#0記述)が、processの中断と,現在時刻のinactive eventとして加えられることを要求します.
そのため,processは,現在の時刻の次のシミュレーションサイクルに再開されます.

ノンブロッキング代入(9.2.2参照)は,現在または後のシミュレーション時刻にスケジューリングされた,ノンブロッキング代入更新イベントを作り出します.
$monitorと$strobeのシステムタスク(17.1参照)は,各々の引数のためにモニタイベントを作成します.
これらのイベントはあらゆる連続した時間間隔で,絶え間なく再始動(be re-enabled)にされます.
モニターイベントは,いかなる他のイベントも引き起こすことができないので,独立です.
tf_synchronize() (25.58参照) や vpi_register_cb(cb_readwrite) (27.33参照)のようなPLI関数によってスケジューリングされたcall back proceduresは,inactiveイベントとして扱われるものとします.




5.4 Verilogシミュレーションのリファレンスモデル(The Verilog simulation reference model)

前節までのまとめで,事例を示す.簡単なイベント処理フローを示し,その説明を補足している.シミュレータを作る方,HDL記述をどのように解釈されるのかを理解するのに有用であろう.

5.4.1 Determinism

begin-end blockを1単位として,イベントqueで処理の停止/再開を行う.ノンブロッキング代入で,代入先が同じ変数の場合,記述順に"ノンブロッキング代入イベント"が生成され,queueに入る.したがって,イベント処理時には,一瞬前の値が入るが,最終的には最後に記述している値を保持することになる.


5.4.2 Nondeterminism

非決定の一例は, active eventがqueueから取り出され,あらゆるオーダで実行されることにより発生する.
ビヘイビアブロック内の,時間制御制約の無い命令文が,1つのイベントで実行してはならないときに生じる(意訳)
時間制御(命令)文は,#式・@式構文である(9.7参照)
ビヘイビア文を評価しいている全ての時には,シミュレータは実行を停止し,イベントキュー上のペンディングしているactive eventのような完了したイベントをおき続けるべきである.(意訳:キューの話が意味を取り違えているかもしれない.)
この効果は,プロセス実行のインタリーブを可能にする.インタリーブ実行の順序は,非決定論者的で,ユーザ制御下にはない.




5.5 レースコンディション(Race conditions)

式評価や,ネット更新イベントの実行は,混ぜられるので,レースコンディションが起こりえる.

assign p = q;
initial begin
     q = 1;
  #1 q = 0;
     $display(p);
end

シミュレータは,1か0を表示することは正しい.
qに対する0代入は,pに対する更新イベントを有効にする.
シミュレータは,連続して,$displayタスクを実行するか,$displayタスクが後に続いたpのための更新を実行するでしょう.




5.6 Scheduling implication of assignments

代入は,以下のようにプロセスとイベントに変換される.

5.6.1 連続代入文(Continuous assignment)

連続代入文(6章参照)は,プロセスと式中のソース要素の感度(sensitive)に対応する.
式の値が変化したとき,目標を決定するため,現在の値を用いて,active update eventをイベント待ち行列に追加します.


5.6.2 手続き上の連続した代入(Procedural continuous assignment)

手続き上の連続した代入(assign文かforce代入文(9.3参照))は,式中のソース要素の感度プロセスに対応します.
式の値が変化したとき,目標を決定するため,現在の値を用いて,active update eventをイベント待ち行列に追加します.
deassign文やrelease文は,対応する代入やforce文を無効にする.


5.6.3 Blocking assignment

遅延付きブロッキング代入文(9.2.1参照)は,右辺の値を現在の値を用いて計算ます.そのあと,実行中のプロセスを中断し,未来のイベントとしてスケジューリングされます.
もし,遅延がゼロならば,そのプロセスは現在時刻のinactiveイベントとしてスケジューリングされます.
プロセスから返ってきたとき,(または,遅延指定が無かったとき,即時に返ってきたとき),そのプロセスは左辺への代入を評価し,左辺の更新に基づくイベントを有効にします.
プロセスが再開したときの値は,目標を決定するために使われる.
実行は,その後,次のシーケンシャル文か他のアクティブイベントに続くでしょう.


5.6.4 Non blocking assignment

このtime stepでdelayがゼロのときで,かつ future eventでdelayがゼロではないときのノンブロッキング代入更新イベントでは,ノンブロッキング代入文(9.2.2参照)は,常に更新された値を計算し,更新のスケジュールをします.(ごめん わからん)
更新がイベント待ち行列に置かれると,有効な値は右辺の値と左辺の目標の両方を計算するのに使用されます.

A NON BLOCKING ASSIGNMENT STATEMENT  always computes the updated value and schedules the update
as a NON BLOCKING ASSIGN UPDATE EVENT, either in this TIME STEP if the delay is zero or as a future event if the delay is nonzero.

5.6.5 Switch (transistor) processing

LRM 5.4で示すイベントドリブンシミュレーションアルゴリズムは,片方向信号のフローに依存し,各々のイベントに対して独立に処理可能です.入力が読まれ,結果が計算され,そして更新がスケジュールされます.
Verilog HDLは,ビヘイビアとゲートレベルモデリングに加えて,スイッチレベルモデリングを提供します.
スイッチは双方向信号のフローを提供し,スイッチによって接続されたノードの連携処理を必要とします.
スイッチをモデル化するVerilog HDLソース要素は,tran, tranif0, tranif1, rtran, rtranif0, and rtranif1と呼ばれる様々な形式のトランジスタです.
スイッチ処理は,入力と出力が相互作用するので,ネットの全てのノードのために適切な値を決定する前に,双方向のスイッチで接続されたネットですべてのデバイスを考えるものとします.
シミュレータは,リラクゼーションテクニックを用いることで,これを可能にします.
そのシミュレータは,どのようなときにでも,tran処理ができます.
それは他のアクティブなイベントの実行で混ぜ合わされた特定の時に,tran-connected eventのサブセットとして処理できます.(意訳あやしい. 全部怪しいけれどw)

いくつかのトランジスタにゲート値xがあると、さらなる改善が必要です。

概念的に簡単なテクニックは,完全に伝導・非伝導のトランジスタのすべての可能な組み合わせに設定した,これらのトランジスタで,繰り返してネットワークを解決することです。(意訳:スイッチON/OFFの状態組み合わせを全部見ればOKということでしょう)
すべての場合におけるユニークなロジックレベルを持っているどんなノードも,このレベルと等しい定常応答(steady-state)を持ちます.他のすべてのノードには、定常応答Xがあります.(直訳そのまま.理解できてません.>< )


5.6.6 Port connections

ポート接続手順は,暗黙の連続したassign文か,暗黙の双方向の接続で処理します.
双方向接続は,2つのネットの間で常にenableにされたtran接続に類似していますが,(信号)強度の減少を伴いません.
ポート接続ルールは,値を受け取るのが,ネットまたは構造的なネット式(structural net expression)であることを要求します.ポートは,以下に示すような接続されたオブジェクトを宣言することで,常に表すことができます.

  • input port:外側の式から,ローカルのネット(input)への連続代入(continuous assignment*2
  • output port:ローカルのoutput式から,外側のネットへの連続代入
  • inout:ローカルネットから外側のネットへの,強度減衰の無いトランジスタ接続

5.6.7 Functions and tasks

task parameterとfunction parameterは値渡しとなり,起動時にコピーインされ,リターン時にコピーアウトされます.
functionリターン時のコピーアウトは,どんなブロッキング代入のように同じ挙動で振る舞います.
※意味が通じないナ... functionの値を貰うのは,ノンブロッキング代入と同じ扱いよ,ということかな.

*1 : activeより後ろで処理できないイベント,という意味だろう

*2 : "continuous"とわざわざ着いているのはなんだろう….moduleのポート接続のことかと思ったけど違うのかな...portという型があるんだっけ(汗

LRM読解

2008/09/10Verilogimport

LRM読解

wikiコンテンツとして,Verilogの配下におきます.
気ままに翻訳・転記しているので,結構なボリュームになってきましたので,章ごとにページを分けることにします.それでも結構大きい章があるので悩みどころですが・・・.

あと,私は英語力が弱いので,誤訳も多いと思います.よろしければ指摘いただくと幸いです.あくまでもreferenceですので,使用される処理系依存となっているところもあるかと思います.そのアタリの情報も併記できると良いかな,と考えております.

Xilinx WebPack ISEであれば,言語資料が公開されているのを見た記憶があります.あとはALTERAのQuartus IIでしょうか.
個人で触れるのはそこらへんまでと思いますので,業務で御利用の場合は自社のサポート部門等をあたってください・・・.

といいいつつ,LRM追いかけている途中で力尽きるかもしれませんが..

何も順序どおりに見ていく必要は無いんだ.必要そうなところだけ,かいつまんでもいいんだ・・・(挫折気味(笑

1. 概要 ~ Overview (13)
2. 語彙規約 ~ Lexical conventions 	(14)
3. データ型 ~ Data types	(20)
4. 式 ~ Expressions 	(24)
5. スケジューリング意味ネット? ~ Scheduling semantics	(5)
6. 代入 ~ Assignments	(6)
7. gate/switchレベルモデリング ~ Gate and switch level modeling	(32)
8. ユーザ定義primitive ~ User-defined primitives (UDPs) 	(11)
9. ビヘイビアモデリング ~ Behavioral modeling	(33)
10. taskとfunction ~ Tasks and functions	(11)
11. 名前つきブロックとタスクの無効化 ~ Disabling of named blocks and tasks	(3)
12. 階層構造 ~ Hierarchical structures 	(34)
13. 設計コンテンツのコンフィギュレーション ~ Configuring the contents of a design	(12)
14. Specifyブロック ~ Specify blocks	(26)
15. タイミングチェック ~ Timing checks	(32)
16. SDFを使ったバックアノテーション ~ Backannotation using the Standard Delay Format (SDF)	(8)
17. システムtaskとシステムfunction ~ System tasks and functions 	(47)
18.  ~ Value change dump (VCD) files	(26)
19. コンパイラディレクティブ ~ Compiler directives	(11)

20.  ~ PLI overview	(3)
21.  ~ PLI TF and ACC interface mechanism	(4)
22.  ~ Using ACC routines	(35)
23.  ~ ACC routine definitions	(161)
24.  ~ Using TF routines 	(4)
25.  ~ TF routine definitions 	(55)

26.  ~ Using VPI routines	(41)
27.  ~ VPI routine definitions	(47)

Annex A (normative) Formal syntax definition	(25)
Annex B (normative) List of keywords 	(2)
Annex C (informative) System tasks and functions 	(7)
Annex D (informative) Compiler directives 	(2)
Annex E (normative) acc_user.h	(9)
Annex F (normative) veriuser.h	(8)
Annex G (normative) vpi_user.h 	(14)
Annex H (informative) Bibliography	(1)

LRM読解(Chap.4 式 - Expression)

2008/09/09Verilog::文法import

式 - Expression [LRM 4]

LRM 4.1 Operators

式のまとめ

演算子と,実数(real型? integerとか)・論理型(login型? regとか)に対して演算可能かどうかの対応表を以下に記す.
詳細な説明は4.1.xに記載されているので参照されたい.個人的に気になった部分だけ抜粋し,紹介する.

expressionoperation namefor Realfor Logic
{} {{}}データ連結, 括り(Concatenation, replication)xo
+ - * / **算術演算(和/差/積/商/累乗)(Arithmetic)oo
%モジュロ演算子(Modulus)xo
> >= < <=比較演算子(Relational)oo
!論理否定(Logical negation)oo
&&論理積(Logical and)oo
||論理和(Logical or)oo
==論理一致(Logical equality)oo
!=論理不一致(Logical inequality)oo
===case一致(Case equality)xo
!==case不一致(Case inequality)xo
~Bit的な否定(Bit-wise negation)xo
&Bit的な論理積(Bit-wise and)xo
|Bit的な論理和(Bit-wise inclusive or)xo
Bit的な排他的論理和(Bit-wise exclusive or)xo
^~ or ~^Bit的な一致 (Bit-wise equivalence)xo
&圧縮論理積(Reduction and)xo
~&圧縮論理積/出力否定(NAND)(Reduction nand)xo
|圧縮論理和(Reduction or)xo
~|圧縮論理和/出力否定(NOR)(Reduction nor)xo
^圧縮排他的論理和(XOR)(Reduction xor)xo
~^ or ^~圧縮排他的論理和/否定(XNOR)(Reduction xnor)xo
<<論理的左シフト(Logical left shift)xo
>>論理的右シフト(Logical right shift)xo
<<<算術左シフト(Arithmetic left shift)xo
>>>算術右シフト(Arithmetic right shift)xo
? :3項演算子(Conditional)oo
orイベント和(Event or)oo

real数の論理式・関係演算結果は,1bitのスカラー値として得られます.


LRM 4.1.2 Binary operator precedence // 演算子の優先度

演算子優先度
+ - ! ~ (unary:単項演算子)
**
* / %
+ - (binary)
<< >> <<< >>>
< <= > >=
== != === !==*1
& ~&
^ ^~ ~^
| ~|
&&
||
? : (conditional operator)

LRM 4.1.8 Equality operators(同等式?)

数式例を表形式で示す.ただし,以下の点に注意すること.

  • 同等式の優先度は,関係式よりも低い.
  • 比較時にa,bのbit幅が異なる場合,短いほうの上位bitを拡張し,ゼロフィルして比較する.
  • 関係式の比較値に'x'/'z'が含まれている場合,結果はあいまいとなるので,比較結果としても'1'bx'を返す.
  • 同等式の場合,'x'/'z'の比較も行われるため,結果は必ず真(1)/偽(0)が返る

※resultは1bitであることに変わりは無い.

説明補足
a === b同等式, 一致bitごとに 0,1,z,x を比較. 全部一致で真(1)
a !== b同等式, 不一致bitごとに 0,1,z,x を比較. 全部一致で偽(0)
a == b関係式, 一致bitごとに 0,1 を比較. 全部一致で真(1).
a != b関係式, 不一致bitごとに 0,1 を比較. 全部一致で偽(0).

4.1.10 Bit-wise operators bit演算の真理値表を以下に示す.ANDは0が強く,ORは1が強く,その他は演算を行うと不定になる.→ハイインピは伝播しない.

  • binary AND
& 0 1 x z
00000
101xx
x0xxx
z0xxx
  • binary OR
| 0 1 x z
001xx
11111
xxxxx
zxxxx
  • binary EXOR
0 1 x z
001xx
110xx
xxxxx
zxxxx
  • binary EXNOR
^~ ~^ 0 1 x z
010xx
101xx
xxxxx
zxxxx
  • 単項演算子
~
01
10
xx
zx
LRM 4.1.12 Shift operators

論理シフトは,<<.>>です.算術シフトは,<<<,>>>です.
Verilog HDLでは,シフト演算子の定義はそれぞれ明確になっています.算術演算子は,演算結果がsignedである場合にだけ,MSB bitをシフトしてあいたビットに埋めます.それ以外の全てのケースでは,シフト後のあいたビットをゼロフィルします.

また,演算子の右辺について,下記の注意書きがありました.

If the right operand has an unknown or high impedence value, then the result shall be unknown.
The right operand is always treated as an unsigned number and has no effect on the signedness of the result.
The result signedness is determined by the left-hand operand and the remainder of the expression, as outlined in 4.5.1.


LRM 4.1.13 Conditional operator

3項演算子についての記載です.ここでもz,xの値が存在するため,注意が必要なようです.

syntax

conditional_expression ::= (From Annex A - A.8.3)
  expression1 ? { attribute_instance } expression2 : expression3

expression1 ::=
  expression

expression2 ::=
  expression

expression3 ::=
  expression

expression1を評価し,真(非0)ならばexpression2を評価し,結果を左辺に渡す.
偽(0)ならば,expression3を評価し,結果を左辺に渡す.
expression1が'x'や'z'の場合,expression2とexpression3を評価して,それぞれの結果をビットごとに下記の表に基づいて演算し,左辺に渡す.ただし,実数型ではないことを前提とする.(実数の場合は0となるでしょう?)
演算時にbit幅が異なる場合,短いほうの上位にゼロビットを埋めて長さをあわせる.

both expression2 and expression3 shall be evaluated and their results shall be combined, bit by bit,
using Table 28 to calculate the final result unless expression2 or expression3 is real,
in which case the result shall be 0.
?: 0 1 x z
00xxx
1x1xx
xxxxx
zxxxx

※どちらも同じ値のときだけ値が返る.それ以外はどちらとも考えられるため,不定を返す.
おそらく論理合成するとどちらかの値が出るとは思うのだけれど.

注意
If~Then~Elseと同等と思ったら大間違い!!
exp1の結果に依存するが,不定が入らないように!!!
回路を作る側から考えると,入力不定なのだから,出力はいずれかの値を返すとしかいえない.セレクタのセレクト信号が不定な状態をイメージすればよいのだろう.if文だと,不定の場合はelseに流れてくれるので,ある意味シミュレーション不足になるのかもしれない.シミュレーション結果の不定は,原則は撲滅しましょう,ということでしょうね.


LRM 4.1.14 Concatenations

{}を用いると,bitレベルの結合ができる.ここで,繰り返し指定も可能である.書式は{}の前に繰り返し回数を記述する.ただし,不定値を返すようなものや,0は指定してはいけない(自然数だけ).
例を以下に示す.

{4{w}} // This is equivalent to {w, w, w, w}
a[31:0] = {1’b1, {0{1’b0}} }; //illegal. RHS becomes {1’b1,;
a[31:0] = {1’b1, {1’bz{1’b0}} }; //illegal. RHS becomes {1’b1,;
a[31:0] = {1’b1, {1’bx{1’b0}} }; //illegal. RHS becomes {1’b1,;



*1 : 関係式のほうが強い.同等式は弱いLRM4.1.8

4.2 Operands [4.2]

4.2.1 Vector bit-select and part-select addressing [4.2.1]

real型/realtime型で宣言された変数のビット選択・部分選択は不正と判断されます.

constant part-select

vector net, vector regのみ可.

  vect[msb_expr:lsb_expr]

ただし,いずれの式(msb_expr,lsb_expr)も定数を返す必要がある.変数になった場合は不定を返すことになるだろう.また,msb_exprのほうが,lsb_exprよりも重いbit(more significant bit)をアサインする必要がある.*2


indexed part-select

vector net, vector reg, integer variable, time variableが可.

reg [15:0] big_vect;    // Big endian
reg [0:15] little_vect; // Little endian

    big_vect[lsb_base_expr +: width_expr]
 little_vect[msb_base_expr +: width_expr]
    big_vect[msb_base_expr -: width_expr]
 little_vect[lsb_base_expr -: width_expr]

ただし,width_exprは定数式で,実行時に決定することは許されない.lsb_base_exprとmsb_base_exprは実行時に決定されても良い*3

例を張っておく.宣言時にMSB:LSBで指定しているはずなので,指定した単項演算子+と-がどちらに伸びていくかは把握できるはず.伸びていかないほうの数字を固定して,伸びていく方向にwidthだけビットが取り出されると,理解すればよさそう.

initial begin
if ( big_vect[0 +:8] == big_vect[7 : 0]) begin end
if (little_vect[0 +:8] == little_vect[0 : 7]) begin end
if ( big_vect[15 -:8] == big_vect[15 : 8]) begin end
if (little_vect[15 -:8] == little_vect[8 :15]) begin end
if (sel >0 && sel < 8)
  dword[8*sel +:8] = big_vect[7:0]; // Replace the byte selected.

LRM 4.2.3 Strings

4.2.3.3 Null string handling

ダブルクォートで囲った文字には NULL文字(\0)が付かないけれども,ダブルクォートだけで中身が無い場合("")は,'\0'となるらしい.


4.3 Minimum, typical, and maximum delay expressions

表題のとおり,遅延時間のmin./typ./max.を演算する.



4.4 Expression bit lengths

ビット長拡張について.和算のときは,左辺を含めた演算対象のビット幅のうち,最も大きい幅を用いる.

Expression Bit length Comments
Unsized constant number*4Same as integer
Sized constant numberAs given
i op j, where op is: + - * / % & | ^ ^~ ~^max(L(i),L(j))
op i, where op is: + - ~L(i)
i op j, where op is: === !== == != && || > >= < <=1 bitOperands are sized to max(L(i),L(j))
op i, where op is: & ~& | ~| ^ ~^ ^~ !1 bitAll operands are self-determined
i op j, where op is: >> << **L(i)j is self-determined
i ? j : kmax(L(j),L(k))i is self-determined
{i,...,j}L(i)+..+L(j)All operands are self-determined
{i{j,..,k}}i * (L(j)+..+L(k))All operands are self-determined

乗算時のビット幅に注意.積の場合は,(L(i) + L(j))を期待するが,表のとおり拡張はされない.結果を受ける側(左辺)で必要なビットを用意してasignすること.

例を見たが,納得できない.三つ目.

reg [3:0] a;
reg [5:0] b;
reg [15:0] c;

initial begin
  a = 4’hF;
  b = 6’ha;
  $display("a*b=%x", a*b); // expression size is self determined
  c = {a**b};              // expression a**b is self determined
  $display("a**b=%x", c);  // due to {}
  c = a**b;                // expression size is determined by c
  $display("c=%x", c);
end

//Result:
//  a*b=16 // 96 was truncated since expression size is 6
//  a**b=1 // expression size is 4 bits (size of a)
//  c=21   // example size is 16 bits (size of c)
//  コレ, なぜ21? 4'hF の 10乗だよねぇ?

4.5 Signed expressions

符号拡張について.C言語のキャストと同じように,Verilog-HDLにも型変換のためのシステム関数がある.

$signed - 返り値は符号つきである.
$unsigned - 返り値は符号なしである.
4.5.1 Rules for expressions types
  • operandにのみ依存し,左辺の影響は受けない.
  • 10進数はsigned(符号あり)とみなす.
  • 基数書式つきはunsigned(符号なし)とみなす.ただし,明示的に's'がついている場合は符号ありとする.
  • Bit-selectの結果は,operandにかかわらず,unsigned(符号なし)とみなす.
  • Part-selectの結果は,operandにかかわらず,unsigned(符号なし)とみなす.端から端まで選択した場合も,符号ナシとして扱われる.
Note:
 Concatenate results are unsigned, regardless of the operands.
 Comparison results (1, 0) are unsigned, regardless of the operands.
 Reals converted to integers by type coercion are signed
 The sign and size of any self-determined operand is determined by the operand itself and independent of the remainder of the expression.
 For non-self-determined operands the following rules apply:
 if any operand is real, the result is real;
 if any operand is unsigned, the result is unsigned, regardless of the operator;
 if all operands are signed, the result will be signed, regardless of operator, except as noted.

4.5.2 Steps for evaluating an expression
  • 基本ルールにのっとって,数式のビット長を決定する.
  • 4.5.1のルールを用いて,式の符号を決定する.
  • 式のoperandの型を,式にあわせて強制する.ただし,self-determinedしていないoperandのみ.
  • 同様に,self-determinedしていないbit長を拡張する.必要であれば,符号拡張処理を行う.
-Determine the expression size based upon the standard rules of expression size determination.
-Determine the sign of the expression using the rules outlined in 4.5.1.
-Coerce the type of each operand of the expression (excepting those which are self-determined) to the type of the expression.
-Extend the size of each operand (excepting those which are self-determined) to the size of the expression.
 Perform sign extension if and only if the operand type (after type coercion) is signed.

まともに訳せていないようだな....bit長決定→符号決定→演算のために項ごとに型キャスト→演算のためにbit長拡張/符号拡張


4.5.3 Steps for evaluating an assignment
  • LRM 4.4のルールに基づいて,右辺のサイズを決定する.
  • 必要であれば,右辺のサイズを拡張する.このとき,右辺がsignedで,かつbit長拡張が必要な場合に符号拡張を行う.
  • Determine the size of the RHS by the standard assignment size determination rules (see 4.4)
  • If needed, extend the size of the RHS, performing sign extension if and only if the type of the RHS is signed.

4.5.4 x,zを含むときの符号拡張

signed bitにx,zが入っているときは,bit拡張するときに それぞれx,zで埋める.signed bit以外のx,zについては,触れずにおいておく.

*2 : 添え字の値の大小ではなく,複数ビットとして値を扱う際のbitの並び,だろう.

*3 : 合成結果は,バレルシフタになるんでしょうねぇ.

*4 : 32bitを超える場合はMSBが不定となる.

LRM読解(Chap.3 データタイプ~型の種類)

2008/09/02Verilog::文法import

データタイプ~型の種類[LRM Chap.3]

値 [3.1]

Verilog-HDLには下記の4つの値しか存在しません. *1ただし,NET型では論理値に強度(Strength)を与えることができます.(LRM Chap.7)

文字説明
0論理値0,もしくはfalse状態を示す
1論理値1,もしくはtrue状態を示す
x論理値不定を示す
zHigh Impedance状態を示す

NET型とVariable型 [3.2]

NET

値を保持することは無く,PAD間をつなぐための配線材相当である.syntaxを引用する.

net_declaration ::= (From Annex A - A.2.1.3)
    net_type [ signed ] [ delay3 ] list_of_net_identifiers ;
  | net_type [ drive_strength ] [ signed ] [ delay3 ] list_of_net_decl_assignments ;
  | net_type [ vectored | scalared ] [ signed ] range [ delay3 ] list_of_net_identifiers ;
  | net_type [ drive_strength ] [ vectored | scalared ] [ signed ] range [ delay3 ] list_of_net_decl_assignments ;
  | trireg [ charge_strength ] [ signed ] [ delay3 ] list_of_net_identifiers ;
  | trireg [ drive_strength ] [ signed ] [ delay3 ] list_of_net_decl_assignments ;
  | trireg [ charge_strength ] [ vectored | scalared ] [ signed ] range [ delay3 ] list_of_net_identifiers ;
  | trireg [ drive_strength ] [ vectored | scalared ] [ signed ] range [ delay3 ] list_of_net_decl_assignments ;

net_type ::= (From Annex A - A.2.2.1)
    supply0 | supply1
  | tri | triand | trior | tri0 | tri1
  | wire | wand | wor

drive_strength ::= (From Annex A - A.2.2.2)
   ( strength0 , strength1 )
  | ( strength1 , strength0 )
  | ( strength0 , highz1 )
  | ( strength1 , highz0 )
  | ( highz0 , strength1 )
  | ( highz1 , strength0 )

strength0 ::= supply0 | strong0 | pull0 | weak0

strength1 ::= supply1 | strong1 | pull1 | weak1

charge_strength ::= ( small ) | ( medium ) | ( large )

delay3 ::= (From Annex A - A.2.2.3)
  # delay_value | # ( delay_value [ , delay_value [ , delay_value ] ] )

delay2 ::=
  # delay_value | # ( delay_value [ , delay_value ] )

delay_value ::=
    unsigned_number
  | parameter_identifier
  | specparam_identifier
  | mintypmax_expression

list_of_net_decl_assignments ::= (From Annex A - A.2.3)
  net_decl_assignment { , net_decl_assignment }

list_of_net_identifiers ::=
  net_identifier [ dimension { dimension }]
  { , net_identifier [ dimension { dimension }] }

net_decl_assignment ::= (From Annex A - A.2.4)
  net_identifier = expression

dimension ::= (From Annex A -A.2.5)
  [ dimension_constant_expression : dimension_constant_expression ]

range ::=
  [ msb_constant_expression : lsb_constant_expression ]

(かなりテキトウな理解)
要は,配線と思えばよい?.

  • wire - 単純に端子?間を結ぶ
  • tri - tri-state?何に使うんだろうな...

Variable

syntaxを引用する.値を保持できる器となります.

integer_declaration ::= (From Annex A - A.2.1.3)
  integer list_of_variable_identifiers ;

real_declaration ::=
  real list_of_real_identifiers ;

realtime_declaration ::=
  realtime list_of_real_identifiers ;

reg_declaration ::=
  reg [ signed ] [ range ] list_of_variable_identifiers ;

time_declaration ::=
  time list_of_variable_identifiers ;

real_type ::= (From Annex A - A.2.2.1)
    real_identifier [ = constant_expression ]
  | real_identifier dimension { dimension }

variable_type ::=
    variable_identifier [ = constant_expression ]
  | variable_identifier dimension { dimension }

list_of_real_identifiers ::= (From Annex A - A.2.3)
  real_type { , real_type }

list_of_variable_identifiers ::=
  variable_type { , variable_type }

dimension ::= (From Annex A - A.2.5)
  [ dimension_constant_expression : dimension_constant_expression ]

range ::=
  [ msb_constant_expression : lsb_constant_expression ]

変数としては,下記の種類がある.integer, real, realtime, reg, time.



Vector [3.3]

NET/Variable宣言時に,型とシンボルの間に記述する.書式では'range'と記していたもの.VectorのReg/Netは,2を法とする,2^nの演算に従う.(n=ベクタのビット長)

range ::=
  [ msb_constant_expression : lsb_constant_expression ]

MSB>LSBである必要は無い.,2^(abs(MSB-LSB)).Noteにて,ここで確保可能なサイズについて記されている.

1) Implementations may set a limit on the maximum length of a vector, but they will at least be 65536 (216) bits.
2) Implementations do not have to detect overflow of integer operations.

1)最低でも,ベクタ長は 2^16(65536) をサポートすること.
2)整数演算のオーバフローは検出する必要は無い.



Arrays [3.10]

net/variable宣言時に,シンボル名の後ろに"[mm:ll]"で指定する.また,LRM 3.10.noteより,

Implementations may limit the maximum size of an array, but they shall at least be 16777216 (224).

Parameters [3.11]

Parametersは,variable型にも,net型にも属さない.また,変数ではなく,定数である.
module parameters と specify parameters とがある.Parameter宣言は,net型/parameter型/variable型で,既に宣言された名称で再定義することはできない.

Parameters

syntax

local_parameter_declaration ::= (From Annex A - A.2.1.1)
  localparam [ signed ] [ range ] list_of_param_assignments ;
  | localparam integer list_of_param_assignments ;
  | localparam real list_of_param_assignments ;
  | localparam realtime list_of_param_assignments ;
  | localparam time list_of_param_assignments ;

parameter_declaration ::=
  parameter [ signed ] [ range ] list_of_param_assignments ;
  | parameter integer list_of_param_assignments ;
  | parameter real list_of_param_assignments ;
  | parameter realtime list_of_param_assignments ;
  | parameter time list_of_param_assignments ;

list_of_param_assignments ::= (From Annex A - A.2.3)
  param_assignment { , param_assignment }

param_assignment ::= (From Annex A - A.2.4)
  parameter_identifier = constant_expression

range ::= (From Annex A - A.2.5)
  [ msb_constant_expression : lsb_constant_expression ]
  • list_of_param_assignmentsは,module itemの中か,module_parameter_port_list*2の中のみ記述可能.
  • param_assignmentsが,module_parameter_port_list内に存在しない場合,param_assignmentsはlocal parameterとなり,どんな手段でもoverride不可能となる.

Parameterの定数再定義について

runtimeに書き換えることはできません.しかし,module parameterは,compilation時に,module定義時の値と異なる値に書き換えることは可能です.これはmodule instanceのカスタムを許容します.
parameterの修正は,defparam文か,module instance文で修正可能です.

parameter文の代表的な使い方は,delay(遅延時間)や変数のビット幅(width)を定義するのに使います.Chap..12で詳細に記します.


module parameterはタイプ指定とrange指定(range)を持つことができます。以下の規則に従って、module parameterのタイプとrange(range)があるものとします.

  • タイプもrange指定もないparameter宣言は,すべての値のオーバーライドも適用された後の,パラメタに割り当てられた最終値のタイプとrangeをデフォルトとするものとします。
  • range指定はあるが,タイプ指定のないパラメタは,符号なしのパラメタ定義rangeになるでしょう.
    符号とrangeは,値のオーバーライドによる影響を受けさせないものとします.
  • range指定が無い,タイプ指定を伴うパラメタは,タイプ指定になるでしょう。
  • 符号ありparameterは,全ての値のオーバーライドを適用した後に,パラメタに割り当てられた最終値のrangeをデフォルトとするものとします、。
  • 符号あり,型指定ありかつrange指定ありのparameterは,符号あり・定義されたrangeとなるでしょう.符号・rangeは,値のオーヴァーライドによる影響を受けない.
  • range指定が無く,かつ,(符号あり型指定されているか,型指定が無い)parameter宣言は,LSB=0, MSBは最終的にparametaにアサインされた値が収まる大きさ以下となるでしょう.
  • range指定が無く,かつ,(符号あり型指定されているか,型指定が無い),かつ最終的にparametaにアサインされた値が符号なしとなるようなparameter宣言は,LSB=0, MSBは31となるでしょう.

// an implied range with an lsb equal to 0 and an msb equal to an implementation-dependent value of at least 31.

※直訳すぎてスミマセン.宣言時に省略した場合や上書きしたときのコンパイラの挙動について仕様が切られているようです.



Local parameters - localparam [3.11.2]

Verilog HDL localparamについて.local parameterは,defparam文や,並び順または名前付きの直接書き換えができません.local parameterは, - local parameter(s) are identical to parameters except that they can not directly be modified with the defparam statement or by the ordered or named parameter value assignment.

Local parameters can be assigned to a constant expression containing a parameter which can be modified with the defparam statement or by the ordered or named parameter value assignment.

See 12.1.3 for details. The syntax for local parameter declarations is given in Syntax 3-4.


Specify parameters[3.11.3]
specparam_declaration ::= (From Annex A - A.2.2.1)
  specparam [ range ] list_of_specparam_assignments ;

list_of_specparam_assignments ::= (From Annex A- A.2.3)
  specparam_assignment { , specparam_assignment }

specparam_assignment ::= (From Annex A - A.2.4)
  specparam_identifier = constant_mintypmax_expression
  | pulse_control_specparam

pulse_control_specparam ::=
  PATHPULSE$ = ( reject_limit_value [ , error_limit_value ] ) ;
  | PATHPULSE$specify_input_terminal_descriptor$specify_output_terminal_descriptor
  = ( reject_limit_value [ , error_limit_value ] ) ;

error_limit_value ::=
  limit_value

reject_limit_value ::=
  limit_value

limit_value ::=
  constant_mintypmax_expression

range ::= (From Annex A - A.2.5)
  [ msb_constant_expression : lsb_constant_expression ]

Table 8. Differences between specparams and parameters

Specparams(specify parameter)Specparams(specify parameter)
Use keyword specparamUse keyword parameter
Shall be declared inside a module or specify blockShall be declared outside specify blocks
May only be used inside a module or specify blockMay not be used inside specify blocks
May be assigned specparams and parametersMay not be assigned specparams
Use SDF annotation to override valuesUse defparam or instance declaration parameter value passing to override values


Name spaces [3.12]

*1 : 例外としてevent型(LRM9.7.3)があります.

*2 : referto SS.12

LRM読解(Chap.2 字句定義/語彙規約)

2008/08/31Verilog::文法import

字句定義/語彙規約 ~ Lexical conventions (LRM-Chap.2)

LRMから,少し抜粋.

数値表現

| binary  | [size]*'[s|S]*(b|B)[01]+
| octal   | [size]*'[s|S]*(o|O)[0-7]+
| hexa    | [size]*'[s|S]*(h|H)[0-9a-fA-F]+
| decimal | ([size]*'[s|S]*(d|D)[0-9]+)|([0-9]+)

LRM 2.5.1 Integer constants

Example 3 Using sign with constant numbers

8'd-6   // 構文違反.
-8'd6   // 6の2の補数を示します.8bitサイズを保持します.
4'shf   // これはbinaryで 4bitの'1111'と書き直せます.
        // 2の補数表現では-1になります.
        // 即ち,これは -4'h1と等価です.
-4'sd15 // 同様にして,これは 4'd1と等価です.(-(-4'd1))

LRM 2.6 Strings

一行内で,double quotes("")で閉じられた部分を文字列とみなします.unsigned int定数として 8bit ASCII文字を取り扱うことができます.

文字列変数?の定義と使い方

stringvarというレジスタ変数を用意し,"Hello world!"を代入してみましょう.

 reg [8*12:1] stringvar;
 initial begin
   stringvar = "Hello world!";
 end

8bit widthの[12:1]配列,と見ればいいんですかねぇ.[8*(欲しい文字数):1]とすればよいようです.C言語と違い,NULL挿入はされない模様です.


LRM 2.6.2 の NOTE

意訳で敵どうだけれど,まぁ,こんなもんで.

When a variable is larger than required to hold a value being assigned,
the contents on the left are padded with zeros after the assignment.
This is consistent with the padding that occurs during assignment of nonstring values.

変数のほうが,文字列よりも大きい場合には,左側がゼロパディングされます.これは,定数のパディングと矛盾しないようになっているからである.(意訳)

If a string is larger than the destination string variable,
the string is truncated to the left, and the leftmost characters will be lost.
文字列のほうが長い場合には,文字列の左側が失われます.
LRM 2.6.3 特殊文字

C言語と同様に,下記の特殊文字が定義されます.エスケープ記号とか..

Escape Stringescape stringで示される文字
\n改行文字
\tタブ文字
\\\(バックスラッシュ, \x5C)
\"double quote(",\x22)
\dddキャラクタコード指定. dは0~7の数値を示す. ただし, 1~3個で構成する(3個必要なわけではない).

LRM 2.7 Identifiers, keywords, and system names

識別子は、それに参照をつけることができるようにユニークな名前をオブジェクトに与えるのに使用されます。識別子は、簡単な識別子かエスケープされた識別子(LRM 2.7.1参照)のどちらかです。簡単な識別子は 文字、数字、ドル記号($)、およびアンダースコア(_)の組み合わせである。簡単な識別氏の一文字目は,数値やドル記号にすべきではないです.英字か,アンダースコアなら可能です.識別子は大文字と小文字を区別するでしょう.

原文

An identifier is used to give an object a unique name so it can be referenced.
An identifier is either a simple identifier or an escaped identifier (see 2.7.1).
A simple identifier shall be any sequence of letters, digits, dollar signs ($), and underscore characters (_).
The first character of a simple identifier shall not be a digit or $;
it can be a letter or an underscore. Identifiers shall be case sensitive.

naming rule?
  • System task/functionの名前は,'$'で始まる.[LRM2.7.4]

2.8 Attribute[LRM 2.8]

syntax

attribute_instance ::= (From Annex A - A.9.1)
  (* attr_spec { , attr_spec } *)

attr_spec ::=
  attr_name = constant_expression
  | attr_name

attr_name ::=
  identifier