From: Skybuck Flying on 25 May 2010 09:54 My advice will be: Create test programs which test full ranges, and have independent code which test for correct input, correct memory and correct output value's... bit by bit if necessary. Such test programs will catch all cases. I already created such a test program to test my WriteBitfield routines... and the test program proved to be highly successfull and usefull ! =D Bye, Skybuck.
From: Chad on 25 May 2010 11:14 On May 25, 6:54 am, "Skybuck Flying" <IntoTheFut...(a)hotmail.com> wrote: > My advice will be: > > Create test programs which test full ranges, and have independent code which > test for correct input, correct memory and correct output value's... bit by > bit if necessary. > > Such test programs will catch all cases. > > I already created such a test program to test my WriteBitfield routines.... > and the test program proved to be highly successfull and usefull ! =D > <off topic> I can't tell if you are holding a conversation with yourself or if the computers at my job are just doing some kind of wierd filtering that isn't allowing me to see who you are talking to. </off topic>
From: James Harris on 25 May 2010 16:59 On 25 May, 16:51, Andy 'Krazy' Glew <ag-n...(a)patten-glew.net> wrote: .... > When shifts are slow, instruction sets are advised to have instructions to generate bitmasks. > > dest := bitmask(frombit,tobit) > > but even these have 2 6 bit constants (on a 64 bit machine). > > dest := bitmask(bitpos6,len) > > not much better, except for small masks. Right. For what the OP is looking for (rightmost N bits set) a simple lookup table would do. James
From: Skybuck Flying on 25 May 2010 18:32 "James Harris" <james.harris.1(a)googlemail.com> wrote in message news:de444692-fb87-4c7e-9831-c10ae147ab7e(a)v18g2000vbc.googlegroups.com... > On 25 May, 16:51, Andy 'Krazy' Glew <ag-n...(a)patten-glew.net> wrote: > ... >> When shifts are slow, instruction sets are advised to have instructions >> to generate bitmasks. >> >> dest := bitmask(frombit,tobit) >> >> but even these have 2 6 bit constants (on a 64 bit machine). >> >> dest := bitmask(bitpos6,len) >> >> not much better, except for small masks. > > Right. For what the OP is looking for (rightmost N bits set) a simple > lookup table would do. Seems like a waste of L1 data cache to me... it will already be massively used me thinks... I could be wrong though... None the less, the lookup table method is idea another way to do it, I have seen it before... LookupTable : array[0..32] of longword; ^ BitCount goes into it as the index and a longword goes out with a maximum of 32 bits ;) So that'll be number 5. I'll have to consult my "source "databas"" to see who's name it was who's I first saw ! ;) :) Bye, Skybuck.
From: James Harris on 26 May 2010 05:06
On 25 May, 23:32, "Skybuck Flying" <IntoTheFut...(a)hotmail.com> wrote: > "James Harris" <james.harri...(a)googlemail.com> wrote in message > > news:de444692-fb87-4c7e-9831-c10ae147ab7e(a)v18g2000vbc.googlegroups.com... > > > On 25 May, 16:51, Andy 'Krazy' Glew <ag-n...(a)patten-glew.net> wrote: > > ... > >> When shifts are slow, instruction sets are advised to have instructions > >> to generate bitmasks. > > >> dest := bitmask(frombit,tobit) > > >> but even these have 2 6 bit constants (on a 64 bit machine). > > >> dest := bitmask(bitpos6,len) > > >> not much better, except for small masks. > > > Right. For what the OP is looking for (rightmost N bits set) a simple > > lookup table would do. > > Seems like a waste of L1 data cache to me... Possibly, though that was in the context of Andy's comment: "When shifts are slow...." Shifts are fast on the CPUs we normally deal with which have the silicon to shift all the bit positions at once but there are/were processors which carry out shifts one bit at a time. For example, see the timings for the 8086 and the 80286 shift left here http://home.comcast.net/~fbui/intel_s.html#sal Also, if a particular loop doesn't already use much data cache a lookup table can still be a good way to go. On some CPUs L1 cache reads can be as fast or nearly as fast as reading registers. On the other hand bit twiddling can be faster, depending on requirements and hardware. YMMV! James |