[fpc-devel] Bitset assembler
Jy V
jyv110 at gmail.com
Sun Sep 11 09:43:58 CEST 2016
Thank you Jonas,
so back to my original question,
is there an asm expert out there who knows if the syntax is invalid, or
simply the compiler does not implement bt, bts, btr instructions
function BitsetGet(const Bits; Index: UInt32): Boolean; assembler;
asm
{$IFDEF WIN64} // Win64 IN: rcx = Bits, edx = Index OUT: rax = Result
bt (%rcx), %edx // -> Error asm: [bt reg32,mem32]
// bt (%rcx), %rdx // -> Error asm: [bt reg64,mem64]
sbb %eax, %eax
and %eax, $1
{$ELSE} // Linux IN: rdi = Bits, esi = Index OUT: rax = Result
bt (%rdi), %esi
sbb %rax, %rax
and %rax, $1
{$ENDIF}
end;
On Sat, Sep 10, 2016 at 5:17 PM, Jonas Maebe <jonas.maebe at elis.ugent.be>
wrote:
> 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
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160911/6829584e/attachment.html>
More information about the fpc-devel
mailing list