All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Andrew Cooper <amc96@srcf.net>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Wei Liu" <wl@xen.org>, "Roger Pau Monné" <roger.pau@citrix.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH] x86: replace a few do_div() uses
Date: Wed, 12 Jan 2022 10:28:59 +0100	[thread overview]
Message-ID: <f4dd528a-d1e0-f516-bb7d-f1ec01abc3d5@suse.com> (raw)
In-Reply-To: <a5af3a6a-da51-2624-622e-2566c8db7dce@srcf.net>

On 12.01.2022 10:22, Andrew Cooper wrote:
> On 12/01/2022 09:00, Jan Beulich wrote:
>> When the macro's "return value" is not used, the macro use can be
>> replaced by a simply division, avoiding some obfuscation.
>>
>> According to my observations, no change to generated code.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> I like this change in principle, but see below.
> 
> do_div() needs to be deleted, because it's far too easy screw up.  At a
> bare minimum, it should be replaced with a static inline that takes it's
> first parameter by pointer, because then at least every callsite reads
> correctly in terms of the C language.

That ought to be a 2nd step, requiring agreement with Arm folks (and
adjustments to their code).

>> --- a/xen/arch/x86/time.c
>> +++ b/xen/arch/x86/time.c
>> @@ -610,8 +610,7 @@ static uint64_t xen_timer_cpu_frequency(
>>      struct vcpu_time_info *info = &this_cpu(vcpu_info)->time;
>>      uint64_t freq;
>>  
>> -    freq = 1000000000ULL << 32;
>> -    do_div(freq, info->tsc_to_system_mul);
>> +    freq = (1000000000ULL << 32) / info->tsc_to_system_mul;
>>      if ( info->tsc_shift < 0 )
>>          freq <<= -info->tsc_shift;
> 
> do_div()'s output is consumed here.  I don't think this hunk is safe to
> convert.

If by "output" you mean its "return value", then it clearly isn't
consumed. And I continue to think that I did express correctly the
effect do_div() did have on "freq".

Jan



  reply	other threads:[~2022-01-12  9:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-12  9:00 [PATCH] x86: replace a few do_div() uses Jan Beulich
2022-01-12  9:22 ` Andrew Cooper
2022-01-12  9:28   ` Jan Beulich [this message]
2022-02-18  8:39     ` Ping: " Jan Beulich
2022-02-18 13:22       ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f4dd528a-d1e0-f516-bb7d-f1ec01abc3d5@suse.com \
    --to=jbeulich@suse.com \
    --cc=amc96@srcf.net \
    --cc=andrew.cooper3@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.