JP2004303081A - Instruction prefetching circuit and microcontroller - Google Patents
Instruction prefetching circuit and microcontroller Download PDFInfo
- 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
Links
Images
Landscapes
- Advance Control (AREA)
Abstract
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,
[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
[0018]
The
[0019]
The prefetch
[0020]
The address generated by the prefetch
[0021]
The instruction prefetched from the
[0022]
The instruction that is prefetched and held in the
[0023]
The
[0024]
FIG. 3 is a block diagram illustrating an example of the
The
[0025]
The first and
[0026]
Accordingly, the
[0027]
The first AND
[0028]
Therefore, the
[0029]
The
[0030]
More specifically, the
[0031]
When the
[0032]
When a conditional branch instruction is detected by the
[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
[0034]
For example, when the types of conditional branch instructions executed by the
[0035]
The control flag of such a prefetch control register 25 (the
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
[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
[0039]
FIG. 5 is a block diagram of the
[0040]
The
[0041]
Therefore, the
[0042]
Next, the operation of the
[0043]
The
[0044]
Therefore, in these cases, it is possible to prevent the instruction prefetched by the
[0045]
When the prefetched instruction is a conditional branch instruction A or a conditional branch instruction C with a low branch occurrence frequency, the
[0046]
Therefore, in these cases, an instruction required when a branch does not occur can be stored in the
[0047]
As described above, the present embodiment has the following advantages.
(1) When a conditional branch instruction is detected, the
[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
[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
[0050]
(4) In the present embodiment, it is possible to realize the
[0051]
(5) In the present embodiment, since the
[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
[0053]
The address
The address
[0054]
The address
[0055]
Then, the address
[0056]
FIG. 7 is an explanatory diagram showing a specific example of the address
In the present embodiment, the address
[0057]
That is, the address
Here, in each of the address
[0058]
FIG. 8 is a block diagram of the address
The
[0059]
The
[0060]
The
Therefore, the address
[0061]
Hereinafter, the operation of the address
In the execution of the program by the
[0062]
Here, when the access address of the
[0063]
Next, when the access address of the
[0064]
Next, when the access address of the
[0065]
As described above, the address
[0066]
In other words, the address
[0067]
As described above, in the present embodiment, the control flag set in the prefetch control register 25 (the
[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
[0069]
The data
Then, the data
[0070]
In the
[0071]
FIG. 10 is a block diagram of the data
The data
[0072]
The
[0073]
The AND
[0074]
Therefore, the
[0075]
The AND
[0076]
The output signal of the AND
Therefore, when the pattern of the data accessed by the
[0077]
In the instruction look-
[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
[0080]
Further, the data
[0081]
The
[0082]
First, the
[0083]
Similarly, the
[0084]
Therefore, the data
[0085]
The flag switching signal FC2 is input to the
[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 (
[0087]
As shown in FIG. 13, the
[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
[0090]
The
[0091]
The
[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
[0094]
As described above, the present embodiment has the following advantages.
Each of the above embodiments may be implemented in the following manner.
The
[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
[0097]
In the third embodiment, a specific data pattern may be detected by a control signal from the
[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 3) The instruction prefetch circuit according to
(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
(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
(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 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
(Supplementary Note 13) A microcontroller including the instruction prefetch circuit according to any one of
[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乃至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.
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)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2013250593A (en) * | 2012-05-30 | 2013-12-12 | Renesas Electronics Corp | Semiconductor device |
-
2003
- 2003-03-31 JP JP2003097240A patent/JP2004303081A/en active Pending
Cited By (1)
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 |