Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Mask a Variable with another one

I've tried to make Delphi a little faster for a routine which is often called (very often):

Delphi Code:
procedure TMyClass.SetMarkerBit(
const aBit: Cardinal;
const aSwitch: Boolean;
var aMarker: LongWord );
begin
if aSwitch then
aMarker := aMarker or aBit
else
aMarker := aMarker and not aBit;
end;
----
Delphi (D7) codes that 'likely' performant, if one specifies register as a compiler hint. The compiler is a 'little' dumb and puts all the passed registers at first on the stack.
This little peace of code is called very often so I've made a more optimzed version of it:

asm
mov eax, &aMarker // Load the address of aMarker into EAX
cmp aSwitch, $00
jz @NotSwitch
or [eax], edx
jmp @End
@NotSwitch:
not edx
and [eax], edx
@End:
end;

Has anyone a better solution? I'm not so familar with the mmx commands, may be there is a faster solution?

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : I've tried to make Delphi a little faster for a routine which is
    : often called (very often):
    :
    : Delphi Code:
    : procedure TMyClass.SetMarkerBit(
    : const aBit: Cardinal;
    : const aSwitch: Boolean;
    : var aMarker: LongWord );
    : begin
    : if aSwitch then
    : aMarker := aMarker or aBit
    : else
    : aMarker := aMarker and not aBit;
    : end;
    : ----
    : Delphi (D7) codes that 'likely' performant, if one specifies
    : register as a compiler hint. The compiler is a 'little' dumb and
    : puts all the passed registers at first on the stack.
    : This little peace of code is called very often so I've made a more
    : optimzed version of it:
    :
    : asm
    : mov eax, &aMarker // Load the address of aMarker into EAX
    : cmp aSwitch, $00
    : jz @NotSwitch
    : or [eax], edx
    : jmp @End
    : @NotSwitch:
    : not edx
    : and [eax], edx
    : @End:
    : end;
    :
    : Has anyone a better solution? I'm not so familar with the mmx
    : commands, may be there is a faster solution?
    :

    Could you post the original compiler code?
    That'll make it easier to check whether what you are doing is correct, because I have not had any Delphi experience.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.