Re: improvement of index-calculation
- From: "Guenther Wimpassinger" <gw_spam@xxxxxxxxx>
- Date: Wed, 27 Jul 2005 17:02:20 +0200
"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;
.
- Follow-Ups:
- Re: improvement of index-calculation
- From: Guenther Wimpassinger
- Re: improvement of index-calculation
- From: Guenther Wimpassinger
- Re: improvement of index-calculation
- References:
- improvement of index-calculation
- From: Guenther Wimpassinger
- improvement of index-calculation
- Prev by Date: Re: Fastcode SSE3 Support Implementation
- Next by Date: Re: improvement of index-calculation
- Previous by thread: Re: improvement of index-calculation
- Next by thread: Re: improvement of index-calculation
- Index(es):