lkml.org 
[lkml]   [2005]   [Sep]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] NTP shift_right cleanup (v. A3)
- 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.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-09-21 13:52    [W:0.026 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site