From patchwork Mon Jul 6 18:52:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 234881 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp229457ilg; Mon, 6 Jul 2020 11:53:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDUGABozVW3Xt7rs/pMxKYrUX+IQ9rBMm9/LyF0z6sviZko1n0QY3HKRN6PqRAHvupmlhc X-Received: by 2002:a25:9843:: with SMTP id k3mr79795334ybo.444.1594061587592; Mon, 06 Jul 2020 11:53:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594061587; cv=none; d=google.com; s=arc-20160816; b=uvJd4wXvQ0cyProIGKyJXBySqlYhJDDBitGzCVolj2kzjR44zzLtAxXLwmzO4SR6mJ o1Egj+5FElYJXoMmTbF/Af/pKXqn2D9ndVyy4XztTR0QhoaH+XCZSF2EWSECYFLnk2Mv qwUpr9htCJ3dEwvBsMAVj0rSpHn4FwtOSE1XS2iQgl35ROX+ey+rIdlZ6CdmzOKQiBMh paIhE0eRaPDHQ6FGripawVx4RFK51b+eT7Dg81aFhb17qdB5cevqTH5H/B0qMthp77O7 lWe6bAp8ZpRYq0DIefIewIUq36O18LRLebULrVaM9gKEa+L3hIONQe/Xo/nFUzo9m29S XcxA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Qxipx9m0vKeP12B9CxfpMSMsmfVBM9RcOjG9qZgvzwg=; b=Dkqvy67cZGbzPzrFRwZtBPPZXWtIVdTcTDFdsvSFniCCRDOC++YBjFKwmFqTAYO9kQ HVC5I7ffMFb2coIH96DgKMd1WeWSjXzSrkAT7LhvD+xyz8jw/me3lyu2RLxinXqyc8BD dasQujArDsrOtn7pc8skQ78/I9Kj01/6aldeRv6AzeBlo6ktxf3r+MD9VSVyQYNnVK3f N/xwbGshDAPpAjb/7gSXVBacW+Pk9oEu7exZL5VJxoXeGGMj2edhVJYcRDjK/jQQyWHC MfnMnKNJg/a3VOQpsuKag+OwxBPW3xYAqZh7QF+tyoNwBRQcswJQ+UZ9GmY0rbYJ5jks Iuxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b0bz8qB1; 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 l2si31992215ybt.63.2020.07.06.11.53.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Jul 2020 11:53:07 -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=b0bz8qB1; 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]:43848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jsWEl-00010J-3f for patch@linaro.org; Mon, 06 Jul 2020 14:53:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jsWEa-0000vj-FL for qemu-devel@nongnu.org; Mon, 06 Jul 2020 14:52:56 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:36313) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jsWEY-0000fL-Sm for qemu-devel@nongnu.org; Mon, 06 Jul 2020 14:52:56 -0400 Received: by mail-pl1-x630.google.com with SMTP id d10so3650431pll.3 for ; Mon, 06 Jul 2020 11:52:54 -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 :mime-version:content-transfer-encoding; bh=Qxipx9m0vKeP12B9CxfpMSMsmfVBM9RcOjG9qZgvzwg=; b=b0bz8qB12ZZi91OgFBDHu+nLsCehcBtofcgLpJz8Ob5PtCV70tOUllcYegKAEuv3Wp dRRx30v9FqmFIAWhF546BpMKXaX8fqqfJ6tY7g8r3YLMuVGAyZrsxx+/PL9O/3/Y7cKm 3JyjQKWUFQiLfKRxxXOsw+qW2pTeL9A0fnOzB1BEfKp241LeptdTo3Bd0ZInTh5mlX6H zbyTa7Az64m6rJn1eHoM8kgTmavdWqrNWmrgulKbNXSjluNOxVzyfdlA1aLvPhp0jmXa T3llOE5s+avY9MPzBNSnqLks32vapxNfkuLEZ6R6G+b4hJE6McxKGlLwMThhdFdeFtnw 8PDw== 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:mime-version:content-transfer-encoding; bh=Qxipx9m0vKeP12B9CxfpMSMsmfVBM9RcOjG9qZgvzwg=; b=f6DU90zQWGI26gmlCA6cq7g+bAflaoP9h+LKDqSkmwB1D1usGAS9m1nVmmZPmyYrsa ZPoUlvt7Nbg7/WubN0Okfq3ydvSPKyWPaE2QsesVkjL4WvFzsLSMq5BR1CrX408JE6EG mFC1rBZ6q0175TvVPnQAyH5osfT8QxunAvLap8svvq8k5Bej1nRDqZs/w7dEBIf6qhCZ X4UA1Gz5AG/biinIreoA/G0fAc5G4OaVFBl7x1nA9hzv5KdAwFxHkaNVipLO86lXwVIY /3zXy9CC65OFsKdu/mgqDhUD/njyAHGf0nTyP2m3qzBWp8YmYYxI08CfU9gdZbedNoTQ EFpw== X-Gm-Message-State: AOAM533ZXPnCQw93A9+7H6H0LghYfFLx4Me8E+T6FYEMM1X0jX+mS04X +PmAq1XKbk/M4l2SZf/GhPgYPVXa2zI= X-Received: by 2002:a17:90a:222d:: with SMTP id c42mr616406pje.126.1594061573146; Mon, 06 Jul 2020 11:52:53 -0700 (PDT) Received: from localhost.localdomain (097-090-106-114.biz.spectrum.com. [97.90.106.114]) by smtp.gmail.com with ESMTPSA id q6sm19988179pfg.76.2020.07.06.11.52.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2020 11:52:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 1/2] tcg/ppc: Sanitize immediate shifts Date: Mon, 6 Jul 2020 11:52:47 -0700 Message-Id: <20200706185248.118447-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706185248.118447-1-richard.henderson@linaro.org> References: <20200706185248.118447-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, "Catherine A. Frederick" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Catherine A. Frederick" Sanitize shift constants so that shift operations with large constants don't generate invalid instructions. Signed-off-by: Catherine A. Frederick Message-Id: <20200607211100.22858-1-agrecascino123@gmail.com> Signed-off-by: Richard Henderson --- tcg/ppc/tcg-target.inc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) -- 2.25.1 diff --git a/tcg/ppc/tcg-target.inc.c b/tcg/ppc/tcg-target.inc.c index 7da67086c6..c8d1e765d9 100644 --- a/tcg/ppc/tcg-target.inc.c +++ b/tcg/ppc/tcg-target.inc.c @@ -2610,21 +2610,24 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, case INDEX_op_shl_i32: if (const_args[2]) { - tcg_out_shli32(s, args[0], args[1], args[2]); + /* Limit immediate shift count lest we create an illegal insn. */ + tcg_out_shli32(s, args[0], args[1], args[2] & 31); } else { tcg_out32(s, SLW | SAB(args[1], args[0], args[2])); } break; case INDEX_op_shr_i32: if (const_args[2]) { - tcg_out_shri32(s, args[0], args[1], args[2]); + /* Limit immediate shift count lest we create an illegal insn. */ + tcg_out_shri32(s, args[0], args[1], args[2] & 31); } else { tcg_out32(s, SRW | SAB(args[1], args[0], args[2])); } break; case INDEX_op_sar_i32: if (const_args[2]) { - tcg_out32(s, SRAWI | RS(args[1]) | RA(args[0]) | SH(args[2])); + /* Limit immediate shift count lest we create an illegal insn. */ + tcg_out32(s, SRAWI | RS(args[1]) | RA(args[0]) | SH(args[2] & 31)); } else { tcg_out32(s, SRAW | SAB(args[1], args[0], args[2])); } @@ -2696,14 +2699,16 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, case INDEX_op_shl_i64: if (const_args[2]) { - tcg_out_shli64(s, args[0], args[1], args[2]); + /* Limit immediate shift count lest we create an illegal insn. */ + tcg_out_shli64(s, args[0], args[1], args[2] & 63); } else { tcg_out32(s, SLD | SAB(args[1], args[0], args[2])); } break; case INDEX_op_shr_i64: if (const_args[2]) { - tcg_out_shri64(s, args[0], args[1], args[2]); + /* Limit immediate shift count lest we create an illegal insn. */ + tcg_out_shri64(s, args[0], args[1], args[2] & 63); } else { tcg_out32(s, SRD | SAB(args[1], args[0], args[2])); } From patchwork Mon Jul 6 18:52:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 234884 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp230371ilg; Mon, 6 Jul 2020 11:54:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzespuF/yOlRrHCwRlwOoSNv6kR9TQL6ksNrXFiqYBtQYWor0/xLBBqs4PyYELnv+uq/nHK X-Received: by 2002:a25:aaa9:: with SMTP id t38mr79337648ybi.312.1594061683766; Mon, 06 Jul 2020 11:54:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594061683; cv=none; d=google.com; s=arc-20160816; b=j7o9nlK16Zjmg9+by+vtToUQ0HHYrmIICpna7M43CnKq9hkn6bPbq1iGpjAcp/Ie8+ TUkz5aIXLbmXgIFckLYICxKIfa1f5UiAqPPu1pF0b/qPTRTp1/6yofJCxzxFn7+WjR7h nYfEx3NBzNDcj2+Gi8BUf/4NLZeSz1b8Oy29sgAapKrE0KOa+aQBXvmxE6uCmC76gLDX UGY1liMeIF4VDsNoCuiD8AXshSdN9VZKZfx+9+EPgZcJXIfNWMmCbSfj6iIBYe2MKHCq Ezpit2jn+/H76ym3737KMzgLOaBzr7sQnBxbZbxNjquCNGFGw8HbrZHzJrCrma6HOlzC Px0Q== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=hUkw5IV25PzdOpbKU56LvtYexDUOIKyrljMdyGHGiXE=; b=RyNj/RlS17C4H8v15wCaVOSRQy4f4V31w88GKXsHyClhj5HfWaxgoiGTV3AtUd0K4a vZ7X2dvR4bH1uwqYSUjs13P8wHbQAeIPSFGxuKjfTvJKYO4ynIFdv2e4VXFzE1idt0R7 Jh3jn57wghsQnEd0emEzFXj15MA4hV1Y4tOLFkZnzQJOoNmvmEX8c4lCoyqzoijrjH4N SDWv6Iqb4bDei3KML3iVg6SCFASZn3EI8dxbxA2mXViuEk1jgozMW6IbM73ifDR/leSM 0Z92wOowfqY+waQ6rIX2doG5X/mogeKjLzNcosODwakb5VMVVYsUT7d8elBanoucVUgW 10xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qfyWv7Rl; 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 z18si8505598ybk.41.2020.07.06.11.54.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Jul 2020 11:54:43 -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=qfyWv7Rl; 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]:50126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jsWGJ-0003pT-93 for patch@linaro.org; Mon, 06 Jul 2020 14:54:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jsWEc-00010W-0w for qemu-devel@nongnu.org; Mon, 06 Jul 2020 14:52:58 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:52065) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jsWEa-0000fg-FS for qemu-devel@nongnu.org; Mon, 06 Jul 2020 14:52:57 -0400 Received: by mail-pj1-x1032.google.com with SMTP id l6so14089819pjq.1 for ; Mon, 06 Jul 2020 11:52:56 -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 :mime-version:content-transfer-encoding; bh=hUkw5IV25PzdOpbKU56LvtYexDUOIKyrljMdyGHGiXE=; b=qfyWv7RleJAdZTrZmwUL4ineINZT9SG9RU3WZbqZOU4XufGdslg9daes6nC1hcwZTb s1mLxJRj6glIT103LtuoYoIXcCvT5GzUpiUREre6/zhGBsyMkLMAXMxW9guOYeM3jBEp 8Dvel4Gu4mpsAHupPoZD+CJkw/u3wknsASa/tnMxpk+y8NxwSsWSQnMB7SYXOGRpgULD qKzANq+7dBcEOwokg17gwIeU9v7yut0TejndXsc4wFJpxaojyt5TtGvCEzbWl5QaNB31 AhGmHfLhWQqrmChxJRr2oMJmVfFwSTUyzDIVe+srpeopzSb80hfBRJz8iuyRNR/hWIdF 06Ug== 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:mime-version:content-transfer-encoding; bh=hUkw5IV25PzdOpbKU56LvtYexDUOIKyrljMdyGHGiXE=; b=kUhg3UsYmkijd3+W2E8RbcNitEXbbR2jBklg8L3FcgnozvbYHTg5O42BuNjbLVM3v1 /IS5YxLpU0rtt/AhHFLi3t5g8pYOnC/gBU1Xq++Q/pZqEr6p4IBa2AkIl5C+FavR0mft sWc+PXbAvsrQrQy82kHV3umhLPwXd/D/l5DZfNqzqkQxmi4LntYKL5BXCmFaJZgxHgvo xK90B1pme+3j1BKOsClUFyPIbPONDJtZL+w2yofD0jXnuUfyp8q7HXcjdKwwXss5oilR u7QvpNEbLGSRWll3BQvMmy4/KgnFZxQdzVT01Fp6OuQ+OY40gTFeXXo7YAMNVX8WpueY w5EA== X-Gm-Message-State: AOAM532uFuAVQ3zNW9fPxkYfLwooEQnItXFVRm0w43zpPtO0TWxtM87k 5P/e515MXNDPr9OjV2OiGBogoCeN+n0= X-Received: by 2002:a17:90a:a887:: with SMTP id h7mr615794pjq.0.1594061574641; Mon, 06 Jul 2020 11:52:54 -0700 (PDT) Received: from localhost.localdomain (097-090-106-114.biz.spectrum.com. [97.90.106.114]) by smtp.gmail.com with ESMTPSA id q6sm19988179pfg.76.2020.07.06.11.52.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jul 2020 11:52:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 2/2] tcg: Fix do_nonatomic_op_* vs signed operations Date: Mon, 6 Jul 2020 11:52:48 -0700 Message-Id: <20200706185248.118447-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200706185248.118447-1-richard.henderson@linaro.org> References: <20200706185248.118447-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, LIU Zhiwei Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The smin/smax/umin/umax operations require the operands to be properly sign extended. Do not drop the MO_SIGN bit from the load, and additionally extend the val input. Reviewed-by: LIU Zhiwei Reported-by: LIU Zhiwei Signed-off-by: Richard Henderson Message-Id: <20200701165646.1901320-1-richard.henderson@linaro.org> --- tcg/tcg-op.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) -- 2.25.1 diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c index e60b74fb82..4b8a473fad 100644 --- a/tcg/tcg-op.c +++ b/tcg/tcg-op.c @@ -3189,8 +3189,9 @@ static void do_nonatomic_op_i32(TCGv_i32 ret, TCGv addr, TCGv_i32 val, memop = tcg_canonicalize_memop(memop, 0, 0); - tcg_gen_qemu_ld_i32(t1, addr, idx, memop & ~MO_SIGN); - gen(t2, t1, val); + tcg_gen_qemu_ld_i32(t1, addr, idx, memop); + tcg_gen_ext_i32(t2, val, memop); + gen(t2, t1, t2); tcg_gen_qemu_st_i32(t2, addr, idx, memop); tcg_gen_ext_i32(ret, (new_val ? t2 : t1), memop); @@ -3232,8 +3233,9 @@ static void do_nonatomic_op_i64(TCGv_i64 ret, TCGv addr, TCGv_i64 val, memop = tcg_canonicalize_memop(memop, 1, 0); - tcg_gen_qemu_ld_i64(t1, addr, idx, memop & ~MO_SIGN); - gen(t2, t1, val); + tcg_gen_qemu_ld_i64(t1, addr, idx, memop); + tcg_gen_ext_i64(t2, val, memop); + gen(t2, t1, t2); tcg_gen_qemu_st_i64(t2, addr, idx, memop); tcg_gen_ext_i64(ret, (new_val ? t2 : t1), memop);