From: James Harris on
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
From: io_x on

"Chad" <cdalten(a)gmail.com> ha scritto nel messaggio
news:8853a458-f688-461d-9863-424fb40bc30b(a)g39g2000pri.googlegroups.com...
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>

any answer here should be for the all NG,
so for who write and all the remain people that read.

so even if i answer to myself i speak to all, me too :)



From: MitchAlsup on
On May 25, 10:51 am, Andy 'Krazy' Glew <ag-n...(a)patten-glew.net>
wrote:
> > 4. (MitchAlsup) Mask := not word((not 0) shl BitCount); // not((not 0 =
> > 1111111) shl 3 = 1111000) = 0000111
>
> Trades off constant size for instruction count.

Not in C

Mitch
From: pete on
Skybuck Flying wrote:
>
> Ok people,
>
> I keep coming across different ways in source codes for creating a bit mask
> for a certain ammount of bits and it's kinda funnieing me out ! =D
>
> Therefore to have some fun, it's time to create a thread dedicated to
> creating bitmasks... how many ways are there ?
>
> So far I have come across these methods:
>
> 1. (My own way:) Mask := not word(65535 shl BitCount); // not 1111000 =
> 0000111
>
> 2. Mask := (1 shl BitCount)-1; // 10000-1 = 09999 = 01111 ;) :)
>
> 3. Mask := ($FFFF shl BitCount) xor $FFFF; // 1111000 xor 1111111 = 0000111


size_t odd_mask = size ^ size - 1;
and
size_t bytes = nmemb * size;
implies that if ((bytes & odd_mask) != 0)
then nmemb must be odd.

--
pete
From: Skybuck Flying on
Question is what happens when "shl 32" is done.

According to the intel manual the result would be undefined ?!?

Does that mean the result could be garbage ???

Bye,
Skybuck.