All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Hopwood <david.nospam.hopwood@blueyonder.co.uk>
To: xen-devel@lists.xensource.com
Subject: Re: code question?
Date: Thu, 11 Aug 2005 17:55:53 +0100	[thread overview]
Message-ID: <42FB8319.8090706@blueyonder.co.uk> (raw)
In-Reply-To: <1123775716.3043.15.camel@thinkpad>

Jerone Young wrote:
> Doing some janitorial (you cleaning the flooded toilets and such) work
> today. I have come across this line of code that really I'm not sure
> what the intent was..in xen/include/sched.h
> 
> #define hypercall_preempt_check() (unlikely(            \
>         softirq_pending(smp_processor_id()) |           \
>         (!!current->vcpu_info->evtchn_upcall_pending &  \
>           !current->vcpu_info->evtchn_upcall_mask)      \
>     ))
> 
> the part where we have !!current->vcpu_info_evtchen_upcall pending
> should this be..should the "!! just be "!"?
> 
> And if so shouldn't this just be changed to 
> 
> #define hypercall_preempt_check() (unlikely( \
> 	softirq_pending(smp_processor_id()) |           \
> 	(!(current->vcpu_info->evtchn_upcall_pending & \
> 	  current->vcpu_info->evtchn_upcall_mask)) \
> 	))

Seems more likely to have been intended as:

   #define hypercall_preempt_check() (unlikely(           \
           softirq_pending(smp_processor_id()) ||         \
           (current->vcpu_info->evtchn_upcall_pending &&  \
             !current->vcpu_info->evtchn_upcall_mask)     \
       ))

Keir wrote:
 > Forming compound predicates for bitwise operators can be faster than using the
 > logical operators because they are non 'short circuiting'. This means you end
 > up with fewer branches in the generated code and end up with nice straight-line
 > code that should execute fast.

If that's true on a given platform, the compiler can optimize it. Note that
in this case "(current->vcpu_info->evtchn_upcall_pending &&
!current->vcpu_info->evtchn_upcall_mask)" has no side effects (unless current
or current->vcpu_info are not valid pointers, which is undefined behaviour so
still optimizable).

-- 
David Hopwood <david.nospam.hopwood@blueyonder.co.uk>

  parent reply	other threads:[~2005-08-11 16:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-11 15:55 code question? Jerone Young
2005-08-11 16:18 ` Anthony Liguori
2005-08-11 16:22 ` Keir Fraser
2005-08-11 18:14   ` Tim Newsham
2005-08-11 16:55 ` David Hopwood [this message]
2005-08-11 17:03 ` M.A. Williamson
2005-08-11 17:23   ` Keir Fraser
2005-08-11 18:53     ` David Hopwood

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=42FB8319.8090706@blueyonder.co.uk \
    --to=david.nospam.hopwood@blueyonder.co.uk \
    --cc=xen-devel@lists.xensource.com \
    /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.