From patchwork Thu Sep 7 22:40:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 111990 Delivered-To: patch@linaro.org Received: by 10.37.128.210 with SMTP id c18csp766501ybm; Thu, 7 Sep 2017 15:54:48 -0700 (PDT) X-Received: by 10.55.104.87 with SMTP id d84mr1253118qkc.202.1504824888727; Thu, 07 Sep 2017 15:54:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504824888; cv=none; d=google.com; s=arc-20160816; b=ZP82dwjPGGpi7KQwhrFMFqF/QQ9SoR+H8VzQDmLm9zeM9aL/KFVO0kpiGAZWDHZspn CooNiSgPkJfA1R9g+mmXlidTXo03wzeXn6CmgUDeSAnImy0Y0jVYHS6ccSr9XbMdS8H3 7SvWP1GJ5nD5Hi9YVTJw+3oD3X9esMB7c+VKzuIvpEawITE536v8t4Ygx1S3ZQcecjAn o/js2ZMCxoavMbh4Vtb17rhdE2mEfWSzfPZHTkM5eghXbkWDyM5WL5elA3c3wRIGvp7Q q2ftSbBNPdQk1NGEPO3Zv4DGGf+4OsmpV03hE/lJWzx6jIcAiYIn8jSmutOjIaYf2Gzx a1mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=5QX8KOLakpmoalYp7gpxxqobtH+OmlG68TqfOqz5jpo=; b=Xxr5CWNqdlGM3G1OW5vdEI4JrZxTeLOeAmgCPnwIwwJi7ew39p0tlZb7ypgr5AXwmQ cgBnT2mdoAAAdmTg62jh0tdz00o+0FWOfr07J91wwNDOpWsMShP9aN6gCDeLv9vZac4l TStMBDLxBE35qj4RXiI9ca11n7P4NwqKOeQ3oZf301dyShKIpXNEwlc8ARGppvq6d6AV GqFdZt0Vqb4wxYLAmWRIbvGil2rb37Cykf68v6cm5JIj6+HFNY72UHA8HW70zbi75eI6 6JG2xuN3NMUekA4R0xXB4iKpFfhuuydgZb6wXOPRHhtWzOUP6rY8MLFs8PhSTYkqLLXL sJXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=avymF+iO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d17si500400qtl.109.2017.09.07.15.54.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Sep 2017 15:54:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=avymF+iO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5h8-0005zD-Fj for patch@linaro.org; Thu, 07 Sep 2017 18:54:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dq5UA-0003B0-DV for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dq5U5-0008JB-Js for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:22 -0400 Received: from mail-pg0-x235.google.com ([2607:f8b0:400e:c05::235]:37080) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dq5U5-0008Ig-Af for qemu-devel@nongnu.org; Thu, 07 Sep 2017 18:41:17 -0400 Received: by mail-pg0-x235.google.com with SMTP id d8so1804111pgt.4 for ; Thu, 07 Sep 2017 15:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5QX8KOLakpmoalYp7gpxxqobtH+OmlG68TqfOqz5jpo=; b=avymF+iOfoV8ayOmc8Mnwihij2BQDSjIC91GwHzdyHC85dBGmOAKFQVUNUKL6SoqHR HfsCyZPnb5oWDhqxFe5uMxIAm36ZL0815l1YPzK18v761+2voPbgt1wBv39eNtrBpyku LtzGCRbLx46rV185K81dEjxWwxjp6yl7diF9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5QX8KOLakpmoalYp7gpxxqobtH+OmlG68TqfOqz5jpo=; b=JgkVAgAiKIDm6H/0nC15PrjYpkT2gRyy13enAxkF/ukQlJzgAKoPZb1gQxEEf6IYlW rDGHxkh/B/9PzEKR1N0j8jWrKWWpb9MfAQbYIWuxF6vildGztQzyn9LtQuVw91nvbIH2 VkibDzOllyA4q3Hn4si16uBmfXAcWrvEdZ07znvt5T3IOKH34k1YlrycImMKF0YzuFRQ 1QUut3EXaAt2y0pIyHIFpnh8XQsRDpRI0xr9z8BTNhZaNwu8a+QgivZVpo8wegrShEI2 f0DUrmJxjrdDf5hG5ELwyhIU903sGHa4ux3uz6MyVmnK1IEKNzp7JaUhiEZwPWDcNtLj SXog== X-Gm-Message-State: AHPjjUh8PLoIduf1YyN8KbTp5450uIRQSpVEhlNxRPafejJrWut1cOzy ErfA4PpVI40KWcW709Wvzg== X-Google-Smtp-Source: ADKCNb63ADnTh4NOSJD7r9onJtaYBix66AUmwIAEck69NSjD9CCs//JMcSPn5sgDBOYDsft4+/w9pw== X-Received: by 10.84.132.1 with SMTP id 1mr1003215ple.253.1504824076120; Thu, 07 Sep 2017 15:41:16 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-108-236.tukw.qwest.net. [97.126.108.236]) by smtp.gmail.com with ESMTPSA id h19sm770678pfh.142.2017.09.07.15.41.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 07 Sep 2017 15:41:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 7 Sep 2017 15:40:43 -0700 Message-Id: <20170907224051.21518-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org> References: <20170907224051.21518-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::235 Subject: [Qemu-devel] [PULL 15/23] tcg/arm: Improve tlb load for armv7 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Richard Henderson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Richard Henderson Use UBFX to avoid limitation on CPU_TLB_BITS. Since we're dropping the initial shift, we need to replace the page masking. We can use MOVW+BIC to do this without shifting. The result is the same size as the armv6 path with one less conditional instruction. Signed-off-by: Richard Henderson --- tcg/arm/tcg-target.inc.c | 72 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 20 deletions(-) -- 2.13.5 diff --git a/tcg/arm/tcg-target.inc.c b/tcg/arm/tcg-target.inc.c index 81ea900852..66c369c239 100644 --- a/tcg/arm/tcg-target.inc.c +++ b/tcg/arm/tcg-target.inc.c @@ -1173,18 +1173,33 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, unsigned s_bits = opc & MO_SIZE; unsigned a_bits = get_alignment_bits(opc); - /* Should generate something like the following: - * shr tmp, addrlo, #TARGET_PAGE_BITS (1) + /* V7 generates the following: + * ubfx r0, addrlo, #TARGET_PAGE_BITS, #CPU_TLB_BITS * add r2, env, #high - * and r0, tmp, #(CPU_TLB_SIZE - 1) (2) - * add r2, r2, r0, lsl #CPU_TLB_ENTRY_BITS (3) - * ldr r0, [r2, #cmp] (4) + * add r2, r2, r0, lsl #CPU_TLB_ENTRY_BITS + * ldr r0, [r2, #cmp] + * ldr r2, [r2, #add] + * movw tmp, #page_align_mask + * bic tmp, addrlo, tmp + * cmp r0, tmp + * + * Otherwise we generate: + * shr tmp, addrlo, #TARGET_PAGE_BITS + * add r2, env, #high + * and r0, tmp, #(CPU_TLB_SIZE - 1) + * add r2, r2, r0, lsl #CPU_TLB_ENTRY_BITS + * ldr r0, [r2, #cmp] + * ldr r2, [r2, #add] * tst addrlo, #s_mask - * ldr r2, [r2, #add] (5) * cmpeq r0, tmp, lsl #TARGET_PAGE_BITS */ - tcg_out_dat_reg(s, COND_AL, ARITH_MOV, TCG_REG_TMP, - 0, addrlo, SHIFT_IMM_LSR(TARGET_PAGE_BITS)); + if (use_armv7_instructions) { + tcg_out_extract(s, COND_AL, TCG_REG_R0, addrlo, + TARGET_PAGE_BITS, CPU_TLB_BITS); + } else { + tcg_out_dat_reg(s, COND_AL, ARITH_MOV, TCG_REG_TMP, + 0, addrlo, SHIFT_IMM_LSR(TARGET_PAGE_BITS)); + } /* We checked that the offset is contained within 16 bits above. */ if (add_off > 0xfff || (use_armv6_instructions && cmp_off > 0xff)) { @@ -1194,9 +1209,10 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, add_off -= cmp_off & 0xff00; cmp_off &= 0xff; } - - tcg_out_dat_imm(s, COND_AL, ARITH_AND, - TCG_REG_R0, TCG_REG_TMP, CPU_TLB_SIZE - 1); + if (!use_armv7_instructions) { + tcg_out_dat_imm(s, COND_AL, ARITH_AND, + TCG_REG_R0, TCG_REG_TMP, CPU_TLB_SIZE - 1); + } tcg_out_dat_reg(s, COND_AL, ARITH_ADD, TCG_REG_R2, base, TCG_REG_R0, SHIFT_IMM_LSL(CPU_TLB_ENTRY_BITS)); @@ -1212,24 +1228,40 @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi, } } + /* Load the tlb addend. */ + tcg_out_ld32_12(s, COND_AL, TCG_REG_R2, TCG_REG_R2, add_off); + /* Check alignment. We don't support inline unaligned acceses, but we can easily support overalignment checks. */ if (a_bits < s_bits) { a_bits = s_bits; } - if (a_bits) { - tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, addrlo, (1 << a_bits) - 1); - } - /* Load the tlb addend. */ - tcg_out_ld32_12(s, COND_AL, TCG_REG_R2, TCG_REG_R2, add_off); + if (use_armv7_instructions) { + tcg_target_ulong mask = ~(TARGET_PAGE_MASK | ((1 << a_bits) - 1)); + int rot = encode_imm(mask); - tcg_out_dat_reg(s, (a_bits ? COND_EQ : COND_AL), ARITH_CMP, 0, - TCG_REG_R0, TCG_REG_TMP, SHIFT_IMM_LSL(TARGET_PAGE_BITS)); + if (rot >= 0) { + tcg_out_dat_imm(s, COND_AL, ARITH_BIC, TCG_REG_TMP, addrlo, + rotl(mask, rot) | (rot << 7)); + } else { + tcg_out_movi32(s, COND_AL, TCG_REG_TMP, mask); + tcg_out_dat_reg(s, COND_AL, ARITH_BIC, TCG_REG_TMP, + addrlo, TCG_REG_TMP, 0); + } + tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0, TCG_REG_R0, TCG_REG_TMP, 0); + } else { + if (a_bits) { + tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, addrlo, + (1 << a_bits) - 1); + } + tcg_out_dat_reg(s, (a_bits ? COND_EQ : COND_AL), ARITH_CMP, + 0, TCG_REG_R0, TCG_REG_TMP, + SHIFT_IMM_LSL(TARGET_PAGE_BITS)); + } if (TARGET_LONG_BITS == 64) { - tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0, - TCG_REG_R1, addrhi, SHIFT_IMM_LSL(0)); + tcg_out_dat_reg(s, COND_EQ, ARITH_CMP, 0, TCG_REG_R1, addrhi, 0); } return TCG_REG_R2;