Re: from number to power of two

1999-08-23 Thread Ollivier Robert
According to Brian F. Feldman: -O lets you do explicit inlining, and -O2 enables -finline-functions. You meant -O3 of course. -O3Optimize yet more. This turns on everything -O2 does, along with also turning on -finline-func- tions. -- Ollivier

Re: from number to power of two

1999-08-22 Thread John-Mark Gurney
Mark Murray scribbled this message on Aug 22: Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc.

Re: from number to power of two

1999-08-22 Thread Daniel C. Sobral
John-Mark Gurney wrote: Shift a bit until it becomes greater than (or less than) the number in question. ummm, didn't you read his post?? he wanted a O(1) routine, NOT a O(n) routine... That technique is O(ln(n)), where n is the number in question. Frankly, for numbers up to 32, a

Re: from number to power of two

1999-08-22 Thread Ollivier Robert
According to Brian F. Feldman: -O lets you do explicit inlining, and -O2 enables -finline-functions. You meant -O3 of course. -O3Optimize yet more. This turns on everything -O2 does, along with also turning on -finline-func- tions. -- Ollivier

Re: from number to power of two

1999-08-22 Thread Mark Murray
Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So %1101 should become either %1 or %1000. Shift a

Re: from number to power of two

1999-08-22 Thread John-Mark Gurney
Mark Murray scribbled this message on Aug 22: Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc.

Re: from number to power of two

1999-08-22 Thread Nick Hibma
It seems that all the solutions are too generic and slow. As I only have to check the numbers 0-32 (actually 1-32), a block of if statements is almost as fast as a table look up in 33 elements. Cheers, Nick On Sun, 22 Aug 1999, Mark Murray wrote: Does anyone know an inexpensive algorithm

Re: from number to power of two

1999-08-22 Thread Daniel C. Sobral
John-Mark Gurney wrote: Shift a bit until it becomes greater than (or less than) the number in question. ummm, didn't you read his post?? he wanted a O(1) routine, NOT a O(n) routine... That technique is O(ln(n)), where n is the number in question. Frankly, for numbers up to 32, a

Re: from number to power of two

1999-08-22 Thread Peter Dufault
It seems that all the solutions are too generic and slow. As I only have to check the numbers 0-32 (actually 1-32), a block of if statements is almost as fast as a table look up in 33 elements. I doubt it - use the table for a small fixed size set then use Warner's (n) ? (1 (ffs(n) - 1)) : 0.

Re: from number to power of two

1999-08-22 Thread Kazufumi-MIT-Mitani
Daniel C. Sobral d...@newsguy.com wrote That technique is O(ln(n)), where n is the number in question. Frankly, for numbers up to 32, a table will wield the best results, and might actually be smaller than some of the suggestions given so far. Counting n as bit, it is O(n) :p Unrolling

Re: from number to power of two

1999-08-22 Thread Nick Hibma
Unfortunately the kernel is compiled with -O which does not include inlining (dunno about explicit inlining, but don't think so). Nick On Sun, 22 Aug 1999, Peter Dufault wrote: It seems that all the solutions are too generic and slow. As I only have to check the numbers 0-32 (actually

Re: from number to power of two

1999-08-22 Thread Tommy Hallgren
--- Kazufumi-MIT-Mitani m...@mit-s.otaru-uc.ac.jp skrev: Daniel C. Sobral d...@newsguy.com wrote That technique is O(ln(n)), where n is the number in question. Frankly, for numbers up to 32, a table will wield the best results, and might actually be smaller than some of the

Re: from number to power of two

1999-08-22 Thread Peter Wemm
Peter Dufault wrote: It seems that all the solutions are too generic and slow. As I only have to check the numbers 0-32 (actually 1-32), a block of if statements is almost as fast as a table look up in 33 elements. I doubt it - use the table for a small fixed size set then use Warner's

Re: from number to power of two

1999-08-22 Thread Brian F. Feldman
On Sun, 22 Aug 1999, Nick Hibma wrote: Unfortunately the kernel is compiled with -O which does not include inlining (dunno about explicit inlining, but don't think so). Nick -O lets you do explicit inlining, and -O2 enables -finline-functions. Anyway, I think the simple solution to the

Re: from number to power of two

1999-08-22 Thread Bakul Shah
The best I can come up with is this: /* kk+1 k * given n, return 2 such that 2 n = 2 */ inline unsigned long n2power2(unsigned long n) { /* `smear' the highest set bit to the right */ n |= n1; n |= n2; n |= n4; n |= n8; n |= n16;

Re: from number to power of two

1999-08-21 Thread Leigh Hart
G'day Nick, Nick Hibma [EMAIL PROTECTED] wrote: Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So

Re: from number to power of two

1999-08-21 Thread Luigi Rizzo
Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So %1101 should become either %1 or %1000. The

Re: from number to power of two

1999-08-21 Thread Patryk Zadarnowski
Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So %1101 should become either %1 or %1000. The

Re: from number to power of two

1999-08-21 Thread Johan Karlsson
At Sat, 21 Aug 1999 12:54:32 +0200, Nick Hibma wrote: Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3- 2 4,5,6,7- 4 8,9,10,11,12,13,14,15 - 8 etc. So

Re: from number to power of two

1999-08-21 Thread Warner Losh
In message [EMAIL PROTECTED] Nick Hibma writes: : Does anyone know an inexpensive algorithm (O(1)) to go from an number to : the next (lower or higher) power of two. 1 ffs(x) Warner To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the message

Re: from number to power of two

1999-08-21 Thread John-Mark Gurney
Nick Hibma scribbled this message on Aug 21: Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So %1101

from number to power of two

1999-08-21 Thread Nick Hibma
Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So %1101 should become either %1 or %1000. The only

Re: from number to power of two

1999-08-21 Thread Leigh Hart
G'day Nick, Nick Hibma n_hi...@skylink.it wrote: Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So

Re: from number to power of two

1999-08-21 Thread Luigi Rizzo
Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So %1101 should become either %1 or %1000. The

Re: from number to power of two

1999-08-21 Thread Patryk Zadarnowski
Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So %1101 should become either %1 or %1000. The

Re: from number to power of two

1999-08-21 Thread Johan Karlsson
At Sat, 21 Aug 1999 12:54:32 +0200, Nick Hibma wrote: Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3- 2 4,5,6,7- 4 8,9,10,11,12,13,14,15 - 8 etc. So

RE: from number to power of two

1999-08-21 Thread Don Read
On 21-Aug-99 Nick Hibma wrote: Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So %1101 should

Re: from number to power of two

1999-08-21 Thread Warner Losh
In message pine.bsf.4.10.9908211250310.7595-100...@heidi.plazza.it Nick Hibma writes: : Does anyone know an inexpensive algorithm (O(1)) to go from an number to : the next (lower or higher) power of two. 1 ffs(x) Warner To Unsubscribe: send mail to majord...@freebsd.org with unsubscribe

Re: from number to power of two

1999-08-21 Thread John-Mark Gurney
Nick Hibma scribbled this message on Aug 21: Does anyone know an inexpensive algorithm (O(1)) to go from an number to the next (lower or higher) power of two. 1 - 1 2,3 - 2 4,5,6,7 - 4 8,9,10,11,12,13,14,15 - 8 etc. So %1101