Page 3 of 3

Posted: Sun Jun 14, 2009 2:52 pm
by cxAlex
My Results:

Test #1 (If a If b) = 128 ms
Test #2 (If a And b) = 147 ms
Test #3 (Asm /!\ with ESI reg) = 148 ms
XP SP3, Intel Core 2 Quad @ 3,2 Ghz, Avira Antivirus

Posted: Mon Jun 15, 2009 3:55 am
by Ollivier
@Demivec and @cxAlex

Thank you!

I think we have a problem with the mean to count the execution duration.

By the way, I don't need it to optimize it. Respecting the norm :
If true, eax = 1
If false, eax = 0
...the native algo has too many instructions.

Here is my conclusion code:

Code: Select all

DisableDebugger

   Define A.I = 0
   Define B.I = 0

Macro ExecutionIfTrue()
   ; Nothing
EndMacro

Macro ExecutionIfFalse()
   ; Nothing
EndMacro



Macro Test1()
   ! xor eax, eax
   ! cmp [v_A], 0
   ! je l_falsex
   ! cmp [v_B], 0
   ! je l_falsex
   ! or eax, 1
   ExecutionIfTrue()
   ! jmp l_endx
falsex:
   ExecutionIfFalse()
endx:
EndMacro
I am sure it's the quickest algo!

Posted: Mon Jun 15, 2009 5:47 am
by Ollivier

Code: Select all



DisableDebugger



Macro ExecutionIfTrue()
   ; Nothing
EndMacro

Macro ExecutionIfFalse()
   ; Nothing
EndMacro



Macro Test1()
   ! xor eax, eax
   ! cmp [v_A], 0
   ! je l_faux
   ! cmp [v_B], 0
   ! je l_faux
vrai:
   ! or eax, 1
   ExecutionIfTrue()
   ! jmp l_fin
faux:
   ExecutionIfFalse()
fin:
EndMacro


Macro Test2()
            If A And B
               ExecutionIfTrue()
            Else
               ExecutionIfFalse()
            EndIf
EndMacro




Macro Counter(InternalMacro)
      Cumul = 0
      For A = 0 To 1
         For B = 0 To 1
            !Rdtsc
            !Mov [v_ValeurIni], EAX
            InternalMacro
            !Rdtsc
            !Mov [v_ValeurFin], EAX
            Cumul + (ValeurFin - ValeurIni)
         Next
      Next
EndMacro




   Define Test1.I
   Define Test2.I
   Define Test3.I
   Define ValeurIni.I
   Define ValeurFin.I
   Define Cumul.I
   Define A.I = 0
   Define B.I = 0
   Define Sum.F
   Define Qty.F
   Define Mean.F

   InitSprite()
   InitKeyboard()
   OpenScreen(1024, 768, 32, "")
   For I = 0 To 300
      CreateSprite(I, 1, I + 1)
      CreateSprite(I + 300, 1, I + 1)
      StartDrawing(SpriteOutput(I) )
         Box(0, 0, 1, I, #Green)
      StopDrawing()
      StartDrawing(SpriteOutput(300 + I) )
         Box(0, 0, 1, I, #Red)
      StopDrawing()
   Next I
   CreateSprite(1001, 1024, 768)
   CreateSprite(1000, 1024, 1)
   StartDrawing(SpriteOutput(1000) )
      For XX = 0 To 1023 Step 32
         Line(XX, 0, 16, 0, #White)         
         Line(XX + 16, 0, 16, 0, #Black)         
      Next XX
   StopDrawing()
   CreateSprite(1002, 100, 768)
   StartDrawing(SpriteOutput(1002) )
      For I = 1 To 10
         YP = 384 - 30 * I
         Box(0, YP, 32, 1, #White)
         DrawText(30, YP - 8, "+" + Str(I * 10) + "%", #White, 1)
         YN = 384 + 30 * I
         Box(0, YN, 32, 1, #White)
         DrawText(30, YN - 8, "-" + Str(I * 10) + "%", #White, 1)
      Next I
      Box(0, 384, 32, 1, #White)
      DrawText(550, 384 - 8, "0%", #White, #Black)
   StopDrawing()
   Delay(250)
   Repeat
   Delay(16)
   DisplaySprite(1001, 0, 0)
   For x = 0 To 1023
      Test1 = 0
      Test2 = 0
      Test3 = 0
      Counter(Test1() ): Test1 - Cumul
      Counter(Test2() ): Test2 - Cumul
      Delta.F = (Test1 - Test2) * 300 / Test2
      Sum + Delta
      Qty + 1.0
      Mean = Sum / Qty
         If Delta > 0
            If Delta > 300: Delta = 300: EndIf
            DisplaySprite(Delta + 300, x, 384)
         Else
            If Delta < 0 - 300: Delta = 0 - 300: EndIf
            DisplaySprite(- Delta, x, 384 + Delta)
         EndIf
      ExamineKeyboard()
      If KeyboardReleased(#PB_Key_Space)
         Repeat
            Delay(16)
            ExamineKeyboard()
         Until KeyboardReleased(#PB_Key_Space) Or KeyboardPushed(#PB_Key_Escape)
      EndIf
      If KeyboardPushed(#PB_Key_Escape)
         Quit | 1
      EndIf
   Next
   DisplaySprite(1000, 0, 384 + Mean)
   DisplayTransparentSprite(1002, 512, 0)
   FlipBuffers()     
   Until Quit



Posted: Tue Jun 16, 2009 7:48 pm
by Ollivier
Is there a problem with the internal flags register in my conclusion?