@dodicat
If we take the top 32-bit of your 64-bit output and call it x then the bottom 32-bit is 'Not x'. The two 32-bit sections may have differing Hamming weights. For example, we could have 15 set bits in the top 32-bit and 17 set bits in the bottom 32-bit; giving a total of 32 ie 50%.
I then looked at my HammingSeed, which returns a 32-bit, and with a value of x, say, I determine mkulongint( x, Not x ) where
Code: Select all
Function mkulongint(n1 As Ulong, n2 As Ulong) As Ulongint ' by MrSwiss
Dim As Ulongint res
Cast(Ulong Ptr,@res)[0]=n1
Cast(Ulong Ptr,@res)[1]=n2
Return res
End Function
Both 32-bit sections will have a Hamming weight of 50%.
The $64,000 question: Who is faster in 32-bit mode?
Looking at the code with all those Shr going on in popcount64 and reverseuLongint I figured my code would have the edge.
Here is the result of one run:
Code: Select all
max 93.58732495456934 Total time 20.55839813436614 seed = 9876365401811589630, bits(1) = 32
max 84.29843001067638 Total time 20.5543753465754 seed = 404132379232582590, bits(1) = 32
max 52.0317698828876 Total time 20.56150362687185 seed = 12798398361755645055, bits(1) = 32
max 72.42540596053004 Total time 20.54087418928975 seed = 17350642864970146365, bits(1) = 32
max 75.49842121079564 Total time 20.55441361962585 seed = 5653663512825308925, bits(1) = 32
max 222.9333622381091 Total time 23.55614498490468 seed = 12546855733743885615, bits(1) = 32
max 194.3683018907905 Total time 23.53725068410859 seed = 9419557490678760030, bits(1) = 32
max 181.5174473449588 Total time 23.53084463253617 seed = 9723528281949410955, bits(1) = 32
max 195.5556217581034 Total time 23.55422805133276 seed = 2404895000428026045, bits(1) = 32
max 198.8380681723356 Total time 23.5312987404759 seed = 7079608129532472810, bits(1) = 32
Done
I was wrong! The top results are
yours.
Your max values are better than half mine. Your popcnt replacement
is fast.
The two function innards could be inlined into the hammingseed64 for a little boost,
With an average of about 76 microseconds for your max values we don't need a boost and the code as is will do fine.
The next question is: Have you got a new computer because your 'Total time' figures are leaving mine standing?