Ok, i've got a solution but it's only if you intended the packing of the bytes into the long to work like the line below:
Code: Select all
var1.l = (a&$ff)<<16|(b&$ff)<<8|(c&$ff )
Because of how PB works your version of the line above produces some unwanted (wanted by you?) effects if the byte values are negative.. anyhow below is some asm that should work..(badly commented as usual):
Code: Select all
DisableDebugger
var1.l = 0
var2.l = 0
t1.l = GetTickCount_()
For i.l = 0 To $02ffffff
a.b=i>>16
b.b=i>>8
c.b=i
If a<b
 c+1
 If c>b:c=a:EndIf
Else
 c-1
 If c<b:c=a:EndIf
EndIf
var1.l = (a&$ff)<<16|(b&$ff)<<8|(c&$ff )
Next i
t2.l = GetTickCount_()
For i.l = 0 To $02ffffff
! MOV eax, dword [v_i]
! MOV cl, al
! SHR eax, 8
! MOV bl, al
! SHR eax, 8
; c = cl, b = bl, a = al
! CMP al, bl ; ?a = b
! SETL bh ; if a < b then 'bh = 1' else 'bh = 0'
! ADD cl, bh ; c+1
! DEC bh     ; |
! ADD cl, bh ; | c-1
! CMP cl, bl ; ?c=b
! SETL dh ; if c < b then 'dh = 1' elase 'dh = 0'
! SETG dl ; if c > b then 'dl = 1' else 'dl = 0'
! And dh, bh
! INC bh
! And dl, bh
! MOV bh, al
! Or dl, dh
! DEC dl
! And cl, dl
! NOT dl
! And bh, dl
! Or cl, bh
! SHL eax, 8
! MOV al, bl
! SHL eax, 8
! MOV al, cl
! MOV dword [v_var2], eax
Next i
t3.l = GetTickCount_()
EnableDebugger
Debug "finished!"
Debug "T1 = "+Str(t2-t1)+"ms, T2 = "+Str(t3-t2)+"ms"
There's probably some room for improvements to speed up the asm even more, but i'll leave that to someone else to do..