From: Skybuck Flying on
Ok,

I tried a couple of things... and it turns out Delphi actually has a
"simulated shift left 64 bitcount support" wow ! ;) :)

But first I tried to implement it myself in Delphi-code :

This seemed to fail miserably, possibly because of shitty Delphi ?!? ;)

// 64 bitcount shift left support:
// doesn't work it seems.
mNewContent :=
(
mContent shl
(
mBitCount and (1+2+4+8+16)
)
) shl
(
(
mBitCount shr (1+1+1+1+1)
) and (1+2+4+8+16)
);

The funny thing is that this is probably not needed at all, by just using an
int64 it could be done as follows:

int64's:

mNewContent := mContent shl BitCount;

The following routine would probably be called by Delphi:

@_llshl:
00404D38 80F920 cmp cl,$20
00404D3B 7C11 jl $00404d4e
00404D3D 80F940 cmp cl,$40
00404D40 7C05 jl $00404d47
00404D42 31D2 xor edx,edx
00404D44 31C0 xor eax,eax
00404D46 C3 ret
00404D47 89C2 mov edx,eax
00404D49 D3E2 shl edx,cl
00404D4B 31C0 xor eax,eax
00404D4D C3 ret
00404D4E 0FA5C2 shld edx,eax,cl
00404D51 D3E0 shl eax,cl
00404D53 C3 ret

So this would mean 6 instructions for just the call setup and storing the
results in memory:

TestProgram.dpr.33: mNewContent := mContent shl mBitCount;
00408DF6 8B45F8 mov eax,[ebp-$08]
00408DF9 8B55FC mov edx,[ebp-$04]
00408DFC 8BCB mov ecx,ebx
00408DFE E835BFFFFF call @_llshl
00408E03 8945F0 mov [ebp-$10],eax
00408E06 8955F4 mov [ebp-$0c],edx

Plus the one or two branches above plus 3 to 4 instructions...

So that's a total of 12 instructions or so... for worst case...

It used to be 4 to 5... so now it's double that... but all in all not to
bad.

However the funny thing is that the problem is still not fully solved.

I would bet that shl 64 could still give problems ?

I am not sure though ;)

Bye,
Skybuck.


From: Skybuck Flying on
Ok,

I just checked it...

Content shl 64 will be executed by this branch !:

> 00404D42 31D2 xor edx,edx
> 00404D44 31C0 xor eax,eax
> 00404D46 C3 ret

^ The developers of Delphi just got some major love points from me ! =D

I think this will solve all of my problems for now ! ;) :)

Bye,
Skybuck =D


From: Skybuck Flying on
Wow good thing I tested it...

Shifting "contents" has to be done slightly different than shifting "masks".

Content needs to be shifted as follows:

Content shl (mBitCount-1)

Proof: when bitcount is exactly 1 bit, no shift should happen this it should
be shift 0, thus minus -1.

However for the mask the opposite needs to be happen:

not ($FFFFFFFFetc shl mBitCount);

if the bitcount is 1 then the mask needs to shift up 1 place to make room
for a zero, which will then be converted to a 1.

That's kinda funny... little inconsistency here...

I wonder if the mask calculation can be slightly altered to make it more
consistent with the content...

Perhaps ($FFFFFFFF-1) might do the trick...

Then it could be written as:

not (($FFFFFFFF-1) shl (mBitCount-1))

This could be handy to "recycle" mBitCount-1 calculation by storing it in a
variable or so...

Hmmm...

Tricky stuff as usual ;) :)

Bye,
Skybck =D


From: Skybuck Flying on
Oh my god !

I think Delphi just showed me the light/the solution/the way !!! =D

Another method WOOOOOWWW this just doesn't stop ever/never! OH YEAH gooooddd
stuff ! ;) =D

Method 9:

Mask := not (-1 shl BitCount);

^^^ Awesomeness ^^^ ! =D

Now I go test it ! ;) =D

Bye,
Skybuck =D


From: Skybuck Flying on

"Skybuck Flying" <IntoTheFuture(a)hotmail.com> wrote in message
news:71434$4bfe2737$54190f09$18448(a)cache4.tilbu1.nb.home.nl...
> Oh my god !
>
> I think Delphi just showed me the light/the solution/the way !!! =D
>
> Another method WOOOOOWWW this just doesn't stop ever/never! OH YEAH
> gooooddd stuff ! ;) =D
>
> Method 9:
>
> Mask := not (-1 shl BitCount);
>
> ^^^ Awesomeness ^^^ ! =D
>
> Now I go test it ! ;) =D

Hmm very nice... seems to work just nicely for 16 bits... also signed
integers tested, seems to work as well...

For unsigned version not even typecasts needed it seems...

The int64 version will probably work as well...

Pretty nice.

Bye,
Skybuck.