From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JwhHk-0000mF-3P for qemu-devel@nongnu.org; Thu, 15 May 2008 13:30:32 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JwhHi-0000m0-Lg for qemu-devel@nongnu.org; Thu, 15 May 2008 13:30:30 -0400 Received: from [199.232.76.173] (port=41546 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JwhHi-0000lx-Dt for qemu-devel@nongnu.org; Thu, 15 May 2008 13:30:30 -0400 Received: from savannah.gnu.org ([199.232.41.3]:36210 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 1JwhHh-00054Q-3b for qemu-devel@nongnu.org; Thu, 15 May 2008 13:30:30 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1JwhHc-0004su-9q for qemu-devel@nongnu.org; Thu, 15 May 2008 17:30:24 +0000 Received: from blueswir1 by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1JwhHZ-0004sP-Bi for qemu-devel@nongnu.org; Thu, 15 May 2008 17:30:23 +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: Thu, 15 May 2008 17:30:21 +0000 Subject: [Qemu-devel] [4460] Fix bit fitting checks 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: 4460 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4460 Author: blueswir1 Date: 2008-05-15 17:30:17 +0000 (Thu, 15 May 2008) Log Message: ----------- Fix bit fitting checks Modified Paths: -------------- trunk/tcg/sparc/tcg-target.c Modified: trunk/tcg/sparc/tcg-target.c =================================================================== --- trunk/tcg/sparc/tcg-target.c 2008-05-15 16:46:30 UTC (rev 4459) +++ trunk/tcg/sparc/tcg-target.c 2008-05-15 17:30:17 UTC (rev 4460) @@ -134,7 +134,12 @@ return 0; } -#define ABS(x) ((x) < 0? -(x) : (x)) +static inline int check_fit(tcg_target_long val, unsigned int bits) +{ + return ((val << ((sizeof(tcg_target_long) * 8 - bits)) + >> (sizeof(tcg_target_long) * 8 - bits)) == val); +} + /* test if a constant matches the constraint */ static inline int tcg_target_const_match(tcg_target_long val, const TCGArgConstraint *arg_ct) @@ -144,9 +149,9 @@ ct = arg_ct->ct; if (ct & TCG_CT_CONST) return 1; - else if ((ct & TCG_CT_CONST_S11) && ABS(val) == (ABS(val) & 0x3ff)) + else if ((ct & TCG_CT_CONST_S11) && check_fit(val, 11)) return 1; - else if ((ct & TCG_CT_CONST_S13) && ABS(val) == (ABS(val) & 0xfff)) + else if ((ct & TCG_CT_CONST_S13) && check_fit(val, 13)) return 1; else return 0; @@ -217,10 +222,10 @@ int ret, tcg_target_long arg) { #if defined(__sparc_v9__) && !defined(__sparc_v8plus__) - if (arg != (arg & 0xffffffff)) + if (!check_fit(arg, 32)) fprintf(stderr, "unimplemented %s with constant %ld\n", __func__, arg); #endif - if (arg == (arg & 0xfff)) + if (check_fit(arg, 13)) tcg_out32(s, ARITH_OR | INSN_RD(ret) | INSN_RS1(TCG_REG_G0) | INSN_IMM13(arg)); else { @@ -243,9 +248,9 @@ tcg_target_long arg) { #if defined(__sparc_v9__) && !defined(__sparc_v8plus__) - if (arg != (arg & 0xffffffff)) + if (!check_fit(arg, 32)) fprintf(stderr, "unimplemented %s with offset %ld\n", __func__, arg); - if (arg != (arg & 0xfff)) + if (!check_fit(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)); @@ -256,7 +261,7 @@ static inline void tcg_out_ldst(TCGContext *s, int ret, int addr, int offset, int op) { - if (offset == (offset & 0xfff)) + if (check_fit(offset, 13)) tcg_out32(s, op | INSN_RD(ret) | INSN_RS1(addr) | INSN_IMM13(offset)); else @@ -306,7 +311,7 @@ static inline void tcg_out_addi(TCGContext *s, int reg, tcg_target_long val) { if (val != 0) { - if (val == (val & 0xfff)) + if (check_fit(val, 13)) tcg_out_arithi(s, reg, reg, val, ARITH_ADD); else fprintf(stderr, "unimplemented addi %ld\n", (long)val); @@ -344,8 +349,7 @@ case INDEX_op_goto_tb: if (s->tb_jmp_offset) { /* direct jump method */ - if (ABS(args[0] - (unsigned long)s->code_ptr) == - (ABS(args[0] - (unsigned long)s->code_ptr) & 0x1fffff)) { + if (check_fit(args[0] - (unsigned long)s->code_ptr, 26)) { tcg_out32(s, BA | INSN_OFF22(args[0] - (unsigned long)s->code_ptr)); } else {