[fpc-devel] Bitset assembler

Jonas Maebe jonas.maebe at elis.ugent.be
Sat Sep 10 17:17:20 CEST 2016


On 10/09/16 12:55, Jy V wrote:
> I am not sure the FreePascal compiler is able to convert the code of the
> procedure BitsetSet(var Bits; Index: UInt32);
>   PUInt64Array(@Bits)^[Index shr 6] := PUInt64Array(@Bits)^[Index shr 6]
> or (Int64(1) shl (Index and 63));
>
> into a single instruction:
>
>  bts [eax], edx

It could easily do it with

type
   tbitarray = bitpacked array[0..high(qword)-1] of boolean;
   pbitarray = ^tbitarray;

var
   ba: pbitarray;
   index: qword;
begin
   ...
   ba^[index]:=1;
end.

but only *if* someone would first override 
thlcgobj.a_load_regconst_subsetref_intern() for x86 in the compiler 
source code and implement the special cases for setting a single bit to 
0 or 1 (which is not the case, currently). The bts instruction is 
already used for include(setvar,value), but sets are obviously limited 
to 256 elements.


Jonas



More information about the fpc-devel mailing list