From patchwork Sun May 16 12:33:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 439840 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp253104jac; Sun, 16 May 2021 05:35:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwz361/q9jRRot5aqz+bqCDrpnQIW3x6zrRKwyPTFU7mR07QTGYEFdKuosAQa45SUJRSKu X-Received: by 2002:a02:cb4f:: with SMTP id k15mr9397448jap.3.1621168555063; Sun, 16 May 2021 05:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621168555; cv=none; d=google.com; s=arc-20160816; b=DSQfvkMO6Afm65xU2c+jQpI/8LhumJiodsj906XEqana8KRnptSKbhr6B4ytP/9vgK /XSwGT2v3K8JQz+lfqzzbxjI1Zc/36u9bLAMUsX2xfSxOnqVFJ2W2tLU8LzGzotfeF6U XASUBQsjud3s5xJqa7t5LWCX7OYPlqrrzZXlXbImO/RfkD7ULiLHEXFbKd2oNBf9ElqH bTHUz2MxJ5yx78i3e/FjFvMfJKRLhM9cuFHw+prB2HMPTB+4DicW2J5dNFox19QiFWsb iUh/+4xnhk6Av5EVU7jtyOfSYLA+To+zKdTbsaOUjLwl54y8wjgpdltUt13miiibYEv+ 62kg== 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=WCooW+37Z0FxZm2Vga9KGLb5BfCR58QdDfT18gmnbx0=; b=Ri4BTYVd/ua7Szb16saPUZbGgLmVrF2L0un5v7gucF58+i7azGgmPAdJRbgAi8Pzie 6sLvkhussEE2Llf+J2qe4K2d4Xs3PVx2soHVXG+NoLncZ4z/cysRcCRNrKs8aBNfyqKh afEzoRr+ItjDfB1MSnx5N2Xm9dypcNFFGq1dRiV1OK5ldXFthGwiLYNRcQHUouF0WKsM 1Cm4eIo8ZWzHJGhJVOEzFxbRcOWJAPwZI10OT1KVkbX/1+WrQ/DgG8S+fucYBFU2y+s+ DrlXPjfDJzom3QmsqBlrGbu/5t1nYrZrJB7WWWeedStqSUBqCBR+6WleGYVp4re6fhZx S94w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=ZeDISgmZ; 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 h21si14034075jav.99.2021.05.16.05.35.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 16 May 2021 05:35:55 -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=ZeDISgmZ; 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]:52372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1liFzt-0007Ga-Cn for patch@linaro.org; Sun, 16 May 2021 08:35:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1liFyh-0007DP-Ul for qemu-devel@nongnu.org; Sun, 16 May 2021 08:34:39 -0400 Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]:39929) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1liFyf-0007hG-1b for qemu-devel@nongnu.org; Sun, 16 May 2021 08:34:39 -0400 Received: by mail-qt1-x82e.google.com with SMTP id f8so3012693qth.6 for ; Sun, 16 May 2021 05:34:36 -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=WCooW+37Z0FxZm2Vga9KGLb5BfCR58QdDfT18gmnbx0=; b=ZeDISgmZHPvHyI1DWuDMQ6dhjakWxLPKfcGiem1eP6J8lJEiQUhi2zdW6oS49jpaoh rD4ZVb3x9zHlaH97Nd3rGjBIvfmIIvvEvFg1Gh63K1GN1QO70gym4x56EjYpgEt4LghK 94xCSqLz1ulbsvLDUf1JmXfZyEIKVGBjkyqTNl7ix7JpzzqUCp2eLgjIiA7hHpPYhVHX sWS/ax2/4JIlVBYDFOvhjgmMUXDngEqXT63xzX2DJarVAii/moLgmzNmYk3vd7W/SyL0 aEJhHSkCrlLqwe4O4dUzXhlhmA2CnphjywYVk66a6/xO/JRvUK2/kEuzMTGRj8zJi0vk 8a/w== 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=WCooW+37Z0FxZm2Vga9KGLb5BfCR58QdDfT18gmnbx0=; b=Kr79T1VMYJeZwjLpgeXmxHDrv/X2f2Mqa11o49Cn/vRYp48m39X7eRuCNp2RqyXbsu tCZo2MdMWarNB9IHgwaFYEWKuuJ45U1e8mQdLCrnhaVsp55JVF+OxSeAMUhPR+QKFoJa QUyDvN9S6FSVt5yWMGlrEka9piKS4nDAfk0bX/4LB7tO5KHZxBfRp3/jIqqWwztW/d0r PLfXJtK57amc1vYtGdSUuyHg7688dQtwPcKkqVqr36rpckbQoSLTUgU28rwkXsiGbF1i E5YbUuDwZYnce0u6WseEXYXE1FYvsKH24GEjcM/QaB8BbYavQ+GabrrLLMpIBAiDKLVi yJ/Q== X-Gm-Message-State: AOAM532TXdhIekadVVEPFkq+aSiZQXbyfqGh2qmWVY9mL/myfPWFpLZi wF9hMJnWRMUMuK/dvb18JEvznehmTEjMMRotK38= X-Received: by 2002:ac8:4750:: with SMTP id k16mr35381823qtp.13.1621168476251; Sun, 16 May 2021 05:34:36 -0700 (PDT) Received: from localhost.localdomain (163.189-204-200.bestelclientes.com.mx. [189.204.200.163]) by smtp.gmail.com with ESMTPSA id s5sm8500553qkg.88.2021.05.16.05.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 May 2021 05:34:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 04/46] accel/tcg: Use add/sub overflow routines in tcg-runtime-gvec.c Date: Sun, 16 May 2021 07:33:49 -0500 Message-Id: <20210516123431.718318-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210516123431.718318-1-richard.henderson@linaro.org> References: <20210516123431.718318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::82e; envelope-from=richard.henderson@linaro.org; helo=mail-qt1-x82e.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: peter.maydell@linaro.org, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , David Hildenbrand Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Obvious uses of the new functions. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée Reviewed-by: David Hildenbrand Signed-off-by: Richard Henderson --- accel/tcg/tcg-runtime-gvec.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) -- 2.25.1 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;