Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Borland Delphi > Skybuck present...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 12 Topic 3728 of 3852
Post > Topic >>

Skybuck presents FastGetBit ( Value, BitPosition ) (latency 3)

by "Skybuck Flying" <BloodyShame@[EMAIL PROTECTED] > May 4, 2008 at 06:56 PM

Hello,

Here is my fast (latency 3) get bit routine:

Enjoy ! ;) =D

// *** Begin of Code ***

program Project1;

{$APPTYPE CONSOLE}

{

Skybuck presents FastGetBit

version 0.01 created on 4 may 2008 by Skybuck Flying.

This routine has just 3 latency on AMD X2 3800+.

Ofcourse it also has some call and ret latency as usual.

It is limited to bit positions 0 to 31.

Could still be a nice and interesting function or just asm code 
demonstration
when having to deal with these kinds of limited situations ! ;) =D

I wish Delphi sup****ted something like this in high level language !

Would be nice ! =D and fast too ! ;) :)

Currentl Delphi compiler is limited to "test" and "set byte" instruction
for 
set of bit enum.
which kinda sux anyway... special/fast bit operator/indexing would be
nice.

}

uses
 SysUtils;

// returns true (1) if bit position set, or false(0) if bit position not 
set.
// 3 latency plus ofcourse call + ret latency ;)
// bit position range: 0 to 31
function FastGetBit( Value : longword; BitPosition : longword ) : boolean;
asm
 bt eax, edx  // latency: 1
 mov eax, 0      // latency: 1
 adc eax, 0      // latency: 1
end;

// when you just wanna get 0 and 1 and not a boolean.
function FastGetBitInt( Value : longword; BitPosition : longword ) : 
longword;
asm
 bt eax, edx  // latency: 1
 mov eax, 0      // latency: 1
 adc eax, 0      // latency: 1
end;

procedure Main;
var
 B : boolean;
 L : longword;
begin

 B := false;
 writeln( longword( B ) ); // 0

 B := true;
 writeln( longword( B ) ); // 1

 L := 2147483648;

 if FastGetBit( L, 31 ) then
 begin
  writeln( 'Bit Position is set');
 end;
end;

begin
 try
  Main;
 except
  on E:Exception do
   Writeln(E.Classname, ': ', E.Message);
 end;
 readln;
end.

// *** End of Code ***

Bye,
  Skybuck.
 




 12 Posts in Topic:
Skybuck presents FastGetBit ( Value, BitPosition ) (latency 3)
"Skybuck Flying"  2008-05-04 18:56:13 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
Wojciech =?ISO-8859-2?Q?M  2008-05-04 19:09:13 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
"Skybuck Flying"  2008-05-04 19:23:47 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
Rob Kennedy <me3@[EMAI  2008-05-04 16:16:54 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
"Skybuck Flying"  2008-05-05 00:31:41 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
"Skybuck Flying"  2008-05-05 00:56:14 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
Robert Redelmeier <red  2008-05-04 18:42:53 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
"Skybuck Flying"  2008-05-04 22:30:28 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
"Wolfgang Kern"  2008-05-05 11:00:20 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
Wojciech =?ISO-8859-2?Q?M  2008-05-04 21:08:09 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
"Skybuck Flying"  2008-05-04 22:09:12 
Re: Skybuck presents FastGetBit ( Value, BitPosition ) (latency
"Skybuck Flying"  2008-05-04 22:32:55 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 0:14:28 CDT 2008.