diff --git a/adr/0001-value-change-callback-gpi-vpi.md b/adr/0001-value-change-callback-gpi-vpi.md deleted file mode 100644 index 18814e54095..00000000000 --- a/adr/0001-value-change-callback-gpi-vpi.md +++ /dev/null @@ -1,106 +0,0 @@ -# ADR-0001: Value Change Callback / GPI / VPI - -- **Date**: 2026-03-07 -- **Status**: proposed - -## Context - -Simulation に値変化コールバック (VCC) がなく、cocotb 連携や JS/TS からのリアクティブな信号監視ができない。 - -cocotb は GPI (Generic Programming Interface) を通じてシミュレータと通信する。Celox をcocotb バックエンドとして使うには GPI 互換レイヤーが必要。また JS/TS テストベンチでも同等の機能が求められる。 - -## Decision - -4 段階のフェーズで VCC → JS/TS API → GPI → VPI を積み上げる。 - -### Phase 1: Value Change Callback in Simulation - -Snapshot Compare 方式(JIT ノータッチ)で実装する。 - -- `step()` 前後で watched signal のバイト列を比較し変化を検出 -- JIT コード変更不要 -- watched signal 数は cocotb 典型で 10–20 個程度、スケジューラ処理に比べてオーバーヘッドは誤差 - -#### API (Rust) - -```rust -pub type WatchId = u32; - -impl Simulation { - fn watch(&mut self, signal: SignalRef, callback: WatchCallback) -> WatchId; - fn unwatch(&mut self, id: WatchId); -} -``` - -#### Implementation - -- `step()` 前: watched signal の値を snapshot (`Vec` バッファ) -- `step()` 実行 -- `step()` 後: snapshot と現在値を比較、変化していたら callback 発火 -- バッファは watch リスト変更時のみ再確保 - -### Phase 2: JS/TS API (NAPI) - -Simulation の VCC を NAPI 経由で JS に expose する。 - -```typescript -const watchId = simulation.watch(signal, (newValue) => { - console.log(`signal changed: ${newValue}`); -}); -simulation.unwatch(watchId); - -// cocotb-like sugar -await simulation.risingEdge(clockSignal); -await simulation.valueChange(dataSignal); -``` - -JS callback は `step()` の同期コンテキスト内で呼ばれる(napi-rs の threadsafe function は不要、single-threaded)。 - -### Phase 3: cocotb GPI Backend - -cocotb の `GpiImplInterface` を C ABI で実装する。 - -| GPI operation | Celox mapping | -|---|---| -| `gpi_get_root_handle` | `Simulation::named_hierarchy()` | -| `gpi_iterate` / `gpi_next` | hierarchy traversal | -| `gpi_get_handle_by_name` | `Simulation::signal()` | -| `gpi_get_signal_val_*` | `Simulation::get()` | -| `gpi_set_signal_val_*` | `Simulation::modify()` | -| `gpi_register_value_change_callback` | `Simulation::watch()` | -| `gpi_register_timed_callback` | `Simulation::schedule()` | -| `gpi_deregister_callback` | `Simulation::unwatch()` | - -Build: -- Rust crate (`celox-gpi`) exporting `extern "C"` functions -- cocotb discovers it via `GPI_EXTRA` / `MODULE` env vars -- Shared library (.so) that cocotb loads at startup - -### Phase 4: VPI Compatibility Layer - -GPI の上に thin VPI wrapper を載せる。 - -- `vpi_get_value` / `vpi_put_value` -- `vpi_register_cb` (cbValueChange, cbAfterDelay, cbNextSimTime) -- `vpi_iterate` / `vpi_scan` -- `vpi_handle_by_name` - -初期化は VPI 標準の `vlog_startup_routines` ではなく Celox 独自のロード機構で良い。 - -### Non-goals - -- JIT コードへの dirty bit 埋め込み(不要) -- VPI 完全準拠(cocotb + 基本操作のみ) -- マルチスレッド対応(single-threaded で十分) - -## Consequences - -- cocotb の Python テストベンチがそのまま Celox 上で動くようになる -- JS/TS テストベンチでリアクティブな信号監視が可能になる -- Snapshot Compare はシンプルだが、watched signal が大量(数百以上)になると性能懸念あり(その場合は JIT 内 dirty bit を検討) - -### Open Questions - -- cocotb の GPI C ABI は安定しているか?バージョン間で互換性は? -- `cbReadWriteSynch` / `cbReadOnlySynch` の region scheduling をどこまでサポートするか -- Python ↔ Rust の FFI: PyO3 vs 生 C ABI diff --git a/adr/0002-external-modules.md b/adr/0002-external-modules.md deleted file mode 100644 index 02ab1aed2ed..00000000000 --- a/adr/0002-external-modules.md +++ /dev/null @@ -1,195 +0,0 @@ -# ADR-0002: External Modules - -- **Date**: 2026-03-07 -- **Status**: proposed - -## Context - -Celox は現在 Veryl ソースコードのみをシミュレーション対象としている。全モジュールが Veryl で記述されている必要があり、外部 IP コア(メモリモデル、アナログモデル、プロプライエタリ IP のスタブ等)をシミュレーションに組み込む手段がない。 - -将来の SystemVerilog フロントエンド対応の布石としても、フロントエンド非依存なモジュール抽象が必要。 - -### 現状の制約 - -- `Component::SystemVerilog` は `ParserError::unsupported()` で拒否される -- 全モジュールが `Veryl Source → Analyzer → SIR → JIT` パイプラインを通る前提 -- 外部/スタブモジュールの概念がない - -## Decision - -Rust trait で振る舞いを実装したモジュールを、Veryl 設計内で透過的にインスタンスできる仕組みを導入する。DLL/SO からの動的ロードもサポートする。 - -### Architecture - -``` -Veryl Source (stub module + design) - │ - ▼ -Veryl Analyzer ── ポート情報を正常に解析 - │ - ▼ -Celox Parser - ├── 通常モジュール → SimModule → SIR → JIT - └── 外部モジュール → ExternalSimModule (ポートのみ、ロジックなし) - │ - ▼ -Flatten (hierarchy expansion) - ├── 通常インスタンス: glue blocks + relocate - └── 外部インスタンス: glue blocks のみ (内部ロジックなし) - │ - ▼ -JIT Compilation - └── eval_comb 内で外部モジュールは call_indirect で呼出し - │ - ▼ -Runtime - ├── JIT コード: 通常の組合せ/順序ロジック - └── 外部モジュール: trait method 呼出し (eval / clock_edge) -``` - -### 1. Rust Trait API - -Factory と Instance の 2 層構造: - -```rust -/// 外部モジュールの定義。ポート宣言とインスタンス生成を担う。 -pub trait ExternalModule: Send + Sync + 'static { - fn name(&self) -> &str; - fn ports(&self) -> &[PortDef]; - fn instantiate(&self) -> Box; -} - -/// 各インスタンスの振る舞い。 -pub trait ExternalModuleInstance: Send + 'static { - fn eval(&mut self, io: &mut PortIO); - fn on_rising_edge(&mut self, _clock: &str, _io: &mut PortIO) {} - fn on_falling_edge(&mut self, _clock: &str, _io: &mut PortIO) {} -} -``` - -Port I/O は JIT メモリバッファへの直接アクセス: - -```rust -pub struct PortIO<'a> { - memory: &'a mut [u8], - ports: &'a [PortSlot], -} - -impl<'a> PortIO<'a> { - pub fn get_u64(&self, name: &str) -> u64; - pub fn get_bool(&self, name: &str) -> bool; - pub fn get_wide(&self, name: &str) -> BigUint; - pub fn set_u64(&mut self, name: &str, val: u64); - pub fn set_bool(&mut self, name: &str, val: bool); - pub fn set_wide(&mut self, name: &str, val: BigUint); -} -``` - -### 2. Veryl Stub - -Analyzer 変更不要。stub をヘッダファイルとして使う: - -```veryl -module Memory ( - clk: input '_ clock, - addr: input logic<16>, - wdata: input logic<8>, - we: input logic, - rdata: output logic<8>, -) {} -``` - -- Analyzer は普通のモジュールとして処理する -- ポート型チェックが Veryl 側で完結する -- `inst` のポート接続構文がそのまま使える - -### 3. Builder API - -```rust -let sim = Simulator::builder(code, "Top") - .external_module(MemoryModel::descriptor()) // 同一バイナリ - .load_external_module("path/to/libcustom.so") // DLL/SO - .build()?; -``` - -Builder 内部処理: -1. `parse_ir()` で Veryl を解析 -2. 外部モジュール名と `SimModule` 名をマッチング -3. マッチしたモジュールを `ExternalSimModule` に置換(ポート Variables 保持、ロジック空) -4. `flatten()` で外部インスタンスも通常通り `InstanceId` を割当て -5. JIT コンパイル時、外部モジュールの `eval` を組込み - -### 4. Parser Integration - -`Component::SystemVerilog` と stub(ロジック空の `Component::Module`)の両方を外部モジュール名でマッチング。マッチしたら `ExternalSimModule`(ポートのみ)として扱う。 - -### 5. JIT Integration (eval_comb) - -Cranelift の外部関数呼出しで eval_comb 内から直接コールバック: - -``` -eval_comb JIT function: - ... (通常の comb ロジック) ... - ┌─ glue: parent → external module input ports (JIT) - │ call external_module_eval(instance_ptr, memory_ptr) - └─ glue: external module output ports → parent (JIT) - ... (通常の comb ロジック 続き) ... -``` - -トポロジカルソートには合成 `LogicPath` で参加(保守的に全出力が全入力に依存)。 - -### 6. Clock Edge Handling - -`tick(event)` 時: -1. `eval_comb()` — 外部モジュール `eval` 含む -2. 通常の FF apply -3. 外部モジュールの `on_rising_edge()` / `on_falling_edge()` 呼出し -4. `eval_comb()` — 再評価 - -クロックエッジ処理は JIT 外で実行。出力ポートへの反映は次の `eval_comb` で。 - -### 7. DLL/SO Loading - -```rust -pub type RegisterFn = unsafe extern "C" fn(registry: &mut dyn ModuleRegistry); - -pub trait ModuleRegistry { - fn register(&mut self, module: Box); -} -``` - -- `celox_register` 関数のシグネチャは C ABI (`extern "C"`) -- trait は Rust ABI — 同一 rustc バージョン制約 -- 将来、完全な C ABI vtable (`abi_stable` 等) に移行する可能性あり -- `libloading` で動的ロード - -### Implementation Phases - -| Phase | Scope | -|-------|-------| -| 1 | 基盤: trait 定義、builder API、parser 統合、eval_comb 組込み(同一バイナリ、comb のみ) | -| 2 | 順序ロジック: `on_rising_edge` / `on_falling_edge` の tick() 統合 | -| 3 | DLL/SO ロード: `celox-module-abi` crate、`libloading` | -| 4 | 拡張: TS/JS コールバック (NAPI ラッパー)、proc macro、stub 自動生成 | - -## Consequences - -### Positive - -- メモリモデル、IP スタブ等をシミュレーションに組み込める -- Veryl 側は `inst` 構文がそのまま使え、外部モジュールを意識しない -- DLL/SO で配布可能 — ソース非公開の IP モデルに対応 -- TS/JS コールバックは Rust trait の NAPI ラッパーとして自然に拡張可能 - -### Negative - -- eval_comb 内の外部関数呼出しが JIT 最適化の境界になる -- DLL は同一 rustc バージョン制約(v1) -- Veryl stub と trait の `ports()` の整合性を build 時に検証する必要がある - -### Open Questions - -1. **eval_comb 分割戦略**: JIT 関数分割 vs Cranelift `call_indirect`。後者が実装は楽だが最適化境界になる。 -2. **4-state サポート**: 外部モジュールポートでの X/Z 値の扱い。v1 では 2-state のみで十分か。 -3. **配列インスタンス**: `inst mem: Memory[4]` — `instantiate()` が 4 回呼ばれ独立した状態を持つ。 -4. **パラメトリック外部モジュール**: `instantiate()` にパラメータを渡す仕組みが必要。 diff --git a/adr/0003/README.md b/adr/0003/README.md deleted file mode 100644 index 02516b2f89d..00000000000 --- a/adr/0003/README.md +++ /dev/null @@ -1,186 +0,0 @@ -# ADR-0003: Self-Hosted x86-64 Backend - -- **Date**: 2026-03-24 -- **Status**: implemented -- **Updated**: 2026-03-28 - -## Context - -Celox は Cranelift を JIT バックエンドとして使用していたが、以下の問題により限界に達していた。 - -### Cranelift / regalloc2 の問題 - -1. **Live register 数のスケーリング破綻**: regalloc2 の backtracking allocator は、同時に live な register が数百〜数千になるとコンパイル時間が爆発する。wasmtime issue #3523 では、大きな関数のコンパイル時間の 96% が regalloc に消費された(15.48s / 16.04s) -2. **VReg 上限**: regalloc2 は Operand を 32bit に pack しており、VReg 数が 2^21(約 210 万)に制限される。64bit 化は 5-10% の性能劣化を伴う -3. **メモリ割り当てオーバーヘッド**: `try_to_allocate_bundle_to_reg` 単体で 1600 万回の一時 HashSet 確保が発生(issue #87) -4. **大きい Execution Unit への対応不能**: HDL シミュレーションの組み合わせ回路は巨大な関数を生成するが、Cranelift の主要ユーザーである wasmtime は小さな WASM 関数が前提 - -### 以前の workaround(Cranelift 時代) - -- **Tail-call splitting**: EU を CLIF 命令閾値・VReg 閾値以下に分割 -- **split_wide_commits**: Cranelift が wide value を扱えないため SIRT 側で事前分割 -- **reschedule**: Cranelift の regalloc のためのプレッシャー制御 - -## Decision - -Cranelift を自前の x86-64 コードジェネレータで完全に置き換えた。デフォルトバックエンドとして切り替え済み。 - -## Pipeline Architecture(実装済み) - -``` -SIR (bit-level SSA) - ↓ ISel (isel.rs) -MIR (word-level SSA, virtual registers) + SpillDesc per VReg - ↓ Analysis (analysis.rs) — liveness, next-use distance - ↓ Unified single-pass allocator (unified.rs) - — simultaneous spilling + assignment using RegFile -MIR (physical registers) - ↓ Emit (emit.rs) — iced-x86 CodeAssembler -x86-64 machine code -``` - -### MIR Design - -MIR は SIR(bit-level)と machine code の間に位置する word-level SSA IR。 - -- **64-bit レジスタ単位**: 全操作は 64-bit VReg 上で行う。>64-bit 値はチャンク配列 -- **SpillDesc サイドテーブル**: 各 VReg のスピルコスト情報。bit-level のアクセス情報を保持し、regalloc 本体は bit layout を知らなくてよい - -``` -SpillCost: - Rematerializable → cost 0 // 即値、再生成するだけ - SimStateAligned → cost 1 // static offset, word-aligned - SimStateSmall → cost 2 // static offset, width < native width - SimStateDynamic → cost 4 // dynamic offset - Transient → cost 2 // スタック spill slot -``` - -### ISel (isel.rs) - -SIR → MIR 変換。以下を処理: - -- **Narrow (≤64-bit)**: Load/Store, 全算術・論理・比較・シフト演算、Concat, Slice -- **Wide (>64-bit)**: チャンク分割による Add/Sub(carry chain), Mul(schoolbook O(n²)), Div/Rem(bit-by-bit restoring), Shl/Shr/Sar(定数: チャンクシフト+キャリー、ランタイム: select chain), 比較(MSB-to-LSB cascading), Concat repack, Slice -- **4-state**: 全操作に対するマスク伝播。値の正規化(`v |= m`、X = v:1,m:1) - - AND/OR/XOR: per-bit mask formula - - Arithmetic/Comparison: conservative(any X → all-X) - - Shift: 定数シフトはマスクも同様にシフト、ランタイムシフト amount X → all-X - - LogicAnd/Or: IEEE 1800 dominant-value semantics - - Reduction AND/OR: IEEE 1800 dominant-value semantics(definite-0/1 → 結果確定) - - Wildcard ==?/!=?: RHS X/Z ビットは don't-care - - Concat: narrow/wide ともマスクチャンクの repack - - Store to bit type: ソースレジスタのマスクを 0 にクリア - -### Unified Register Allocator (unified.rs) - -当初は Braun & Hack の separate-pass 設計(spilling → assignment)を実装したが、spilling と assignment の live set tracking に構造的な差分が生じ、k-1 ハックや eviction fallback が必要になった。最終的に **unified single-pass allocator** に置き換えた。 - -#### RegFile - -```rust -struct RegFile { - preg_to_vreg: BTreeMap, - vreg_to_preg: BTreeMap, -} -``` - -物理レジスタ ↔ VReg の双方向マップで、各プログラムポイントの正確なレジスタ状態を追跡。 - -#### アルゴリズム - -1. **Entry state**: predecessor の exit RegFile をマージ。phi coalescing を試行 -2. **Forward walk**: 各命令で uses を ensure(reload if needed)→ evict to k → assign def -3. **Eviction**: next-use distance 最遠 + remat/store-back-only を優先的に evict -4. **Fixed constraints**: shift rhs → RCX。occupant を spill + Mov で退避。pinned VReg 追跡 -5. **Clobbers**: UDiv/URem の RAX/RDX clobber。blocked set でこれらを def 割り当てから排除 -6. **Coupling code**: predecessor exit ↔ successor entry の差分で spill/reload を挿入 - -k = NUM_REGS = 13 (x86-64: 16 GPR - RSP - RBP - SimState base)。k-1 ハック不要。 - -#### next-use lookup - -`use_positions: BTreeMap>` による O(log n) binary search。O(n) forward scan を置き換え。 - -### Verifier (regalloc.rs) - -`#[cfg(debug_assertions)]` で有効。同時 live な VReg が同一 PhysReg を共有しないことを検証。use_positions テーブルによる O(n log n) dead check(O(n²) verifier を修正、sorter N=64 が 180s timeout → 5.3s に改善)。 - -### Code Emission (emit.rs) - -iced-x86 CodeAssembler で x86-64 機械語を生成。 - -- Prologue/Epilogue: callee-saved push/pop, frame allocation, SimState base (R15) setup -- Multi-EU chaining: 各 EU の ret を jmp rel32 にパッチして連鎖 -- Select emit: `dst == true_val` 時の reverse logic(cmove) -- UMulHi: `mul r64` → RDX 取得(wide Mul の上位 64 bit) - -## 4-State Support - -IEEE 1800 の 4-state logic をネイティブサポート。 - -### Memory Layout - -`MemoryLayout::build(sir, four_state=true)` で全変数に value + mask の二重領域を割り当て。mask は value の直後(`offset + byte_size`)。 - -### Encoding - -| mask | value | 意味 | -|------|-------|------| -| 0 | 0 | 0(definite zero)| -| 0 | 1 | 1(definite one)| -| 1 | 0 | Z(high-impedance)| -| 1 | 1 | X(unknown)| - -### 値の正規化 - -Binary 演算後に `value |= mask` を適用。X ポジション(mask=1)の値ビットを必ず 1 にし、エンコーディングの一貫性を保証。 - -### 初期化 - -`logic` 型変数は X で初期化(value=0xFF, mask=0xFF)。`bit` 型は 0 で初期化。 - -## Complexity - -| Phase | 計算量 | -|---|---| -| Analysis (liveness, next-use distance) | O(n) per iteration, bounded | -| ISel | O(n) | -| Unified allocator (spill + assign) | O(n × k) | -| Verifier (debug builds) | O(n × k × log n) | -| Code emission | O(n) | -| **Total** | **O(n × k)** ≈ **O(n)** | - -### Benchmark: SorterTreeDistEntry - -| N | 旧 (Cranelift workaround 時代) | 新 (native backend) | -|---|---|---| -| 16 | ~24 min (branch-based mux) | 1.0s | -| 64 | timeout | 5.3s | -| 128 | — | 15.1s | - -## 削減・簡素化されたパス - -| パス | Cranelift 時代 | Native backend 後 | -|---|---|---| -| `tail_call_split` | regalloc2 の VReg 上限回避 | **不要** | -| `split_wide_commits` | Cranelift が wide value を扱えない | **不要**(ISel がチャンク処理)| -| `reschedule` | regalloc のためのプレッシャー制御 | **簡素化可能** | - -## Target Architecture Strategy - -MIR はターゲット中立。emit phase のみターゲット別に分岐。 - -``` -SIR (bit-level, 共通) - ├── native backend: SIR → ISel → MIR → Unified Alloc → Emit (x86-64) - └── wasm backend: SIR → WASM codegen(MIR を経由しない) -``` - -AArch64 / RISC-V 対応は emit phase の追加で可能(k, ABI, 命令エンコーディングが異なる)。 - -## References - -- Braun, M. and Hack, S. (2009). "Register Spilling and Live-Range Splitting for SSA-Form Programs." CC 2009. -- Hack, S., Grund, D., and Goos, G. (2006). "Register Allocation for Programs in SSA-Form." CC 2006. -- Schwarz, T., Kamm, T., and Engelke, A. (2025). "TPDE: A Fast Adaptable Compiler Back-End Framework." CGO 2026. -- Cranelift/regalloc2 issues: wasmtime#3523, wasmtime#8783, regalloc2#87 diff --git a/adr/0004-software-modules-sequential-first.md b/adr/0004-software-modules-sequential-first.md deleted file mode 100644 index 3613dfabfa8..00000000000 --- a/adr/0004-software-modules-sequential-first.md +++ /dev/null @@ -1,179 +0,0 @@ -# ADR-0004: Software Modules Are Sequential-First - -- **Date**: 2026-04-12 -- **Status**: proposed - -## Context - -Celox で HDL モジュールの代わりに software 実装を差し込めるようにしたい。主な動機は、Vivado の MIG のような大きくて扱いづらい IP を、検証時だけ software 実装に置き換えたいことにある。 - -要件としては次が強い。 - -- HDL source 上では普通の module として存在してほしい -- どの階層でも普通の module と置き換えて使えてほしい -- host 側が module 名で software 実装へ差し替えたい - -一方で、software module の内部 signal と combinational scheduling を真面目に扱おうとすると、次の問題がある。 - -- same-cycle の input -> output combinational path があると、global scheduler の dependency graph に参加する必要がある -- callback ベースで雑に `eval_comb()` すると性能の根幹が死ぬ -- dependency を手で書かせると correctness が壊れやすい -- host language で graph/IR を組ませる方向に寄せると、「それなら RTL を書けばよい」に近づく - -特に MIG 代替のようなユースケースでは、本当に欲しいのは arbitrary combinational component 一般ではなく、 - -- 大きな内部 state を持つ -- bus-facing である -- cycle 単位で進む -- 入出力のどちらか、または両方が register で切られている - -ような externally synchronous component であることが多い。 - -## Decision - -software module は 2 種類に分けて扱う。 - -1. **Sequential software module** -2. **Combinational software module** - -v1 では **Sequential software module のみを正式対象** とする。Combinational software module は将来課題として分離し、同じ仕組みで一気に解こうとしない。 - -### 1. Instantiation model - -HDL source 上では普通の module を使い、host 側が module 名で software 実装へ差し替える。 - -- Veryl 側に専用構文は追加しない -- software module は top 専用ではなく、任意階層の instance と置き換え可能であるべき -- 親モジュールからは普通の instance と同じ port shape を持つ - -### 2. v1 で許可する software module - -v1 の software module は、**externally synchronous** でなければならない。 - -具体的には、module の外から観測可能な - -- input -> output - -の same-cycle combinational pathを持ってはならない。 - -言い換えると、 - -- 入力変化が同一 cycle 中にそのまま出力へ反映される component -- global comb scheduler の fixpoint に参加しないと正しく動かない component - -は v1 の対象外とする。 - -この制約により、MIG 代替や bus-facing memory model のような stateful component を先に扱える。 - -### 3. Internal signal - -Sequential software module は内部 state / internal signal を持ってよい。 - -ただし v1 では、それらは **module 内部に閉じた state** として扱い、global combinational scheduler に参加させない。 - -- 内部 state 更新は event / cycle 境界で行う -- 出力の更新も cycle 単位の contract に従う -- software module 内部の combinational detail を global dependency graph へ露出しない - -### 4. Host API registration first - -v1 は host 側 API で software module を登録する。 - -```rust -let sim = Simulator::builder(code, "Top") - .register_software_module("MigModel", |ctx| Box::new(MigModel::new(ctx))) - .build()?; -``` - -builder は module 名を key に registry を持ち、elaboration 時に一致した module instance を software 実装へ差し替える。 - -- HDL source 上では普通の module 定義を置く -- host は `module_name -> factory` を登録する -- factory は parameter / port metadata / instance path を受けて instance state を生成する - -想定する最小 API は次の 2 層である。 - -```rust -pub trait SoftwareModuleFactory: Send + Sync + 'static { - fn module_name(&self) -> &str; - fn instantiate(&self, ctx: &SoftwareModuleContext) -> Box; -} - -pub trait SequentialSoftwareModule: Send + 'static { - fn on_event(&mut self, event: EventId, io: &mut SoftwareIo); - fn settle_outputs(&mut self, io: &mut SoftwareIo); -} -``` - -`settle_outputs()` は pure combinational callback 一般ではなく、「外部から見て cycle 境界に閉じた output 導出」であることを要求する。 - -### 5. Execution model - -software module instance は instance graph の正式メンバーとして扱う。 - -- 親から見える port shape は元の HDL module と一致しなければならない -- flatten / path 解決 / hierarchy 上は普通の instance として見える -- 中身の実行だけが software 実装になる - -v1 の scheduler contract は次の通り。 - -1. 通常の HDL comb を評価 -2. event 境界で software module の `on_event()` を実行 -3. event 後に software module の `settle_outputs()` を実行 -4. software module output の変化を downstream に反映 - -この contract は、same-cycle input -> output path を持たない externally synchronous component を対象にしている。 - -### 6. DLL/SO loading later - -将来は host registry と同じ registry interface を DLL/SO から埋められるようにする。 - -```rust -pub trait SoftwareModuleRegistry { - fn register(&mut self, factory: Box); -} - -pub type RegisterFn = unsafe extern "C" fn(registry: &mut dyn SoftwareModuleRegistry); -``` - -- v1 は同一バイナリ内の host API 登録だけをサポートする -- v2 以降で `libloading` により `celox_register` をロードする -- 初期段階では Rust ABI 制約を許容する -- 必要なら将来 `abi_stable` 等で C ABI に寄せる - -### 7. What is deferred - -次は v1 では扱わない。 - -- same-cycle input -> output path を持つ software module -- global combinational scheduler への software node 参加 -- software module 内部 signal の global dirty propagation -- arbitrary callback ベースの `eval_comb()` による汎用 combinational component -- DLL/SO の安定 ABI - -これらは別 ADR / 別設計課題として扱う。 - -## Consequences - -### Positive - -- MIG 代替のような大きな stateful component を、RTL を無理に書かずに差し替えられる -- software module を module 名置換で使えるため、HDL 側の記述は自然 -- いきなり global comb scheduler を壊さずに導入できる -- 「汎用 software module」と「comb scheduler 統合」という別難題を分離できる -- v1 は host API 登録だけで始められるため、ABI/配布問題を後回しにできる - -### Negative - -- v1 では truly combinational な software component は扱えない -- input -> output same-cycle path を持つ memory/peripheral model は対象外になる -- 将来 combinational software module をやる場合、別の execution model が必要 -- DLL/SO ロードは別フェーズになる - -### Open Questions - -1. `settle_outputs()` をどこまで pure / side-effect-free に強制するか -2. `ready/valid` のような bus interface を v1 制約の下でどこまで自然に扱えるか -3. software module の internal state を introspection/debug でどこまで見せるか -4. module 名差し替え時に、元 HDL module body をどの段階で無視するか -5. parameterized module を factory にどう渡すか diff --git a/adr/README.md b/adr/README.md deleted file mode 100644 index 845a6006c5f..00000000000 --- a/adr/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# Architecture Decision Records - -プロジェクト内部の設計意思決定を時系列で記録する。 - -## Format - -`NNNN-title.md` — 連番 + kebab-case タイトル。 - -各 ADR は以下のセクションを持つ: - -- **Date**: 作成日 -- **Status**: `proposed` / `accepted` / `superseded` / `deprecated` -- **Context**: 背景・課題 -- **Decision**: 決定事項 -- **Consequences**: 結果・影響 - -Status が変わった場合は ADR 内に履歴を追記する。 -superseded の場合は後継 ADR へのリンクを記載する。 - -## Index - -| # | Title | Date | Status | -|---|-------|------|--------| -| [0001](0001-value-change-callback-gpi-vpi.md) | Value Change Callback / GPI / VPI | 2026-03-07 | proposed | -| [0002](0002-external-modules.md) | External Modules | 2026-03-07 | proposed | -| [0004](0004-software-modules-sequential-first.md) | Software Modules Are Sequential-First | 2026-04-12 | proposed | diff --git a/scripts/ci-changes.mjs b/scripts/ci-changes.mjs index ff5349b3e4f..7f4b683d2f3 100644 --- a/scripts/ci-changes.mjs +++ b/scripts/ci-changes.mjs @@ -143,7 +143,7 @@ export function classifyFiles(files, { releasePlease = false } = {}) { } if ( - startsWithAny(path, ["docs/", "adr/"]) || + startsWithAny(path, ["docs/"]) || path === "README.md" || path === "CONTRIBUTING.md" ) { diff --git a/scripts/ci-changes.test.mjs b/scripts/ci-changes.test.mjs index 54f41654427..b8431896085 100644 --- a/scripts/ci-changes.test.mjs +++ b/scripts/ci-changes.test.mjs @@ -33,7 +33,7 @@ const all = { test("documentation changes only build documentation", () => { assert.deepEqual( - classifyFiles(["docs/index.md", "adr/README.md", "CONTRIBUTING.md"]), + classifyFiles(["docs/index.md", "README.md", "CONTRIBUTING.md"]), { ...none, docs: true,