Hello,
I need two fast procedures which can turn a bit on and off as fast as
possible with the following prototypes:
procedure TurnBitOn( BaseAddress : pointer; BitIndex : byte );
begin
end;
procedure TurnBitOff( BaseAddress : pointer; BitIndex : byte );
begin
end;
BaseAddress points to a memory block.
BitIndex ranges from 0 to 255, being the bit offset from the base address.
What is the fastest code in Delphi (win32) ?
What is the fastest code in Assembler (win32) ?
All entries will be benchmarked and results posted.
Code should work on 286, 386, 486, pentium, pentium pro, pentium iii, amd x2
3800, etc.
Specific code for specific cpu's is also interesting. Especially if cpu
detection code is provided.
For specific code please specify for which cpu's it works.
I look forward to your entries in this modest contest. I shall later also
provide my own slow implementation but for now I do not want to influence
the entries.
Bye,
Skybuck.
|
|
0
|
|
|
|
Reply
|
Skybuck
|
1/4/2007 3:14:50 PM |
|
"Skybuck Flying" <spamtrap@crayne.org> wrote:
>
>I need two fast procedures which can turn a bit on and off as fast as
>possible with the following prototypes:
>
>procedure TurnBitOn( BaseAddress : pointer; BitIndex : byte );
>begin
>
>end;
>
>procedure TurnBitOff( BaseAddress : pointer; BitIndex : byte );
>begin
>
>end;
The right way to do this in Delphi is to define BaseAddress as a "set of
byte". Then, TurnBitOn becomes
BaseAddress := BaseAddress + BitIndex;
and TurnBitOff becomes
BaseAddress := BaseAddress - BitIndex;
IsBitSet becomes
IsBitSet := BitIndex in BaseAddress;
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
|
|
0
|
|
|
|
Reply
|
Tim
|
1/5/2007 5:35:11 AM
|
|
"Tim Roberts" <spamtrap@crayne.org> wrote in message
news:ngorp2ldm999c22m4gj528b7ibolh12bqj@4ax.com...
> "Skybuck Flying" <spamtrap@crayne.org> wrote:
>>
>>I need two fast procedures which can turn a bit on and off as fast as
>>possible with the following prototypes:
>>
>>procedure TurnBitOn( BaseAddress : pointer; BitIndex : byte );
>>begin
>>
>>end;
>>
>>procedure TurnBitOff( BaseAddress : pointer; BitIndex : byte );
>>begin
>>
>>end;
>
> The right way to do this in Delphi is to define BaseAddress as a "set of
> byte". Then, TurnBitOn becomes
> BaseAddress := BaseAddress + BitIndex;
> and TurnBitOff becomes
> BaseAddress := BaseAddress - BitIndex;
>
> IsBitSet becomes
> IsBitSet := BitIndex in BaseAddress;
> --
> Tim Roberts, timr@probo.com
> Providenza & Boekelheide, Inc.
>
Ahhhhh such a pleasure =D
The first contester (besides myself ;)) has entered the contest =D
I have turned your idea and code into an implementation, if you are afraid I
did not implement it optimal you must add your implementation otherwise my
implementation of your concept code/idea will have to suffice ;) :) I have
done my best to make it as short as possible though ;) :)
Bye,
Skybuck.
|
|
0
|
|
|
|
Reply
|
Skybuck
|
1/5/2007 7:43:37 AM
|
|
"Skybuck Flying" <spamtrap@crayne.org> wrote:
>
>I have turned your idea and code into an implementation, if you are afraid I
>did not implement it optimal you must add your implementation otherwise my
>implementation of your concept code/idea will have to suffice ;) :) I have
>done my best to make it as short as possible though ;) :)
I used to be a studly Delphi guru, but since I got turned on to Python, I
don't even have Delphi installed any more.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
|
|
0
|
|
|
|
Reply
|
Tim
|
1/7/2007 5:37:47 AM
|
|
"Skybuck Flying" <spamtrap@crayne.org> wrote in message
news:enj5kv$6ll$1@news6.zwoll1.ov.home.nl...
> Hello,
>
> I need two fast procedures which can turn a bit on and off as fast as
> possible with the following prototypes:
>
> procedure TurnBitOn( BaseAddress : pointer; BitIndex : byte );
> begin
>
> end;
>
> procedure TurnBitOff( BaseAddress : pointer; BitIndex : byte );
> begin
>
> end;
>
> BaseAddress points to a memory block.
>
> BitIndex ranges from 0 to 255, being the bit offset from the base address.
>
> What is the fastest code in Delphi (win32) ?
The obvious way to do it with Delphi is to use a set:
type
PByteSet = ^TByteSet;
TByteSet = set of [0..255];
procedure TurnBitOn(BaseAddress: Pointer; BitIndex: Byte);
var
P: PByteSet absolute BaseAddress;
begin
Include(P^, BitIndex);
end;
procedure TurnBitOff(BaseAddress: Pointer; BitIndex: Byte);
var
P: PByteSet absolute BaseAddress;
begin
Exclude(P^, BitIndex);
end;
function GetBitState(BaseAddress: Pointer; BitIndex: Byte): Boolean;
var
P: PByteSet absolute BaseAddress;
begin
GetBitState := BitIndex in P^;
end;
Untested.
--
Jay
Jason Burgon - author of Graphic Vision
http://homepage.ntlworld.com/gvision
|
|
0
|
|
|
|
Reply
|
Jason
|
7/7/2007 12:36:57 AM
|
|
"Tim Roberts" wrote:
: I used to be a studly Delphi guru, but since I got turned on to Python,
: I don't even have Delphi installed any more.
I've avoided Python for awhile. You're using it in a Windows OS?
Don't know anything about it, except for the fact that I ran across
an application or two in the last year that requires it to compile the
apps.
--
Jim Carlock
|
|
0
|
|
|
|
Reply
|
Jim
|
7/7/2007 2:20:27 AM
|
|
The fastest way is to execute in-line code, not call a function.
First:
Break address into word or byte number and bit number remainder (could
be already available as register usage, else a long shift).
Second:
Use bit number to index a table of n words/bytes (in form 00010000
etc) where n is the word/byte width of memory you are working with,
(looks like 16 bits since OP mentions 256), and pick up the word (or
byte) from the table.
Third:
Use operation XOR to flip, OR to set, AND inverse to turn off
(alternative but table or one more operation).
"Operation" this word/byte to memory indexed by the shift result of
operation 1).
|
|
0
|
|
|
|
Reply
|
Terence
|
7/7/2007 11:36:35 PM
|
|
"Jim Carlock" <spamtrap@crayne.org> wrote:
>
>"Tim Roberts" wrote:
>: I used to be a studly Delphi guru, but since I got turned on to Python,
>: I don't even have Delphi installed any more.
>
>I've avoided Python for awhile. You're using it in a Windows OS?
I use it on both Windows and Linux. It is clearly my language of choice
for web applications, and I reach for it on Windows any time I need the
kind of shell tools that one used to do in sh and awk (or perl).
I write drivers for a living, and those drivers often need test harnesses
and demo applications. I do those almost exclusively in Python, partly
because it's a quick prototype language, and partly because I can actually
read what I've written.
>Don't know anything about it, except for the fact that I ran across
>an application or two in the last year that requires it to compile the
>apps.
Yes. The RealPlayer components (now called Helix) use a rather complicated
Python-based build system.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
|
|
0
|
|
|
|
Reply
|
Tim
|
7/8/2007 1:36:02 AM
|
|
Thank you for your entry :)
1. Your entry has been verified OK and thus is entered into the contest.
2. The fastest entry is 70% faster than your method.
Your method uses:
2 moves.
1 BTS.
3 pops.
Also a little typo/bug has been corrected for you:
"Jason Burgon" <spamtrap@crayne.org> wrote in message
news:JeBji.3345$XR.3105@newsfe4-win.ntli.net...
> "Skybuck Flying" <spamtrap@crayne.org> wrote in message
> news:enj5kv$6ll$1@news6.zwoll1.ov.home.nl...
>> Hello,
>>
>> I need two fast procedures which can turn a bit on and off as fast as
>> possible with the following prototypes:
>>
>> procedure TurnBitOn( BaseAddress : pointer; BitIndex : byte );
>> begin
>>
>> end;
>>
>> procedure TurnBitOff( BaseAddress : pointer; BitIndex : byte );
>> begin
>>
>> end;
>>
>> BaseAddress points to a memory block.
>>
>> BitIndex ranges from 0 to 255, being the bit offset from the base
>> address.
>>
>> What is the fastest code in Delphi (win32) ?
>
> The obvious way to do it with Delphi is to use a set:
>
> type
> PByteSet = ^TByteSet;
> TByteSet = set of [0..255];
^^^ typo/bug ^^^
Should be:
TByteSet = set of 0..255;
>
> procedure TurnBitOn(BaseAddress: Pointer; BitIndex: Byte);
> var
> P: PByteSet absolute BaseAddress;
> begin
> Include(P^, BitIndex);
> end;
^^^ only this method tested ^^^
> procedure TurnBitOff(BaseAddress: Pointer; BitIndex: Byte);
> var
> P: PByteSet absolute BaseAddress;
> begin
> Exclude(P^, BitIndex);
> end;
>
> function GetBitState(BaseAddress: Pointer; BitIndex: Byte): Boolean;
> var
> P: PByteSet absolute BaseAddress;
> begin
> GetBitState := BitIndex in P^;
> end;
Bye,
Skybuck.
|
|
0
|
|
|
|
Reply
|
Skybuck
|
7/8/2007 4:47:15 AM
|
|
Skybuck Flying wrote:
> "Jason Burgon" <spamtrap@crayne.org> wrote in message
> news:JeBji.3345$XR.3105@newsfe4-win.ntli.net...
>> type
>> PByteSet = ^TByteSet;
>> TByteSet = set of [0..255];
>
> ^^^ typo/bug ^^^
>
> Should be:
>
> TByteSet = set of 0..255;
Even better, TByteSet = set of byte;
Cheers,
Nicholas Sherlock
|
|
0
|
|
|
|
Reply
|
Nicholas
|
7/8/2007 9:23:28 AM
|
|
"Nicholas Sherlock" <spamtrap@crayne.org> wrote in message
news:f6qaa9$1tl$1@lust.ihug.co.nz...
> Skybuck Flying wrote:
> > "Jason Burgon" <spamtrap@crayne.org> wrote in message
> > news:JeBji.3345$XR.3105@newsfe4-win.ntli.net...
> >> type
> >> PByteSet = ^TByteSet;
> >> TByteSet = set of [0..255];
> >
> > ^^^ typo/bug ^^^
> >
> > Should be:
> >
> > TByteSet = set of 0..255;
Yep, I'm always doing that, but then again I have only being programming in
Pascal for about 15 years. ;-)
> Even better, TByteSet = set of byte;
Yes. That's the best definition.
Jay
--
Jason Burgon - author of Graphic Vision
http://homepage.ntlworld.com/gvision
|
|
0
|
|
|
|
Reply
|
Jason
|
7/9/2007 12:15:39 AM
|
|
I see everybody ignored by 3(4?) asm instruction method.
Since we supply market research software since 1972, we use the method
described for:-
1) setting a logical bit reply in a logical array of bits, to 0 or 1
(no,yes)
2) noting a presence to be counted once only (OR=setting bit in
presence array to 1)
3) testing for a logical condition (TEST bit)
4) covering conditional cases only once en a selected set (.NOT. bit)
5) Bit flipping (XOR).
6) testing for multiple conditions progressively (AND bits or words).
And since we can access bits in parallel as words, we can do most
required opeerations in parallel too, which why we devised (not
invented) the method when we started.
Note: I have several patents in image processing and machine vision;
the development of techniques used hand-coded programs before making
hardwired (fast) cpus for the jobs.
|
|
0
|
|
|
|
Reply
|
Terence
|
7/13/2007 12:01:37 AM
|
|
|
11 Replies
133 Views
(page loaded in 0.101 seconds)
Similiar Articles: Fastest way to draw lots of triangles -- redux (FYI) - comp ...... and off - comp.emacs Fastest way to draw lots of triangles -- redux (FYI) - comp ... Turning line number on and off - comp.emacs Fastest way to turn on/off a bit in memory ... Fast way to display number in exponential form? - comp.sys.hp48 ...Fast way to display number in exponential form? - comp.sys.hp48 ... Fastest way to turn on/off a bit in memory ? - comp.lang.asm.x86 ... Second: Use bit number to index a ... Turning line number on and off - comp.emacsTurning line number on and off - comp.emacs Fastest way to turn on/off a bit in memory ? - comp.lang.asm.x86 ... The fastest way is to execute in-line code, not call a ... Macro to turn on and off add ins - comp.cad.solidworks[bochs][nasm][video memory] - comp.lang.asm.x86 Macro to turn on and off add ins - comp.cad.solidworks [bochs ... To add a bit of detail: it has to do with the 'overhang ... Fastest way of partitioning an array based on a cutoff value ...... comp.dsp data points to an array that is shuffled in place, 8 ... you'd still need to access 32-bit or 64-bit value as ... Fastest way to turn on/off a bit in memory ... [bochs][nasm][video memory] - comp.lang.asm.x86Then make it run fast. > When I have changed this: > point word [wall ... mov ax,09000h mov ... instruction: 00081401: ( ): add ... Fastest way to turn on/off a bit in memory ... displaying number as an exponential? - comp.sys.hp48Fast way to display number in exponential form? - comp.sys.hp48 ... Fastest way to turn on/off a bit in memory ? - comp.lang.asm.x86 ... Second: Use bit number to index a ... Bit-Shifting in ASM - comp.lang.asm.x86The use it's pretty simple: SHL AX, CL ; CL contains the number of bit to shift, AX the word to shift ROL AX, CL ; same as SHL Note that with the SHL/SHR the bit that ... Quickest way to bulk copy many files from one disk cluster to ...... is that rsync can take a lot of time and memory with ... be a fairly : slow network, but that's just an off ... in ... address into word or byte number and bit ... Quickest way to ... Fast bit-reverse on an x86? - comp.dspNo memory accesses involved so perhaps not slower ... It's for a bunch of data that's recorded off of a 1-bit ADC ... in delphi ? - comp.lang.asm.x86... be the fastest way in ... Reading rendered image into memory - comp.graphics.api.opengl ...... the hardware accelerated rendered frames into main memory in efficient way on all hardware. I have done quite a bit ... finally did that worked just fine (wasn't blazing fast ... User Port expansion - comp.sys.cbmAnother way to get 16 bits of I/O is to use Port B ... Generating /Rd /Wr off of an active-low demux connected ... Isn't the cartridge port the fastest 8-bit IDE port? restore from one solaris 10 x86 to another server (identical ...I'm a bit worried about the boot sector stuff ... Quickest way to bulk copy many files from one disk cluster to ... running process in ..... of having to allocate memory ... jpeg decoding speeds: x86, ARM, dsp, fpga, GPU - comp.compression ...... 1000 5mpix images, what would be the fastest way ... card, you could improve the speed a bit, but the bottleneck is really the memory ... data with the PC, you're better off with ... input & output in assembly - comp.lang.asm.x86in 16-bit assembly is there any way to accept numbers as input and ... Or all new pilots start off with a biplane ... could access a whole whopping 1meg of memory this way. [Solved] Turn Virtual Memory off with 8gb ram? - Memory ...Is it ever recommended to turn virtual memory off (for faster system ... • With 8gb ddr2 ram, running Vista64 with a fast 4gb ... This was an old trick way back in the Win 95/98 ... Fast Guide to RAM - Reference from WhatIs.comWhen you turn the computer off, RAM loses its data. When you turn ... facts stored in long-term memory. A computer also works this way. ... However, because it is fast memory ... 7/25/2012 4:23:08 PM
|