Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NIrOO-0004mE-Ej for qemu-devel@nongnu.org; Thu, 10 Dec 2009 17:21:48 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NIrOK-0004jb-P5 for qemu-devel@nongnu.org; Thu, 10 Dec 2009 17:21:48 -0500 Received: from [199.232.76.173] (port=58437 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NIrOK-0004jP-IA for qemu-devel@nongnu.org; Thu, 10 Dec 2009 17:21:44 -0500 Received: from fmmailgate02.web.de ([217.72.192.227]:55347) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NIrOJ-0003FA-TD for qemu-devel@nongnu.org; Thu, 10 Dec 2009 17:21:44 -0500 Message-Id: <4CC2A3A0-B3BC-48C2-850B-3EC92BAC4ED8@web.de> From: =?ISO-8859-1?Q?Andreas_F=E4rber?= In-Reply-To: Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: [Qemu-devel] TCG is hard to understand! Date: Thu, 10 Dec 2009 23:21:21 +0100 References: Sender: andreas.faerber@web.de List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jun Koi Cc: qemu-devel@nongnu.org Hi, Am 10.12.2009 um 17:44 schrieb Jun Koi: > I am trying to understand how TCG works. For example, I look at the > LLDT insn on x86. > > In target-i386/translate.c, we translate LLDT to TCG code, like below: > > > static TCGv_i32 > cpu_tmp2_i32; // 1 > ... > gen_ldst_modrm(s, modrm, OT_WORD, OR_TMP0, 0); // 2 > gen_jmp_im(pc_start - s->cs_base); // 3 > tcg_gen_trunc_tl_i32(cpu_tmp2_i32, cpu_T[0]); // 4 > gen_helper_lldt > (cpu_tmp2_i32); // 5 > > > This is quite confused. I understand that: [...] > - Line (4) generate the code to copy cpu_T[0] to the (local) variable > cpu_tmp2_i32. > However, as tcg_gen_trunc_tl_i32() put the *value* of that variable, > but not its *address*, into the generated code, I dont see how next > line (5) can generate code that use the same variable. > Clearly there is no connection between cpu_tmp2_i32 on line (4) and > line (5), so how the generated code works here?? Line 4 generates code to truncate the value from the source associated with cpu_T[0] and put it into the destination associated with cpu_tmp2_i32, which may be a general-purpose register on PowerPC for instance (i.e., not an address). The connection between line 4 and 5 is that cpu_tmp2_i32 has as its value the same identifier (sort of a handle), allowing TCG internal code to lookup its location. Btw if the code confuses you, cpu_T[n] is actually a leftover from the dyngen to TCG conversion. Feel free to provide patches replacing the remaining occurrences by individual local TCG variables if it helps your understanding. :) Andreas