Re: improvement of index-calculation




"Guenther Wimpassinger" <gw_spam@xxxxxxxxx> schrieb

> Hi!
>
> I want to improve the speed of the following function
>
> function TMathCloudParticles.GetVoxelFromXYZ(const x, y, z: integer): boolean;
> begin
> // result := GetArrayBit(pCldFront, GetVoxelIndex(x, y, z));
>
> result := (pCldFront[
> x or
> (z shl iCloudDimXZ) or
> ((y and not iBitMaskY) shl ((iCloudDimXZ shl 1)-5))] and
> (1 shl (y and iBitMaskY))) <>0;
> end;
>
> pCldFront : PDwordArray;
> iCloudDimXZ,iBitMaskY : Integer (private fields of the class).
>
> It is possible to pre-calculate ((iCloudDimXZ shl 1)-5) in the
> constructor of the class to another private field.

Here is my first asm-routine:
//-----------------------------
//GetVoxelFormXYZ
// in EAX : Self
// in EDX : x
// in ECX : y
// Stack : z
// out EAX : result (1=true/0=false)
function TMathCloudParticles.GetVoxelFromXYZ(
const x, y, z: integer): boolean;
asm
push ESI // store ESI on stack
push EBX // store EBX on stack

mov ESI,EAX // ESI := Self

mov EAX,[ESI+iBitMaskY] // EAX := iBitMaskY
mov EBX,ECX // EBX := y
and EBX,EAX // EBX := y and iBitMaskY
not EAX
and EAX,ECX // EAX := y and not iBitMaskY
mov ECX,[ESI+iShiftMaskY_sub_X_sub_Y32Bit]
shl EAX,CL // EAX := "masked y" shl
// iShiftMaskY_sub_X_sub_Y32Bit

or EAX,EDX // EAX := "shifted and masked y" or x

mov EDX,[z] // EDX := z
mov ECX,[ESI+iCloudDimXZ] // ECX := iCloudDimXZ
shl EDX,CL // z shl iCloudDimXZ
or EDX,EAX // EDX := "shifted and masked y with x"
// or "shifted z"

mov EAX,[ESI+pCldFront]
mov EAX,[EAX+EDX*4]
bt EAX,EBX
lahf
xchg AL,AH
and EAX,$1

pop ESI
pop EBX
end;


.