Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JtoDb-0003AH-7G for qemu-devel@nongnu.org; Wed, 07 May 2008 14:18:19 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JtoDZ-000390-Ok for qemu-devel@nongnu.org; Wed, 07 May 2008 14:18:18 -0400 Received: from [199.232.76.173] (port=45930 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JtoDZ-00038v-Cv for qemu-devel@nongnu.org; Wed, 07 May 2008 14:18:17 -0400 Received: from savannah.gnu.org ([199.232.41.3] helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JtoDZ-0000Ho-EF for qemu-devel@nongnu.org; Wed, 07 May 2008 14:18:17 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1JtoDW-00043p-Gf for qemu-devel@nongnu.org; Wed, 07 May 2008 18:18:14 +0000 Received: from ths by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1JtoDU-00043T-BJ for qemu-devel@nongnu.org; Wed, 07 May 2008 18:18:13 +0000 MIME-Version: 1.0 Errors-To: ths Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Thiemo Seufer Message-Id: Date: Wed, 07 May 2008 18:18:12 +0000 Subject: [Qemu-devel] [4384] Be more economical with local temporaries. Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 4384 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4384 Author: ths Date: 2008-05-07 18:18:09 +0000 (Wed, 07 May 2008) Log Message: ----------- Be more economical with local temporaries. Modified Paths: -------------- trunk/target-mips/translate.c Modified: trunk/target-mips/translate.c =================================================================== --- trunk/target-mips/translate.c 2008-05-07 18:04:29 UTC (rev 4383) +++ trunk/target-mips/translate.c 2008-05-07 18:18:09 UTC (rev 4384) @@ -424,6 +424,46 @@ /* global register indices */ static TCGv cpu_env, current_tc_gprs, cpu_T[2]; +/* The code generator doesn't like lots of temporaries, so maintain our own + cache for reuse within a function. */ +#define MAX_TEMPS 4 +static int num_temps; +static TCGv temps[MAX_TEMPS]; + +/* Allocate a temporary variable. */ +static TCGv new_tmp(void) +{ + TCGv tmp; + if (num_temps == MAX_TEMPS) + abort(); + + if (GET_TCGV(temps[num_temps])) + return temps[num_temps++]; + + tmp = tcg_temp_new(TCG_TYPE_I32); + temps[num_temps++] = tmp; + return tmp; +} + +/* Release a temporary variable. */ +static void dead_tmp(TCGv tmp) +{ + int i; + num_temps--; + i = num_temps; + if (GET_TCGV(temps[i]) == GET_TCGV(tmp)) + return; + + /* Shuffle this temp to the last slot. */ + while (GET_TCGV(temps[i]) != GET_TCGV(tmp)) + i--; + while (i < num_temps) { + temps[i] = temps[i + 1]; + i++; + } + temps[i] = tmp; +} + /* General purpose registers moves */ const unsigned char *regnames[] = { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3", @@ -464,7 +504,7 @@ /* Moves to/from shadow registers */ static inline void gen_op_load_srsgpr_T0(int reg) { - int r_tmp = tcg_temp_new(TCG_TYPE_I32); + int r_tmp = new_tmp(); tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSCtl)); tcg_gen_shri_i32(r_tmp, r_tmp, CP0SRSCtl_PSS); @@ -473,11 +513,12 @@ tcg_gen_add_i32(r_tmp, cpu_env, r_tmp); tcg_gen_ld_tl(cpu_T[0], r_tmp, sizeof(target_ulong) * reg); + dead_tmp(r_tmp); } static inline void gen_op_store_srsgpr_T0(int reg) { - int r_tmp = tcg_temp_new(TCG_TYPE_I32); + int r_tmp = new_tmp(); tcg_gen_ld_i32(r_tmp, cpu_env, offsetof(CPUState, CP0_SRSCtl)); tcg_gen_shri_i32(r_tmp, r_tmp, CP0SRSCtl_PSS); @@ -486,6 +527,7 @@ tcg_gen_add_i32(r_tmp, cpu_env, r_tmp); tcg_gen_st_tl(cpu_T[0], r_tmp, sizeof(target_ulong) * reg); + dead_tmp(r_tmp); } /* Load immediates, zero being a special case. */