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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id D2129C71153 for ; Mon, 4 Sep 2023 13:32:06 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qd9gI-0001g1-Db; Mon, 04 Sep 2023 09:31:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qd9fk-0001ZD-9N; Mon, 04 Sep 2023 09:31:25 -0400 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qd9fd-0001fx-17; Mon, 04 Sep 2023 09:31:19 -0400 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4RfTzs6MHQz4wxW; Mon, 4 Sep 2023 23:31:05 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4RfTzn6064z4wb0; Mon, 4 Sep 2023 23:31:01 +1000 (AEST) Message-ID: Date: Mon, 4 Sep 2023 15:30:57 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v2 05/19] host-utils: Add muldiv64_round_up Content-Language: en-US To: Nicholas Piggin , Richard Henderson , Daniel Henrique Barboza Cc: David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Peter Maydell , =?UTF-8?Q?Daniel_P=2e_Berrang=c3=a9?= References: <20230808042001.411094-1-npiggin@gmail.com> <20230808042001.411094-6-npiggin@gmail.com> <52695ffb-9294-f6ad-85e2-da4c3841682b@linaro.org> From: =?UTF-8?Q?C=c3=a9dric_Le_Goater?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=kZzc=EU=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-1.473, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 9/4/23 15:07, Nicholas Piggin wrote: > On Sat Sep 2, 2023 at 3:02 AM AEST, Richard Henderson wrote: >> On 9/1/23 04:51, Cédric Le Goater wrote: >>> Adding more reviewers since this patch is modifying a common service. >>> >>> Thanks, >>> >>> C. >>> >>> >>> On 8/8/23 06:19, Nicholas Piggin wrote: >>>> This will be used for converting time intervals in different base units >>>> to host units, for the purpose of scheduling timers to emulate target >>>> timers. Timers typically must not fire before their requested expiry >>>> time but may fire some time afterward, so rounding up is the right way >>>> to implement these. >>>> >>>> Signed-off-by: Nicholas Piggin >>>> --- >>>>   include/qemu/host-utils.h | 21 ++++++++++++++++++++- >>>>   1 file changed, 20 insertions(+), 1 deletion(-) >>>> >>>> diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h >>>> index 011618373e..e2a50a567f 100644 >>>> --- a/include/qemu/host-utils.h >>>> +++ b/include/qemu/host-utils.h >>>> @@ -56,6 +56,11 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) >>>>       return (__int128_t)a * b / c; >>>>   } >>>> +static inline uint64_t muldiv64_round_up(uint64_t a, uint32_t b, uint32_t c) >>>> +{ >>>> +    return ((__int128_t)a * b + c - 1) / c; >>>> +} >>>> + >>>>   static inline uint64_t divu128(uint64_t *plow, uint64_t *phigh, >>>>                                  uint64_t divisor) >>>>   { >>>> @@ -83,7 +88,8 @@ void mulu64(uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b); >>>>   uint64_t divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor); >>>>   int64_t divs128(uint64_t *plow, int64_t *phigh, int64_t divisor); >>>> -static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) >>>> +static inline uint64_t __muldiv64(uint64_t a, uint32_t b, uint32_t c, >>>> +                                  bool round_up) >> >> Perhaps better avoiding the reserved name: muldiv64_internal? > > Thanks, that would be okay. Or could be muldiv64_rounding? > >> >> Otherwise, >> Reviewed-by: Richard Henderson oh, and I already sent the PR with the Rb of Richard ... :/ Sorry about that. Can we fix it later ? Or I will respin with the update. Someone really ought to take over PPC. Daniel and I are real busy on other subsystems. Volunteers ? Thanks, C. >> >> >> r~ >> >> >>>>   { >>>>       union { >>>>           uint64_t ll; >>>> @@ -99,12 +105,25 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) >>>>       u.ll = a; >>>>       rl = (uint64_t)u.l.low * (uint64_t)b; >>>> +    if (round_up) { >>>> +        rl += c - 1; >>>> +    } >>>>       rh = (uint64_t)u.l.high * (uint64_t)b; >>>>       rh += (rl >> 32); >>>>       res.l.high = rh / c; >>>>       res.l.low = (((rh % c) << 32) + (rl & 0xffffffff)) / c; >>>>       return res.ll; >>>>   } >>>> + >>>> +static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) >>>> +{ >>>> +    return __muldiv64(a, b, c, false); >>>> +} >>>> + >>>> +static inline uint64_t muldiv64_round_up(uint64_t a, uint32_t b, uint32_t c) >>>> +{ >>>> +    return __muldiv64(a, b, c, true); >>>> +} >>>>   #endif >>>>   /** >>> >>> >