Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JxdzF-0001f2-Tc for qemu-devel@nongnu.org; Sun, 18 May 2008 04:11:21 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JxdzF-0001eq-7p for qemu-devel@nongnu.org; Sun, 18 May 2008 04:11:21 -0400 Received: from [199.232.76.173] (port=52046 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JxdzF-0001en-4C for qemu-devel@nongnu.org; Sun, 18 May 2008 04:11:21 -0400 Received: from savannah.gnu.org ([199.232.41.3]:47435 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 1JxdzE-0002Rj-Sk for qemu-devel@nongnu.org; Sun, 18 May 2008 04:11:21 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1Jxdz9-0005QG-8k for qemu-devel@nongnu.org; Sun, 18 May 2008 08:11:15 +0000 Received: from blueswir1 by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1Jxdz9-0005QA-2L for qemu-devel@nongnu.org; Sun, 18 May 2008 08:11:15 +0000 MIME-Version: 1.0 Errors-To: blueswir1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Blue Swirl Message-Id: Date: Sun, 18 May 2008 08:11:15 +0000 Subject: [Qemu-devel] [4486] Fix constant checks on Sparc64 host 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: 4486 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4486 Author: blueswir1 Date: 2008-05-18 08:11:14 +0000 (Sun, 18 May 2008) Log Message: ----------- Fix constant checks on Sparc64 host Modified Paths: -------------- trunk/tcg/sparc/tcg-target.c Modified: trunk/tcg/sparc/tcg-target.c =================================================================== --- trunk/tcg/sparc/tcg-target.c 2008-05-18 07:49:05 UTC (rev 4485) +++ trunk/tcg/sparc/tcg-target.c 2008-05-18 08:11:14 UTC (rev 4486) @@ -87,12 +87,17 @@ TCG_REG_O1, }; -static inline int check_fit(tcg_target_long val, unsigned int bits) +static inline int check_fit_tl(tcg_target_long val, unsigned int bits) { - return ((val << ((sizeof(tcg_target_long) * 8 - bits)) - >> (sizeof(tcg_target_long) * 8 - bits)) == val); + return (val << ((sizeof(tcg_target_long) * 8 - bits)) + >> (sizeof(tcg_target_long) * 8 - bits)) == val; } +static inline int check_fit_i32(uint32_t val, unsigned int bits) +{ + return ((val << (32 - bits)) >> (32 - bits)) == val; +} + static void patch_reloc(uint8_t *code_ptr, int type, tcg_target_long value, tcg_target_long addend) { @@ -106,7 +111,7 @@ case R_SPARC_WDISP22: value -= (long)code_ptr; value >>= 2; - if (!check_fit(value, 22)) + if (!check_fit_tl(value, 22)) tcg_abort(); *(uint32_t *)code_ptr = ((*(uint32_t *)code_ptr) & ~0x3fffff) | value; break; @@ -158,9 +163,9 @@ ct = arg_ct->ct; if (ct & TCG_CT_CONST) return 1; - else if ((ct & TCG_CT_CONST_S11) && check_fit(val, 11)) + else if ((ct & TCG_CT_CONST_S11) && check_fit_tl(val, 11)) return 1; - else if ((ct & TCG_CT_CONST_S13) && check_fit(val, 13)) + else if ((ct & TCG_CT_CONST_S13) && check_fit_tl(val, 13)) return 1; else return 0; @@ -248,10 +253,10 @@ int ret, tcg_target_long arg) { #if defined(__sparc_v9__) && !defined(__sparc_v8plus__) - if (!check_fit(arg, 32)) + if (!check_fit_tl(arg, 32) && (arg & ~0xffffffff) != 0) fprintf(stderr, "unimplemented %s with constant %ld\n", __func__, arg); #endif - if (check_fit(arg, 13)) + if (check_fit_i32(arg, 13)) tcg_out32(s, ARITH_OR | INSN_RD(ret) | INSN_RS1(TCG_REG_G0) | INSN_IMM13(arg)); else { @@ -274,9 +279,9 @@ tcg_target_long arg) { #if defined(__sparc_v9__) && !defined(__sparc_v8plus__) - if (!check_fit(arg, 32)) + if (!check_fit_tl(arg, 32) && (arg & ~0xffffffff) != 0) fprintf(stderr, "unimplemented %s with offset %ld\n", __func__, arg); - if (!check_fit(arg, 13)) + if (!check_fit_i32(arg, 13)) tcg_out32(s, SETHI | INSN_RD(ret) | (((uint32_t)arg & 0xfffffc00) >> 10)); tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(ret) | INSN_IMM13(arg & 0x3ff)); @@ -287,7 +292,7 @@ static inline void tcg_out_ldst(TCGContext *s, int ret, int addr, int offset, int op) { - if (check_fit(offset, 13)) + if (check_fit_tl(offset, 13)) tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(addr) | INSN_IMM13(offset)); else { @@ -340,7 +345,7 @@ static inline void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val) { if (val != 0) { - if (check_fit(val, 13)) + if (check_fit_tl(val, 13)) tcg_out_arithi(s, reg, reg, val, ARITH_ADD); else { tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_I5, val);