Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8685BCD5BD5 for ; Thu, 28 May 2026 09:05:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wSWfL-0002ih-52; Thu, 28 May 2026 05:04:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSWfJ-0002ht-7a for qemu-devel@nongnu.org; Thu, 28 May 2026 05:04:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wSWfG-0003vh-Vd for qemu-devel@nongnu.org; Thu, 28 May 2026 05:04:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779959068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=xUKfB7MDcwhvFQjsL1YXzxObEUHdWokdnxPOeB9AUTQ=; b=A1CZCCGd0WLdXTQEAtF5lk2JZXwGwFwNawIGqbo/aiRcXV4zrhDkRkB2dfTg4jOumqtQCy vPJUg4JPtPXd3jxt5l2cmtpMJ1RR8kWjBJVqDfKLIQY+LFeAOpeUJB6GYLnkPP5jJftRy9 3czmnErl/n8XEaL4qgFne71H/ffEsnY= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-91-8qM651yFORqe1yAWKAqB8A-1; Thu, 28 May 2026 05:04:22 -0400 X-MC-Unique: 8qM651yFORqe1yAWKAqB8A-1 X-Mimecast-MFC-AGG-ID: 8qM651yFORqe1yAWKAqB8A_1779959060 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2C052195608A; Thu, 28 May 2026 09:04:20 +0000 (UTC) Received: from [10.44.32.217] (unknown [10.44.32.217]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CADCF1800347; Thu, 28 May 2026 09:04:17 +0000 (UTC) Message-ID: <893dd362-b70c-4c24-bb19-428808ceaa6d@redhat.com> Date: Thu, 28 May 2026 11:04:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] docs/devel/tcg: Expand on multi-threaded TCG To: =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Cc: Alistair Francis , Peter Maydell , Richard Henderson , Pierrick Bouvier , Anton Johansson References: <20260528082022.32359-1-philmd@linaro.org> Content-Language: en-US From: Paolo Bonzini Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2Sf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4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: <20260528082022.32359-1-philmd@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Before looking at the specifics, I appreciate you bold and experimenting with how to improve our documentation. I can see that this is largely unedited LLM output, and honestly, that is actually a good thing for this experiment. On the other hand, it exposes where the tool falls short, and highlights very clearly the risks of accepting AI-generated content too leisurely. On 5/28/26 10:20, Philippe Mathieu-Daudé wrote: > Significantly expands the TCG documentation to provide more > comprehensive overview of its internal architecture. > > Use more rST anchors to improve cross-referencing across the > documentation. > > Clarify front-end / optimization / back-end phases. > > Detail a bit memory consistency barriers under MTTCG mode. > > Add the following new sections: > > - Register Allocation and Liveness analysis > - Overviews of the Vector/SIMD internal strategy > - Deterministic Execution (icount) > - TCG Plugins > - Instruction Decoding with decodetree This commit message is not really up to the standards. It is purely a "what" which can be obtained just by glancing at the section headers. It should explain the purpose of tcg.rst and why these new sections were singled out. > +The translation process occurs in several distinct passes: > + > +1. **Front-end**: Guest instructions are parsed (often using the > + `decodetree `_ tool) and converted > + into target-independent TCG Intermediate Representation (IR) opcodes. > +2. **Optimization**: TCG performs passes such as constant folding, liveness > + analysis, and dead code elimination on the IR. > +3. **Back-end**: The optimized IR is converted by a host-specific code > + generator into native instructions for the host CPU. The sections below should be sorted according to these sections, when applicable. Register allocation also fits somewhere, probably in "back-end". There should be also another sentence for the TCG run-time (accel/tcg). > +Register Allocation and Liveness > +-------------------------------- > + > +During the translation phase, guest instructions are converted into TCG IR > +using an **unlimited number of temporaries (TEMPs)**. > +This allows guest translators to express logic without being constrained > +by the finite register set of the host CPU. > + > +To resolve these TEMPs into physical registers, TCG performs two passes: > + > +1. **Liveness Analysis**: This pass determines the "live range" of each > + temporary within a basic block. By identifying when a variable > + becomes "dead" (i.e., its value is no longer needed), TCG can suppress > + redundant moves and remove instructions that compute unused results. > +2. **Register Allocation**: The Global Register Allocator maps live TEMPs > + to host physical registers. Fixed globals, such as the pointer > + to the CPU architecture state (``cpu_env``), are often permanently > + held in host registers to minimize memory traffic during execution. > + > +Vector/SIMD Internal Strategy > +----------------------------- > + > +TCG supports SIMD operations through a set of generic vector instructions > +(e.g., ``add_vec``, ``shli_vec``) parameterized by vector length and element > +size. The length is specified as a ``TCGType`` (V64, V128, or V256), and the > +element size is given in log2 8-bit units. > + > +The internal strategy relies on the backend mapping these generic opcodes > +to native host SIMD instructions, such as x86 AVX or ARM NEON. If the host > +backend does not support a specific vector operation or length, TCG's > +expansion layer automatically decomposes the opcode into smaller supported > +vector sizes or standard integer operations. > + > +Deterministic Execution (icount) > +-------------------------------- > + > +The :ref:`icount` mechanism provides deterministic execution by ensuring > +that each Translation Block executes a fixed number of instructions. Hallucination (to put it kindly). It ensures that QEMU_CLOCK_VIRTUAL is a multiple of the number of instructions executed. > This > +is essential for features like record/replay and deterministic virtual time, > +where instruction counts serve as the system clock. > + > +Instrumentation and Plugins > +--------------------------- > + > +:ref:`TCG Plugins` provide a mechanism for runtime instrumentation. Opcodes > +like ``plugin_cb`` and ``plugin_mem_cb`` are inserted during translation to > +trigger callbacks in external modules, allowing analysis of instruction > +execution or memory access. > + > +Instruction Decoding (decodetree) > +--------------------------------- > + > +The first step of the translation process is converting a raw bitstream of > +guest instructions into a structured format that the translator can process. Is this true? Maybe "extracting operands from the raw bitstream of guest instructions, for easier processing in the translator"? > +QEMU simplifies this using the ``decodetree.py`` script, which generates C > +code decoders from a domain-specific language defined in ``.decode`` files. > + > +The decodetree tool allows developers to define instruction **patterns** > +based on a bitmask and fixed bits. When a match is found, the generated > +decoder automatically extracts defined **fields** (such as registers or > +immediates) and passes them to a manually written translation function. > + > +This declarative approach drastically reduces the amount of error-prone > +manual bit-shifting and nested "if-else" logic required in guest translators. I would just say "``decodetree`` simplifies writing and maintaining the front-end compared to manual decoding". Maybe it's worth adding something like "Note however that it is mostly applicable to processors whose instruction encoding is fixed length, or mostly fixed length.". > +For detailled implementation see :ref:`decodetree`. "detailed". Honestly, I'm not impressed by the quality of the output. There's no organization, just a bunch of new sections in no order (decodetree comes last). They might be good enough for a glossary, but for developer documentation it would just add structural debt(*). At the very least all the "----"-level sections should be split into front-end, optimization, back-end and run-time. Again, this is not about you---I hope you knew that this wasn't going to be included as is. :) Submitting this without manual editing shows the baseline capabilities of the LLM and highlights the importance of human steering. Paolo (*) I have just made this term up, but I think it should be a thing - we have a lot of it already in QEMU docs