From patchwork Sat May 8 01:46:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 432518 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp840447jao; Fri, 7 May 2021 18:49:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQZiLzwsTKaBQtYWE4Y2JRYibfhuUrlsUp+a9Jr7NIhOh8Ws3qui06mpKd7hwICKn8la5P X-Received: by 2002:a02:a04d:: with SMTP id f13mr11758397jah.38.1620438566037; Fri, 07 May 2021 18:49:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620438566; cv=none; d=google.com; s=arc-20160816; b=uVGodtQNq7k2xEv/gUQO6/Qeb00/f3TkXoz+YYb8uJQ/ddgC81WTjhiWZ8WkHVFdIW iL6kWeagMF1DRORxmyg88Hg1CjFGqyszM3jfQE/hIVds8B8y59X/5xFPhXU+YpPjrL1r +zoZgifX2yuav3jn4CYcm6bnbzg1gwW3h5w3HeKFtWL5C9TpKGEmgP5BpPtGEIr3uRF0 qiflVrw8ou14+ROmL51j48N3vzZxjFDEkmsxHlY0JzCVqMDgbYTEz6xOUTcQ8rLtHLZu rxKo87/lLVN6woSTAS6loKLEQ+nNPu10IKN8P4CnMCN6jfDRnHXZ1qmSJ9+ET1Ff05c5 XoWQ== 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=62inUraaTVgAI6l4Edj8J42LMU7wWh7GjwLbvqFnK/4=; b=IZ25rDliilcu/FrluT5qHg8xHC5obfBh0nIbFK1f9h6nUhlRkVeWwwMZcI261asss0 +C4KCn+30cARmd/H80Fteixfwk+LwLWsirj7Cf0hrIRgOW9WCIaBv8CaDD2PN/TgdcJc Kb4DAepC8+upISH/TRb7KVJqQzIRXy9MAr0SGFsnyDXVVz90Kg3McVhJfWCMfr1HWkeR t1+N62yM5bs1+3H8wktAoo8EQnhABPc5iQ0lp/Hv7XXcrx+gq/mKTnWFXuaPdPLPQQ+u sds1kwm+x911TjJzbb7YSBoEGkTHMThyLDW+Xa8vS5fRBk9623jBSAXdKp8dkxPkruR4 AGZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fFy18+Oa; 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=fail (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 i8si2630223ilu.58.2021.05.07.18.49.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 May 2021 18:49:26 -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=fail header.i=@linaro.org header.s=google header.b=fFy18+Oa; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lfC5t-00047X-E6 for patch@linaro.org; Fri, 07 May 2021 21:49:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lfC4i-00042p-IT for qemu-devel@nongnu.org; Fri, 07 May 2021 21:48:12 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:55160) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lfC4d-0003Ve-Pl for qemu-devel@nongnu.org; Fri, 07 May 2021 21:48:12 -0400 Received: by mail-pj1-x1036.google.com with SMTP id g24so6197601pji.4 for ; Fri, 07 May 2021 18:48:07 -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=62inUraaTVgAI6l4Edj8J42LMU7wWh7GjwLbvqFnK/4=; b=fFy18+OadbygXgGrQQ4cw0p2IgbCeFaCIXub/VlDcu/WP2pP0CL0izgWE2HhFVSrtF KhN/ApbxwfwBC+6Oi7+XOcEJ2wh+qLNCnGxVvsWFWPgFPY4qnO45LDCqfPVvIwQsnKen nFH/Rm0M2RjWE5cNLEFsKeKrzAlZKs4BQVTnNVwrAHK3RErmxSSvSL7UUfNpM/sVQsua 2ssrns8Xv/FSRSY8SMKs5E8m0lGwU8OgkZdl90kCUcivQ6jfaqesI07sSRdkFvgfDngS XI/Qxm2AdltXkPTqHB55JgcwemBpKEPcdnR289z0gZVj4FDvDpP+jPFwVZf6iM3vDReb ZZ1A== 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=62inUraaTVgAI6l4Edj8J42LMU7wWh7GjwLbvqFnK/4=; b=Hg3i8ySDQXIp5fDuthe7nMRqsDpTJETcczZSJWqH3z4eDwcgNjh7SghfmyQzNZJc93 X2fS4R+wWotPmxgKGQX+SmWxjkY4BTjtcwttyMWqZdpYA0hbuCObziJEnGKiiQpcyqL2 OuJu1NAs7Y86Z8lrMGmo58koC4K/zMiZ0iUGzmvffFR+Eru/XRkCYDhAJCKTaTxy1v0d cWd2kBDKDlmp0XoZJEDECM8g68QG3VE6vdLhIPyJybu2+I+XAAj2P+sSafMKio2vM3Td QoLinwv0s3h8v95PS8NgS9LAtwOomP+8WEEKI0EAFrF6eRT3PrN1dFgHBaeFV4W3nFOz uXIw== X-Gm-Message-State: AOAM532Jx3mPf665LOLuH+dLHJ/ERE+anJX0pfHTNJO1uS8Kmzff6e0s QQQZ7d26u3MEF2GGtz5v9yjtXyMuxvJHVQ== X-Received: by 2002:a17:90a:ea92:: with SMTP id h18mr14025808pjz.105.1620438486534; Fri, 07 May 2021 18:48:06 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id t4sm5819681pfq.165.2021.05.07.18.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 May 2021 18:48:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 04/72] accel/tcg: Use add/sub overflow routines in tcg-runtime-gvec.c Date: Fri, 7 May 2021 18:46:54 -0700 Message-Id: <20210508014802.892561-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210508014802.892561-1-richard.henderson@linaro.org> References: <20210508014802.892561-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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 autolearn=ham autolearn_force=no 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: alex.bennee@linaro.org, david@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Obvious uses of the new functions. Signed-off-by: Richard Henderson --- accel/tcg/tcg-runtime-gvec.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) -- 2.25.1 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée Reviewed-by: David Hildenbrand diff --git a/accel/tcg/tcg-runtime-gvec.c b/accel/tcg/tcg-runtime-gvec.c index 521da4a813..ac7d28c251 100644 --- a/accel/tcg/tcg-runtime-gvec.c +++ b/accel/tcg/tcg-runtime-gvec.c @@ -1073,9 +1073,8 @@ void HELPER(gvec_ssadd32)(void *d, void *a, void *b, uint32_t desc) for (i = 0; i < oprsz; i += sizeof(int32_t)) { int32_t ai = *(int32_t *)(a + i); int32_t bi = *(int32_t *)(b + i); - int32_t di = ai + bi; - if (((di ^ ai) &~ (ai ^ bi)) < 0) { - /* Signed overflow. */ + int32_t di; + if (sadd32_overflow(ai, bi, &di)) { di = (di < 0 ? INT32_MAX : INT32_MIN); } *(int32_t *)(d + i) = di; @@ -1091,9 +1090,8 @@ void HELPER(gvec_ssadd64)(void *d, void *a, void *b, uint32_t desc) for (i = 0; i < oprsz; i += sizeof(int64_t)) { int64_t ai = *(int64_t *)(a + i); int64_t bi = *(int64_t *)(b + i); - int64_t di = ai + bi; - if (((di ^ ai) &~ (ai ^ bi)) < 0) { - /* Signed overflow. */ + int64_t di; + if (sadd64_overflow(ai, bi, &di)) { di = (di < 0 ? INT64_MAX : INT64_MIN); } *(int64_t *)(d + i) = di; @@ -1143,9 +1141,8 @@ void HELPER(gvec_sssub32)(void *d, void *a, void *b, uint32_t desc) for (i = 0; i < oprsz; i += sizeof(int32_t)) { int32_t ai = *(int32_t *)(a + i); int32_t bi = *(int32_t *)(b + i); - int32_t di = ai - bi; - if (((di ^ ai) & (ai ^ bi)) < 0) { - /* Signed overflow. */ + int32_t di; + if (ssub32_overflow(ai, bi, &di)) { di = (di < 0 ? INT32_MAX : INT32_MIN); } *(int32_t *)(d + i) = di; @@ -1161,9 +1158,8 @@ void HELPER(gvec_sssub64)(void *d, void *a, void *b, uint32_t desc) for (i = 0; i < oprsz; i += sizeof(int64_t)) { int64_t ai = *(int64_t *)(a + i); int64_t bi = *(int64_t *)(b + i); - int64_t di = ai - bi; - if (((di ^ ai) & (ai ^ bi)) < 0) { - /* Signed overflow. */ + int64_t di; + if (ssub64_overflow(ai, bi, &di)) { di = (di < 0 ? INT64_MAX : INT64_MIN); } *(int64_t *)(d + i) = di; @@ -1209,8 +1205,8 @@ void HELPER(gvec_usadd32)(void *d, void *a, void *b, uint32_t desc) for (i = 0; i < oprsz; i += sizeof(uint32_t)) { uint32_t ai = *(uint32_t *)(a + i); uint32_t bi = *(uint32_t *)(b + i); - uint32_t di = ai + bi; - if (di < ai) { + uint32_t di; + if (uadd32_overflow(ai, bi, &di)) { di = UINT32_MAX; } *(uint32_t *)(d + i) = di; @@ -1226,8 +1222,8 @@ void HELPER(gvec_usadd64)(void *d, void *a, void *b, uint32_t desc) for (i = 0; i < oprsz; i += sizeof(uint64_t)) { uint64_t ai = *(uint64_t *)(a + i); uint64_t bi = *(uint64_t *)(b + i); - uint64_t di = ai + bi; - if (di < ai) { + uint64_t di; + if (uadd64_overflow(ai, bi, &di)) { di = UINT64_MAX; } *(uint64_t *)(d + i) = di; @@ -1273,8 +1269,8 @@ void HELPER(gvec_ussub32)(void *d, void *a, void *b, uint32_t desc) for (i = 0; i < oprsz; i += sizeof(uint32_t)) { uint32_t ai = *(uint32_t *)(a + i); uint32_t bi = *(uint32_t *)(b + i); - uint32_t di = ai - bi; - if (ai < bi) { + uint32_t di; + if (usub32_overflow(ai, bi, &di)) { di = 0; } *(uint32_t *)(d + i) = di; @@ -1290,8 +1286,8 @@ void HELPER(gvec_ussub64)(void *d, void *a, void *b, uint32_t desc) for (i = 0; i < oprsz; i += sizeof(uint64_t)) { uint64_t ai = *(uint64_t *)(a + i); uint64_t bi = *(uint64_t *)(b + i); - uint64_t di = ai - bi; - if (ai < bi) { + uint64_t di; + if (usub64_overflow(ai, bi, &di)) { di = 0; } *(uint64_t *)(d + i) = di;