Optimizations
Posted: Tue Nov 13, 2007 7:57 pm
A more optimized code!
Yes, more than C please.Armoured wrote:A more optimized code!
lol!Psychophanta wrote:Yes, more than C please.
Excellent idea! However, I think it's already patented and in use by Microsoft, see here: http://www.purebasic.fr/english/viewtopic.php?t=29526Foz wrote:Just add a redundant syntax that you can add just before a procedure: OptimiseProcedureBetterThanCorC++
Or even better a little checkbox in the compiler options that says the same thing...
It doesn't have to do anything at all
Code: Select all
Structure SFrameMap
StructureUnion
Alloc.b[1048576/8]
BitsL.l[0]
EndStructureUnion
EndStructure
Global Frames.SFrameMap
Procedure UnlockFrame(Frame)
Index = Frame / 32
Offset = Frame % 32
Frames\BitsL[Index] &~ (1 << Offset)
EndProcedure
Code: Select all
_Procedure0:
PUSH ebp
PUSH ebx
PUSH edi
PS0=24
XOR eax,eax
PUSH eax
PUSH eax
; Index = Frame / 32
MOV ebx,dword [esp+PS0+0]
MOV eax,ebx
MOV ebx,32
CDQ
IDIV ebx
MOV ebx, eax
MOV dword [esp],ebx
; Offset = Frame % 32
MOV ebx,dword [esp+PS0+0]
AND ebx,31
MOV dword [esp+4],ebx
; Frames\BitsL[Index] &~ (1 << Offset)
LEA ebp,[v_Frames]
PUSH ebp
MOV eax,dword [esp+4]
SAL eax,2
POP ebp
ADD ebp,eax
MOV ebx,dword [ebp]
MOV edi,dword [esp+4]
MOV ecx,edi
MOV eax,1
SAL eax,cl
MOV edi,eax
NOT edi
AND ebx,edi
PUSH ebx
LEA ebp,[v_Frames]
PUSH ebp
MOV eax,dword [esp+8]
SAL eax,2
POP ebp
ADD ebp,eax
POP eax
MOV dword [ebp],eax
; EndProcedure
XOR eax,eax
_EndProcedure1:
ADD esp,8
POP edi
POP ebx
POP ebp
RET 4
Code: Select all
_Procedure0:
MOV eax, [esp+4]
MOV ecx, eax
SHR eax, 5
AND ecx, 31
MOV edx, 1
SHL edx, cl
NOT edx
AND [eax*4+frames], edx
RET 4
Code: Select all
_UnlockFrame@4:
push ebp
mov eax, -2
mov ebp, esp
mov ecx, DWORD PTR [ebp+8]
pop ebp
mov edx, ecx
and ecx, 31
shr edx, 5
rol eax, cl
and DWORD PTR _Frames[0+edx*4], eax
ret 4
Code: Select all
_UnlockFrame@4:
push ebp
mov ebp, esp
mov ecx, DWORD PTR [ebp+8]
test ecx, ecx
mov eax, ecx
js L5
pop ebp
mov edx, eax
sar edx, 5
mov eax, edx
sal eax, 5
sub ecx, eax
mov eax, -2
rol eax, cl
and DWORD PTR _Frames[0+edx*4], eax
ret 4
.p2align 4,,7
L5:
pop ebp
lea eax, [ecx+31]
mov edx, eax
sar edx, 5
mov eax, edx
sal eax, 5
sub ecx, eax
mov eax, -2
rol eax, cl
and DWORD PTR _Frames[0+edx*4], eax
ret 4
+1Armoured wrote:A more optimized code!
of course, nobody expects Fantaisie to compete with these large outfits. There's a way out though: don't use assembly as an intermediate language but have PB create C, so you can leverage the "years that large teams spend on their code optimisation".freak wrote: You do realize that companies developing industrial grade C compilers spend years with large teams on their code optimisation ?
I wonder how you expect us to compete with that...
Compiling a small project in GLBasic took a whopping 21 seconds.A few of those that elected to go this route: Eiffel, SmartEiffel, GLBasic, BCX, ....
Wait until you get something over 10,000 lines.Trond wrote:Compiling a small project in GLBasic took a whopping 21 seconds.
of course there are disadvantages as well.... but if you're a small outfit and want good code optimisation nonetheless it might be an approach to take.Trond wrote:Compiling a small project in GLBasic took a whopping 21 seconds.