--- nono/m680x0/m68030cache.h 2026/04/29 17:05:22 1.1.1.1 +++ nono/m680x0/m68030cache.h 2026/04/29 17:05:26 1.1.1.2 @@ -9,37 +9,71 @@ #pragma once #include "m68030.h" +#include +#include +#include "fixedqueue.h" // キャッシュライン struct m68030CacheLine { // タグは命令キャッシュ/データキャッシュで共通だが、 - // 命令キャッシュなら下位1ビットが S (FC2)、 - // データキャッシュなら下位3ビットが FC1,FC0,FC2 の順。 + // 命令キャッシュなら bit2 が S (FC2)、 + // データキャッシュなら下位3ビットが FC (2,1,0 の順)。 // 3 2 1 // 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Tag Address (24bit) | |S| (Inst) + // |S|1|0|S| Tag Address (24bit) | | (Inst) // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Tag Address (24bit) | |1|0|S| (Data) + // |FC2-0|S| Tag Address (24bit) | | (Data) // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ uint32 tag {}; - - std::array data {}; union { uint32 valid_all {}; uint8 valid[4]; }; + std::array data {}; - bool IsSuper() const { return (tag & 1); } - uint32 TagAddr() const { return (tag & 0xffffff00); } + bool IsSuper() const { return (tag & 0x80000000); } + uint32 GetFC() const { return (tag >> 29); } + uint32 TagAddr() const { return (tag << 4); } +}; + +// キャッシュの統計情報 +struct m68030CacheStat +{ + float hit; // ヒット率 }; // キャッシュ (命令/データ共通) class m68030Cache { public: + // キャッシュイネーブル。 + bool enable {}; + + // 凍結なら true。 + bool freeze {}; + + // バースト転送可能かつ許可なら true。 + bool burst_enable {}; + + // データキャッシュのライトアロケート。 + bool wa {}; + + // キャッシュ。 std::array line {}; + + // 統計情報。 + uint32 stat_fasthit {}; // ファストパスでのヒット回数 + uint32 stat_hit {}; // 通常パスでのヒット回数 + uint32 stat_miss {}; // 通常パスでのミス回数 + + // 移動平均用バッファ。 + FixedQueue hist {}; + std::mutex hist_mtx {}; + + public: + void CalcStat(); };