Unfortunately, for POPCNT assembler, SSE 4.2 is required. For older CPUs, after some tests, I'd finally recommend

function CShift(ANum : QWord) : Cardinal;
var
  n1, n2 : QWord;
begin
  n1 := ANum - (ANum shr 1 and $5555555555555555);
  n2 := (n1 and $3333333333333333) + (n1 shr 2 and $3333333333333333);
  Result :=
    (((n2 + (n2 shr 4)) and $0f0f0f0f0f0f0f0f) * $0101010101010101) shr 56;
end;

What do you do, when it comes to fast pop. counts on vintage CPUs?

The "official" alternative, provided with FPC 2.7.1, seems ca. 10 x slower. Did I grab the wrong version?

Is there a even better solution?

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to