JP2004303081A - Instruction prefetching circuit and microcontroller - Google Patents

Instruction prefetching circuit and microcontroller Download PDF

Info

Publication number
JP2004303081A
JP2004303081A JP2003097240A JP2003097240A JP2004303081A JP 2004303081 A JP2004303081 A JP 2004303081A JP 2003097240 A JP2003097240 A JP 2003097240A JP 2003097240 A JP2003097240 A JP 2003097240A JP 2004303081 A JP2004303081 A JP 2004303081A
Authority
JP
Japan
Prior art keywords
instruction
prefetch
circuit
register
address
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
JP2003097240A
Other languages
Japanese (ja)
Inventor
Masayuki Takeshige
昌之 竹重
Isato Isobe
勇人 磯邊
Kazuya Taniguchi
和也 谷口
Sumitaka Hibino
純孝 日比野
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujitsu Ltd
Original Assignee
Fujitsu Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujitsu Ltd filed Critical Fujitsu Ltd
Priority to JP2003097240A priority Critical patent/JP2004303081A/en
Publication of JP2004303081A publication Critical patent/JP2004303081A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Advance Control (AREA)

Abstract

<P>PROBLEM TO BE SOLVED: To provide an instruction prefetching circuit with which processing capability can be enhanced, using a simplified circuit configuration. <P>SOLUTION: When a conditional branch instruction is detected, an instruction prefetching control part 24, based on its branching frequency, decides whether prefetching the instruction is halted, in accordance with the control flag set on a prefetching control register 25 in advance. <P>COPYRIGHT: (C)2005,JPO&NCIPI

Description

【0001】
【発明の属する技術分野】
本発明は、命令先読み回路及びマイクロコントローラに関するものである。
近年、マイクロコントローラは、CPUの動作周波数の高速化に伴い、メモリ等の周辺回路に比べて動作速度が相対的に速くなってきている。そこで、CPUによる命令の実行に先立って該命令をメモリから予め読み出して保持しておく命令先読み回路を搭載することで、CPUの処理速度の向上を図るようにした構成がある。このようなマイクロコントローラにおけるメモリアクセス効率の向上が要求されている。
【0002】
【従来の技術】
従来、命令先読み機能を備える装置の1つとして、例えばCPU等のプロセッサにより読み出した命令が条件分岐命令である場合に命令の先読みを停止させるようにした構成がある(例えば特許文献1及び特許文献2参照)。
【0003】
すなわち、この構成では、条件分岐命令の種類に依らず該分岐命令が検出される場合には、その命令による分岐先アドレスが確定するまで命令の先読みを停止することで、分岐が発生した場合に先読みされた命令が使用されずに無駄となることが防止される。その結果、命令先読みのためのメモリアクセスを必要最小限に抑えることが可能である。
【0004】
【特許文献1】
特開平5−27972号公報
【特許文献2】
特開2001−312404号公報
【0005】
【発明が解決しようとする課題】
ところが、上記従来技術のように、条件分岐命令が検出される場合に先読みが必ず停止されてしまうと、分岐命令で分岐が発生しない場合に先読み効率が低下するという問題があった。すなわち、条件分岐命令で条件が成立若しくは未成立のため分岐が発生しなかった際に必要な命令が前もって読み出されていないために、CPUの処理能力低下を招くという問題があった。
【0006】
この問題を解消する手段として、条件分岐命令が検出される場合に分岐発生する場合と分岐発生しない場合の双方の命令アドレスを計算して先読みするようにした構成があるが(例えば特許文献2参照)、この構成では多くの命令を先読みする必要があり、結果としてCPUの処理能力の低下を招くことになる。
【0007】
また、他の手段として、過去の分岐発生頻度の情報を予め蓄えておき、条件分岐命令を検出したときに分岐するかしないかを予測して分岐先の命令を先読みするようにした構成があるが、このような分岐予測機能を備えた構成は、回路が複雑化するため、回路規模が増大するというデメリットがある。
【0008】
本発明は上記問題点を解決するためになされたものであって、その目的は簡易な回路構成で処理能力の向上を図ることのできる命令先読み回路及びマイクロコントローラを提供することにある。
【0009】
【課題を解決するための手段】
上記目的を達成するため、請求項1,10に記載の発明によれば、命令先読み回路において、先読み制御部は、命令デコード部により検出される分岐命令が絶対分岐命令の場合には先読みを停止させる。また、先読み制御部は、命令デコード部により検出される分岐命令が条件分岐命令の場合には、先読み制御レジスタに設定されている制御フラグに基づいて先読みを停止させるか否かを判断する。このような構成では、分岐発生頻度の高い条件分岐命令が検出される場合には先読みを停止させ、逆に分岐発生頻度の低い条件分岐命令が検出される場合には先読みを続行させることができる。これにより、外部バスのバス帯域を有効利用して命令の先読みを効率よく行いながら、処理能力の向上を図ることができる。
【0010】
請求項2に記載の発明によれば、前記先読み制御レジスタを前記条件分岐命令の種類毎にそれぞれ設けたため、より精度の高い先読み制御が可能である。
請求項3に記載の発明によれば、先読みする命令のアドレスが予め定めたアドレス範囲内のアドレスであるか否かを判断し、該判断結果に基づいて前記先読み制御レジスタに設定された制御フラグを切り替え可能とするアドレス範囲比較部を備えた。これにより、プログラム実行時に制御フラグを適宜切り替えることが可能となるため、より精度の高い先読み制御が可能である。
【0011】
請求項4に記載の発明によれば、前記アドレス範囲比較部には、前記アドレス範囲を指定する第一のアドレスと第二のアドレスが格納されるアドレス範囲設定レジスタが備えられている。
【0012】
請求項5に記載の発明によれば、前記アドレス範囲を、先読みする命令が含まれる命令ルーチン毎に設定した。これにより、プログラムに含まれる各命令ルーチン毎に条件分岐命令の分岐発生頻度がそれぞれ異なる場合にも精度の高い先読み制御が可能である。
【0013】
請求項6に記載の発明によれば、メモリから読み出されるデータパターンが予め定めた特定のデータパターンである場合に、前記先読み制御レジスタに設定された制御フラグを切り替え可能とするデータパターン検出部を備えた。これにより、プログラム実行時に制御フラグを適宜切り替えることが可能となるため、より精度の高い先読み制御が可能である。
【0014】
請求項7に記載の発明によれば、前記データパターン検出部には、前記特定のデータパターンを保持するデータ保持レジスタが備えられている。
請求項8に記載の発明によれば、メモリから読み出される命令が予め定めた特定の命令コードである場合に、前記先読み制御レジスタに設定された制御フラグを切り替え可能とした。これにより、プログラム実行時に制御フラグを適宜切り替えることが可能となるため、より精度の高い先読み制御が可能である。
【0015】
請求項9に記載の発明によれば、予め指定した条件分岐命令を検出する場合にカウントアップする第一のカウンタと、前記予め指定した条件分岐命令が分岐発生した場合にカウントアップする第二のカウンタとを備え、前記第一及び第二のカウンタのカウント値に基づいて前記条件分岐命令の分岐発生頻度を算出するためのアシスト回路を備えた。これによって、先読み制御レジスタに設定する制御フラグの値を決定することができる。
【0016】
【発明の実施の形態】
(第一実施形態)
以下、本発明を具体化した第一実施形態を図1及び図2に従って説明する。
【0017】
図1は、第一実施形態の命令先読み回路を備えたマイクロコントローラを示す概略ブロック図である。
マイクロコントローラ11は、CPU12と、命令先読み回路13と、外部バスインターフェース(以下、バスI/Fと略す)14とを含み、それらは同一の半導体チップ15に形成されている。このマイクロコントローラ11には、バスI/F14に接続された外部バス16を介してメモリ17が接続され、メモリ17には、CPU12が実行するプログラムやデータが格納されている。
【0018】
命令先読み回路13は、先読みアドレス生成部21、先読みバッファ部22、命令デコード部23及び先読み制御部24を含み、該先読み制御部24には、先読み制御レジスタ25が備えられている。
【0019】
先読みアドレス生成部21は、CPU12から出力されるアドレスに基づいてCPU12が次に実行すべき命令のアドレスを生成する。具体的には、電源投入後やリセット後の最初の命令フェッチ、或いは後述する絶対分岐命令や条件分岐命令により分岐発生した後の最初の命令フェッチのときにロードしたアドレスを順次カウントアップして先読みする命令のアドレスを生成する。
【0020】
先読みアドレス生成部21により生成されたアドレスは、演算部26及びバスI/F14を介して外部バス16に出力される。これにより、命令先読み回路13は、各アドレスに対応する命令をメモリ17から読み出す(先読みする)。
【0021】
メモリ17から先読みされた命令は、先読みバッファ部22に保持されるとともに命令デコード部23にてデコードされる。先読みバッファ部22は、例えばFIFO(First−In First−Out)メモリにて構成され、先読みされた命令を順次取り込んで、該取り込んだ命令を演算部27を介してCPU12に出力する。従って、CPU12は、命令先読み回路13により先読みされた命令をデコードして順次処理を実行する。
【0022】
尚、先読みされて先読みバッファ部22内に保持されている命令は、後述する絶対分岐命令や条件分岐命令にて分岐発生した命令がCPU12により実行される場合にクリアされるようになっている。
【0023】
命令デコード部23は、メモリ17から先読みされた命令をデコードして分岐命令を検出する。詳しくは、命令デコード部23は、先読みされる命令に含まれる絶対分岐命令と条件分岐命令を検出し、該検出結果として絶対分岐命令検出信号Iabと条件分岐命令検出信号Icbを先読み制御部24に出力する。また、本実施形態において、命令デコード部23は、条件分岐命令を検出する場合には、該条件分岐命令の種類毎に応じた検出結果(検出信号)を先読み制御部24に出力する。
【0024】
図3は、絶対分岐命令と1つの条件分岐命令を検出する命令デコード部23の一例を示すブロック図である。
命令デコード部23は、第1及び第2コンパレータ31,32と、第1及び第2記憶部33,34と、第1及び第2アンド回路35,36とから構成されている。第1及び第2コンパレータ31,32には外部バスI/F14からのリードデータRDが入力される。また、第1コンパレータ31には第1記憶部33の出力信号が入力され、第2コンパレータ32には第2記憶部34の出力信号が入力される。
【0025】
第1及び第2記憶部33,34は、CPU12又は外部から書き換え可能なレジスタ、又はマスクROM等の作り込まれたハードワイヤからなり、それぞれ絶対分岐命令と条件分岐命令が記憶されている。図4に示すように、命令37は、オペコード部(OPコード部)38とオペランド部39とから構成されている。第1記憶部33には絶対分岐命令のOPコード部38のデータが記憶され、第2記憶部34には条件分岐命令のOPコード部38のデータが記憶されている。第1及び第2記憶部33,34は、記憶したオペコード部38のデータをそれぞれ出力する。
【0026】
従って、第1コンパレータ31は、リードデータRDと絶対分岐命令のOPコード部38のデータとが入力され、両者を比較した結果に対応する信号を出力する。また、第2コンパレータ32は、リードデータRDと条件分岐命令のOPコード部38のデータとが入力され、両者を比較した結果に対応する信号を出力する。
【0027】
第1アンド回路35は、第1コンパレータ31の出力信号と命令フェッチ信号SFとが入力され、両信号に基づいて絶対分岐命令検出信号Iabを出力する。第2アンド回路36は、第2コンパレータ32の出力信号と命令フェッチ信号SFとが入力され、両信号に基づいて条件分岐命令検出信号Icbを出力する。命令フェッチ信号SFは、外部バスI/F14が入力してきたデータ(リードデータRD)が命令なのかデータなのかを判断する信号である。
【0028】
従って、命令デコード部23は、リードデータRDが命令であり、絶対分岐命令を検出した場合には所定レベル(例えばHレベル:1)の検出信号Iabを出力し、条件分岐命令を検出した場合には所定レベル(例えばHレベル:1)の検出信号Icbを出力する。
【0029】
先読み制御部24は、命令デコード部23の検出結果に基づいて、命令の先読みを制御する(先読みを続行させるか停止させるかを判断する)。尚、先読み制御部24は、前記先読みバッファ部22に保持されたデータ(命令)が満杯状態になるときには、その状態を示す満杯フラグFFに基づいて、命令の先読みを停止させるようになっている。
【0030】
詳述すると、先読み制御部24は、命令デコード部23により分岐命令が検出されない場合(検出信号Iab,IcbがLレベルの場合)、すなわち絶対分岐命令及び条件分岐命令のいずれも検出されない場合には命令の先読みを続行させる。
【0031】
また、先読み制御部24は、命令デコード部23により絶対分岐命令が検出される場合には命令の先読みを停止させる。詳しくは、先読みアドレス生成部21によるアドレスの生成を停止させる。
【0032】
また、先読み制御部24は、命令デコード部23により条件分岐命令が検出される場合には、先読み制御レジスタ25に予め設定されている制御フラグに従って命令の先読みを停止させるか否かを判断する。
【0033】
ここで、先読み制御レジスタ25について説明すると、該先読み制御レジスタ25は、本実施形態ではプログラム中に含まれる条件分岐命令の各種類にそれぞれ対応して設けられている。従って、先読み制御部24は、条件分岐命令が検出される場合には、その種類に応じて命令の先読みを個別に制御可能である。
【0034】
例えば、CPU12が実行する条件分岐命令の種類がA〜Dの4種類であるとする場合、先読み制御部24には、図2に示すように、各条件分岐命令A〜Dにそれぞれ対応した4つの先読み制御レジスタ25a〜25dが設けられる。従って、先読み制御部24は、命令デコード部23により条件分岐命令A〜Dの何れかが検出される場合には、それに対応した先読み制御レジスタ25a〜25dの何れかに設定されている制御フラグを参照することで、先読みを停止させるか否かを判断する。
【0035】
このような先読み制御レジスタ25(図2において先読み制御レジスタ25a〜25d)の制御フラグは、プログラム開発段階のデバッグ時に設定される。
これは、プログラム中のどの命令で条件分岐命令の分岐発生が多発するかをプログラムデバッグ時に把握可能であり、それに従って条件分岐命令の種類(図2において条件分岐命令A〜D)に応じた最適なレジスタ値(制御フラグ)の設定を行うことができるためである。
【0036】
ここで、最適な制御フラグの設定は、分岐発生頻度が高い条件分岐命令に対応した先読み制御レジスタ25の制御フラグを先読み停止を示す値に設定し、逆に分岐発生頻度が低い条件分岐命令に対応した先読み制御レジスタ25の制御フラグを先読み続行を示す値に設定することである。
【0037】
例えば、図2において、条件分岐命令Aが分岐発生頻度の低い分岐命令である場合、先読み制御レジスタ25aには、先読み継続を示す値「0」の制御フラグが設定される。従って、先読み制御部24は、条件分岐命令Aが検出される場合には先読みを継続させる。
【0038】
また、図2において、条件分岐命令Bが分岐発生頻度の高い分岐命令である場合、先読み制御レジスタ25bには、先読み停止を示す値「1」の制御フラグが設定される。従って、先読み制御部24は、条件分岐命令Bが検出される場合には先読みを停止させる。即ち、先読みアドレス生成部21によるアドレスの生成を停止させる。
【0039】
図5は、1つの条件分岐命令に対応して先読みを停止する先読み制御部24のブロック図である。尚、図5は、図2に示す条件分岐命令Bを検出した場合に先読みを停止する先読み制御部である。
【0040】
先読み制御部24は、先読み制御レジスタ25bと、組合せ回路41と、フリップフロップ(FF)42と、アンド回路43とから構成されている。先読み制御レジスタ25bには、図1のCPU12からのライトデータが書き込まれる。先読み制御レジスタ25bは、書き込まれたデータに応じたレベルの信号を出力する。組合せ回路41は、先読み制御レジスタ25bからの信号と、満杯フラグFFと、FF42の出力信号とが入力され、それら信号の組合せにより決定されるレベルを持ち命令の先読みを制御するための信号を出力する。FF42は、組合せ回路41からの信号と、クロック信号CLKが入力される。FF42は、クロック信号CLKに応答して組合せ回路41から出力される信号と実質的に同一レベルの信号を出力する。その信号は、組合せ回路41に出力される。従って、FF42により、先読み制御レジスタ25bのデータと満杯フラグFFの組合せ結果(FF42の出力信号)が保持される。また、FF42の出力信号はアンド回路43に入力される。アンド回路43には条件分岐命令検出信号Icb(条件分岐命令Bに対応した検出信号IB)が入力される。アンド回路43は、両信号に基づいて生成した先読み停止信号FSを図1の先読みアドレス生成部21に出力する。
【0041】
従って、先読み制御部24は、先読みバッファ部22に保持されたデータが満杯状態でなくFF42の出力が「1」(CPU12からのライトデータが「1」)、且つ条件分岐命令検出信号IBが「1」の場合に先読み停止を指示する(レベルが「1」の先読み停止信号FSを出力する)。
【0042】
次に、上記のような命令先読み回路13を搭載したマイクロコントローラ11の作用について説明する。ここでは、図2に示すように、先読み制御部24は、4種類の条件分岐命令A〜Dにそれぞれ対応する4つの先読み制御レジスタ25a〜25dを備え、各レジスタ25a〜25dにそれぞれ「0」,「1」,「0」,「1」の制御フラグが設定される場合を想定する。尚、値「0」は先読み続行を示す制御フラグ、値「1」は先読み停止を示す制御フラグである。
【0043】
命令先読み回路13は、先読みした命令が絶対分岐命令である場合には先読みを停止させる。また、命令先読み回路13は、先読みした命令が分岐発生頻度の高い条件分岐命令Bや条件分岐命令Dである場合には、それぞれ値「1」の制御フラグが設定された先読み制御レジスタ25b,25dに従って先読みを停止させる。
【0044】
従って、これらの場合には、命令先読み回路13により先読みした命令が使用されずに無駄になることが未然に防止される。また、外部バス16のバス帯域が開放されることで、CPU12によるメモリ17へのデータアクセスや分岐後の命令フェッチ等を効率良く行うことが可能となる。
【0045】
また、命令先読み回路13は、先読みした命令が分岐発生頻度の低い条件分岐命令Aや条件分岐命令Cである場合には、それぞれ値「0」の制御フラグが設定された先読み制御レジスタ25a,25cに従って命令の先読みを続行する。
【0046】
従って、これらの場合には、分岐発生しなかった際に必要な命令を先読みバッファ部22に前もって蓄えておくことができるため、CPU12の処理能力を低下させることはない。
【0047】
以上記述したように、本実施形態によれば、以下の効果を奏する。
(1)先読み制御部24は、条件分岐命令が検出される場合には、その分岐発生頻度に基づいて先読み制御レジスタ25に予め設定された制御フラグに従って、命令の先読みを停止させるか否かを判断する。従って、分岐発生頻度の高い条件分岐命令が検出される場合には先読みを停止して先読みした命令が無駄となるのを未然に防止できる。その結果、CPU12の処理能力を向上させることができる。
【0048】
(2)分岐発生頻度の高い条件分岐命令が検出される場合には先読みが停止されることで、外部バス16のバス帯域を有効利用して命令の先読みを効率よく行うことが可能となる。
【0049】
(3)分岐発生頻度の低い条件分岐命令が検出される場合には先読みが続行されることで、分岐発生しなかった際に必要な命令を前もって先読みバッファ部22に蓄えておくことができる。従って、それによるCPU12の処理能力低下を招くこともない。
【0050】
(4)本実施形態では、先読み制御部24に先読み制御レジスタ25を備えた極めて簡易な構成で、精度の高い先読み制御を可能とした命令先読み回路13を実現することができる。従って、分岐予測機能を備えた回路等は不要であり、回路規模の増大もない。
【0051】
(5)本実施形態では、プログラムに含まれる条件分岐命令A〜Dにそれぞれ対応する先読み制御レジスタ25a〜25dを備えたため、より精度の高い命令先読み制御が可能である。
【0052】
(第二実施形態)
以下、本発明を具体化した第二実施形態を図6〜図8に従って説明する。
図6は、第二実施形態の命令先読み回路を備えたマイクロコントローラを示すブロック図である。尚、本実施形態は、第一実施形態の命令先読み回路13にアドレス範囲比較部51を新たに追加した構成であり、その他の構成は図1と同様である。
【0053】
アドレス範囲比較部51は、アドレス範囲設定レジスタ52を備えている。
アドレス範囲設定レジスタ52には、先読みされる命令のアドレスが予め指定したアドレス範囲内にあるかどうかを判断するための第一のアドレスと第二のアドレスとが格納されている。尚、本実施形態では、プログラムの各命令ルーチン毎にそれぞれ対応したアドレス範囲を示す先頭アドレス(第一のアドレス)と終了アドレス(第二のアドレス)とがそれぞれ格納されている。
【0054】
アドレス範囲比較部51は、CPU12から出力されるアドレス(即ちメモリ17をアクセスするアドレス)と、前記レジスタ52内に設定された第一及び第二のアドレスとを比較することにより、先読みされる命令のアドレスが予め指定したアドレス範囲内のアドレスであるか否かを判断する。
【0055】
そして、アドレス範囲比較部51は、その判断結果(範囲内か否か)に基づいて、先読みを制御するためのフラグ切替信号FCを先読み制御部24に出力する。
【0056】
図7は、アドレス範囲設定レジスタ52の具体例を示す説明図である。
本実施形態において、アドレス範囲設定レジスタ52は、条件分岐命令の種類(図において条件分岐命令A〜D)にそれぞれ対応する先読み制御レジスタ25a〜25dの制御フラグを個別に切り替え制御可能とする4つのレジスタを含む。
【0057】
すなわち、アドレス範囲比較部51は、アドレス範囲設定レジスタ52a〜52dを備え、それらに設定されたアドレス範囲に従って切り替え制御を行う。
ここで、各アドレス範囲設定レジスタ52a〜52dには、プログラムに含まれる各命令ルーチンに対応して、それぞれアドレス範囲S100,S200,S300,…を示す先頭アドレスADS1,ADS2,ADS3,…と終了アドレスADE1,ADE2,ADE3,…とが記憶されている。
【0058】
図8は、1つのアドレス範囲設定レジスタ52aに対応するアドレス範囲比較部51aのブロック図である。
このアドレス範囲比較部51aは、スタートアドレスレジスタ61、エンドアドレスレジスタ62、内外設定レジスタ63、大小比較回路64、排他的論理和(EOR)回路65から構成されている。スタートアドレスレジスタ61には範囲の先頭を示すアドレスが格納され、エンドアドレスレジスタ62には範囲の終わりを示すアドレスが格納される。内外設定レジスタ63には、指定の領域がスタートアドレスからエンドアドレスの範囲内か範囲外かを示す設定値が格納される。例えば、内外設定レジスタ63には、範囲内を指定する場合には「1」が、範囲外を指定する場合には「0」が格納される。
【0059】
大小比較回路64は、入力されるアドレスADDが先頭アドレスと終了アドレスの範囲に入っているか否かを検出するためのコンパレータであり、その検出結果を出力する。例えば、大小比較回路64は、アドレスADDが先頭アドレスと終了アドレスの範囲内に入っている時には「1」の信号を出力し、アドレスADDがその範囲に入っていない時には「0」の信号を出力する。
【0060】
EOR回路65は、大小比較回路64の出力信号と内外設定レジスタ63のデータとを排他的論理和演算して生成したフラグ切替信号FCを出力する。
従って、アドレス範囲比較部51aは、上記の条件が一致している場合に例えばHレベル(1)のフラグ切替信号FCを出力し、少なくとも1つの条件が不一致の場合にLレベル(0)のフラグ切替信号FCを出力する。
【0061】
以下、アドレス範囲設定レジスタ52aを例としてその作用を説明する。
CPU12によるプログラムの実行において、アドレス範囲比較部51は、CPU12のアクセスアドレスを監視し、それが現在どの命令ルーチンに対応したアドレス範囲のアドレスであるかをチェックする。
【0062】
ここで、CPU12のアクセスアドレスが例えば先頭アドレスADS1と終了アドレスADE1とで示されるアドレス範囲S100内のアドレスである場合、アドレス範囲比較部51は、先読みを継続させるようにフラグ切替信号FCを生成する。
【0063】
次いで、CPU12のアクセスアドレスが例えば先頭アドレスADS2と終了アドレスADE2とで示されるアドレス範囲S200内のアドレスである場合、アドレス範囲比較部51は、先読みを停止させるようにフラグ切替信号FCを生成する。
【0064】
次いで、CPU12のアクセスアドレスが例えば先頭アドレスADS3と終了アドレスADE3とで示されるアドレス範囲S300内のアドレスである場合、アドレス範囲比較部51は、先読みを継続させるようにフラグ切替信号FCを生成する。
【0065】
このように、アドレス範囲比較部51は、CPU12のアクセスアドレスがどのアドレス範囲内にあるか(即ち先読みされる命令がどの命令ルーチンに含まれるか)を判断してフラグ切替信号FCを生成する。そのフラグ切替信号FCは図5に示す先読み制御部24の組合せ回路41に入力される。従って、先読み制御部24は、フラグ切替信号FCと満杯フラグFFと先読み制御レジスタ25(図5において25b)との組合せと、条件分岐命令検出信号IBが「1」の場合に先読みを制御する信号を出力する。
【0066】
つまり、アドレス範囲比較部51は、CPU12のアクセスアドレスがどのアドレス範囲内にあるかに応じて、命令先読みを続行させるか否かの制御を切り替える。尚、ここでは説明を省略するが、その他のアドレス範囲設定レジスタ52b〜52dに関しても同様である。
【0067】
以上記述したように、本実施形態では、先読み制御レジスタ25(先読み制御レジスタ25a〜25d)に設定された制御フラグを、プログラム実行時にCPU12のアクセスアドレスが属するアドレス範囲に応じて切り替え可能とした。この構成では、各命令ルーチンで条件分岐命令(条件分岐命令A〜D)の分岐発生頻度がそれぞれ異なる場合にも適切な先読み制御を行うことが可能である。従って、第一実施形態に比べて精度の高い先読み制御が可能である。
【0068】
(第三実施形態)
以下、本発明を具体化した第三実施形態を図9,図10に従って説明する。
図9は、第三実施形態の命令先読み回路を備えたマイクロコントローラを示すブロック図である。尚、本実施形態は、第一実施形態の命令先読み回路13に、第二実施形態のアドレス範囲比較部51に替えてデータパターン検出部71を新たに追加した構成であり、その他の構成は図1と同様である。
【0069】
データパターン検出部71は、CPU12がメモリ17から読み出す特定のデータパターンを保持するデータ保持レジスタ72を備えている。
そして、データパターン検出部71は、CPU12がアクセスしたデータパターンと、データ保持レジスタ72に保持されているデータパターンとを比較し、それぞれのデータが一致する場合に、先読みを制御するためのフラグ切替信号FC1を先読み制御部24に出力する。そのフラグ切替信号FC1は図5に示す先読み制御部24の組合せ回路41に入力される。従って、先読み制御部24は、フラグ切替信号FC1と満杯フラグFFと先読み制御レジスタ25(図5において25b)との組合せと、条件分岐命令検出信号IBが「1」の場合に先読みを制御する信号を出力する。
【0070】
尚、本実施形態のデータ保持レジスタ72には、条件分岐命令の種類(図2において条件分岐命令A〜D)にそれぞれ対応した先読み制御レジスタ25a〜25dの制御フラグをデータパターンに応じて個別に切り替え可能とする4つのレジスタが設けられている。
【0071】
図10は、1つのデータパターンと一致する条件分岐命令を検出するデータパターン検出部71aのブロック図である。
このデータパターン検出部71aは、複数のビット判定部81、アンド回路82,83を備えている。ビット判定部81は、図9のCPU12がアクセスしたデータパターンの所定ビットが指定したデータのビットと一致するか否かを判定する回路である。従って、データパターン検出部71aは、判定するビット数に対応する数のビット判定部81を備える。
【0072】
ビット判定部81は、データパターンレジスタ84、マスクレジスタ85、ビット比較回路86、アンド回路87を備えている。データパターンレジスタ84とマスクレジスタ85は1ビットのレジスタであり、データパターンレジスタ84は図9のデータ保持レジスタ72を構成する。データパターンレジスタ84には、指定したデータパターンの1ビットが記憶されている。ビット比較回路86は、CPU12がアクセスしたデータの1ビットとデータパターンレジスタ84の内容とを比較し、その比較結果を出力する。例えば、ビット比較回路86は、両データが一致する場合には「1」の信号を、それらが一致しない場合には「0」の信号を出力する。
【0073】
アンド回路87は、ビット比較回路86の出力信号とマスクレジスタ85のデータとを論理積演算して生成した信号を出力する。マスクレジスタ85には、CPU12がアクセスしたデータの比較結果をマスクするデータが記憶されている。従って、アンド回路87は、マスクレジスタ85のマスクが「1」の場合にはビット比較回路86の出力信号と実質的に同じレベルの信号を出力し、マスクレジスタ85のマスクが「0」の場合には「1」レベルの信号を出力する。
【0074】
従って、ビット判定部81は、対応する位置のビットが一致するか否かを判定するとともに、その判定結果をマスクレジスタ85の内容に基づいてマスクする。
【0075】
アンド回路82は複数入力素子であり、入力数はビット判定部81の数に相当する。即ち、アンド回路82は、複数のビット判定部81の出力信号を入力し、それら信号を論理和演算した信号を出力する。従って、アンド回路82は、複数のビット判定部81におけるデータパターンと指定したデータとの比較判定が全て一致である場合に例えばHレベルの信号を出力し、少なくとも一つが不一致である場合にLレベルの信号を出力する。
【0076】
アンド回路83には、アンド回路82の出力信号とデータアクセス信号ACCが入力され、フラグ切替信号FC1aを出力する。
従って、データパターン検出部71aは、図9のCPU12がアクセスしたデータのパターンが指定したデータ(データ保持レジスタ72のデータの1ビット)のパターンと一致する場合に、先読みを制御するためのフラグ切替信号FC1aを先読み制御部24に出力する。上記と同様にして、そのフラグ切替信号FC1aは図5に示す先読み制御部24の組合せ回路41に入力される。そして、先読み制御部24は、フラグ切替信号FC1aと満杯フラグFFと先読み制御レジスタ25(図5において25b)との組合せと、条件分岐命令検出信号IBが「1」の場合に先読みを制御する信号を出力する。
【0077】
このようなデータパターン検出部71を備える命令先読み回路13では、先読み制御レジスタ25(先読み制御レジスタ25a〜25d)に設定された制御フラグを、プログラム実行時にCPU12がアクセスするデータパターンに応じて変更することができる。従って、第一実施形態に比べて精度の高い先読み制御が可能となる。
【0078】
尚、本実施形態では、特定のデータパターンを検出した場合にレジスタ設定を切り替えるようにしたが、特定のデータパターンが連続、もしくは複数種の固有のデータパタンが連続した場合にレジスタ設定を切り替えるようにしてもよい。
【0079】
即ち、図10において、フラグレジスタ88とアンド回路89を更に備える。フラグレジスタ88は、アンド回路83の出力信号を保持すると共に、その保持した信号と実質的に同じレベルの信号を出力する。アンド回路89は、フラグレジスタ88の出力信号とアンド回路83の出力信号が入力され、フラグ切替信号FC1bを出力する。アンド回路89の入力信号がともに「一致」を示す場合、即ち、図9のCPU12が連続してアクセスしたデータのパターンが指定したデータのパターンとが一致する場合に、先読みを制御するためのフラグ切替信号FC1bを先読み制御部24に出力する。そして、上記と同様に、先読み制御部24は、フラグ切替信号FC1bと満杯フラグFFと先読み制御レジスタ25(図5において25b)との組合せと、条件分岐命令検出信号IBが「1」の場合に先読みを制御する信号を出力する。
【0080】
また、図11に示すようにデータパターン検出部71bを構成する。このデータパターン検出部71bは、複数(本例では4つ)の一致検出回路91a〜91dとステートマシン92とから構成される。各一致検出回路91a〜91dは同じ構成であり、1つの一致検出回路91dにて図示するように、図9のデータパターン検出部71aと同様にビット判定部81とアンド回路82とを備えている。そして、各一致検出回路91a〜91dのデータパターンレジスタ84、即ち各一致検出回路91a〜91dのデータ保持レジスタ72にはそれぞれ指定したデータ(指定データDA〜DD:図において左下に記す)が格納される。従って、各一致検出回路91a〜91dは、図9のCPU12がアクセスしたデータのパターンとそれぞれ指定データDA〜DDと一致するか否かを検出して信号を出力する。
【0081】
ステートマシン92は、各一致検出回路91a〜91dの出力信号に基づいて複数種の固有パターンのデータが連続した場合に先読みを制御するためのフラグ切替信号FC2を先読み制御部24に出力する。詳しくは、ステートマシン92はCPU12がデータをアクセスする毎に各一致検出回路91a〜91dの出力信号に基づいて図12に示される状態を遷移し、フラグ切替信号FC2をアサートする。
【0082】
先ず、ステートマシン92はリセット後にアイドル状態(IDLE)101にある。この時、ステートマシン92は第1の一致検出回路91aにおいてCPU12のアクセスデータと指定データDAとが一致する場合に第1の状態102に遷移する。次に、ステートマシン92は、第2の一致検出回路91bにおいてCPU12のアクセスデータと指定データDBとが一致する場合に第2の状態103に遷移し、不一致の場合にアイドル状態101に遷移する。
【0083】
同様に、ステートマシン92は、第3の一致検出回路91cにおいてCPU12のアクセスデータと指定データDCとが一致する場合に第3の状態104に遷移し、不一致の場合にアイドル状態101に遷移する。更に、ステートマシン92は、第4の一致検出回路91dにおいてCPU12のアクセスデータと指定データDDとが一致する場合に第5の状態105に遷移し、不一致の場合にアイドル状態101に遷移する。そして、第5の状態105において、ステートマシン92はフラグ切替信号FC2をアサートし、アイドル状態101に遷移する。
【0084】
従って、このデータパターン検出部71bは、CPU12が連続してアクセスした4つのデータが各一致検出回路91a〜91dの指定データDA〜DDとそれぞれ一致し、且つ4つのデータの順番がステートマシン92の状態遷移順と一致する場合にフラグ切替信号FC2をアサートする。
【0085】
そのフラグ切替信号FC2は、上記と同様に図5に示す先読み制御部24の組合せ回路41に入力される。従って、先読み制御部24は、フラグ切替信号FC2と満杯フラグFFと先読み制御レジスタ25(図5において25b)との組合せと、条件分岐命令検出信号IBが「1」の場合に先読みを制御する信号を出力する。
【0086】
(第四実施形態)
以下、本発明を具体化した第四実施形態を図13に従って説明する。
尚、本実施形態は、プログラムデバッグ時に、条件分岐命令の分岐発生頻度を算出して、上述した各実施形態における先読み制御レジスタ25(先読み制御レジスタ25a〜25d)の制御フラグの設定を行うためのアシスト回路について説明するものである。
【0087】
図13に示すように、アシスト回路110は、条件分岐命令格納レジスタ111、コンパレータ112、第一のカウンタ113、第二のカウンタ114及び制御回路115を含む。アシスト回路110は、マイクロコントローラ11を構成する半導体チップ15上に形成され、具体的にはメモリ17から読み出された命令がバスI/F14を介してCPU12に転送されるデータバスに接続して形成される。
【0088】
条件分岐命令格納レジスタ111には、プログラムデバッグに先立って該プログラムに含まれる条件分岐命令のうち何れかの命令(分岐発生頻度を把握したい命令)が予め格納される。
【0089】
コンパレータ112は、デバッグ実行時にCPU12により読み込まれた条件分岐命令と、前記レジスタ111内に予め格納されている条件分岐命令とを比較し、互いの命令が一致する場合に一致信号S1を第一のカウンタ113及び制御回路115に出力する。第一のカウンタ113は、そのコンパレータ112からの一致信号S1に応答してカウント値N1をカウントアップする。
【0090】
制御回路115は、前記互いの命令が一致する場合において、それに該当する条件分岐命令が実際に分岐発生するときにCPU12から出力される分岐発生信号BENに応答して、第二のカウンタ114に分岐発生検出信号S2を出力する。第二のカウンタ114は、その制御回路115からの分岐発生検出信号S2に応答してカウント値N2をカウントアップする。
【0091】
このように構成されるアシスト回路110では、プログラムを一度動作させ、カウント値N1に対するカウント値N2の割合を求めることで、前記レジスタ111に格納されている条件分岐命令の分岐発生頻度を算出することができる。
【0092】
そして、このような操作をプログラムに含まれる全ての条件分岐命令に対して行うことで、それぞれの条件分岐命令について分岐発生頻度を算出することができる。
【0093】
従って、このようなアシスト回路110を用いて求めた分岐発生頻度に基づいてレジスタ設定を行うことで、各条件分岐命令(図2において条件分岐命令A〜D)に応じた最適なレジスタ値の設定を行うことができる。
【0094】
以上記述したように、本実施形態によれば、以下の効果を奏する。
尚、上記各実施形態は、以下の態様で実施してもよい。
・第一実施形態の命令先読み回路13に、第二実施形態のアドレス範囲比較部51及び第三実施形態のデータパターン検出部71を共に備える構成としてもよい。その場合、図5に示す先読み制御部24の組合せ回路41は、先読み制御レジスタ25bからの信号と、満杯フラグFFと、フラグ切替信号FC,FC1と、FF42の出力信号とが入力され、それら信号の組合せにより決定されるレベルを持ち命令の先読みを制御するための信号を出力する。そして、先読み制御部24は、組合せ回路41の出力信号が「1」、且つ条件分岐命令検出信号IBが「1」の場合に先読み停止を指示する(レベルが「1」の先読み停止信号FSを出力する)。
【0095】
・各実施形態では、プログラムに含まれる条件分岐命令の種類毎に命令先読み制御を行うようにしたが、必ずしもその必要はなく、プログラム中の条件分岐命令のうち特定の条件分岐命令についてのみ行うようにしてもよい。
【0096】
・各実施形態では、先読み制御レジスタ25(先読み制御レジスタ25a〜25d)の制御フラグを、CPU12が特定の命令コードを読み込むときに切り替えるようにしてもよい。但し、この場合には、プログラム中に特定の命令コードを予め設定しておく必要がある。
【0097】
・第三実施形態では、データ保持レジスタ72を備える代わりに、例えばCPU12からの制御信号によって特定のデータパターンを検出するようにしてもよい。
【0098】
上記各実施形態の特徴をまとめると以下のようになる。
(付記1) メモリから命令を先読みする命令先読み回路において、
先読みした命令をデコードして分岐命令を検出する命令デコード部と、
前記命令デコード部により検出される分岐命令が絶対分岐命令の場合に先読みを停止させる先読み制御部とを備え、
前記先読み制御部には、前記命令デコード部により検出される分岐命令が条件分岐命令の場合に先読みを停止させるか否かを判断するための制御フラグが設定された先読み制御レジスタが備えられていることを特徴とする命令先読み回路。
(付記2) 前記先読み制御レジスタを前記条件分岐命令の種類毎に設けたことを特徴とする付記1記載の命令先読み回路。
(付記3) 前記制御フラグを前記条件分岐命令の分岐発生頻度に基づいて設定したことを特徴とする付記1又は2記載の命令先読み回路。
(付記4) 先読みする命令のアドレスが予め定めたアドレス範囲内のアドレスであるか否かを判断し、該判断結果に基づいて前記先読み制御レジスタに設定された制御フラグを切り替え可能とするアドレス範囲比較部を備えたことを特徴とする付記1乃至3の何れか一記載の命令先読み回路。
(付記5) 前記アドレス範囲比較部には、前記アドレス範囲を指定する第一のアドレスと第二のアドレスとが格納されるアドレス範囲設定レジスタが備えられていることを特徴とする付記4記載の命令先読み回路。
(付記6) 前記アドレス範囲設定レジスタを前記条件分岐命令の種類毎にそれぞれ設けたことを特徴とする付記5記載の命令先読み回路。
(付記7) 前記アドレス範囲を、先読みする命令が含まれる命令ルーチン毎に設定したことを特徴とする付記4乃至6の何れか一記載の命令先読み回路。
(付記8) 前記メモリから読み出されるデータパターンが予め定めた特定のデータパターンである場合に、前記先読み制御レジスタに設定された制御フラグを切り替え可能とするデータパターン検出部を備えたことを特徴とする付記1乃至7の何れか一記載の命令先読み回路。
(付記9) 前記データパターン検出部には、前記特定のデータパターンを保持するデータ保持レジスタが備えられていることを特徴とする付記8記載の命令先読み回路。
(付記10) 前記データ保持レジスタを前記条件分岐命令の種類毎にそれぞれ設けたことを特徴とする付記9記載の命令先読み回路。
(付記11) 前記メモリから読み出される命令が予め定めた特定の命令コードである場合に、前記先読み制御レジスタに設定された制御フラグを切り替え可能としたことを特徴とする付記1乃至10の何れか一記載の命令先読み回路。
(付記12) 予め指定した条件分岐命令を検出する場合にカウントアップする第一のカウンタと、
前記予め指定した条件分岐命令が分岐発生した場合にカウントアップする第二のカウンタとを備え、
前記第一及び第二のカウンタのカウント値に基づいて前記条件分岐命令の分岐発生頻度を算出するためのアシスト回路を備えることを特徴とする付記1乃至11の何れか一記載の命令先読み回路。
(付記13) 付記1乃至12の何れか一記載の命令先読み回路を備えたことを特徴とするマイクロコントローラ。
【0099】
【発明の効果】
以上詳述したように、本発明によれば、簡易な回路構成で処理能力の向上を図ることのできる命令先読み回路及びマイクロコントローラを提供することができる。
【図面の簡単な説明】
【図1】第一実施形態の命令先読み回路を示すブロック図である。
【図2】先読み制御レジスタを示す説明図である。
【図3】命令デコード部を示すブロック図である。
【図4】命令の構造を示す説明図である。
【図5】先読み制御部を示すブロック図である。
【図6】第二実施形態の命令先読み回路を示すブロック図である。
【図7】アドレス範囲設定レジスタを示す説明図である。
【図8】アドレス範囲比較部を示すブロック図である。
【図9】第三実施形態の命令先読み回路を示すブロック図である。
【図10】データパターン検出部を示すブロック図である。
【図11】別のデータパターン検出部を示すブロック図である。
【図12】ステートマシンの状態遷移図である。
【図13】第四実施形態を説明するブロック図である。
【符号の説明】
Iab 絶対分岐命令検出信号
Icb 条件分岐命令検出信号
A〜D 条件分岐命令
ADD アドレス
ADS1,ADS2,ADS3,… 第一のアドレスとしての先頭アドレス
ADE1,ADE2,ADE3,… 第二のアドレスとしての終了アドレス
S100,S200,S300,… アドレス範囲
N1,N2 カウント値
11 マイクロコントローラ
13 命令先読み回路
17 メモリ
23 命令デコード部
24 先読み制御部
25,25a〜25d 先読み制御レジスタ
37 命令
51,51a アドレス範囲比較部
52,52a〜52d アドレス範囲設定レジスタ
71,71a,71b データパターン検出部
72 データ保持レジスタ
110 アシスト回路
113 第一のカウンタ
114 第二のカウンタ
[0001]
TECHNICAL FIELD OF THE INVENTION
The present invention relates to an instruction prefetch circuit and a microcontroller.
In recent years, the operation speed of a microcontroller has been relatively higher than that of peripheral circuits such as a memory, as the operating frequency of a CPU has been increased. Therefore, there is a configuration in which a processing speed of the CPU is improved by mounting an instruction prefetch circuit that reads the instruction from a memory in advance and holds the instruction before executing the instruction by the CPU. There is a demand for improved microcontroller memory access efficiency.
[0002]
[Prior art]
2. Description of the Related Art Conventionally, as one of devices having an instruction prefetching function, there is a configuration in which prefetching of an instruction is stopped when an instruction read by a processor such as a CPU is a conditional branch instruction (for example, Patent Documents 1 and 2). 2).
[0003]
That is, in this configuration, when the branch instruction is detected regardless of the type of the conditional branch instruction, the prefetching of the instruction is stopped until the branch destination address of the instruction is determined, so that when a branch occurs, It is prevented that the prefetched instruction is not used and is wasted. As a result, it is possible to minimize memory access for instruction prefetching.
[0004]
[Patent Document 1]
JP-A-5-27972
[Patent Document 2]
JP 2001-312404 A
[0005]
[Problems to be solved by the invention]
However, if the prefetch is always stopped when a conditional branch instruction is detected, as in the above-described related art, there is a problem that the prefetch efficiency is reduced when the branch instruction does not cause a branch. That is, there is a problem in that the processing capability of the CPU is reduced because necessary instructions are not read in advance when a branch does not occur because the condition is satisfied or not satisfied in the conditional branch instruction.
[0006]
As a means for solving this problem, there is a configuration in which both instruction addresses when a conditional branch instruction is detected and when a branch does not occur are calculated and prefetched (for example, see Patent Document 2). In this configuration, it is necessary to pre-read many instructions, and as a result, the processing capacity of the CPU is reduced.
[0007]
Further, as another means, there is a configuration in which information on the frequency of occurrence of a past branch is stored in advance, and when a conditional branch instruction is detected, whether or not to branch is predicted and a branch destination instruction is prefetched. However, the configuration having such a branch prediction function has a disadvantage that the circuit scale is increased because the circuit is complicated.
[0008]
SUMMARY OF THE INVENTION The present invention has been made to solve the above problems, and an object of the present invention is to provide an instruction prefetch circuit and a microcontroller capable of improving processing performance with a simple circuit configuration.
[0009]
[Means for Solving the Problems]
In order to achieve the above object, according to the first and tenth aspects of the present invention, in the instruction prefetching circuit, the prefetch control unit stops prefetching when the branch instruction detected by the instruction decoding unit is an absolute branch instruction. Let it. When the branch instruction detected by the instruction decoding unit is a conditional branch instruction, the prefetch control unit determines whether to stop prefetch based on a control flag set in the prefetch control register. In such a configuration, prefetching can be stopped when a conditional branch instruction having a high branch occurrence frequency is detected, and conversely, prefetching can be continued when a conditional branch instruction having a low branch occurrence frequency is detected. . As a result, it is possible to improve the processing capability while efficiently prefetching instructions by effectively using the bus bandwidth of the external bus.
[0010]
According to the second aspect of the present invention, since the prefetch control register is provided for each type of the conditional branch instruction, more accurate prefetch control is possible.
According to the third aspect of the present invention, it is determined whether or not the address of an instruction to be prefetched is within a predetermined address range, and a control flag set in the prefetch control register based on the judgment result. And an address range comparison unit that can be switched. As a result, the control flag can be appropriately switched at the time of executing the program, so that more accurate read-ahead control can be performed.
[0011]
According to the fourth aspect of the present invention, the address range comparing section is provided with an address range setting register for storing a first address and a second address designating the address range.
[0012]
According to the fifth aspect of the present invention, the address range is set for each instruction routine including a prefetch instruction. As a result, even when the branch occurrence frequency of the conditional branch instruction differs for each instruction routine included in the program, highly accurate prefetch control can be performed.
[0013]
According to the invention described in claim 6, when the data pattern read from the memory is a predetermined specific data pattern, a data pattern detection unit that can switch a control flag set in the prefetch control register is provided. Equipped. As a result, the control flag can be appropriately switched at the time of executing the program, so that more accurate read-ahead control can be performed.
[0014]
According to the seventh aspect of the present invention, the data pattern detection unit includes a data holding register that holds the specific data pattern.
According to the invention described in claim 8, when the instruction read from the memory is a predetermined specific instruction code, the control flag set in the prefetch control register can be switched. As a result, the control flag can be appropriately switched at the time of executing the program, so that more accurate read-ahead control can be performed.
[0015]
According to the ninth aspect of the present invention, the first counter counts up when a pre-specified conditional branch instruction is detected, and the second counter counts up when the pre-specified conditional branch instruction branches. A counter, and an assist circuit for calculating a branch occurrence frequency of the conditional branch instruction based on count values of the first and second counters. Thus, the value of the control flag set in the prefetch control register can be determined.
[0016]
BEST MODE FOR CARRYING OUT THE INVENTION
(First embodiment)
Hereinafter, a first embodiment of the present invention will be described with reference to FIGS.
[0017]
FIG. 1 is a schematic block diagram illustrating a microcontroller including the instruction prefetch circuit according to the first embodiment.
The microcontroller 11 includes a CPU 12, a command prefetch circuit 13, and an external bus interface (hereinafter, abbreviated as bus I / F) 14, which are formed on the same semiconductor chip 15. A memory 17 is connected to the microcontroller 11 via an external bus 16 connected to a bus I / F 14. The memory 17 stores programs and data executed by the CPU 12.
[0018]
The instruction prefetch circuit 13 includes a prefetch address generation unit 21, a prefetch buffer unit 22, an instruction decoding unit 23, and a prefetch control unit 24. The prefetch control unit 24 includes a prefetch control register 25.
[0019]
The prefetch address generation unit 21 generates an address of an instruction to be executed next by the CPU 12 based on an address output from the CPU 12. Specifically, the addresses loaded at the time of the first instruction fetch after power-on or reset, or the first instruction fetch after a branch is generated by an absolute branch instruction or a conditional branch instruction described later are sequentially counted up and prefetched. Generate the address of the instruction to execute.
[0020]
The address generated by the prefetch address generation unit 21 is output to the external bus 16 via the arithmetic unit 26 and the bus I / F 14. Thus, the instruction prefetching circuit 13 reads out (prefetches) the instruction corresponding to each address from the memory 17.
[0021]
The instruction prefetched from the memory 17 is held in the prefetch buffer unit 22 and decoded by the instruction decoding unit 23. The prefetch buffer unit 22 is configured by, for example, a FIFO (First-In First-Out) memory, sequentially fetches prefetched instructions, and outputs the fetched instructions to the CPU 12 via the arithmetic unit 27. Therefore, the CPU 12 decodes instructions prefetched by the instruction prefetch circuit 13 and sequentially executes the processes.
[0022]
The instruction that is prefetched and held in the prefetch buffer unit 22 is cleared when the CPU 12 executes an instruction that has been branched by an absolute branch instruction or a conditional branch instruction described later.
[0023]
The instruction decoding unit 23 decodes an instruction read ahead from the memory 17 and detects a branch instruction. Specifically, the instruction decoding unit 23 detects an absolute branch instruction and a conditional branch instruction included in the prefetched instruction, and sends the absolute branch instruction detection signal Iab and the conditional branch instruction detection signal Icb to the prefetch control unit 24 as the detection result. Output. In this embodiment, when detecting a conditional branch instruction, the instruction decoding unit 23 outputs a detection result (detection signal) corresponding to each type of the conditional branch instruction to the prefetch control unit 24.
[0024]
FIG. 3 is a block diagram illustrating an example of the instruction decoding unit 23 that detects an absolute branch instruction and one conditional branch instruction.
The instruction decoding unit 23 includes first and second comparators 31 and 32, first and second storage units 33 and 34, and first and second AND circuits 35 and 36. Read data RD from the external bus I / F 14 is input to the first and second comparators 31 and 32. The output signal of the first storage unit 33 is input to the first comparator 31, and the output signal of the second storage unit 34 is input to the second comparator 32.
[0025]
The first and second storage units 33 and 34 are composed of hardwires such as a register rewritable from the CPU 12 or externally, or a mask ROM, and store an absolute branch instruction and a conditional branch instruction, respectively. As shown in FIG. 4, the instruction 37 includes an operation code section (OP code section) 38 and an operand section 39. The first storage unit 33 stores the data of the OP code unit 38 of the absolute branch instruction, and the second storage unit 34 stores the data of the OP code unit 38 of the conditional branch instruction. The first and second storage units 33 and 34 output the stored data of the operation code unit 38, respectively.
[0026]
Accordingly, the first comparator 31 receives the read data RD and the data of the OP code part 38 of the absolute branch instruction, and outputs a signal corresponding to the result of comparing the two. The second comparator 32 receives the read data RD and the data of the OP code part 38 of the conditional branch instruction, and outputs a signal corresponding to the result of comparing the two.
[0027]
The first AND circuit 35 receives the output signal of the first comparator 31 and the instruction fetch signal SF, and outputs an absolute branch instruction detection signal Iab based on both signals. The second AND circuit 36 receives the output signal of the second comparator 32 and the instruction fetch signal SF, and outputs a conditional branch instruction detection signal Icb based on both signals. The instruction fetch signal SF is a signal for determining whether the data (read data RD) input to the external bus I / F 14 is an instruction or data.
[0028]
Therefore, the instruction decoding unit 23 outputs a detection signal Iab of a predetermined level (for example, H level: 1) when the read data RD is an instruction and detects an absolute branch instruction, and outputs a detection signal Iab when detecting a conditional branch instruction. Outputs a detection signal Icb of a predetermined level (for example, H level: 1).
[0029]
The prefetch control unit 24 controls prefetching of the instruction based on the detection result of the instruction decoding unit 23 (determines whether to continue or stop the prefetching). When the data (instruction) held in the prefetch buffer unit 22 is full, the prefetch control unit 24 stops prefetching the instruction based on a full flag FF indicating the state. .
[0030]
More specifically, the prefetch control unit 24 determines whether the instruction decoding unit 23 does not detect a branch instruction (when the detection signals Iab and Icb are at L level), that is, when neither the absolute branch instruction nor the conditional branch instruction is detected. Causes the instruction to look ahead.
[0031]
When the instruction decoding unit 23 detects an absolute branch instruction, the prefetch control unit 24 stops prefetching the instruction. Specifically, the generation of addresses by the prefetch address generation unit 21 is stopped.
[0032]
When a conditional branch instruction is detected by the instruction decoding unit 23, the prefetch control unit 24 determines whether to stop prefetching of an instruction according to a control flag preset in a prefetch control register 25.
[0033]
Here, the prefetch control register 25 will be described. In the present embodiment, the prefetch control register 25 is provided corresponding to each type of conditional branch instruction included in the program in the present embodiment. Therefore, when the conditional branch instruction is detected, the prefetch control unit 24 can individually control the prefetch of the instruction according to the type.
[0034]
For example, when the types of conditional branch instructions executed by the CPU 12 are four types of A to D, the prefetch control unit 24 stores four types of conditional branch instructions A to D, as shown in FIG. Two prefetch control registers 25a to 25d are provided. Therefore, when any one of the conditional branch instructions A to D is detected by the instruction decoding unit 23, the prefetch control unit 24 resets the control flag set in any of the prefetch control registers 25a to 25d corresponding to the condition branch instruction. By referencing, it is determined whether or not to stop the prefetching.
[0035]
The control flag of such a prefetch control register 25 (the prefetch control registers 25a to 25d in FIG. 2) is set at the time of debugging in the program development stage.
This makes it possible to grasp at the time of program debugging which instruction in the program causes the occurrence of a conditional branch instruction to frequently occur, and accordingly optimizes the type of the conditional branch instruction (the conditional branch instructions A to D in FIG. 2) according to the type. This is because a register value (control flag) can be set.
[0036]
Here, the optimal control flag is set by setting the control flag of the prefetch control register 25 corresponding to the conditional branch instruction having a high branch occurrence frequency to a value indicating stop of prefetch, and conversely, setting the control flag to the conditional branch instruction having a low branch occurrence frequency. That is, the control flag of the corresponding prefetch control register 25 is set to a value indicating continuation of prefetch.
[0037]
For example, in FIG. 2, when the conditional branch instruction A is a branch instruction with a low branch occurrence frequency, a control flag of a value “0” indicating continuation of prefetch is set in the prefetch control register 25a. Therefore, when the conditional branch instruction A is detected, the prefetch control unit 24 continues the prefetch.
[0038]
In FIG. 2, when the conditional branch instruction B is a branch instruction having a high branch occurrence frequency, a control flag of a value “1” indicating stop of prefetch is set in the prefetch control register 25b. Therefore, when the conditional branch instruction B is detected, the prefetch control unit 24 stops the prefetch. That is, the generation of the address by the prefetch address generation unit 21 is stopped.
[0039]
FIG. 5 is a block diagram of the prefetch control unit 24 that stops prefetching in response to one conditional branch instruction. FIG. 5 shows a prefetch control unit which stops prefetching when the conditional branch instruction B shown in FIG. 2 is detected.
[0040]
The prefetch control unit 24 includes a prefetch control register 25b, a combination circuit 41, a flip-flop (FF) 42, and an AND circuit 43. Write data from the CPU 12 in FIG. 1 is written in the pre-read control register 25b. The prefetch control register 25b outputs a signal of a level according to the written data. The combinational circuit 41 receives the signal from the prefetch control register 25b, the full flag FF, and the output signal of the FF42, and outputs a signal having a level determined by a combination of these signals and controlling the prefetching of the instruction. I do. The FF 42 receives the signal from the combination circuit 41 and the clock signal CLK. The FF outputs a signal having substantially the same level as the signal output from the combination circuit 41 in response to the clock signal CLK. The signal is output to the combination circuit 41. Therefore, the combination result (the output signal of the FF42) of the data of the prefetch control register 25b and the full flag FF is held by the FF42. The output signal of the FF 42 is input to the AND circuit 43. The AND circuit 43 receives a conditional branch instruction detection signal Icb (a detection signal IB corresponding to the conditional branch instruction B). The AND circuit 43 outputs a prefetch stop signal FS generated based on both signals to the prefetch address generation unit 21 in FIG.
[0041]
Therefore, the prefetch control unit 24 determines that the data held in the prefetch buffer unit 22 is not full, the output of the FF 42 is “1” (the write data from the CPU 12 is “1”), and the conditional branch instruction detection signal IB is “1”. In the case of "1", a prefetch stop is instructed (a prefetch stop signal FS having a level of "1" is output).
[0042]
Next, the operation of the microcontroller 11 equipped with the instruction prefetch circuit 13 as described above will be described. Here, as shown in FIG. 2, the prefetch control unit 24 includes four prefetch control registers 25a to 25d corresponding to four types of conditional branch instructions A to D, respectively, and each register 25a to 25d has “0”. , “1”, “0”, and “1” are set. Note that the value “0” is a control flag indicating that prefetching is to be continued, and the value “1” is a control flag indicating stopping prefetching.
[0043]
The instruction prefetch circuit 13 stops prefetching when the prefetched instruction is an absolute branch instruction. When the prefetched instruction is the conditional branch instruction B or the conditional branch instruction D having a high branch occurrence frequency, the instruction prefetch circuit 13 sets the prefetch control registers 25b and 25d in which the control flag of the value “1” is set, respectively. The prefetching is stopped according to.
[0044]
Therefore, in these cases, it is possible to prevent the instruction prefetched by the instruction prefetching circuit 13 from being wasted without being used. Further, since the bus bandwidth of the external bus 16 is released, it is possible to efficiently perform data access to the memory 17 by the CPU 12 and instruction fetch after branching.
[0045]
When the prefetched instruction is a conditional branch instruction A or a conditional branch instruction C with a low branch occurrence frequency, the instruction prefetch circuit 13 sets the prefetch control registers 25a and 25c each having a control flag of a value “0” set therein. And continues the look-ahead instruction.
[0046]
Therefore, in these cases, an instruction required when a branch does not occur can be stored in the prefetch buffer unit 22 in advance, so that the processing capability of the CPU 12 is not reduced.
[0047]
As described above, the present embodiment has the following advantages.
(1) When a conditional branch instruction is detected, the prefetch control unit 24 determines whether or not to stop prefetching of an instruction in accordance with a control flag preset in a prefetch control register 25 based on the branch occurrence frequency. to decide. Accordingly, when a conditional branch instruction having a high branch occurrence frequency is detected, prefetching can be stopped and the prefetched instruction can be prevented from being wasted. As a result, the processing capability of the CPU 12 can be improved.
[0048]
(2) When a conditional branch instruction having a high branch occurrence frequency is detected, the prefetching is stopped, so that the prefetching of the instruction can be efficiently performed by effectively utilizing the bus bandwidth of the external bus 16.
[0049]
(3) If a conditional branch instruction with a low branch occurrence frequency is detected, prefetching is continued, so that necessary instructions can be stored in the prefetch buffer unit 22 in advance when a branch does not occur. Therefore, the processing performance of the CPU 12 is not reduced.
[0050]
(4) In the present embodiment, it is possible to realize the instruction prefetch circuit 13 that enables highly accurate prefetch control with a very simple configuration in which the prefetch control unit 24 includes the prefetch control register 25. Therefore, a circuit or the like having a branch prediction function is unnecessary, and the circuit scale does not increase.
[0051]
(5) In the present embodiment, since the prefetch control registers 25a to 25d corresponding to the conditional branch instructions A to D included in the program are provided, more precise instruction prefetch control is possible.
[0052]
(Second embodiment)
Hereinafter, a second embodiment of the present invention will be described with reference to FIGS.
FIG. 6 is a block diagram illustrating a microcontroller including the instruction prefetch circuit according to the second embodiment. Note that the present embodiment has a configuration in which an address range comparison unit 51 is newly added to the instruction prefetch circuit 13 of the first embodiment, and other configurations are the same as those in FIG.
[0053]
The address range comparison unit 51 includes an address range setting register 52.
The address range setting register 52 stores a first address and a second address for determining whether or not the address of a prefetched instruction is within an address range designated in advance. In this embodiment, a start address (first address) and an end address (second address) indicating an address range corresponding to each instruction routine of the program are stored.
[0054]
The address range comparison unit 51 compares the address output from the CPU 12 (that is, the address for accessing the memory 17) with the first and second addresses set in the register 52, thereby obtaining a prefetched instruction. Is determined to be within the address range specified in advance.
[0055]
Then, the address range comparison unit 51 outputs a flag switching signal FC for controlling prefetch to the prefetch control unit 24 based on the determination result (whether or not the address is within the range).
[0056]
FIG. 7 is an explanatory diagram showing a specific example of the address range setting register 52.
In the present embodiment, the address range setting register 52 is provided with four types of control flags that enable the control flags of the prefetch control registers 25a to 25d corresponding to the types of conditional branch instructions (conditional branch instructions A to D in the figure) to be individually switched. Including registers.
[0057]
That is, the address range comparison unit 51 includes the address range setting registers 52a to 52d, and performs switching control in accordance with the address ranges set therein.
Here, in each of the address range setting registers 52a to 52d, a start address ADS1, ADS2, ADS3,... Indicating an address range S100, S200, S300,. ADE1, ADE2, ADE3,... Are stored.
[0058]
FIG. 8 is a block diagram of the address range comparison unit 51a corresponding to one address range setting register 52a.
The address range comparator 51a includes a start address register 61, an end address register 62, an internal / external setting register 63, a magnitude comparison circuit 64, and an exclusive OR (EOR) circuit 65. The start address register 61 stores an address indicating the start of the range, and the end address register 62 stores an address indicating the end of the range. The internal / external setting register 63 stores a set value indicating whether the designated area is within the range from the start address to the end address or outside the range. For example, “1” is stored in the inside / outside setting register 63 when the inside is specified, and “0” is stored when outside the range is specified.
[0059]
The magnitude comparison circuit 64 is a comparator for detecting whether or not the input address ADD falls within the range between the start address and the end address, and outputs the detection result. For example, the magnitude comparison circuit 64 outputs a signal of “1” when the address ADD is within the range between the start address and the end address, and outputs a signal of “0” when the address ADD is not within the range. I do.
[0060]
The EOR circuit 65 outputs a flag switching signal FC generated by performing an exclusive OR operation on the output signal of the magnitude comparison circuit 64 and the data of the internal / external setting register 63.
Therefore, the address range comparing unit 51a outputs, for example, the flag switching signal FC of H level (1) when the above conditions are matched, and outputs the flag of L level (0) when at least one condition is not matched. It outputs the switching signal FC.
[0061]
Hereinafter, the operation of the address range setting register 52a will be described as an example.
In the execution of the program by the CPU 12, the address range comparing unit 51 monitors the access address of the CPU 12, and checks which instruction routine is currently in the address range corresponding to the instruction routine.
[0062]
Here, when the access address of the CPU 12 is within the address range S100 indicated by, for example, the start address ADS1 and the end address ADE1, the address range comparison unit 51 generates the flag switching signal FC so as to continue the prefetch. .
[0063]
Next, when the access address of the CPU 12 is an address in the address range S200 indicated by, for example, the start address ADS2 and the end address ADE2, the address range comparison unit 51 generates the flag switching signal FC so as to stop the prefetch.
[0064]
Next, when the access address of the CPU 12 is within the address range S300 indicated by, for example, the start address ADS3 and the end address ADE3, the address range comparison unit 51 generates the flag switching signal FC so as to continue the prefetch.
[0065]
As described above, the address range comparison unit 51 determines which address range the access address of the CPU 12 is in (that is, which instruction routine includes the prefetched instruction) and generates the flag switching signal FC. The flag switching signal FC is input to the combination circuit 41 of the prefetch control unit 24 shown in FIG. Therefore, the prefetch control unit 24 controls the combination of the flag switching signal FC, the full flag FF, and the prefetch control register 25 (25b in FIG. 5), and the signal that controls the prefetch when the conditional branch instruction detection signal IB is “1”. Is output.
[0066]
In other words, the address range comparison unit 51 switches the control of whether or not to continue the instruction prefetch according to the address range within which the access address of the CPU 12 is located. Although the description is omitted here, the same applies to the other address range setting registers 52b to 52d.
[0067]
As described above, in the present embodiment, the control flag set in the prefetch control register 25 (the prefetch control registers 25a to 25d) can be switched according to the address range to which the access address of the CPU 12 belongs when executing the program. With this configuration, appropriate prefetch control can be performed even when the frequency of occurrence of conditional branch instructions (conditional branch instructions A to D) differs in each instruction routine. Therefore, prefetch control with higher accuracy than in the first embodiment can be performed.
[0068]
(Third embodiment)
Hereinafter, a third embodiment of the present invention will be described with reference to FIGS.
FIG. 9 is a block diagram illustrating a microcontroller including the instruction prefetch circuit according to the third embodiment. Note that the present embodiment has a configuration in which a data pattern detection unit 71 is newly added to the instruction prefetch circuit 13 of the first embodiment instead of the address range comparison unit 51 of the second embodiment. Same as 1.
[0069]
The data pattern detection unit 71 includes a data holding register 72 that holds a specific data pattern read from the memory 17 by the CPU 12.
Then, the data pattern detection unit 71 compares the data pattern accessed by the CPU 12 with the data pattern held in the data holding register 72, and when the respective data match, switches the flag for controlling prefetching. The signal FC1 is output to the prefetch control unit 24. The flag switching signal FC1 is input to the combination circuit 41 of the prefetch control unit 24 shown in FIG. Accordingly, the prefetch control unit 24 controls the combination of the flag switching signal FC1, the full flag FF, and the prefetch control register 25 (25b in FIG. 5), and the signal that controls the prefetch when the conditional branch instruction detection signal IB is “1”. Is output.
[0070]
In the data holding register 72 of the present embodiment, the control flags of the prefetch control registers 25a to 25d corresponding to the types of the conditional branch instructions (the conditional branch instructions A to D in FIG. 2) are individually set in accordance with the data pattern. Four registers that can be switched are provided.
[0071]
FIG. 10 is a block diagram of the data pattern detection unit 71a that detects a conditional branch instruction that matches one data pattern.
The data pattern detection unit 71a includes a plurality of bit determination units 81 and AND circuits 82 and 83. The bit determination unit 81 is a circuit that determines whether a predetermined bit of the data pattern accessed by the CPU 12 in FIG. 9 matches a bit of the specified data. Therefore, the data pattern detection unit 71a includes the number of bit determination units 81 corresponding to the number of bits to be determined.
[0072]
The bit determination unit 81 includes a data pattern register 84, a mask register 85, a bit comparison circuit 86, and an AND circuit 87. The data pattern register 84 and the mask register 85 are 1-bit registers, and the data pattern register 84 forms the data holding register 72 in FIG. The data pattern register 84 stores one bit of the specified data pattern. The bit comparison circuit 86 compares one bit of the data accessed by the CPU 12 with the contents of the data pattern register 84 and outputs the result of the comparison. For example, the bit comparison circuit 86 outputs a signal of “1” when both data match, and outputs a signal of “0” when they do not match.
[0073]
The AND circuit 87 outputs a signal generated by performing an AND operation on the output signal of the bit comparison circuit 86 and the data of the mask register 85. The mask register 85 stores data for masking the comparison result of the data accessed by the CPU 12. Therefore, the AND circuit 87 outputs a signal having substantially the same level as the output signal of the bit comparison circuit 86 when the mask of the mask register 85 is “1”, and outputs the signal at the level of “0” when the mask of the mask register 85 is “0”. Outputs a "1" level signal.
[0074]
Therefore, the bit determination unit 81 determines whether the bit at the corresponding position matches, and masks the determination result based on the contents of the mask register 85.
[0075]
The AND circuit 82 has a plurality of input elements, and the number of inputs corresponds to the number of the bit determination units 81. That is, the AND circuit 82 receives the output signals of the plurality of bit determination units 81 and outputs a signal obtained by performing an OR operation on the signals. Therefore, the AND circuit 82 outputs, for example, an H-level signal when all the comparisons between the data pattern and the specified data in the plurality of bit determination units 81 match, and outputs an L-level signal when at least one does not match. The signal of is output.
[0076]
The output signal of the AND circuit 82 and the data access signal ACC are input to the AND circuit 83, and the AND circuit 83 outputs a flag switching signal FC1a.
Therefore, when the pattern of the data accessed by the CPU 12 in FIG. 9 matches the pattern of the specified data (one bit of the data of the data holding register 72), the data pattern detection unit 71a switches the flag for controlling the prefetch. The signal FC1a is output to the prefetch control unit 24. Similarly to the above, the flag switching signal FC1a is input to the combination circuit 41 of the prefetch control unit 24 shown in FIG. Then, the prefetch control unit 24 controls the combination of the flag switching signal FC1a, the full flag FF, the prefetch control register 25 (25b in FIG. 5), and the prefetch control signal when the conditional branch instruction detection signal IB is “1”. Is output.
[0077]
In the instruction look-ahead circuit 13 including such a data pattern detection unit 71, the control flag set in the look-ahead control register 25 (the look-ahead control registers 25a to 25d) is changed according to the data pattern accessed by the CPU 12 at the time of executing the program. be able to. Therefore, it is possible to perform prefetch control with higher accuracy than in the first embodiment.
[0078]
In the present embodiment, the register setting is switched when a specific data pattern is detected. However, the register setting is switched when a specific data pattern is continuous or a plurality of types of unique data patterns are continuous. It may be.
[0079]
That is, in FIG. 10, a flag register 88 and an AND circuit 89 are further provided. The flag register 88 holds the output signal of the AND circuit 83 and outputs a signal having substantially the same level as the held signal. The AND circuit 89 receives the output signal of the flag register 88 and the output signal of the AND circuit 83, and outputs a flag switching signal FC1b. When both the input signals of the AND circuit 89 indicate "match", that is, when the pattern of the data continuously accessed by the CPU 12 in FIG. 9 matches the pattern of the specified data, a flag for controlling prefetching is set. The switching signal FC1b is output to the prefetch control unit 24. Then, similarly to the above, the prefetch control unit 24 determines whether the combination of the flag switching signal FC1b, the full flag FF, the prefetch control register 25 (25b in FIG. 5) and the conditional branch instruction detection signal IB are “1”. Outputs a signal for controlling prefetching.
[0080]
Further, the data pattern detection unit 71b is configured as shown in FIG. The data pattern detection unit 71b includes a plurality (four in this example) of coincidence detection circuits 91a to 91d and a state machine 92. Each of the coincidence detecting circuits 91a to 91d has the same configuration, and includes a bit judging unit 81 and an AND circuit 82, as shown in one coincidence detecting circuit 91d, similarly to the data pattern detecting unit 71a of FIG. . The designated data (designated data DA to DD: shown at the lower left in the figure) is stored in the data pattern register 84 of each of the coincidence detection circuits 91a to 91d, that is, the data holding register 72 of each of the coincidence detection circuits 91a to 91d. You. Therefore, each of the coincidence detecting circuits 91a to 91d detects whether or not the data pattern accessed by the CPU 12 in FIG. 9 matches the designated data DA to DD, and outputs a signal.
[0081]
The state machine 92 outputs to the prefetch control unit 24 a flag switching signal FC2 for controlling prefetching when data of a plurality of types of unique patterns are continuous based on the output signals of the match detection circuits 91a to 91d. More specifically, every time the CPU 12 accesses data, the state machine 92 transitions to the state shown in FIG. 12 based on the output signals of the respective match detection circuits 91a to 91d, and asserts the flag switching signal FC2.
[0082]
First, the state machine 92 is in an idle state (IDLE) 101 after reset. At this time, the state machine 92 transitions to the first state 102 when the access data of the CPU 12 and the specified data DA match in the first match detection circuit 91a. Next, the state machine 92 makes a transition to the second state 103 when the access data of the CPU 12 and the designated data DB match in the second match detection circuit 91b, and makes a transition to the idle state 101 when they do not match.
[0083]
Similarly, the state machine 92 makes a transition to the third state 104 when the access data of the CPU 12 and the designated data DC match in the third match detection circuit 91c, and makes a transition to the idle state 101 when they do not match. Furthermore, the state machine 92 makes a transition to the fifth state 105 when the access data of the CPU 12 and the specified data DD match in the fourth match detection circuit 91d, and makes a transition to the idle state 101 when they do not match. Then, in the fifth state 105, the state machine 92 asserts the flag switching signal FC2 and makes a transition to the idle state 101.
[0084]
Therefore, the data pattern detection unit 71b determines that the four data successively accessed by the CPU 12 match the designated data DA to DD of the match detection circuits 91a to 91d, respectively, and that the order of the four data is When the state transition order matches, the flag switching signal FC2 is asserted.
[0085]
The flag switching signal FC2 is input to the combinational circuit 41 of the prefetch control unit 24 shown in FIG. Therefore, the prefetch control unit 24 controls the combination of the flag switching signal FC2, the full flag FF, and the prefetch control register 25 (25b in FIG. 5), and the signal that controls the prefetch when the conditional branch instruction detection signal IB is “1”. Is output.
[0086]
(Fourth embodiment)
Hereinafter, a fourth embodiment of the present invention will be described with reference to FIG.
In this embodiment, at the time of program debugging, the branch occurrence frequency of the conditional branch instruction is calculated, and the control flag of the prefetch control register 25 (prefetch control registers 25a to 25d) in each of the above embodiments is set. 5 is a diagram illustrating an assist circuit.
[0087]
As shown in FIG. 13, the assist circuit 110 includes a conditional branch instruction storage register 111, a comparator 112, a first counter 113, a second counter 114, and a control circuit 115. The assist circuit 110 is formed on a semiconductor chip 15 constituting the microcontroller 11, and is specifically connected to a data bus through which an instruction read from the memory 17 is transferred to the CPU 12 via the bus I / F 14. It is formed.
[0088]
Prior to program debugging, the conditional branch instruction storage register 111 stores in advance any of the conditional branch instructions included in the program (instructions for which the occurrence frequency of the branch is to be grasped).
[0089]
The comparator 112 compares the conditional branch instruction read by the CPU 12 at the time of debugging and the conditional branch instruction stored in advance in the register 111, and outputs a match signal S1 when the two instructions match each other. It outputs to the counter 113 and the control circuit 115. The first counter 113 counts up the count value N1 in response to the coincidence signal S1 from the comparator 112.
[0090]
The control circuit 115 branches to the second counter 114 in response to the branch occurrence signal BEN output from the CPU 12 when the corresponding conditional branch instruction actually causes a branch when the instructions match each other. An occurrence detection signal S2 is output. The second counter 114 counts up the count value N2 in response to the branch occurrence detection signal S2 from the control circuit 115.
[0091]
The assist circuit 110 configured as described above operates the program once, calculates the ratio of the count value N2 to the count value N1, and calculates the branch occurrence frequency of the conditional branch instruction stored in the register 111. Can be.
[0092]
By performing such an operation on all the conditional branch instructions included in the program, the branch occurrence frequency can be calculated for each conditional branch instruction.
[0093]
Therefore, by performing register setting based on the branch occurrence frequency obtained by using such an assist circuit 110, setting of an optimal register value according to each conditional branch instruction (conditional branch instructions A to D in FIG. 2). It can be performed.
[0094]
As described above, the present embodiment has the following advantages.
Each of the above embodiments may be implemented in the following manner.
The instruction prefetch circuit 13 of the first embodiment may be configured to include both the address range comparison unit 51 of the second embodiment and the data pattern detection unit 71 of the third embodiment. In this case, the combinational circuit 41 of the prefetch control unit 24 shown in FIG. 5 receives the signal from the prefetch control register 25b, the full flag FF, the flag switching signals FC and FC1, and the output signal of the FF42, and inputs these signals. And outputs a signal for controlling prefetching of an instruction having a level determined by the combination of. When the output signal of the combinational circuit 41 is “1” and the conditional branch instruction detection signal IB is “1”, the prefetch control unit 24 instructs prefetch stop (the prefetch stop signal FS having the level “1” is output). Output).
[0095]
In each of the embodiments, the instruction prefetch control is performed for each type of conditional branch instruction included in the program. However, the prefetch control is not always necessary, and is performed only for a specific conditional branch instruction among the conditional branch instructions in the program. It may be.
[0096]
In each embodiment, the control flag of the prefetch control register 25 (the prefetch control registers 25a to 25d) may be switched when the CPU 12 reads a specific instruction code. However, in this case, it is necessary to set a specific instruction code in the program in advance.
[0097]
In the third embodiment, a specific data pattern may be detected by a control signal from the CPU 12, for example, instead of including the data holding register 72.
[0098]
The features of each of the above embodiments are summarized as follows.
(Supplementary Note 1) In an instruction prefetching circuit that prefetches an instruction from a memory,
An instruction decoding unit for decoding a prefetched instruction and detecting a branch instruction;
A prefetch control unit that stops prefetching when the branch instruction detected by the instruction decoding unit is an absolute branch instruction,
The look-ahead control unit includes a look-ahead control register in which a control flag for determining whether to stop look-ahead when a branch instruction detected by the instruction decoding unit is a conditional branch instruction is set. An instruction look-ahead circuit characterized in that:
(Supplementary note 2) The instruction prefetching circuit according to supplementary note 1, wherein the prefetch control register is provided for each type of the conditional branch instruction.
(Supplementary note 3) The instruction prefetch circuit according to supplementary note 1 or 2, wherein the control flag is set based on a branch occurrence frequency of the conditional branch instruction.
(Supplementary Note 4) An address range in which it is determined whether or not the address of the instruction to be prefetched is within a predetermined address range, and based on the judgment result, the control flag set in the prefetch control register can be switched. 4. The instruction prefetching circuit according to claim 1, further comprising a comparing unit.
(Supplementary note 5) The address range comparing unit according to Supplementary note 4, wherein the address range comparison unit includes an address range setting register that stores a first address and a second address that specify the address range. Instruction look-ahead circuit.
(Supplementary note 6) The instruction prefetch circuit according to supplementary note 5, wherein the address range setting register is provided for each type of the conditional branch instruction.
(Supplementary note 7) The instruction prefetching circuit according to any one of Supplementary notes 4 to 6, wherein the address range is set for each instruction routine including an instruction to be prefetched.
(Supplementary Note 8) A data pattern detection unit that can switch a control flag set in the prefetch control register when a data pattern read from the memory is a predetermined specific data pattern. 8. The instruction look-ahead circuit according to claim 1, wherein
(Supplementary note 9) The instruction prefetch circuit according to supplementary note 8, wherein the data pattern detection unit includes a data holding register that holds the specific data pattern.
(Supplementary note 10) The instruction prefetch circuit according to supplementary note 9, wherein the data holding register is provided for each type of the conditional branch instruction.
(Supplementary note 11) Any of the supplementary notes 1 to 10, wherein a control flag set in the look-ahead control register can be switched when an instruction read from the memory is a predetermined specific instruction code. An instruction prefetch circuit according to claim 1.
(Supplementary Note 12) A first counter that counts up when a pre-designated conditional branch instruction is detected,
A second counter that counts up when the prespecified conditional branch instruction branches.
12. The instruction prefetch circuit according to claim 1, further comprising an assist circuit for calculating a branch occurrence frequency of the conditional branch instruction based on the count values of the first and second counters.
(Supplementary Note 13) A microcontroller including the instruction prefetch circuit according to any one of Supplementary Notes 1 to 12.
[0099]
【The invention's effect】
As described above in detail, according to the present invention, it is possible to provide an instruction prefetch circuit and a microcontroller capable of improving the processing capability with a simple circuit configuration.
[Brief description of the drawings]
FIG. 1 is a block diagram illustrating an instruction prefetch circuit according to a first embodiment.
FIG. 2 is an explanatory diagram showing a prefetch control register.
FIG. 3 is a block diagram illustrating an instruction decoding unit.
FIG. 4 is an explanatory diagram showing the structure of an instruction.
FIG. 5 is a block diagram illustrating a prefetch control unit.
FIG. 6 is a block diagram illustrating an instruction prefetch circuit according to a second embodiment.
FIG. 7 is an explanatory diagram showing an address range setting register.
FIG. 8 is a block diagram illustrating an address range comparison unit.
FIG. 9 is a block diagram illustrating an instruction prefetch circuit according to a third embodiment.
FIG. 10 is a block diagram illustrating a data pattern detection unit.
FIG. 11 is a block diagram illustrating another data pattern detection unit.
FIG. 12 is a state transition diagram of the state machine.
FIG. 13 is a block diagram illustrating a fourth embodiment.
[Explanation of symbols]
Iab Absolute branch instruction detection signal
Icb Conditional branch instruction detection signal
A to D conditional branch instructions
ADD address
ADS1, ADS2, ADS3,... First address as first address
ADE1, ADE2, ADE3,... End address as the second address
S100, S200, S300, ... Address range
N1, N2 count value
11 Microcontroller
13 Instruction look-ahead circuit
17 Memory
23 Instruction decoding unit
24 Read-ahead control unit
25, 25a to 25d Prefetch control register
37 instructions
51, 51a Address range comparison unit
52, 52a to 52d Address range setting register
71, 71a, 71b Data pattern detector
72 Data holding register
110 Assist circuit
113 First counter
114 Second counter

Claims (10)

メモリから命令を先読みする命令先読み回路において、
先読みした命令をデコードして分岐命令を検出する命令デコード部と、
前記命令デコード部により検出される分岐命令が絶対分岐命令の場合に先読みを停止させる先読み制御部とを備え、
前記先読み制御部には、前記命令デコード部により検出される分岐命令が条件分岐命令の場合に先読みを停止させるか否かを判断するための制御フラグが設定された先読み制御レジスタが備えられていることを特徴とする命令先読み回路。
In an instruction prefetching circuit that prefetches an instruction from a memory,
An instruction decoding unit for decoding a prefetched instruction and detecting a branch instruction;
A prefetch control unit that stops prefetching when the branch instruction detected by the instruction decoding unit is an absolute branch instruction,
The look-ahead control unit includes a look-ahead control register in which a control flag for determining whether to stop look-ahead when a branch instruction detected by the instruction decoding unit is a conditional branch instruction is set. An instruction look-ahead circuit characterized in that:
前記先読み制御レジスタを前記条件分岐命令の種類毎に設けたことを特徴とする請求項1記載の命令先読み回路。2. The instruction prefetch circuit according to claim 1, wherein said prefetch control register is provided for each type of said conditional branch instruction. 先読みする命令のアドレスが予め定めたアドレス範囲内のアドレスであるか否かを判断し、該判断結果に基づいて前記先読み制御レジスタに設定された制御フラグを切り替え可能とするアドレス範囲比較部を備えたことを特徴とする請求項1又は2記載の命令先読み回路。An address range comparison unit that determines whether an address of an instruction to be prefetched is within a predetermined address range and that can switch a control flag set in the prefetch control register based on a result of the determination; 3. The instruction look-ahead circuit according to claim 1, wherein: 前記アドレス範囲比較部には、前記アドレス範囲を指定する第一のアドレスと第二のアドレスとが格納されるアドレス範囲設定レジスタが備えられていることを特徴とする請求項3記載の命令先読み回路。4. The instruction look-ahead circuit according to claim 3, wherein the address range comparison unit includes an address range setting register for storing a first address and a second address designating the address range. . 前記アドレス範囲を、先読みする命令が含まれる命令ルーチン毎に設定したことを特徴とする請求項3又は4記載の命令先読み回路。5. The instruction prefetch circuit according to claim 3, wherein the address range is set for each instruction routine including a prefetch instruction. 前記メモリから読み出されるデータパターンが予め定めた特定のデータパターンである場合に、前記先読み制御レジスタに設定された制御フラグを切り替え可能とするデータパターン検出部を備えたことを特徴とする請求項1乃至5の何れか一項記載の命令先読み回路。2. A data pattern detecting unit, which is capable of switching a control flag set in the prefetch control register when a data pattern read from the memory is a predetermined specific data pattern. An instruction prefetch circuit according to any one of claims 1 to 5. 前記データパターン検出部には、前記特定のデータパターンを保持するデータ保持レジスタが備えられていることを特徴とする請求項6記載の命令先読み回路。7. The instruction prefetch circuit according to claim 6, wherein the data pattern detection unit includes a data holding register for holding the specific data pattern. 前記メモリから読み出される命令が予め定めた特定の命令コードである場合に、前記先読み制御レジスタに設定された制御フラグを切り替え可能としたことを特徴とする請求項1乃至7の何れか一項記載の命令先読み回路。The control flag set in the prefetch control register can be switched when an instruction read from the memory is a predetermined specific instruction code. Instruction look-ahead circuit. 予め指定した条件分岐命令を検出する場合にカウントアップする第一のカウンタと、
前記予め指定した条件分岐命令が分岐発生した場合にカウントアップする第二のカウンタとを備え、
前記第一及び第二のカウンタのカウント値に基づいて前記条件分岐命令の分岐発生頻度を算出するためのアシスト回路を備えることを特徴とする請求項1乃至8の何れか一項記載の命令先読み回路。
A first counter that counts up when detecting a pre-specified conditional branch instruction;
A second counter that counts up when the prespecified conditional branch instruction branches.
9. The instruction prefetch according to claim 1, further comprising an assist circuit for calculating a branch occurrence frequency of the conditional branch instruction based on count values of the first and second counters. circuit.
請求項1乃至9の何れか一項記載の命令先読み回路を備えたことを特徴とするマイクロコントローラ。A microcontroller comprising the instruction prefetch circuit according to any one of claims 1 to 9.
JP2003097240A 2003-03-31 2003-03-31 Instruction prefetching circuit and microcontroller Pending JP2004303081A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP2003097240A JP2004303081A (en) 2003-03-31 2003-03-31 Instruction prefetching circuit and microcontroller

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP2003097240A JP2004303081A (en) 2003-03-31 2003-03-31 Instruction prefetching circuit and microcontroller

Publications (1)

Publication Number Publication Date
JP2004303081A true JP2004303081A (en) 2004-10-28

Family

ID=33409085

Family Applications (1)

Application Number Title Priority Date Filing Date
JP2003097240A Pending JP2004303081A (en) 2003-03-31 2003-03-31 Instruction prefetching circuit and microcontroller

Country Status (1)

Country Link
JP (1) JP2004303081A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2013250593A (en) * 2012-05-30 2013-12-12 Renesas Electronics Corp Semiconductor device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2013250593A (en) * 2012-05-30 2013-12-12 Renesas Electronics Corp Semiconductor device

Similar Documents

Publication Publication Date Title
JP5172942B2 (en) Method for reducing power consumption by processor, processor, and information processing system
US5941981A (en) System for using a data history table to select among multiple data prefetch algorithms
US7437537B2 (en) Methods and apparatus for predicting unaligned memory access
JP4837305B2 (en) Microprocessor and control method of microprocessor
US20200364054A1 (en) Processor subroutine cache
US6671762B1 (en) System and method of saving and restoring registers in a data processing system
US20020144054A1 (en) Prefetch canceling based on most recent accesses
JP2010066892A (en) Data processor and data processing system
US6237083B1 (en) Microprocessor including multiple register files mapped to the same logical storage and inhibiting sychronization between the register files responsive to inclusion of an instruction in an instruction sequence
US20080162903A1 (en) Information processing apparatus
JPH08221272A (en) Method for loading of instruction onto instruction cache
US6983359B2 (en) Processor and method for pre-fetching out-of-order instructions
EP1609058A2 (en) Method and apparatus for hazard detection and management in a pipelined digital processor
US7836286B2 (en) Data processing system to calculate indexes into a branch target address table based on a current operating mode
JP3345787B2 (en) Data processing device
JP2008542893A (en) Apparatus and method for performing efficient multiply-accumulate operations in a microprocessor
JPWO2005103886A1 (en) Branch prediction apparatus, method thereof, and processor
JP3811140B2 (en) Information processing device
US6963965B1 (en) Instruction-programmable processor with instruction loop cache
JP2004303081A (en) Instruction prefetching circuit and microcontroller
KR19990003937A (en) Prefetch device
TW202219745A (en) Microprocessor and method for adjusting prefetch instruction
CN112395000A (en) Data preloading method and instruction processing device
JP2003202981A (en) Address range checking circuit and method of operation
US6715038B1 (en) Efficient memory management mechanism for digital signal processor and method of operation thereof

Legal Events

Date Code Title Description
A621 Written request for application examination

Effective date: 20060123

Free format text: JAPANESE INTERMEDIATE CODE: A621

A977 Report on retrieval

Effective date: 20061116

Free format text: JAPANESE INTERMEDIATE CODE: A971007

A131 Notification of reasons for refusal

Effective date: 20061121

Free format text: JAPANESE INTERMEDIATE CODE: A131

A521 Written amendment

Effective date: 20070119

Free format text: JAPANESE INTERMEDIATE CODE: A523

A131 Notification of reasons for refusal

Free format text: JAPANESE INTERMEDIATE CODE: A131

Effective date: 20070529

A02 Decision of refusal

Free format text: JAPANESE INTERMEDIATE CODE: A02

Effective date: 20071002