From patchwork Sat Nov 16 11:06:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 1196085 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="EmBxhjx8"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47FXVp6gGzz9s4Y for ; Sat, 16 Nov 2019 22:07:29 +1100 (AEDT) Received: from localhost ([::1]:47352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVvvK-0002nL-B5 for incoming@patchwork.ozlabs.org; Sat, 16 Nov 2019 06:07:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57168) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVvv1-0002n9-DS for qemu-devel@nongnu.org; Sat, 16 Nov 2019 06:07:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iVvv0-0006DD-38 for qemu-devel@nongnu.org; Sat, 16 Nov 2019 06:07:07 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:36759) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iVvuz-0006C8-Ry for qemu-devel@nongnu.org; Sat, 16 Nov 2019 06:07:06 -0500 Received: by mail-wr1-x444.google.com with SMTP id r10so13722561wrx.3 for ; Sat, 16 Nov 2019 03:07:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=r5/4/U12EWC18Vtj87MOva04DZB5a9pp9lqOfXjV2j8=; b=EmBxhjx8LpxI2pIQeBDMXrlcIVjEaOYEaIQHbrRyWJO2fQ6GcrJoatP0GUXYfqMnCL bw2lecejSGTnOs909IZSY7SOZ96mpNXDYNcBtu0mG86uX+CutRAl9bR3JQgsvgOisfML 0OwhrCY5UBf2pbcvQLf9Anfcb11w7My46q5kcnvHK9Ac1+9VV2NPwc/x12gfBLdnfEak LK5BIiBSbHhPAKRytlBspsuXADtgpOJTa1DgPj75fmOr1R3EJcCAFYaHEdYLqD8dUmds ezKtN1R1pwSCCzkT/xHe9fl7yt9O8mSUGsBbgZsRQIN7Q70e0cgoDhEX60wrk3ARlfqr nSLQ== 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; bh=r5/4/U12EWC18Vtj87MOva04DZB5a9pp9lqOfXjV2j8=; b=KDAIM3gUa3oBVHhCWYlSPH0weIqPDWkf4CYmwQDkYrMkV/R9qX8tj6YZNeSKj8scpf J/FPSCyZWC5c8CegJWYGyWzzkiG5ZxPdk9WDy6QGTsnQ52FoGoxx2/zYwZ460AuBpB47 ZQCTtbNQLCep24uupZ9uCiZEw+uUEmJ5aMpyBEsFdhR4aG75bc/SBFmGN9HPq3Gw0zUV Ijm2eXDQruI9mZGKAZrlsydj5WoXmvT00p8plKynJpjOhr9Vig9i2qP2jjSUDlEf1gzH XmgxFbEkgeQkmUmtgCKZShvl/WIHYcokzhxGB0jovfkajsMrenMYQfxUcPwC/r5KfWnV /EaQ== X-Gm-Message-State: APjAAAWSVcCHuH2biMukkm2x4XS5ud9NvwwlQGqhiq54STEBEoXlp2kU GBDny/AfeZBxsps3VZ8ep0wNMEK/y2lgPA== X-Google-Smtp-Source: APXvYqzrc3OEtVngO63Z5t7+XPJL9NlTILLdIC5uOWYvtj4Yfn2eK8Nivg6zesBMgNCOQPAWUyKAwA== X-Received: by 2002:adf:cf10:: with SMTP id o16mr21341181wrj.334.1573902423642; Sat, 16 Nov 2019 03:07:03 -0800 (PST) Received: from localhost.localdomain (87.red-176-87-99.dynamicip.rima-tde.net. [176.87.99.87]) by smtp.gmail.com with ESMTPSA id k14sm15766980wrw.46.2019.11.16.03.07.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Nov 2019 03:07:02 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2] target/arm: Merge arm_cpu_vq_map_next_smaller into sole caller Date: Sat, 16 Nov 2019 12:06:42 +0100 Message-Id: <20191116110642.12454-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 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, drjones@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Coverity reports, in sve_zcr_get_valid_len, "Subtract operation overflows on operands arm_cpu_vq_map_next_smaller(cpu, start_vq + 1U) and 1U" First, the aarch32 stub version of arm_cpu_vq_map_next_smaller, returning 0, does exactly what Coverity reports. Remove it. Second, the aarch64 version of arm_cpu_vq_map_next_smaller has a set of asserts, but they don't cover the case in question. Further, there is a fair amount of extra arithmetic needed to convert from the 0-based zcr register, to the 1-base vq form, to the 0-based bitmap, and back again. This can be simplified by leaving the value in the 0-based form. Finally, use test_bit to simplify the common case, where the length in the zcr registers is in fact a supported length. Reported-by: Coverity (CID 1407217) Signed-off-by: Richard Henderson Reviewed-by: Andrew Jones --- v2: Merge arm_cpu_vq_map_next_smaller into sve_zcr_get_valid_len, as suggested by Andrew Jones. Use test_bit to make the code even more obvious; the current_length + 1 thing to let us find current_length in the bitmap seemed unnecessarily clever. --- target/arm/cpu.h | 3 --- target/arm/cpu64.c | 15 --------------- target/arm/helper.c | 8 ++++++-- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index e1a66a2d1c..47d24a5375 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -185,12 +185,9 @@ typedef struct { #ifdef TARGET_AARCH64 # define ARM_MAX_VQ 16 void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp); -uint32_t arm_cpu_vq_map_next_smaller(ARMCPU *cpu, uint32_t vq); #else # define ARM_MAX_VQ 1 static inline void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp) { } -static inline uint32_t arm_cpu_vq_map_next_smaller(ARMCPU *cpu, uint32_t vq) -{ return 0; } #endif typedef struct ARMVectorReg { diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 68baf0482f..a39d6fcea3 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -458,21 +458,6 @@ void arm_cpu_sve_finalize(ARMCPU *cpu, Error **errp) cpu->sve_max_vq = max_vq; } -uint32_t arm_cpu_vq_map_next_smaller(ARMCPU *cpu, uint32_t vq) -{ - uint32_t bitnum; - - /* - * We allow vq == ARM_MAX_VQ + 1 to be input because the caller may want - * to find the maximum vq enabled, which may be ARM_MAX_VQ, but this - * function always returns the next smaller than the input. - */ - assert(vq && vq <= ARM_MAX_VQ + 1); - - bitnum = find_last_bit(cpu->sve_vq_map, vq - 1); - return bitnum == vq - 1 ? 0 : bitnum + 1; -} - static void cpu_max_get_sve_max_vq(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { diff --git a/target/arm/helper.c b/target/arm/helper.c index be67e2c66d..b5ee35a174 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -5363,9 +5363,13 @@ int sve_exception_el(CPUARMState *env, int el) static uint32_t sve_zcr_get_valid_len(ARMCPU *cpu, uint32_t start_len) { - uint32_t start_vq = (start_len & 0xf) + 1; + uint32_t end_len; - return arm_cpu_vq_map_next_smaller(cpu, start_vq + 1) - 1; + start_len &= 0xf; + end_len = find_last_bit(cpu->sve_vq_map, start_len + 1); + + assert(end_len <= start_len); + return end_len; } /*