From patchwork Tue May 16 19:41:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 682423 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp21075wrt; Tue, 16 May 2023 12:59:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54gXai4tj/uthXSzivDCRfNSs7Nk0M+uubVL9w3xk0PBYP95Ig0ubkShAHma1tpGiYygKc X-Received: by 2002:a5d:55c2:0:b0:306:5149:3aa8 with SMTP id i2-20020a5d55c2000000b0030651493aa8mr27066444wrw.24.1684267170730; Tue, 16 May 2023 12:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684267170; cv=none; d=google.com; s=arc-20160816; b=geZDsUCx2YwXXMPzSiPHao5S621UsGxHubMMpAfDtfjoJZ4i3oaReQSy3n34uBxaYm suA00CbTF5nCZ3i2mSbbVCd/uc47hZZvFD0kNq+5sKjzJy5ml31F+jo+c5vHBZ6gXifY +5GPBZr9HyRZthd6Sl67Tk0DvOuQfc5R2cqG81u0S7qwwSadTVywdSNHSnvUjjfJXAJr NrLYQwT+9X6nY8JdOTmXclKFpg5t5ZJKN3De73j7BQfeH+rt1zRWvtCFUj6XEPg6E9cI vd2WJ9Hdt7Fq+633YJbuvNDa47H9KwG8ECBmj5Hmhs3aL5a6If/cczKlTOfamklb+YMj z5HQ== 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=e3K+79nBiSc5crGCl8vbMQJ8GibyAa5XexENyD2+9r4=; b=wu5ALMBdmykJzez5EuiLcuSJgbKQ4xBs8wdDWugDpSMN28eNk6BifU+B5MOE78UAQ/ gqXUf9UhxjLrexZCpsTJGIgvJBOFFSq7aFkQ9Yq6m5XMmMmsGEyAWSZyk5xHrcmhwlWi LU/kCqab9gzrCmehdgFs1fDQP/j5XeskEaSCXwbcqHIsIqNFzhlq7KYA/WHfu2Ox4s1q 6DDdt5508hXgqcnUAeI4fnfUDmd1iEqEtnVSsPtmqVPkGqH2KWxrGDxFpawYWC4R+AHs 9N2UUvydXTsvZhH3zsSJ7JPFpI9UgjqSzttTbBcroPxSgfFhVe/fBycxzKWnfpp2Z54d B8KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ppBwYKMg; 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 w4-20020adfde84000000b003079e5881d1si172917wrl.839.2023.05.16.12.59.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 May 2023 12:59:30 -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=ppBwYKMg; 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 1pz0cM-0000S2-P2; Tue, 16 May 2023 15:45:54 -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 1pz0c2-0008W0-5p for qemu-devel@nongnu.org; Tue, 16 May 2023 15:45:35 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pz0c0-0003iP-3f for qemu-devel@nongnu.org; Tue, 16 May 2023 15:45:33 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-24df161f84bso38991a91.3 for ; Tue, 16 May 2023 12:45:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684266329; x=1686858329; 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=e3K+79nBiSc5crGCl8vbMQJ8GibyAa5XexENyD2+9r4=; b=ppBwYKMgiuaJj6tOojb90updO3NDRwOMNyEKFUMkcbT/HaF0UR+jEMa8lJiO2+c8QJ 6rBy01m6i34cCT3BpSmkaOkaeI9sz2/zHsGPnR02pykNPAalxFAesDtzdJ0EnrznGhU4 CjSBgI/RsBfJt/XLMWYbvmMd6fcQzZf2+4r7PsYhHR7yJoWbfE10Q2okmaE1ofKcZk4u ZijZ3opbS2il2mJWjQfRE7wu2QvUNfHazZ0WmlrAy9sVV+cVaeOHyXXk90BnuE8DpS6A 4amGUzGFln4x1PikePC5nOyCbXVjvr55Lz6jqF7UwT994gH2JzbPSKlbyXe7x3bbrsx8 QEeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684266329; x=1686858329; 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=e3K+79nBiSc5crGCl8vbMQJ8GibyAa5XexENyD2+9r4=; b=IQHC4WwT43aCxZjA9GKBWLjeEZ3CdqA53Nc+hlyWQwt1wtUZ/4d+002x4o8WDveQOr N0k4b9VHHlXxyfDSE8YQwCJ+iwjhZzlG6pL8w4Z5oDHaZ0u9sWVqfCb5agxxQEkhhEA5 1z/pBVGgBQ9brod1s5zyiWmkgfD+3UJBUDCtHggpYcqOn4sQ33zJSOD8iN/ufKwjkE5u PDuG60CGqi++wHoN6RBTzVlVpeQxvsCXAoEi1mL/i/EZQWTBXtOGRa16ZwugBFZfI0Ls vKR5yYYQd34ciRmAR1RIWhBwnibGdjhGbU/45m/3tjd5g8VdQQh/pLSvUm8Rkl0+52Da 9k7Q== X-Gm-Message-State: AC+VfDw7QhDkAgxvjsKAhDg3UO15tDU2vgwRV+0qDPVPRggUXFhJdPff X1StRFgTG3Kwm9Bx6uVr4Q1QoZNr1V3v+4BrvBU= X-Received: by 2002:a17:90a:9d87:b0:24d:f77c:71e7 with SMTP id k7-20020a17090a9d8700b0024df77c71e7mr36900436pjp.41.1684266329572; Tue, 16 May 2023 12:45:29 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:ec81:440e:33a4:40b9]) by smtp.gmail.com with ESMTPSA id y12-20020a17090abd0c00b002508d73f4e8sm25555pjr.57.2023.05.16.12.45.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 12:45:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 47/80] tcg/i386: Honor 64-bit atomicity in 32-bit mode Date: Tue, 16 May 2023 12:41:12 -0700 Message-Id: <20230516194145.1749305-48-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::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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 Use the fpu to perform 64-bit loads and stores. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- tcg/i386/tcg-target.c.inc | 44 +++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc index 3b8528e332..0415ca2a4c 100644 --- a/tcg/i386/tcg-target.c.inc +++ b/tcg/i386/tcg-target.c.inc @@ -468,6 +468,10 @@ static bool tcg_target_const_match(int64_t val, TCGType type, int ct) #define OPC_GRP5 (0xff) #define OPC_GRP14 (0x73 | P_EXT | P_DATA16) +#define OPC_ESCDF (0xdf) +#define ESCDF_FILD_m64 5 +#define ESCDF_FISTP_m64 7 + /* Group 1 opcode extensions for 0x80-0x83. These are also used as modifiers for OPC_ARITH. */ #define ARITH_ADD 0 @@ -2086,7 +2090,20 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi, datalo = datahi; datahi = t; } - if (h.base == datalo || h.index == datalo) { + if (h.aa.atom == MO_64) { + /* + * Atomicity requires that we use use a single 8-byte load. + * For simplicity and code size, always use the FPU for this. + * Similar insns using SSE/AVX are merely larger. + * Load from memory in one go, then store back to the stack, + * from whence we can load into the correct integer regs. + */ + tcg_out_modrm_sib_offset(s, OPC_ESCDF + h.seg, ESCDF_FILD_m64, + h.base, h.index, 0, h.ofs); + tcg_out_modrm_offset(s, OPC_ESCDF, ESCDF_FISTP_m64, TCG_REG_ESP, 0); + tcg_out_modrm_offset(s, movop, datalo, TCG_REG_ESP, 0); + tcg_out_modrm_offset(s, movop, datahi, TCG_REG_ESP, 4); + } else if (h.base == datalo || h.index == datalo) { tcg_out_modrm_sib_offset(s, OPC_LEA, datahi, h.base, h.index, 0, h.ofs); tcg_out_modrm_offset(s, movop + h.seg, datalo, datahi, 0); @@ -2156,12 +2173,27 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg datalo, TCGReg datahi, if (TCG_TARGET_REG_BITS == 64) { tcg_out_modrm_sib_offset(s, movop + P_REXW + h.seg, datalo, h.base, h.index, 0, h.ofs); + break; + } + if (use_movbe) { + TCGReg t = datalo; + datalo = datahi; + datahi = t; + } + if (h.aa.atom == MO_64) { + /* + * Atomicity requires that we use use one 8-byte store. + * For simplicity, and code size, always use the FPU for this. + * Similar insns using SSE/AVX are merely larger. + * Assemble the 8-byte quantity in required endianness + * on the stack, load to coproc unit, and store. + */ + tcg_out_modrm_offset(s, movop, datalo, TCG_REG_ESP, 0); + tcg_out_modrm_offset(s, movop, datahi, TCG_REG_ESP, 4); + tcg_out_modrm_offset(s, OPC_ESCDF, ESCDF_FILD_m64, TCG_REG_ESP, 0); + tcg_out_modrm_sib_offset(s, OPC_ESCDF + h.seg, ESCDF_FISTP_m64, + h.base, h.index, 0, h.ofs); } else { - if (use_movbe) { - TCGReg t = datalo; - datalo = datahi; - datahi = t; - } tcg_out_modrm_sib_offset(s, movop + h.seg, datalo, h.base, h.index, 0, h.ofs); tcg_out_modrm_sib_offset(s, movop + h.seg, datahi,