From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95383C433F5 for ; Sat, 11 Sep 2021 17:20:44 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BF44060FDA for ; Sat, 11 Sep 2021 17:20:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BF44060FDA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 562D58382C; Sat, 11 Sep 2021 19:20:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QWHZ6Z5s"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4E8AD83831; Sat, 11 Sep 2021 19:20:28 +0200 (CEST) Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D3DD083830 for ; Sat, 11 Sep 2021 19:20:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf2d.google.com with SMTP id w8so3436084qvt.0 for ; Sat, 11 Sep 2021 10:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=g9gFNk0XwB9UcMRXGcFxmIjs9p/aA9OW2a9fHvdZJ9A=; b=QWHZ6Z5ssYMcKy4c+19Qk5TuMwh+dLepp8fks8QYI/EW7Kpxn/Wkw5thdyWYbWCtFG s66bBz1ACO+hQNhiH1Hsxg3KHAQSANseLwrB1kydYToJuYC/3WBEB7KReQGqk7FAKCbe i0pEZ9ZeOF/auHQSmz4SSTsZnfWgqiwv6xj6VWzHCIwAapV+qAWDirL7rik/e1+BfTyh LX7BiNAfFSvyA45wMWqMNjx1O9jfDKhbhVYqXyze3aFxwRKDu9UNoGMUI1vyRT19Bei5 a1c/ADzuih1sZJmYhor9QcMr3KXCFLYeClDyLqED6F2dkNORDpqgbfyebaBIBt+PN4/E WV7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=g9gFNk0XwB9UcMRXGcFxmIjs9p/aA9OW2a9fHvdZJ9A=; b=nO8sIg4W9Kk21cwgKYkTgol5g1MN/Kz1UfGMLCbYsRQiC6r3mmvgS+i1t9AQI1rzjp DKt4jATWRQZA7YAYjr/Df1vQOwLdWof1T6QZgB//fRyPqgY+PZxbdrGN36yp2YXyb/Rf Y0UKFPqoreMzG7C88qgLbFFasx/Pmn1evdjXI7var24v4mYTDhi4J8oEzGfvFKOMxc6L JhHftRcV7Z/02E9pnnHAG+OKa5MosMZkgQiu00CNHU5XOwy73SyKkADJG0AMwnR/Cavo qKFAVTZwxL/wvhcxl7yQ3CH+qlAsG78yn6u2ICIdwlvprVAxazC7TURdiv+TAW96APFz b0Lw== X-Gm-Message-State: AOAM531QMZUB+L+XP2V1wj9gBzBXlWtATmfgKtI072lp785puahGdtVm 2t5Fif4GESKo6+6GOhvKriRyXY4Bt20= X-Google-Smtp-Source: ABdhPJw860w4xyFPLR6s1Wj94g7h7b9ZzCnqY2dSzLTcJn3pp57DITGyt6eHtqGtJ5D8M3Zu5Yb+Ag== X-Received: by 2002:a0c:f38b:: with SMTP id i11mr3004057qvk.42.1631380814281; Sat, 11 Sep 2021 10:20:14 -0700 (PDT) Received: from godwin.fios-router.home (pool-108-45-127-224.washdc.fios.verizon.net. [108.45.127.224]) by smtp.gmail.com with ESMTPSA id d12sm1295669qtq.61.2021.09.11.10.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Sep 2021 10:20:13 -0700 (PDT) From: Sean Anderson To: u-boot@lists.denx.de, Leo Liang Cc: Bin Meng , Damien Le Moal , Lukasz Majewski , Sean Anderson Subject: [PATCH v2 2/4] k210: clk: Refactor out_of_spec tests Date: Sat, 11 Sep 2021 13:20:01 -0400 Message-Id: <20210911172003.899301-2-seanga2@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210911172003.899301-1-seanga2@gmail.com> References: <20210911172003.899301-1-seanga2@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Everything here sits in a while (true) loop. However, this introduces a couple of layers of indentation. We can simplify the code by introducing a single goto instead of using continue/break. This will also make adding loops in the next patch easier. Signed-off-by: Sean Anderson --- (no changes since v1) drivers/clk/clk_kendryte.c | 105 ++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/drivers/clk/clk_kendryte.c b/drivers/clk/clk_kendryte.c index 2caa21aec9..69691c4a04 100644 --- a/drivers/clk/clk_kendryte.c +++ b/drivers/clk/clk_kendryte.c @@ -709,6 +709,10 @@ TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in, * Whether we swapped r and od while enforcing frequency limits */ bool swapped = false; + /* + * Whether the intermediate frequencies are out-of-spec + */ + bool out_of_spec; u64 last_od = od; u64 last_r = r; @@ -767,76 +771,71 @@ TEST_STATIC int k210_pll_calc_config(u32 rate, u32 rate_in, * aren't in spec, try swapping r and od. If everything is * in-spec, calculate the relative error. */ - while (true) { +again: + out_of_spec = false; + if (r > max_r) { + out_of_spec = true; + } else { /* - * Whether the intermediate frequencies are out-of-spec + * There is no way to only divide once; we need + * to examine the frequency with and without the + * effect of od. */ - bool out_of_spec = false; + u64 vco = DIV_ROUND_CLOSEST_ULL(rate_in * f, r); - if (r > max_r) { + if (vco > 1750000000 || vco < 340000000) out_of_spec = true; - } else { - /* - * There is no way to only divide once; we need - * to examine the frequency with and without the - * effect of od. - */ - u64 vco = DIV_ROUND_CLOSEST_ULL(rate_in * f, r); + } - if (vco > 1750000000 || vco < 340000000) - out_of_spec = true; + if (out_of_spec) { + u64 new_r, new_od; + + if (!swapped) { + u64 tmp = r; + + r = od; + od = tmp; + swapped = true; + goto again; } - if (out_of_spec) { - if (!swapped) { - u64 tmp = r; - - r = od; - od = tmp; - swapped = true; - continue; - } else { - /* - * Try looking ahead to see if there are - * additional factors for the same - * product. - */ - if (i + 1 < ARRAY_SIZE(factors)) { - u64 new_r, new_od; - - i++; - new_r = UNPACK_R(factors[i]); - new_od = UNPACK_OD(factors[i]); - if (r * od == new_r * new_od) { - r = new_r; - od = new_od; - swapped = false; - continue; - } - i--; - } - break; + /* + * Try looking ahead to see if there are additional + * factors for the same product. + */ + if (i + 1 < ARRAY_SIZE(factors)) { + i++; + new_r = UNPACK_R(factors[i]); + new_od = UNPACK_OD(factors[i]); + if (r * od == new_r * new_od) { + r = new_r; + od = new_od; + swapped = false; + goto again; } + i--; } - error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); - /* The lower 16 bits are spurious */ - error = abs((error - BIT(32))) >> 16; + /* We ran out of things to try */ + continue; + } - if (error < best_error) { - best->r = r; - best->f = f; - best->od = od; - best_error = error; - } - break; + error = DIV_ROUND_CLOSEST_ULL(f * inv_ratio, r * od); + /* The lower 16 bits are spurious */ + error = abs((error - BIT(32))) >> 16; + + if (error < best_error) { + best->r = r; + best->f = f; + best->od = od; + best_error = error; } } while (f < 64 && i + 1 < ARRAY_SIZE(factors) && error != 0); + log_debug("best error %lld\n", best_error); if (best_error == S64_MAX) return -EINVAL; - log_debug("best error %lld\n", best_error); return 0; } -- 2.33.0