From patchwork Fri Jun 2 14:22:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 688204 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d8a:0:0:0:0:0 with SMTP id b10csp897904wru; Fri, 2 Jun 2023 07:23:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5K8Ka1EUF92nEJwS0UhFuW7BveHS2/gS6DK1hePZy/qMax6jLXzq4yevv75NgMK+8aoLg+ X-Received: by 2002:a05:622a:388:b0:3f5:8b9:7249 with SMTP id j8-20020a05622a038800b003f508b97249mr14107135qtx.11.1685715803077; Fri, 02 Jun 2023 07:23:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685715803; cv=none; d=google.com; s=arc-20160816; b=beTqL9ix86YwJO/Gp2dih+gyvK1WOSSRsM8D8i6xSXDer15994Brh5SjYfBH2ct1JF toDw7UdT/sATQ8ndU7rpA8VQxqPT46V92MO9e1L1aTc5EDe5FFcDSpNJy1SbokI5EHXU Vg8kWD0+HDszwMMI43knVoaeUPLfybHshE18p1etXHybic3SdADveFmbuyvFbNvNi/Z6 RI9L/e6OKDYUsvleIM99D+VoJbt5w0xa/8EHNdi5JSZtZ08ls5IvZBXePnXj4SUfU2f1 fdz7csBOadgq9D4R6JiELvOYgY0qoplok4/2VRfMtPb6uqVkbS/LSxMIWPh4mmH89KM6 lArw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=T5r/LpHJMg7TbmN47HlK1bNQm+yT4WVmfzXQIP2d3t4=; b=o359p29FekcrhXn3I6sLhA8IhF98dL8BY7GHESATED8TjiV2o22IKOayiXPdCQoPao aRHSVAmlAsjKX2J0whAs5ukdmzLRb5bgExSGak/kdAz8+B4pM2Kkz4wU3VZURDBCobvA 8M35JCfPb/jasTtas/9pQRBTo0xn+R7ersiEpT6q6KsT/IjBHQawoUFEr/d6i69EHBsl c5HOH7C2q2xGeeXPSo6xeVg5uUPCQQ8Lr3Z1xb+pMy64KzWBBhgCUnGb5hxlKiJzRogo dovWCitecqb5NXaU0hizQ+NUg/7keGQy+wV8vyUHDhQdLURtaIb6SNkE3e0XdRDhiiYt 4ODQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rH3c9poL; 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 h6-20020ac87d46000000b003e651ef42c3si891608qtb.112.2023.06.02.07.23.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 02 Jun 2023 07:23:23 -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=rH3c9poL; 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 1q55fl-0007ZZ-Kr; Fri, 02 Jun 2023 10:22:33 -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 1q55fc-0007Yb-Bc for qemu-devel@nongnu.org; Fri, 02 Jun 2023 10:22:24 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q55fa-0001Xq-LU for qemu-devel@nongnu.org; Fri, 02 Jun 2023 10:22:24 -0400 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3078a3f3b5fso2106076f8f.0 for ; Fri, 02 Jun 2023 07:22:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685715740; x=1688307740; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=T5r/LpHJMg7TbmN47HlK1bNQm+yT4WVmfzXQIP2d3t4=; b=rH3c9poL6+VxRMz0zrH9MEbijYE5irYGZvtD3v4zY/cAltbltJBSXGBB2D0sxSFMnf z9chXOb1GuN6KS+RGGQ+KHUBVv8BoYX9kUN9uZZXF+5yFbTF7y50QQAjopiahMJoExgz fE2uTl9hso99Qnv0DuSH6y06bVolrIL91XJ/AgE87cWsiHMZO/UbSrhvyjNdXfpeR+PK T8qgbASecb3vk3ipQgUh0VuW9eN61MkM0JJfuAYqBE+X8RBnIqtFvrxi6JUCl30MVlDE KD060NWpl74bmVBzDHuJtYmv6Yvb0t6hzLEOLE5HWpARL4sKw299ezM1DNUOlJ34LsLJ sr5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685715740; x=1688307740; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=T5r/LpHJMg7TbmN47HlK1bNQm+yT4WVmfzXQIP2d3t4=; b=cFxcHBYqKn7aiTInzfUAPJDisrT4CbBh3LNxLwZJxUz0iIqCu6D0FUFQv3yc0+PW6T /ehIY+g7aw+uzexF92iLDpnGaN6/JaczGL/rFo02coAunYGt9BKC7voVK9chUdtx6OO2 +bh1PNAHOacXWBigv+YjhJ1vG3Rhj0EXgexkPG6pWfLoCt+kFHMei47nuiopC1pv6qLW 3DVKRlbApKpr6jtT6dwYYd/U9EoLsAOVR9v7sgw8nNQKAfSPlAYJtC34wz5F6YzDUCnP UrNHvVXADjG9sL8b2ibdTCbGmY1fttZ75XywDe/Bgr8pE0pLUAUS8FL8uMOuJiM/3kK7 dH9g== X-Gm-Message-State: AC+VfDwdQ8jJqgELwd7XCIQazm1DYMZ7Hj/lIEtxahiTHx+LyBpxCTVi femgpWNhJOIPPGzBrEcqg8/hVA== X-Received: by 2002:adf:f08b:0:b0:309:3a60:d791 with SMTP id n11-20020adff08b000000b003093a60d791mr88693wro.54.1685715740643; Fri, 02 Jun 2023 07:22:20 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id e21-20020a05600c219500b003f17af4c4e0sm5753600wme.9.2023.06.02.07.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 07:22:20 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Richard Henderson , qemu-stable@nongnu.org Subject: [PATCH] target/arm: Fix return value from LDSMIN/LDSMAX 8/16 bit atomics Date: Fri, 2 Jun 2023 15:22:19 +0100 Message-Id: <20230602142219.1999756-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x429.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 The atomic memory operations are supposed to return the old memory data value in the destination register. This value is not sign-extended, even if the operation is the signed minimum or maximum. (In the pseudocode for the instructions the returned data value is passed to ZeroExtend() to create the value in the register.) We got this wrong because we were doing a 32-to-64 zero extend on the result for 8 and 16 bit data values, rather than the correct amount of zero extension. Fix the bug by using ext8u and ext16u for the MO_8 and MO_16 data sizes rather than ext32u. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson --- target/arm/tcg/translate-a64.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c index 741a6087399..075553e15f5 100644 --- a/target/arm/tcg/translate-a64.c +++ b/target/arm/tcg/translate-a64.c @@ -3401,8 +3401,22 @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn, */ fn(tcg_rt, clean_addr, tcg_rs, get_mem_index(s), mop); - if ((mop & MO_SIGN) && size != MO_64) { - tcg_gen_ext32u_i64(tcg_rt, tcg_rt); + if (mop & MO_SIGN) { + switch (size) { + case MO_8: + tcg_gen_ext8u_i64(tcg_rt, tcg_rt); + break; + case MO_16: + tcg_gen_ext16u_i64(tcg_rt, tcg_rt); + break; + case MO_32: + tcg_gen_ext32u_i64(tcg_rt, tcg_rt); + break; + case MO_64: + break; + default: + g_assert_not_reached(); + } } }