qemu-tcg-backend
Use for adapting a QEMU TCG host backend, including optional op support, constraints, register allocation, host code emission, qemu_ld/st, atomics, vectors, and native-versus-fallback verification.
processmission · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add processmission/oh-my-qemu --skill qemu-tcg-backend技能说明
SPDX-FileCopyrightText: Copyright (c) 2026 Process Mission
SPDX-License-Identifier: MIT
name: qemu-tcg-backend description: Use for adapting a QEMU TCG host backend, including optional op support, constraints, register allocation, host code emission, qemu_ld/st, atomics, vectors, and native-versus-fallback verification.
QEMU TCG Backend Adaptation
Audit workflow
For non-trivial workspace writes, use a stable
.oh-my-qemu/<task-slug>/ directory and create only needed entries:
.oh-my-qemu/<task-slug>/
├── audit.md # Baseline, scope, decisions, evidence, verification, and gaps
├── commands.md # Redacted commands, working directories, and results
├── logs/ # Decisive build, test, runtime, or diagnostic logs
├── scripts/ # Temporary scripts, probes, parsers, and harnesses
└── output/ # Generated deliverables, dependencies, and non-QEMU binaries
Before changing source or mutable artifacts, record the workspace root,
revision, git status --short, pre-existing changes, goal, scope, and
acceptance checks in audit.md. Log exact redacted commands and results in
commands.md; record revisions, configurations, tool versions, and hashes when
they affect reproducibility. Separate observations from inferences and edit
source only when requested.
Keep QEMU builds under source-root builds/build-<target>/; put third-party
dependencies and non-QEMU binaries in task output/. Before writing audit
artifacts or configuring QEMU in a Git worktree, add .agents/,
.oh-my-qemu/, and builds/ to the repository-local file from
git rev-parse --git-path info/exclude; preserve existing entries and avoid
duplicates. Never stage or commit those directories. At handoff, verify them
absent from git status --short. Report the task directory and unresolved gaps.
Workflow
- Record host architecture/features/toolchain, IR semantics, constraints, emitter path, unsupported cases, and allowed source paths.
- Inspect the checked-out backend and generic fallback before enabling an op.
- Work in small reviewable rounds and record changed paths, verification,
review result, and gaps in
audit.md. - Build for the affected host and run focused tests that exercise both native and fallback behavior where applicable.
- Capture bounded host-code/TCG logs and keep unsupported features disabled until constraints, emission, and evidence agree.
QEMU upstream boundary
QEMU's official GitLab and mailing lists are upstream project channels. A
patch becomes an upstream contribution when sent to the mailing-list recipients
selected through MAINTAINERS; do not prepare or send agent-generated patches
for that submission. Local branches, commits, patch files, pushes, and pull
requests are not by themselves QEMU upstream contributions. Perform those Git
actions only when requested and follow the workspace's Git policy.
Backend contract
A backend change is correct only when these agree:
- IR op semantics from
include/tcg/tcg-opc.handdocs/devel/tcg-ops.rst; - host feature flag in
tcg-target-has.h; - operand constraints in
tcg-target-con-str.handtcg-target-con-set.h; - register class/reserved-register assumptions in
tcg-target.h; tcg_out_op, vector emission, or qemu_ld/st implementation intcg-target.c.inc;- tests/logs proving the native path or intentional generic expansion.
Do not enable TCG_TARGET_HAS_* before constraints and emission support are complete.
Classify the change
Record one category in audit.md:
- new host instruction encoder;
- native emission for existing TCG op;
- optional op enablement;
- constraint/register allocation fix;
- qemu_ld/st or atomic path;
- vector op support;
- host feature gating/runtime CPU detection;
- code generation bug investigation.
Emission checklist
Check:
- immediate ranges and sign extension;
- i32 result extension on 64-bit hosts;
- signed vs unsigned conditions;
- branch displacement and relocation/pool handling;
- clobbers and call ABI;
- scalar vs vector register classes;
- host endianness;
- constant materialization;
- instruction-cache flush needs.
Keep code generation paths allocation-free and simple.
qemu_ld/st and atomics
Verify separately:
MemOpsize, sign, and endianness;- TLB fast path vs slow path labels;
- i128 register pairing;
- user-mode vs system-mode differences;
- guest atomicity vs host capability;
- helper calls and clobbers;
- unaligned behavior.
Vector rules
For vectors, verify:
- host vector feature detection;
v64/v128/v256and specific op flags;- element size coverage;
- constant operand forms;
- scalar fallback vs vector path;
tcg_can_emit_vec_op()/tcg_expand_vec_op()behavior.
Verification expectations
- Build the backend on the host.
- Run focused
tests/tcgwhen available. - Capture TCG IR and host-code logs proving native emission or fallback.
- Check unsupported host features remain disabled.
- Use
one-insn-per-tbwhen frontend/backend attribution is unclear.
Upstream references
- QEMU code provenance and AI policy:
docs/devel/code-provenance.rst. - TCG IR semantics:
docs/devel/tcg-ops.rst. - TCG internals:
docs/devel/tcg.rst. - Backend examples:
tcg/aarch64/,tcg/riscv64/,tcg/loongarch64/. - Core declarations:
include/tcg/tcg.h,include/tcg/tcg-opc.h,include/tcg/tcg-op-common.h.