From: linux@horizon.com
To: johnstul@us.ibm.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] NTP shift_right cleanup (v. A3)
Date: 21 Sep 2005 07:49:31 -0400 [thread overview]
Message-ID: <20050921114931.14363.qmail@science.horizon.com> (raw)
- For fixed shifts, you can just write it as a divide; GCC will DTRT.
For interest's sake, GCC 4.0 generates, for x /= 64:
testl %eax, %eax
jns .L2
addl $63, %eax
.L2:
sarl $6, %eax
- If you want to be more verbose with the explanation, try something like:
(Public domain, copyright abandoned, use freely, yadda yadda.)
/*
* NTP uses power-of-two divides a lot for speed, but it wants to use
* negative numbers.
* 1) ANSI C does not guarantee signed right shifts (but GCC does)
* 2) Such a shift is like a divide that rounds to -infinity.
* NTP wants rounding to zero, i.e. -3/2 = -2, while -3>>1 = -2.
*/
Interestingly, _Hacker's Delight_ chapter 10 skips over this particular
case, signed division by a variable power of two.
next reply other threads:[~2005-09-21 11:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-21 11:49 linux [this message]
-- strict thread matches above, loose matches on Subject: below --
2005-09-14 17:48 [RFC][PATCH] NTP shift_right cleanup (v. A1) john stultz
2005-09-20 1:28 ` [PATCH] NTP shift_right cleanup (v. A2) john stultz
2005-09-21 3:24 ` [PATCH] NTP shift_right cleanup (v. A3) john stultz
2005-09-21 5:24 ` Nick Piggin
2005-09-21 8:13 ` Ulrich Windl
2005-09-21 12:18 ` Nick Piggin
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=20050921114931.14363.qmail@science.horizon.com \
--to=linux@horizon.com \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®