From patchwork Tue May 16 19:40:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 682372 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:558:b0:22d:db33:bb6d with SMTP id w24csp639686ltp; Tue, 16 May 2023 12:45:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5lsJuZk2x1kyoMRxWyfe1aTkybtAcf6EVchv5Gej80ribp3SH3wjuOt9aEmhL4ykoXaIcU X-Received: by 2002:a05:6214:519a:b0:621:65de:f600 with SMTP id kl26-20020a056214519a00b0062165def600mr31588310qvb.1.1684266311731; Tue, 16 May 2023 12:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684266311; cv=none; d=google.com; s=arc-20160816; b=Ed5A+ivURKpD94gm1ilfOsZWOOwkk4hoEbbinDUQCX5CTIZ3PM9Dsrprxwk9A3FuAH he5xH/Fa7Fsgn7OX1yms3FNEj5tS3fXgQvfmrjP/TagsNW7W7kX/hMkHPGbyPm7uuKMH nF8i1QDAieXhrkzMTLFswBJ4Flqsi1FwM+KlbvLhusGrHJttGuBAi/GyaNDiBOoxQYoa SNwqb0b3A50RkgZHElWDGtyHAFoLOWQNZfdRtnA9W95S0z7YMK5svAqGqvcV50mJqJqF fb/zJzslyNBdw5SPKaIw0Wl+BTJ5er/PNZkE92pG2idtXCTbpqqVk/rcJ1kxUKv12Hxi Ar2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4qhfCxW8nZ+AIzOPAndxpM5sZuukyWLZqrgdNp4ChwI=; b=bp9gtVTevvwvgXoqO4AxYYtLCkEmHPhDxtmW3ToSz4Nskg/924ZiiX0tU8OI29E8Vr 5/vmoN6vyB+SEJUrSSv3VNH6aLmLRNYZxec7qHKz7rzDVLiFwX4uHkKsgCwBo4xpc3ix +VipIAXsTaIJEBG9V5LE/D7fi3lVTW04m/naE6kA1zDNBEznF74/zhGo7Nwif1NYkqjn QRxhttv1pfR+OvzpyUYPOg7sQyVb/83lQS1ezwrTOnRJVid4G3jxas47PTsR9QakS8TF zqiAfFKbqGVdTRTJMCZ/gt4IkVGcTaa79E9q2HPQ98ydb3VynkBQPIbOa5bBX+rMAi02 C50Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zMKX732x; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q7-20020ad45ca7000000b005aa3fcc4175si12598271qvh.388.2023.05.16.12.45.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 May 2023 12:45:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zMKX732x; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pz0Ys-0006m6-Ct; Tue, 16 May 2023 15:42:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pz0Yq-0006lF-TR for qemu-devel@nongnu.org; Tue, 16 May 2023 15:42:16 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pz0Yp-0002su-8a for qemu-devel@nongnu.org; Tue, 16 May 2023 15:42:16 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-64a9335a8e7so8218593b3a.0 for ; Tue, 16 May 2023 12:42:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684266134; x=1686858134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4qhfCxW8nZ+AIzOPAndxpM5sZuukyWLZqrgdNp4ChwI=; b=zMKX732xEa5SPswvvFk1EloHDtswzovT+7ivlvjr0R7evVBzi6cVTqOUmT6+BpEKfS ubmh674OUeyGVPX2rh1KXHOi0bXjm4yMoWlFOqHNd8ZIqOu8f6sJp6/YLNaad2wuzzPa O5i1mm0fUnjLYmAvQdpEkmQLuc768o8R+v/qaYMHZxef/8XPRlFa1jEO1OjVofmuSQAZ 2y/tCMQpIhMQk5NupOp5IlN9LYjHpVJuWGv260skCRjFgPaJNXWElboPyVL9MtQo/Yir 8X3q0qjAvuzI1l5pGMpFTi3l7jtn9J/yJdjT2iQcawcuB7nAPqAc667FC+PNOHU/N7EF Jx/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684266134; x=1686858134; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4qhfCxW8nZ+AIzOPAndxpM5sZuukyWLZqrgdNp4ChwI=; b=Dru8Wk6EKt0GXAER2rpC8mvxKQ7xmCQWFvfYni+sQLPeeoxyNM8Y7hrIt2MGy/ycLS 5g3L5/TTrkmNEKyH7ybi+XcU/psaPFDh5RdQUn0pxKTbWIrGwf9NhqKwqwwJizTQfop0 RE5qj/c+DTw1QMJwHQlHwHupgJL0LYHU53PXho661qQPXJ4346li9R9h3aN7++aSwrw1 BjoBjB3EV6UnW5FoaQ6LY8FDRDajrQztNewopMhbN4tHC2pBne9JtPeo7TSKFMIHHGjD 4/F56JpDraZhC26SKzrgHjDoal0FleoD5F5byp/f4bUFBMRiLpqKnVWcFzYYIObFJhnF Szgg== X-Gm-Message-State: AC+VfDzVGNF5vaW7Uct/lDvUlRdyOG9crdVcJBdC/lRKdZArqZ7ZoLWV UyaLurIXAiMmKC3vnmaxJAua1QzHlWQv+l+cpNo= X-Received: by 2002:a05:6a00:b45:b0:63d:3c39:ecc2 with SMTP id p5-20020a056a000b4500b0063d3c39ecc2mr46827241pfo.12.1684266134012; Tue, 16 May 2023 12:42:14 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:ec81:440e:33a4:40b9]) by smtp.gmail.com with ESMTPSA id z21-20020aa791d5000000b006260526cf0csm13771165pfa.116.2023.05.16.12.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 12:42:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 30/80] tcg/loongarch64: Support softmmu unaligned accesses Date: Tue, 16 May 2023 12:40:55 -0700 Message-Id: <20230516194145.1749305-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230516194145.1749305-1-richard.henderson@linaro.org> References: <20230516194145.1749305-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Test the final byte of an unaligned access. Use BSTRINS.D to clear the range of bits, rather than AND. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/loongarch64/tcg-target.c.inc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc index 33d8e67513..7d0165349d 100644 --- a/tcg/loongarch64/tcg-target.c.inc +++ b/tcg/loongarch64/tcg-target.c.inc @@ -848,7 +848,6 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, int fast_ofs = TLB_MASK_TABLE_OFS(mem_index); int mask_ofs = fast_ofs + offsetof(CPUTLBDescFast, mask); int table_ofs = fast_ofs + offsetof(CPUTLBDescFast, table); - tcg_target_long compare_mask; ldst = new_ldst_label(s); ldst->is_ld = is_ld; @@ -872,14 +871,20 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h, tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_TMP2, TCG_REG_TMP2, offsetof(CPUTLBEntry, addend)); - /* We don't support unaligned accesses. */ + /* + * For aligned accesses, we check the first byte and include the alignment + * bits within the address. For unaligned access, we check that we don't + * cross pages using the address of the last byte of the access. + */ if (a_bits < s_bits) { - a_bits = s_bits; + unsigned a_mask = (1u << a_bits) - 1; + unsigned s_mask = (1u << s_bits) - 1; + tcg_out_addi(s, TCG_TYPE_TL, TCG_REG_TMP1, addr_reg, s_mask - a_mask); + } else { + tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_TMP1, addr_reg); } - /* Clear the non-page, non-alignment bits from the address. */ - compare_mask = (tcg_target_long)TARGET_PAGE_MASK | ((1 << a_bits) - 1); - tcg_out_movi(s, TCG_TYPE_TL, TCG_REG_TMP1, compare_mask); - tcg_out_opc_and(s, TCG_REG_TMP1, TCG_REG_TMP1, addr_reg); + tcg_out_opc_bstrins_d(s, TCG_REG_TMP1, TCG_REG_ZERO, + a_bits, TARGET_PAGE_BITS - 1); /* Compare masked address with the TLB entry. */ ldst->label_ptr[0] = s->code_ptr;