According to this:
http://wiki.freepascal.org/FPC_New_Feat ... intrinsics
FreePascal should have intrinsics:
BsfQWord() and BsrQWord()
However, I can't seem to get the compiler to recognize them.
Do any FreePascal experts frequent this forum and can you tell me how to get them to work? I want to make a 64 bit version of Booot.
If need be, I can use these primitives to build my own versions:
not Bitwise negation (unary)
and Bitwise and
or Bitwise or
xor Bitwise xor
shl Bitwise shift to the left
shr Bitwise shift to the right
but I would much rather use the intrinsics if possible.
FreePascal 64 bit question
Moderators: hgm, Rebel, chrisw
-
- Posts: 12542
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
-
- Posts: 2949
- Joined: Mon May 05, 2008 12:16 pm
- Location: Bordeaux (France)
- Full name: Julien Marcel
Re: FreePascal 64 bit question
Dann, this is a quick search answer, as I'm off to bed now, but here is a sample program that use these functions I found. Hopefully it will help :
Code: Select all
program testbitscan;
function test_byte: boolean;
var
x8,f,r: byte;
i: integer;
begin
for i:=0 to 7 do
begin
x8:=1 shl i;
f:=BsfByte(x8);
if (f<>i) then
begin
writeln('BsfByte(',x8,') returned ',f,', should be ',i);
exit(false);
end;
r:=BsrByte(x8);
if r<>i then
begin
writeln('BsrByte(',x8,') returned ',f,', should be ',i);
exit(false);
end;
end;
result:=true;
end;
function test_word: boolean;
var
x16: word;
i,f,r: integer;
begin
for i:=0 to 15 do
begin
x16:=1 shl i;
f:=BsfWord(x16);
if (f<>i) then
begin
writeln('BsfWord(',x16,') returned ',f,', should be ',i);
exit(false);
end;
r:=BsrWord(x16);
if r<>i then
begin
writeln('BsrWord(',x16,') returned ',f,', should be ',i);
exit(false);
end;
end;
result:=true;
end;
function test_dword: boolean;
var
x32: cardinal;
i,f,r: integer;
begin
for i:=0 to 31 do
begin
x32:=1 shl i;
f:=BsfDWord(x32);
if (f<>i) then
begin
writeln('BsfDWord(',x32,') returned ',f,', should be ',i);
exit(false);
end;
r:=BsrDWord(x32);
if r<>i then
begin
writeln('BsrDWord(',x32,') returned ',f,', should be ',i);
exit(false);
end;
end;
result:=true;
end;
function test_qword: boolean;
var
x64: qword;
i, f, r: integer;
begin
for i:=0 to 63 do
begin
x64:=uint64(1) shl i;
f:=BsfQWord(x64);
if f<>i then begin
writeln('BsfQWord(',x64,') returned ',f,', should be ',i);
exit(false);
end;
r:=BsrQWord(x64);
if r<>i then begin
writeln('BsrQWord(',x64,') returned ',r,', should be ',i);
exit(false);
end;
end;
result:=true;
end;
begin
if test_byte then writeln('passed') else writeln('failed');
if test_word then writeln('passed') else writeln('failed');
if test_dword then writeln('passed') else writeln('failed');
if test_qword then writeln('passed') else writeln('failed');
end.
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
-
- Posts: 2949
- Joined: Mon May 05, 2008 12:16 pm
- Location: Bordeaux (France)
- Full name: Julien Marcel
Re: FreePascal 64 bit question
Hmmm... ok, so the problem is : in which unit are those functions found, so you can add it to your "uses" clause? Well... I can't find it either
And the documentation about that is just non-existant at all. All I can say is that it's not in the LCL. Weird.
I guess you'll have to emulate them.
EDIT: Yahoo's cache has a reference to these functions in the free pascal. It might save you some time to copy/paste this code :
http://74.6.239.67/search/cache?ei=UTF- ... B3xcFhWA--
For instance :
But that's in asm, and you probably don't want that
And the documentation about that is just non-existant at all. All I can say is that it's not in the LCL. Weird.
I guess you'll have to emulate them.
EDIT: Yahoo's cache has a reference to these functions in the free pascal. It might save you some time to copy/paste this code :
http://74.6.239.67/search/cache?ei=UTF- ... B3xcFhWA--
For instance :
Code: Select all
function BsfQWord(Const AValue : QWord): cardinal; assembler; nostackframe;
asm
bsfl 4(%esp),%eax
jnz .L2
.L1: bsfl 8(%esp),%eax
add $32,%eax
.L2:
end;
function BsrQWord(Const AValue : QWord): cardinal; assembler; nostackframe;
asm
bsrl 8(%esp),%eax
jz .L1
add $32,%eax
jmp .L2
.L1: bsrl 4(%esp),%eax
.L2:
end;
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
-
- Posts: 481
- Joined: Thu Apr 16, 2009 12:00 pm
- Location: Slovakia, EU
Re: FreePascal 64 bit question
Hi,
You probably need a more recent version of freepascal, at least FPC 2.5.1 revision 16174 or newer. The patch implementing bitscan intrinsics was submitted 2010-10-09 and merged to trunk 2010-10-16. More details on freepascal bugtracker. (By the way, I am the author of this patch )
Richard
You probably need a more recent version of freepascal, at least FPC 2.5.1 revision 16174 or newer. The patch implementing bitscan intrinsics was submitted 2010-10-09 and merged to trunk 2010-10-16. More details on freepascal bugtracker. (By the way, I am the author of this patch )
Richard
-
- Posts: 2949
- Joined: Mon May 05, 2008 12:16 pm
- Location: Bordeaux (France)
- Full name: Julien Marcel
Re: FreePascal 64 bit question
@Richard
I say, this is a small world!
Btw, thanks for Critter, you are the answer to C/C++ programmers looking down at us Pascal lovers
I say, this is a small world!
Btw, thanks for Critter, you are the answer to C/C++ programmers looking down at us Pascal lovers
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
-
- Posts: 12542
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: FreePascal 64 bit question
Where can the most recent versions be downloaded?
-
- Posts: 2949
- Joined: Mon May 05, 2008 12:16 pm
- Location: Bordeaux (France)
- Full name: Julien Marcel
Re: FreePascal 64 bit question
There : http://www.hu.freepascal.org/lazarus/Dann Corbit wrote:Where can the most recent versions be downloaded?
(I always use the daily builds, that way I can blame the FPC/Lazarus team for Prédateur's bugs.)
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
-
- Posts: 12542
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: FreePascal 64 bit question
The latest one there for Windows 64 bit appears to be 2.4.3 and Richard said I would need FPC 2.5.1 revision 16174 or newer so I am not sure if it will workJuLieN wrote:There : http://www.hu.freepascal.org/lazarus/Dann Corbit wrote:Where can the most recent versions be downloaded?
(I always use the daily builds, that way I can blame the FPC/Lazarus team for Prédateur's bugs.)
-
- Posts: 2949
- Joined: Mon May 05, 2008 12:16 pm
- Location: Bordeaux (France)
- Full name: Julien Marcel
Re: FreePascal 64 bit question
Oh, sorry, my mistake. A quick search with people having the same concerns points to Code Typhoon, presumably always up to date to the latest betas of FPC and Lazarus :Dann Corbit wrote: The latest one there for Windows 64 bit appears to be 2.4.3 and Richard said I would need FPC 2.5.1 revision 16174 or newer so I am not sure if it will work
http://www.pilotlogic.com/sitejoom/inde ... Itemid=147
I didn't try it, as I always download Lazarus from the link I gave you, but as far as I can see it looks big and serious.
Please report how it goes if you try it, so maybe I'll switch to it.
EDIT: I found that FreePascal's official repository is more up to date than Lazaru's one. Weird. here's the link to the latests official win64 Lazarus 0.9.31 + FPC 2.5.1 installer :
http://ftp.freepascal.org/snapshots/Laz ... -win64.exe
Last edited by JuLieN on Fri Jan 21, 2011 9:12 pm, edited 1 time in total.
"The only good bug is a dead bug." (Don Dailey)
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
[Blog: http://tinyurl.com/predateur ] [Facebook: http://tinyurl.com/fbpredateur ] [MacEngines: http://tinyurl.com/macengines ]
-
- Posts: 1221
- Joined: Wed Mar 08, 2006 8:28 pm
- Location: Florida, USA
Re: FreePascal 64 bit question
Hi Richard,
I'm a big fan of Delphi. How does FreePascal compare in terms of speed to Delphi. Is FreePascal 64 significantly faster than Delphi 32 bit for bitboard type programs?
Thanks,
Steve
I'm a big fan of Delphi. How does FreePascal compare in terms of speed to Delphi. Is FreePascal 64 significantly faster than Delphi 32 bit for bitboard type programs?
Thanks,
Steve